From 523a170c3e1353c3ab403bb79804289b8948c433 Mon Sep 17 00:00:00 2001 From: Ethan Buchman Date: Tue, 19 Apr 2016 20:59:52 -0400 Subject: [PATCH] EventDataTypeNewBlockHeader --- consensus/state.go | 3 ++- consensus/state_test.go | 6 +++--- types/events.go | 25 +++++++++++++++---------- 3 files changed, 20 insertions(+), 14 deletions(-) diff --git a/consensus/state.go b/consensus/state.go index a768a7a0f..fdbfdb6e6 100644 --- a/consensus/state.go +++ b/consensus/state.go @@ -1205,7 +1205,8 @@ func (cs *ConsensusState) finalizeCommit(height int) { // Fire off event for new block. // TODO: Handle app failure. See #177 - cs.evsw.FireEvent(types.EventStringNewBlock(), types.EventDataNewBlock{&types.BlockHeader{block.Header}}) + cs.evsw.FireEvent(types.EventStringNewBlock(), types.EventDataNewBlock{block}) + cs.evsw.FireEvent(types.EventStringNewBlockHeader(), types.EventDataNewBlockHeader{block.Header}) // Create a copy of the state for staging stateCopy := cs.state.Copy() diff --git a/consensus/state_test.go b/consensus/state_test.go index eaac14dfe..dd2dbe162 100644 --- a/consensus/state_test.go +++ b/consensus/state_test.go @@ -491,7 +491,7 @@ func TestLockPOLRelock(t *testing.T) { proposalCh := subscribeToEvent(cs1.evsw, "tester", types.EventStringCompleteProposal(), 1) voteCh := subscribeToEvent(cs1.evsw, "tester", types.EventStringVote(), 1) newRoundCh := subscribeToEvent(cs1.evsw, "tester", types.EventStringNewRound(), 1) - newBlockCh := subscribeToEvent(cs1.evsw, "tester", types.EventStringNewBlock(), 1) + newBlockCh := subscribeToEvent(cs1.evsw, "tester", types.EventStringNewBlockHeader(), 1) log.Debug("cs2 last round", "lr", cs2.PrivValidator.LastRound) @@ -577,14 +577,14 @@ func TestLockPOLRelock(t *testing.T) { _, _ = <-voteCh, <-voteCh be := <-newBlockCh - b := be.(types.EventDataNewBlock) + b := be.(types.EventDataNewBlockHeader) re = <-newRoundCh rs = re.(types.EventDataRoundState).RoundState.(*RoundState) if rs.Height != 2 { t.Fatal("Expected height to increment") } - if !bytes.Equal(b.Block.Header.Hash(), propBlockHash) { + if !bytes.Equal(b.Header.Hash(), propBlockHash) { t.Fatal("Expected new block to be proposal block") } } diff --git a/types/events.go b/types/events.go index 02e6b072a..3328911c1 100644 --- a/types/events.go +++ b/types/events.go @@ -16,6 +16,7 @@ func EventStringDupeout() string { return "Dupeout" } func EventStringFork() string { return "Fork" } func EventStringNewBlock() string { return "NewBlock" } +func EventStringNewBlockHeader() string { return "NewBlockHeader" } func EventStringNewRound() string { return "NewRound" } func EventStringNewRoundStep() string { return "NewRoundStep" } func EventStringTimeoutPropose() string { return "TimeoutPropose" } @@ -36,9 +37,10 @@ type TMEventData interface { } const ( - EventDataTypeNewBlock = byte(0x01) - EventDataTypeFork = byte(0x02) - EventDataTypeTx = byte(0x03) + EventDataTypeNewBlock = byte(0x01) + EventDataTypeFork = byte(0x02) + EventDataTypeTx = byte(0x03) + EventDataTypeNewBlockHeader = byte(0x04) EventDataTypeRoundState = byte(0x11) EventDataTypeVote = byte(0x12) @@ -47,6 +49,7 @@ const ( var _ = wire.RegisterInterface( struct{ TMEventData }{}, wire.ConcreteType{EventDataNewBlock{}, EventDataTypeNewBlock}, + wire.ConcreteType{EventDataNewBlockHeader{}, EventDataTypeNewBlockHeader}, // wire.ConcreteType{EventDataFork{}, EventDataTypeFork }, wire.ConcreteType{EventDataTx{}, EventDataTypeTx}, wire.ConcreteType{EventDataRoundState{}, EventDataTypeRoundState}, @@ -57,10 +60,11 @@ var _ = wire.RegisterInterface( // but some (an input to a call tx or a receive) are more exotic type EventDataNewBlock struct { - // we drop block data but keep the form the same - Block *BlockHeader `json:"block"` + Block *Block `json:"block"` } -type BlockHeader struct { + +// light weight event for benchmarking +type EventDataNewBlockHeader struct { Header *Header `json:"header"` } @@ -88,7 +92,8 @@ type EventDataVote struct { Vote *Vote } -func (_ EventDataNewBlock) AssertIsTMEventData() {} -func (_ EventDataTx) AssertIsTMEventData() {} -func (_ EventDataRoundState) AssertIsTMEventData() {} -func (_ EventDataVote) AssertIsTMEventData() {} +func (_ EventDataNewBlock) AssertIsTMEventData() {} +func (_ EventDataNewBlockHeader) AssertIsTMEventData() {} +func (_ EventDataTx) AssertIsTMEventData() {} +func (_ EventDataRoundState) AssertIsTMEventData() {} +func (_ EventDataVote) AssertIsTMEventData() {}