Browse Source

events: Add block_id to NewBlockEvent (#6478)

Adds `block_id` to the `newblock` websocket event

Closes #6028
pull/6496/head
Greg Morrison 3 years ago
committed by GitHub
parent
commit
692f23d589
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 11 additions and 3 deletions
  1. +1
    -0
      CHANGELOG_PENDING.md
  2. +5
    -2
      state/execution.go
  3. +3
    -0
      types/event_bus_test.go
  4. +2
    -1
      types/events.go

+ 1
- 0
CHANGELOG_PENDING.md View File

@ -67,6 +67,7 @@ Friendly reminder: We have a [bug bounty program](https://hackerone.com/tendermi
### IMPROVEMENTS ### IMPROVEMENTS
- [types] \#6478 Add `block_id` to `newblock` event (@jeebster)
- [crypto/ed25519] \#5632 Adopt zip215 `ed25519` verification. (@marbar3778) - [crypto/ed25519] \#5632 Adopt zip215 `ed25519` verification. (@marbar3778)
- [privval] \#5603 Add `--key` to `init`, `gen_validator`, `testnet` & `unsafe_reset_priv_validator` for use in generating `secp256k1` keys. - [privval] \#5603 Add `--key` to `init`, `gen_validator`, `testnet` & `unsafe_reset_priv_validator` for use in generating `secp256k1` keys.
- [privval] \#5725 Add gRPC support to private validator. - [privval] \#5725 Add gRPC support to private validator.


+ 5
- 2
state/execution.go View File

@ -216,7 +216,7 @@ func (blockExec *BlockExecutor) ApplyBlock(
// Events are fired after everything else. // Events are fired after everything else.
// NOTE: if we crash between Commit and Save, events wont be fired during replay // NOTE: if we crash between Commit and Save, events wont be fired during replay
fireEvents(blockExec.logger, blockExec.eventBus, block, abciResponses, validatorUpdates)
fireEvents(blockExec.logger, blockExec.eventBus, block, blockID, abciResponses, validatorUpdates)
return state, retainHeight, nil return state, retainHeight, nil
} }
@ -495,11 +495,13 @@ func fireEvents(
logger log.Logger, logger log.Logger,
eventBus types.BlockEventPublisher, eventBus types.BlockEventPublisher,
block *types.Block, block *types.Block,
blockID types.BlockID,
abciResponses *tmstate.ABCIResponses, abciResponses *tmstate.ABCIResponses,
validatorUpdates []*types.Validator, validatorUpdates []*types.Validator,
) { ) {
if err := eventBus.PublishEventNewBlock(types.EventDataNewBlock{ if err := eventBus.PublishEventNewBlock(types.EventDataNewBlock{
Block: block, Block: block,
BlockID: blockID,
ResultBeginBlock: *abciResponses.BeginBlock, ResultBeginBlock: *abciResponses.BeginBlock,
ResultEndBlock: *abciResponses.EndBlock, ResultEndBlock: *abciResponses.EndBlock,
}); err != nil { }); err != nil {
@ -579,7 +581,8 @@ func ExecCommitBlock(
return nil, err return nil, err
} }
fireEvents(be.logger, be.eventBus, block, abciResponses, validatorUpdates)
blockID := types.BlockID{Hash: block.Hash(), PartSetHeader: block.MakePartSet(types.BlockPartSizeBytes).Header()}
fireEvents(be.logger, be.eventBus, block, blockID, abciResponses, validatorUpdates)
} }
// Commit block, get hash back // Commit block, get hash back


+ 3
- 0
types/event_bus_test.go View File

@ -75,6 +75,7 @@ func TestEventBusPublishEventNewBlock(t *testing.T) {
}) })
block := MakeBlock(0, []Tx{}, nil, []Evidence{}) block := MakeBlock(0, []Tx{}, nil, []Evidence{})
blockID := BlockID{Hash: block.Hash(), PartSetHeader: block.MakePartSet(BlockPartSizeBytes).Header()}
resultBeginBlock := abci.ResponseBeginBlock{ resultBeginBlock := abci.ResponseBeginBlock{
Events: []abci.Event{ Events: []abci.Event{
{Type: "testType", Attributes: []abci.EventAttribute{{Key: "baz", Value: "1"}}}, {Type: "testType", Attributes: []abci.EventAttribute{{Key: "baz", Value: "1"}}},
@ -96,6 +97,7 @@ func TestEventBusPublishEventNewBlock(t *testing.T) {
msg := <-blocksSub.Out() msg := <-blocksSub.Out()
edt := msg.Data().(EventDataNewBlock) edt := msg.Data().(EventDataNewBlock)
assert.Equal(t, block, edt.Block) assert.Equal(t, block, edt.Block)
assert.Equal(t, blockID, edt.BlockID)
assert.Equal(t, resultBeginBlock, edt.ResultBeginBlock) assert.Equal(t, resultBeginBlock, edt.ResultBeginBlock)
assert.Equal(t, resultEndBlock, edt.ResultEndBlock) assert.Equal(t, resultEndBlock, edt.ResultEndBlock)
close(done) close(done)
@ -103,6 +105,7 @@ func TestEventBusPublishEventNewBlock(t *testing.T) {
err = eventBus.PublishEventNewBlock(EventDataNewBlock{ err = eventBus.PublishEventNewBlock(EventDataNewBlock{
Block: block, Block: block,
BlockID: blockID,
ResultBeginBlock: resultBeginBlock, ResultBeginBlock: resultBeginBlock,
ResultEndBlock: resultEndBlock, ResultEndBlock: resultEndBlock,
}) })


+ 2
- 1
types/events.go View File

@ -62,7 +62,8 @@ func init() {
// but some (an input to a call tx or a receive) are more exotic // but some (an input to a call tx or a receive) are more exotic
type EventDataNewBlock struct { type EventDataNewBlock struct {
Block *Block `json:"block"`
Block *Block `json:"block"`
BlockID BlockID `json:"block_id"`
ResultBeginBlock abci.ResponseBeginBlock `json:"result_begin_block"` ResultBeginBlock abci.ResponseBeginBlock `json:"result_begin_block"`
ResultEndBlock abci.ResponseEndBlock `json:"result_end_block"` ResultEndBlock abci.ResponseEndBlock `json:"result_end_block"`


Loading…
Cancel
Save