diff --git a/blockchain/wire.go b/blockchain/wire.go index ff02d58c..cfd261ab 100644 --- a/blockchain/wire.go +++ b/blockchain/wire.go @@ -3,6 +3,7 @@ package blockchain import ( "github.com/tendermint/go-amino" cryptoAmino "github.com/tendermint/tendermint/crypto/encoding/amino" + "github.com/tendermint/tendermint/types" ) var cdc = amino.NewCodec() @@ -10,4 +11,5 @@ var cdc = amino.NewCodec() func init() { RegisterBlockchainMessages(cdc) cryptoAmino.RegisterAmino(cdc) + types.RegisterEvidences(cdc) } diff --git a/consensus/reactor_test.go b/consensus/reactor_test.go index 9e2aa0a0..90def612 100644 --- a/consensus/reactor_test.go +++ b/consensus/reactor_test.go @@ -13,6 +13,7 @@ import ( "github.com/tendermint/tendermint/abci/example/kvstore" cmn "github.com/tendermint/tendermint/libs/common" "github.com/tendermint/tendermint/libs/log" + sm "github.com/tendermint/tendermint/state" cfg "github.com/tendermint/tendermint/config" "github.com/tendermint/tendermint/p2p" @@ -91,6 +92,51 @@ func TestReactorBasic(t *testing.T) { }, css) } +// Ensure we can process blocks with evidence +func TestReactorWithEvidence(t *testing.T) { + N := 4 + css := randConsensusNet(N, "consensus_reactor_test", newMockTickerFunc(true), newCounter) + evpool := mockEvidencePool{ + t: t, + ev: []types.Evidence{types.NewMockGoodEvidence(1, 1, []byte("somone"))}, + } + for i := 0; i < N; i++ { + css[i].evpool = evpool + } + reactors, eventChans, eventBuses := startConsensusNet(t, css, N) + defer stopConsensusNet(log.TestingLogger(), reactors, eventBuses) + // wait till everyone makes the first new block + timeoutWaitGroup(t, N, func(j int) { + <-eventChans[j] + }, css) + + // second block should have evidence + timeoutWaitGroup(t, N, func(j int) { + <-eventChans[j] + }, css) +} + +type mockEvidencePool struct { + height int + ev []types.Evidence + t *testing.T +} + +func (m mockEvidencePool) PendingEvidence() []types.Evidence { + if m.height > 0 { + return m.ev + } + return nil +} +func (m mockEvidencePool) AddEvidence(types.Evidence) error { return nil } +func (m mockEvidencePool) Update(block *types.Block, state sm.State) { + m.height += 1 + + if m.height > 0 { + require.True(m.t, len(block.Evidence.Evidence) > 0) + } +} + // Ensure a testnet sends proposal heartbeats and makes blocks when there are txs func TestReactorProposalHeartbeats(t *testing.T) { N := 4 diff --git a/consensus/types/wire.go b/consensus/types/wire.go index 9221de96..c0b858dd 100644 --- a/consensus/types/wire.go +++ b/consensus/types/wire.go @@ -3,10 +3,12 @@ package types import ( "github.com/tendermint/go-amino" cryptoAmino "github.com/tendermint/tendermint/crypto/encoding/amino" + "github.com/tendermint/tendermint/types" ) var cdc = amino.NewCodec() func init() { cryptoAmino.RegisterAmino(cdc) + types.RegisterEvidences(cdc) } diff --git a/evidence/wire.go b/evidence/wire.go index c61b8618..73ff33b2 100644 --- a/evidence/wire.go +++ b/evidence/wire.go @@ -12,14 +12,4 @@ func init() { RegisterEvidenceMessages(cdc) cryptoAmino.RegisterAmino(cdc) types.RegisterEvidences(cdc) - RegisterMockEvidences(cdc) // For testing -} - -//------------------------------------------- - -func RegisterMockEvidences(cdc *amino.Codec) { - cdc.RegisterConcrete(types.MockGoodEvidence{}, - "tendermint/MockGoodEvidence", nil) - cdc.RegisterConcrete(types.MockBadEvidence{}, - "tendermint/MockBadEvidence", nil) } diff --git a/types/evidence.go b/types/evidence.go index 6313f43a..b04d0ece 100644 --- a/types/evidence.go +++ b/types/evidence.go @@ -41,6 +41,10 @@ type Evidence interface { func RegisterEvidences(cdc *amino.Codec) { cdc.RegisterInterface((*Evidence)(nil), nil) cdc.RegisterConcrete(&DuplicateVoteEvidence{}, "tendermint/DuplicateVoteEvidence", nil) + + // mocks + cdc.RegisterConcrete(&MockGoodEvidence{}, "tendermint/MockGoodEvidence", nil) + cdc.RegisterConcrete(&MockBadEvidence{}, "tendermint/MockBadEvidence", nil) } //------------------------------------------- diff --git a/types/wire.go b/types/wire.go index 9221de96..4f7a38c5 100644 --- a/types/wire.go +++ b/types/wire.go @@ -9,4 +9,5 @@ var cdc = amino.NewCodec() func init() { cryptoAmino.RegisterAmino(cdc) + RegisterEvidences(cdc) }