Browse Source

EventDataTypeNewBlockHeader

pull/205/head
Ethan Buchman 9 years ago
parent
commit
523a170c3e
3 changed files with 20 additions and 14 deletions
  1. +2
    -1
      consensus/state.go
  2. +3
    -3
      consensus/state_test.go
  3. +15
    -10
      types/events.go

+ 2
- 1
consensus/state.go View File

@ -1205,7 +1205,8 @@ func (cs *ConsensusState) finalizeCommit(height int) {
// Fire off event for new block. // Fire off event for new block.
// TODO: Handle app failure. See #177 // 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 // Create a copy of the state for staging
stateCopy := cs.state.Copy() stateCopy := cs.state.Copy()


+ 3
- 3
consensus/state_test.go View File

@ -491,7 +491,7 @@ func TestLockPOLRelock(t *testing.T) {
proposalCh := subscribeToEvent(cs1.evsw, "tester", types.EventStringCompleteProposal(), 1) proposalCh := subscribeToEvent(cs1.evsw, "tester", types.EventStringCompleteProposal(), 1)
voteCh := subscribeToEvent(cs1.evsw, "tester", types.EventStringVote(), 1) voteCh := subscribeToEvent(cs1.evsw, "tester", types.EventStringVote(), 1)
newRoundCh := subscribeToEvent(cs1.evsw, "tester", types.EventStringNewRound(), 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) log.Debug("cs2 last round", "lr", cs2.PrivValidator.LastRound)
@ -577,14 +577,14 @@ func TestLockPOLRelock(t *testing.T) {
_, _ = <-voteCh, <-voteCh _, _ = <-voteCh, <-voteCh
be := <-newBlockCh be := <-newBlockCh
b := be.(types.EventDataNewBlock)
b := be.(types.EventDataNewBlockHeader)
re = <-newRoundCh re = <-newRoundCh
rs = re.(types.EventDataRoundState).RoundState.(*RoundState) rs = re.(types.EventDataRoundState).RoundState.(*RoundState)
if rs.Height != 2 { if rs.Height != 2 {
t.Fatal("Expected height to increment") 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") t.Fatal("Expected new block to be proposal block")
} }
} }


+ 15
- 10
types/events.go View File

@ -16,6 +16,7 @@ func EventStringDupeout() string { return "Dupeout" }
func EventStringFork() string { return "Fork" } func EventStringFork() string { return "Fork" }
func EventStringNewBlock() string { return "NewBlock" } func EventStringNewBlock() string { return "NewBlock" }
func EventStringNewBlockHeader() string { return "NewBlockHeader" }
func EventStringNewRound() string { return "NewRound" } func EventStringNewRound() string { return "NewRound" }
func EventStringNewRoundStep() string { return "NewRoundStep" } func EventStringNewRoundStep() string { return "NewRoundStep" }
func EventStringTimeoutPropose() string { return "TimeoutPropose" } func EventStringTimeoutPropose() string { return "TimeoutPropose" }
@ -36,9 +37,10 @@ type TMEventData interface {
} }
const ( 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) EventDataTypeRoundState = byte(0x11)
EventDataTypeVote = byte(0x12) EventDataTypeVote = byte(0x12)
@ -47,6 +49,7 @@ const (
var _ = wire.RegisterInterface( var _ = wire.RegisterInterface(
struct{ TMEventData }{}, struct{ TMEventData }{},
wire.ConcreteType{EventDataNewBlock{}, EventDataTypeNewBlock}, wire.ConcreteType{EventDataNewBlock{}, EventDataTypeNewBlock},
wire.ConcreteType{EventDataNewBlockHeader{}, EventDataTypeNewBlockHeader},
// wire.ConcreteType{EventDataFork{}, EventDataTypeFork }, // wire.ConcreteType{EventDataFork{}, EventDataTypeFork },
wire.ConcreteType{EventDataTx{}, EventDataTypeTx}, wire.ConcreteType{EventDataTx{}, EventDataTypeTx},
wire.ConcreteType{EventDataRoundState{}, EventDataTypeRoundState}, 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 // but some (an input to a call tx or a receive) are more exotic
type EventDataNewBlock struct { 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"` Header *Header `json:"header"`
} }
@ -88,7 +92,8 @@ type EventDataVote struct {
Vote *Vote 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() {}

Loading…
Cancel
Save