diff --git a/CHANGELOG_PENDING.md b/CHANGELOG_PENDING.md index b094fc28e..dbe0fbdec 100644 --- a/CHANGELOG_PENDING.md +++ b/CHANGELOG_PENDING.md @@ -67,6 +67,7 @@ Friendly reminder: We have a [bug bounty program](https://hackerone.com/tendermi ### IMPROVEMENTS +- [types] \#6478 Add `block_id` to `newblock` event (@jeebster) - [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] \#5725 Add gRPC support to private validator. diff --git a/state/execution.go b/state/execution.go index 437d027d0..20f47c5b0 100644 --- a/state/execution.go +++ b/state/execution.go @@ -216,7 +216,7 @@ func (blockExec *BlockExecutor) ApplyBlock( // Events are fired after everything else. // 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 } @@ -495,11 +495,13 @@ func fireEvents( logger log.Logger, eventBus types.BlockEventPublisher, block *types.Block, + blockID types.BlockID, abciResponses *tmstate.ABCIResponses, validatorUpdates []*types.Validator, ) { if err := eventBus.PublishEventNewBlock(types.EventDataNewBlock{ Block: block, + BlockID: blockID, ResultBeginBlock: *abciResponses.BeginBlock, ResultEndBlock: *abciResponses.EndBlock, }); err != nil { @@ -579,7 +581,8 @@ func ExecCommitBlock( 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 diff --git a/types/event_bus_test.go b/types/event_bus_test.go index aff9d20f5..981395718 100644 --- a/types/event_bus_test.go +++ b/types/event_bus_test.go @@ -75,6 +75,7 @@ func TestEventBusPublishEventNewBlock(t *testing.T) { }) block := MakeBlock(0, []Tx{}, nil, []Evidence{}) + blockID := BlockID{Hash: block.Hash(), PartSetHeader: block.MakePartSet(BlockPartSizeBytes).Header()} resultBeginBlock := abci.ResponseBeginBlock{ Events: []abci.Event{ {Type: "testType", Attributes: []abci.EventAttribute{{Key: "baz", Value: "1"}}}, @@ -96,6 +97,7 @@ func TestEventBusPublishEventNewBlock(t *testing.T) { msg := <-blocksSub.Out() edt := msg.Data().(EventDataNewBlock) assert.Equal(t, block, edt.Block) + assert.Equal(t, blockID, edt.BlockID) assert.Equal(t, resultBeginBlock, edt.ResultBeginBlock) assert.Equal(t, resultEndBlock, edt.ResultEndBlock) close(done) @@ -103,6 +105,7 @@ func TestEventBusPublishEventNewBlock(t *testing.T) { err = eventBus.PublishEventNewBlock(EventDataNewBlock{ Block: block, + BlockID: blockID, ResultBeginBlock: resultBeginBlock, ResultEndBlock: resultEndBlock, }) diff --git a/types/events.go b/types/events.go index b71661a05..b926ca828 100644 --- a/types/events.go +++ b/types/events.go @@ -62,7 +62,8 @@ func init() { // but some (an input to a call tx or a receive) are more exotic type EventDataNewBlock struct { - Block *Block `json:"block"` + Block *Block `json:"block"` + BlockID BlockID `json:"block_id"` ResultBeginBlock abci.ResponseBeginBlock `json:"result_begin_block"` ResultEndBlock abci.ResponseEndBlock `json:"result_end_block"`