Browse Source

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
pull/4139/head
Marko 5 years ago
committed by Anton Kaliaev
parent
commit
41403d5261
8 changed files with 37 additions and 35 deletions
  1. +2
    -0
      CHANGELOG_PENDING.md
  2. +0
    -5
      lite/proxy/wrapper.go
  3. +5
    -5
      rpc/client/rpc_test.go
  4. +1
    -1
      rpc/core/blocks.go
  5. +2
    -2
      rpc/core/types/responses.go
  6. +10
    -7
      rpc/swagger/swagger.yaml
  7. +8
    -8
      tools/tm-bench/statistics.go
  8. +9
    -7
      types/block_meta.go

+ 2
- 0
CHANGELOG_PENDING.md View File

@ -11,6 +11,7 @@ program](https://hackerone.com/tendermint).
### BREAKING CHANGES: ### BREAKING CHANGES:
- CLI/RPC/Config - 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) - [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. - [rpc] [\#4077](https://github.com/tendermint/tendermint/pull/4077) Added support for `EXISTS` clause to the Websocket query interface.
- [privval] Add `SignerDialerEndpointRetryWaitInterval` option (@cosmostuba) - [privval] Add `SignerDialerEndpointRetryWaitInterval` option (@cosmostuba)
- [crypto] Add `RegisterKeyType` to amino to allow external key types registration (@austinabell) - [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` - [types] \#2521 Add `NumTxs` to `BlockMeta` and `EventDataNewBlockHeader`
### BUG FIXES: ### BUG FIXES:


+ 0
- 5
lite/proxy/wrapper.go View File

@ -107,11 +107,6 @@ func (w Wrapper) Block(height *int64) (*ctypes.ResultBlock, error) {
} }
sh := resCommit.SignedHeader sh := resCommit.SignedHeader
// now verify
err = ValidateBlockMeta(resBlock.BlockMeta, sh)
if err != nil {
return nil, err
}
err = ValidateBlock(resBlock.Block, sh) err = ValidateBlock(resBlock.Block, sh)
if err != nil { if err != nil {
return nil, err return nil, err


+ 5
- 5
rpc/client/rpc_test.go View File

@ -225,9 +225,9 @@ func TestAppCalls(t *testing.T) {
// and we can even check the block is added // and we can even check the block is added
block, err := c.Block(&apph) block, err := c.Block(&apph)
require.Nil(err, "%d: %+v", i, err) require.Nil(err, "%d: %+v", i, err)
appHash := block.BlockMeta.Header.AppHash
appHash := block.Block.Header.AppHash
assert.True(len(appHash) > 0) assert.True(len(appHash) > 0)
assert.EqualValues(apph, block.BlockMeta.Header.Height)
assert.EqualValues(apph, block.Block.Header.Height)
// now check the results // now check the results
blockResults, err := c.BlockResults(&txh) blockResults, err := c.BlockResults(&txh)
@ -245,9 +245,9 @@ func TestAppCalls(t *testing.T) {
if assert.Equal(1, len(info.BlockMetas)) { if assert.Equal(1, len(info.BlockMetas)) {
lastMeta := info.BlockMetas[0] lastMeta := info.BlockMetas[0]
assert.EqualValues(apph, lastMeta.Header.Height) 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 // and get the corresponding commit with the same apphash


+ 1
- 1
rpc/core/blocks.go View File

@ -78,7 +78,7 @@ func Block(ctx *rpctypes.Context, heightPtr *int64) (*ctypes.ResultBlock, error)
blockMeta := blockStore.LoadBlockMeta(height) blockMeta := blockStore.LoadBlockMeta(height)
block := blockStore.LoadBlock(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. // Commit gets block commit at a given height.


+ 2
- 2
rpc/core/types/responses.go View File

@ -25,8 +25,8 @@ type ResultGenesis struct {
// Single block (with meta) // Single block (with meta)
type ResultBlock struct { 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 // Commit and Header


+ 10
- 7
rpc/swagger/swagger.yaml View File

@ -1162,7 +1162,7 @@ definitions:
x-example: "CB02DCAA7FB46BF874052EC2273FD0B1F2CF2E1593298D9781E60FE9C3DB8638" x-example: "CB02DCAA7FB46BF874052EC2273FD0B1F2CF2E1593298D9781E60FE9C3DB8638"
type: object type: object
type: object type: object
BlockMetaHeader:
BlockHeader:
required: required:
- "version" - "version"
- "chain_id" - "chain_id"
@ -1230,7 +1230,7 @@ definitions:
type: string type: string
x-example: "D540AB022088612AC74B287D076DBFBC4A377A2E" x-example: "D540AB022088612AC74B287D076DBFBC4A377A2E"
type: object type: object
BlockMetaId:
BlockId:
required: required:
- "hash" - "hash"
- "parts" - "parts"
@ -1254,10 +1254,13 @@ definitions:
BlockMeta: BlockMeta:
type: object type: object
properties: properties:
block_size:
type: number
x-example: 1000000
block_id: block_id:
$ref: "#/definitions/BlockMetaId"
$ref: "#/definitions/BlockId"
header: header:
$ref: "#/definitions/BlockMetaHeader"
$ref: "#/definitions/BlockHeader"
Blockchain: Blockchain:
type: object type: object
required: required:
@ -1317,7 +1320,7 @@ definitions:
type: object type: object
properties: properties:
header: header:
$ref: "#/definitions/BlockMetaHeader"
$ref: "#/definitions/BlockHeader"
data: data:
type: array type: array
items: items:
@ -1361,8 +1364,8 @@ definitions:
BlockComplete: BlockComplete:
type: object type: object
properties: properties:
block_meta:
$ref: "#/definitions/BlockMeta"
block_id:
$ref: "#/definitions/BlockID"
block: block:
$ref: "#/definitions/Block" $ref: "#/definitions/Block"
BlockResponse: BlockResponse:


+ 8
- 8
tools/tm-bench/statistics.go View File

@ -35,12 +35,12 @@ func calculateStatistics(
} }
var ( 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... // 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 numBlocksPerSec[i] = 0
numTxsPerSec[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)) 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 return stats, nil
@ -107,8 +107,8 @@ func getBlockMetas(client tmrpc.Client, minHeight int64, timeStart, timeEnd time
return blockMetas, nil 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) { func printStatistics(stats *statistics, outputFormat string) {


+ 9
- 7
types/block_meta.go View File

@ -2,17 +2,19 @@ package types
// BlockMeta contains meta information. // BlockMeta contains meta information.
type BlockMeta struct { 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 { func NewBlockMeta(block *Block, blockParts *PartSet) *BlockMeta {
return &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),
} }
} }


Loading…
Cancel
Save