register evidence interface wherever its used
This commit is contained in:
parent
5fdbcd70df
commit
0e127562bf
|
@ -3,6 +3,7 @@ package blockchain
|
||||||
import (
|
import (
|
||||||
"github.com/tendermint/go-amino"
|
"github.com/tendermint/go-amino"
|
||||||
cryptoAmino "github.com/tendermint/tendermint/crypto/encoding/amino"
|
cryptoAmino "github.com/tendermint/tendermint/crypto/encoding/amino"
|
||||||
|
"github.com/tendermint/tendermint/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
var cdc = amino.NewCodec()
|
var cdc = amino.NewCodec()
|
||||||
|
@ -10,4 +11,5 @@ var cdc = amino.NewCodec()
|
||||||
func init() {
|
func init() {
|
||||||
RegisterBlockchainMessages(cdc)
|
RegisterBlockchainMessages(cdc)
|
||||||
cryptoAmino.RegisterAmino(cdc)
|
cryptoAmino.RegisterAmino(cdc)
|
||||||
|
types.RegisterEvidences(cdc)
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,6 +13,7 @@ import (
|
||||||
"github.com/tendermint/tendermint/abci/example/kvstore"
|
"github.com/tendermint/tendermint/abci/example/kvstore"
|
||||||
cmn "github.com/tendermint/tendermint/libs/common"
|
cmn "github.com/tendermint/tendermint/libs/common"
|
||||||
"github.com/tendermint/tendermint/libs/log"
|
"github.com/tendermint/tendermint/libs/log"
|
||||||
|
sm "github.com/tendermint/tendermint/state"
|
||||||
|
|
||||||
cfg "github.com/tendermint/tendermint/config"
|
cfg "github.com/tendermint/tendermint/config"
|
||||||
"github.com/tendermint/tendermint/p2p"
|
"github.com/tendermint/tendermint/p2p"
|
||||||
|
@ -91,6 +92,51 @@ func TestReactorBasic(t *testing.T) {
|
||||||
}, css)
|
}, 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
|
// Ensure a testnet sends proposal heartbeats and makes blocks when there are txs
|
||||||
func TestReactorProposalHeartbeats(t *testing.T) {
|
func TestReactorProposalHeartbeats(t *testing.T) {
|
||||||
N := 4
|
N := 4
|
||||||
|
|
|
@ -3,10 +3,12 @@ package types
|
||||||
import (
|
import (
|
||||||
"github.com/tendermint/go-amino"
|
"github.com/tendermint/go-amino"
|
||||||
cryptoAmino "github.com/tendermint/tendermint/crypto/encoding/amino"
|
cryptoAmino "github.com/tendermint/tendermint/crypto/encoding/amino"
|
||||||
|
"github.com/tendermint/tendermint/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
var cdc = amino.NewCodec()
|
var cdc = amino.NewCodec()
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
cryptoAmino.RegisterAmino(cdc)
|
cryptoAmino.RegisterAmino(cdc)
|
||||||
|
types.RegisterEvidences(cdc)
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,14 +12,4 @@ func init() {
|
||||||
RegisterEvidenceMessages(cdc)
|
RegisterEvidenceMessages(cdc)
|
||||||
cryptoAmino.RegisterAmino(cdc)
|
cryptoAmino.RegisterAmino(cdc)
|
||||||
types.RegisterEvidences(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)
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,6 +41,10 @@ type Evidence interface {
|
||||||
func RegisterEvidences(cdc *amino.Codec) {
|
func RegisterEvidences(cdc *amino.Codec) {
|
||||||
cdc.RegisterInterface((*Evidence)(nil), nil)
|
cdc.RegisterInterface((*Evidence)(nil), nil)
|
||||||
cdc.RegisterConcrete(&DuplicateVoteEvidence{}, "tendermint/DuplicateVoteEvidence", nil)
|
cdc.RegisterConcrete(&DuplicateVoteEvidence{}, "tendermint/DuplicateVoteEvidence", nil)
|
||||||
|
|
||||||
|
// mocks
|
||||||
|
cdc.RegisterConcrete(&MockGoodEvidence{}, "tendermint/MockGoodEvidence", nil)
|
||||||
|
cdc.RegisterConcrete(&MockBadEvidence{}, "tendermint/MockBadEvidence", nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
//-------------------------------------------
|
//-------------------------------------------
|
||||||
|
|
|
@ -9,4 +9,5 @@ var cdc = amino.NewCodec()
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
cryptoAmino.RegisterAmino(cdc)
|
cryptoAmino.RegisterAmino(cdc)
|
||||||
|
RegisterEvidences(cdc)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue