diff --git a/CHANGELOG_PENDING.md b/CHANGELOG_PENDING.md index 5e4f8585d..6ba9e716c 100644 --- a/CHANGELOG_PENDING.md +++ b/CHANGELOG_PENDING.md @@ -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: diff --git a/lite/proxy/wrapper.go b/lite/proxy/wrapper.go index 82fee97cd..2f608cfa9 100644 --- a/lite/proxy/wrapper.go +++ b/lite/proxy/wrapper.go @@ -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 diff --git a/rpc/client/rpc_test.go b/rpc/client/rpc_test.go index 8d16cbc69..50d3f8684 100644 --- a/rpc/client/rpc_test.go +++ b/rpc/client/rpc_test.go @@ -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 diff --git a/rpc/core/blocks.go b/rpc/core/blocks.go index 228defb4a..4e2331478 100644 --- a/rpc/core/blocks.go +++ b/rpc/core/blocks.go @@ -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. diff --git a/rpc/core/types/responses.go b/rpc/core/types/responses.go index dd6d8e363..72b60b92a 100644 --- a/rpc/core/types/responses.go +++ b/rpc/core/types/responses.go @@ -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 diff --git a/rpc/swagger/swagger.yaml b/rpc/swagger/swagger.yaml index 4daddfc65..7f738f1e2 100644 --- a/rpc/swagger/swagger.yaml +++ b/rpc/swagger/swagger.yaml @@ -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: diff --git a/tools/tm-bench/statistics.go b/tools/tm-bench/statistics.go index ce4bd0f03..1498a61e4 100644 --- a/tools/tm-bench/statistics.go +++ b/tools/tm-bench/statistics.go @@ -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) { diff --git a/types/block_meta.go b/types/block_meta.go index 51c881e14..694130bbc 100644 --- a/types/block_meta.go +++ b/types/block_meta.go @@ -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), } }