mirror of
https://github.com/tendermint/tendermint.git
synced 2026-01-06 21:36:26 +00:00
rpc: remove duplication of data in ResultBlock (#3856)
## Issue:
Removed BlockMeta in ResultBlock in favor of BlockId for /block
Added block_size to BlockMeta this is reflected in /blockchain
fixes #3188
added breaking as some clients may be using header from blockmeta instead of block in /block
## Commits:
* cleanup block path
Remove duplication of data in `/block`
fixes #3188
Signed-off-by: Marko Baricevic <marbar3778@yahoo.com>
* Remove duplication of data in `/block`
- Created a secondary type to be used for /block
fixes #3188
Signed-off-by: Marko Baricevic <marbar3778@yahoo.com>
* remove commented out code
* fix ci
* add changelog_pending entry
* remove extra variable
* update swagger
* change int to uint for blocksize
* fix swagger
* remove extensive comments
* update changelog
* fix conflicts after merge
* use int for BlockSize and NumTxs in BlockMeta
- with 99.9% guarantee, the size of either will never reach int32
- most of the Go "Size" stdlib functions return int
This commit is contained in:
@@ -11,6 +11,7 @@ program](https://hackerone.com/tendermint).
|
||||
### BREAKING CHANGES:
|
||||
|
||||
- CLI/RPC/Config
|
||||
- [rpc] \#3188 Remove `BlockMeta` in `ResultBlock` in favor of `BlockId` for `/block`
|
||||
- [rpc] `/block_results` response format updated (see RPC docs for details)
|
||||
```
|
||||
{
|
||||
@@ -51,6 +52,7 @@ program](https://hackerone.com/tendermint).
|
||||
- [rpc] [\#4077](https://github.com/tendermint/tendermint/pull/4077) Added support for `EXISTS` clause to the Websocket query interface.
|
||||
- [privval] Add `SignerDialerEndpointRetryWaitInterval` option (@cosmostuba)
|
||||
- [crypto] Add `RegisterKeyType` to amino to allow external key types registration (@austinabell)
|
||||
- [rpc] \#3188 Added `block_size` to `BlockMeta` this is reflected in `/blockchain`
|
||||
- [types] \#2521 Add `NumTxs` to `BlockMeta` and `EventDataNewBlockHeader`
|
||||
|
||||
### BUG FIXES:
|
||||
|
||||
@@ -107,11 +107,6 @@ func (w Wrapper) Block(height *int64) (*ctypes.ResultBlock, error) {
|
||||
}
|
||||
sh := resCommit.SignedHeader
|
||||
|
||||
// now verify
|
||||
err = ValidateBlockMeta(resBlock.BlockMeta, sh)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = ValidateBlock(resBlock.Block, sh)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -225,9 +225,9 @@ func TestAppCalls(t *testing.T) {
|
||||
// and we can even check the block is added
|
||||
block, err := c.Block(&apph)
|
||||
require.Nil(err, "%d: %+v", i, err)
|
||||
appHash := block.BlockMeta.Header.AppHash
|
||||
appHash := block.Block.Header.AppHash
|
||||
assert.True(len(appHash) > 0)
|
||||
assert.EqualValues(apph, block.BlockMeta.Header.Height)
|
||||
assert.EqualValues(apph, block.Block.Header.Height)
|
||||
|
||||
// now check the results
|
||||
blockResults, err := c.BlockResults(&txh)
|
||||
@@ -245,9 +245,9 @@ func TestAppCalls(t *testing.T) {
|
||||
if assert.Equal(1, len(info.BlockMetas)) {
|
||||
lastMeta := info.BlockMetas[0]
|
||||
assert.EqualValues(apph, lastMeta.Header.Height)
|
||||
bMeta := block.BlockMeta
|
||||
assert.Equal(bMeta.Header.AppHash, lastMeta.Header.AppHash)
|
||||
assert.Equal(bMeta.BlockID, lastMeta.BlockID)
|
||||
blockData := block.Block
|
||||
assert.Equal(blockData.Header.AppHash, lastMeta.Header.AppHash)
|
||||
assert.Equal(block.BlockID, lastMeta.BlockID)
|
||||
}
|
||||
|
||||
// and get the corresponding commit with the same apphash
|
||||
|
||||
@@ -78,7 +78,7 @@ func Block(ctx *rpctypes.Context, heightPtr *int64) (*ctypes.ResultBlock, error)
|
||||
|
||||
blockMeta := blockStore.LoadBlockMeta(height)
|
||||
block := blockStore.LoadBlock(height)
|
||||
return &ctypes.ResultBlock{BlockMeta: blockMeta, Block: block}, nil
|
||||
return &ctypes.ResultBlock{BlockID: blockMeta.BlockID, Block: block}, nil
|
||||
}
|
||||
|
||||
// Commit gets block commit at a given height.
|
||||
|
||||
@@ -25,8 +25,8 @@ type ResultGenesis struct {
|
||||
|
||||
// Single block (with meta)
|
||||
type ResultBlock struct {
|
||||
BlockMeta *types.BlockMeta `json:"block_meta"`
|
||||
Block *types.Block `json:"block"`
|
||||
BlockID types.BlockID `json:"block_id"`
|
||||
Block *types.Block `json:"block"`
|
||||
}
|
||||
|
||||
// Commit and Header
|
||||
|
||||
@@ -1162,7 +1162,7 @@ definitions:
|
||||
x-example: "CB02DCAA7FB46BF874052EC2273FD0B1F2CF2E1593298D9781E60FE9C3DB8638"
|
||||
type: object
|
||||
type: object
|
||||
BlockMetaHeader:
|
||||
BlockHeader:
|
||||
required:
|
||||
- "version"
|
||||
- "chain_id"
|
||||
@@ -1230,7 +1230,7 @@ definitions:
|
||||
type: string
|
||||
x-example: "D540AB022088612AC74B287D076DBFBC4A377A2E"
|
||||
type: object
|
||||
BlockMetaId:
|
||||
BlockId:
|
||||
required:
|
||||
- "hash"
|
||||
- "parts"
|
||||
@@ -1254,10 +1254,13 @@ definitions:
|
||||
BlockMeta:
|
||||
type: object
|
||||
properties:
|
||||
block_size:
|
||||
type: number
|
||||
x-example: 1000000
|
||||
block_id:
|
||||
$ref: "#/definitions/BlockMetaId"
|
||||
$ref: "#/definitions/BlockId"
|
||||
header:
|
||||
$ref: "#/definitions/BlockMetaHeader"
|
||||
$ref: "#/definitions/BlockHeader"
|
||||
Blockchain:
|
||||
type: object
|
||||
required:
|
||||
@@ -1317,7 +1320,7 @@ definitions:
|
||||
type: object
|
||||
properties:
|
||||
header:
|
||||
$ref: "#/definitions/BlockMetaHeader"
|
||||
$ref: "#/definitions/BlockHeader"
|
||||
data:
|
||||
type: array
|
||||
items:
|
||||
@@ -1361,8 +1364,8 @@ definitions:
|
||||
BlockComplete:
|
||||
type: object
|
||||
properties:
|
||||
block_meta:
|
||||
$ref: "#/definitions/BlockMeta"
|
||||
block_id:
|
||||
$ref: "#/definitions/BlockID"
|
||||
block:
|
||||
$ref: "#/definitions/Block"
|
||||
BlockResponse:
|
||||
|
||||
@@ -35,12 +35,12 @@ func calculateStatistics(
|
||||
}
|
||||
|
||||
var (
|
||||
numBlocksPerSec = make(map[int64]int64)
|
||||
numTxsPerSec = make(map[int64]int64)
|
||||
numBlocksPerSec = make(map[int]int)
|
||||
numTxsPerSec = make(map[int]int)
|
||||
)
|
||||
|
||||
// because during some seconds blocks won't be created...
|
||||
for i := int64(0); i < int64(duration); i++ {
|
||||
for i := 0; i < duration; i++ {
|
||||
numBlocksPerSec[i] = 0
|
||||
numTxsPerSec[i] = 0
|
||||
}
|
||||
@@ -71,9 +71,9 @@ func calculateStatistics(
|
||||
logger.Debug(fmt.Sprintf("%d txs at block height %d", blockMeta.NumTxs, blockMeta.Header.Height))
|
||||
}
|
||||
|
||||
for i := int64(0); i < int64(duration); i++ {
|
||||
stats.BlocksThroughput.Update(numBlocksPerSec[i])
|
||||
stats.TxsThroughput.Update(numTxsPerSec[i])
|
||||
for i := 0; i < duration; i++ {
|
||||
stats.BlocksThroughput.Update(int64(numBlocksPerSec[i]))
|
||||
stats.TxsThroughput.Update(int64(numTxsPerSec[i]))
|
||||
}
|
||||
|
||||
return stats, nil
|
||||
@@ -107,8 +107,8 @@ func getBlockMetas(client tmrpc.Client, minHeight int64, timeStart, timeEnd time
|
||||
return blockMetas, nil
|
||||
}
|
||||
|
||||
func secondsSinceTimeStart(timeStart, timePassed time.Time) int64 {
|
||||
return int64(math.Round(timePassed.Sub(timeStart).Seconds()))
|
||||
func secondsSinceTimeStart(timeStart, timePassed time.Time) int {
|
||||
return int(math.Round(timePassed.Sub(timeStart).Seconds()))
|
||||
}
|
||||
|
||||
func printStatistics(stats *statistics, outputFormat string) {
|
||||
|
||||
@@ -2,17 +2,19 @@ package types
|
||||
|
||||
// BlockMeta contains meta information.
|
||||
type BlockMeta struct {
|
||||
BlockID BlockID `json:"block_id"`
|
||||
Header Header `json:"header"`
|
||||
NumTxs int64 `json:"number_txs"`
|
||||
BlockID BlockID `json:"block_id"`
|
||||
BlockSize int `json:"block_size"`
|
||||
Header Header `json:"header"`
|
||||
NumTxs int `json:"number_txs"`
|
||||
}
|
||||
|
||||
// NewBlockMeta returns a new block meta.
|
||||
// NewBlockMeta returns a new BlockMeta.
|
||||
func NewBlockMeta(block *Block, blockParts *PartSet) *BlockMeta {
|
||||
return &BlockMeta{
|
||||
BlockID: BlockID{block.Hash(), blockParts.Header()},
|
||||
Header: block.Header,
|
||||
NumTxs: int64(len(block.Data.Txs)),
|
||||
BlockID: BlockID{block.Hash(), blockParts.Header()},
|
||||
BlockSize: block.Size(),
|
||||
Header: block.Header,
|
||||
NumTxs: len(block.Data.Txs),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user