mirror of
https://github.com/fluencelabs/tendermint
synced 2025-06-18 15:41:20 +00:00
evidence linked with consensus/node. compiles
This commit is contained in:
@ -260,8 +260,11 @@ func newConsensusStateWithConfigAndBlockStore(thisConfig *cfg.Config, state *sm.
|
|||||||
mempool.EnableTxsAvailable()
|
mempool.EnableTxsAvailable()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// mock the evidence pool
|
||||||
|
evpool := types.MockEvidencePool{}
|
||||||
|
|
||||||
// Make ConsensusReactor
|
// Make ConsensusReactor
|
||||||
cs := NewConsensusState(thisConfig.Consensus, state, proxyAppConnCon, blockStore, mempool)
|
cs := NewConsensusState(thisConfig.Consensus, state, proxyAppConnCon, blockStore, mempool, evpool)
|
||||||
cs.SetLogger(log.TestingLogger())
|
cs.SetLogger(log.TestingLogger())
|
||||||
cs.SetPrivValidator(pv)
|
cs.SetPrivValidator(pv)
|
||||||
|
|
||||||
|
@ -123,7 +123,8 @@ func (pb *playback) replayReset(count int, newStepCh chan interface{}) error {
|
|||||||
pb.cs.Stop()
|
pb.cs.Stop()
|
||||||
pb.cs.Wait()
|
pb.cs.Wait()
|
||||||
|
|
||||||
newCS := NewConsensusState(pb.cs.config, pb.genesisState.Copy(), pb.cs.proxyAppConn, pb.cs.blockStore, pb.cs.mempool)
|
newCS := NewConsensusState(pb.cs.config, pb.genesisState.Copy(), pb.cs.proxyAppConn,
|
||||||
|
pb.cs.blockStore, pb.cs.mempool, pb.cs.evpool)
|
||||||
newCS.SetEventBus(pb.cs.eventBus)
|
newCS.SetEventBus(pb.cs.eventBus)
|
||||||
newCS.startForReplay()
|
newCS.startForReplay()
|
||||||
|
|
||||||
@ -302,7 +303,8 @@ func newConsensusStateForReplay(config cfg.BaseConfig, csConfig *cfg.ConsensusCo
|
|||||||
cmn.Exit(cmn.Fmt("Failed to start event bus: %v", err))
|
cmn.Exit(cmn.Fmt("Failed to start event bus: %v", err))
|
||||||
}
|
}
|
||||||
|
|
||||||
consensusState := NewConsensusState(csConfig, state.Copy(), proxyApp.Consensus(), blockStore, types.MockMempool{})
|
consensusState := NewConsensusState(csConfig, state.Copy(), proxyApp.Consensus(),
|
||||||
|
blockStore, types.MockMempool{}, types.MockEvidencePool{})
|
||||||
|
|
||||||
consensusState.SetEventBus(eventBus)
|
consensusState.SetEventBus(eventBus)
|
||||||
return consensusState
|
return consensusState
|
||||||
|
@ -17,7 +17,6 @@ import (
|
|||||||
|
|
||||||
cfg "github.com/tendermint/tendermint/config"
|
cfg "github.com/tendermint/tendermint/config"
|
||||||
cstypes "github.com/tendermint/tendermint/consensus/types"
|
cstypes "github.com/tendermint/tendermint/consensus/types"
|
||||||
evpool "github.com/tendermint/tendermint/evidence"
|
|
||||||
"github.com/tendermint/tendermint/proxy"
|
"github.com/tendermint/tendermint/proxy"
|
||||||
sm "github.com/tendermint/tendermint/state"
|
sm "github.com/tendermint/tendermint/state"
|
||||||
"github.com/tendermint/tendermint/types"
|
"github.com/tendermint/tendermint/types"
|
||||||
@ -79,7 +78,7 @@ type ConsensusState struct {
|
|||||||
proxyAppConn proxy.AppConnConsensus
|
proxyAppConn proxy.AppConnConsensus
|
||||||
blockStore types.BlockStore
|
blockStore types.BlockStore
|
||||||
mempool types.Mempool
|
mempool types.Mempool
|
||||||
evpool evpool.EvidencePool
|
evpool types.EvidencePool
|
||||||
|
|
||||||
// internal state
|
// internal state
|
||||||
mtx sync.Mutex
|
mtx sync.Mutex
|
||||||
@ -115,7 +114,7 @@ type ConsensusState struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewConsensusState returns a new ConsensusState.
|
// NewConsensusState returns a new ConsensusState.
|
||||||
func NewConsensusState(config *cfg.ConsensusConfig, state *sm.State, proxyAppConn proxy.AppConnConsensus, blockStore types.BlockStore, mempool types.Mempool) *ConsensusState {
|
func NewConsensusState(config *cfg.ConsensusConfig, state *sm.State, proxyAppConn proxy.AppConnConsensus, blockStore types.BlockStore, mempool types.Mempool, evpool types.EvidencePool) *ConsensusState {
|
||||||
cs := &ConsensusState{
|
cs := &ConsensusState{
|
||||||
config: config,
|
config: config,
|
||||||
proxyAppConn: proxyAppConn,
|
proxyAppConn: proxyAppConn,
|
||||||
@ -127,7 +126,7 @@ func NewConsensusState(config *cfg.ConsensusConfig, state *sm.State, proxyAppCon
|
|||||||
done: make(chan struct{}),
|
done: make(chan struct{}),
|
||||||
doWALCatchup: true,
|
doWALCatchup: true,
|
||||||
wal: nilWAL{},
|
wal: nilWAL{},
|
||||||
// evpool: evpool,
|
evpool: evpool,
|
||||||
}
|
}
|
||||||
// set function defaults (may be overwritten before calling Start)
|
// set function defaults (may be overwritten before calling Start)
|
||||||
cs.decideProposal = cs.defaultDecideProposal
|
cs.decideProposal = cs.defaultDecideProposal
|
||||||
@ -1237,6 +1236,8 @@ func (cs *ConsensusState) finalizeCommit(height int64) {
|
|||||||
|
|
||||||
fail.Fail() // XXX
|
fail.Fail() // XXX
|
||||||
|
|
||||||
|
// TODO: cs.evpool.Update()
|
||||||
|
|
||||||
// NewHeightStep!
|
// NewHeightStep!
|
||||||
cs.updateToState(stateCopy)
|
cs.updateToState(stateCopy)
|
||||||
|
|
||||||
|
@ -3,27 +3,28 @@ package evpool
|
|||||||
import (
|
import (
|
||||||
"github.com/tendermint/tmlibs/log"
|
"github.com/tendermint/tmlibs/log"
|
||||||
|
|
||||||
|
cfg "github.com/tendermint/tendermint/config"
|
||||||
"github.com/tendermint/tendermint/types"
|
"github.com/tendermint/tendermint/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
// EvidencePool maintains a pool of valid evidence
|
// EvidencePool maintains a pool of valid evidence
|
||||||
// in an EvidenceStore.
|
// in an EvidenceStore.
|
||||||
type EvidencePool struct {
|
type EvidencePool struct {
|
||||||
config *EvidencePoolConfig
|
config *cfg.EvidenceConfig
|
||||||
logger log.Logger
|
logger log.Logger
|
||||||
|
|
||||||
|
state types.State
|
||||||
evidenceStore *EvidenceStore
|
evidenceStore *EvidenceStore
|
||||||
|
|
||||||
evidenceChan chan types.Evidence
|
evidenceChan chan types.Evidence
|
||||||
}
|
}
|
||||||
|
|
||||||
type EvidencePoolConfig struct {
|
func NewEvidencePool(config *cfg.EvidenceConfig, evidenceStore *EvidenceStore, state types.State) *EvidencePool {
|
||||||
}
|
|
||||||
|
|
||||||
func NewEvidencePool(config *EvidencePoolConfig, evidenceStore *EvidenceStore) *EvidencePool {
|
|
||||||
evpool := &EvidencePool{
|
evpool := &EvidencePool{
|
||||||
config: config,
|
config: config,
|
||||||
logger: log.NewNopLogger(),
|
logger: log.NewNopLogger(),
|
||||||
evidenceStore: evidenceStore,
|
evidenceStore: evidenceStore,
|
||||||
|
state: state,
|
||||||
evidenceChan: make(chan types.Evidence),
|
evidenceChan: make(chan types.Evidence),
|
||||||
}
|
}
|
||||||
return evpool
|
return evpool
|
||||||
@ -52,7 +53,13 @@ func (evpool *EvidencePool) PendingEvidence() []types.Evidence {
|
|||||||
// AddEvidence checks the evidence is valid and adds it to the pool.
|
// AddEvidence checks the evidence is valid and adds it to the pool.
|
||||||
// Blocks on the EvidenceChan.
|
// Blocks on the EvidenceChan.
|
||||||
func (evpool *EvidencePool) AddEvidence(evidence types.Evidence) (err error) {
|
func (evpool *EvidencePool) AddEvidence(evidence types.Evidence) (err error) {
|
||||||
added, err := evpool.evidenceStore.AddNewEvidence(evidence)
|
|
||||||
|
priority, err := evpool.state.VerifyEvidence(evidence)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
added, err := evpool.evidenceStore.AddNewEvidence(evidence, priority)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
} else if !added {
|
} else if !added {
|
||||||
|
@ -51,18 +51,12 @@ func _key(key string, evidence types.Evidence) []byte {
|
|||||||
// evidence that has been committed, evidence that has been seen but not broadcast,
|
// evidence that has been committed, evidence that has been seen but not broadcast,
|
||||||
// and evidence that has been broadcast but not yet committed.
|
// and evidence that has been broadcast but not yet committed.
|
||||||
type EvidenceStore struct {
|
type EvidenceStore struct {
|
||||||
chainID string
|
|
||||||
db dbm.DB
|
db dbm.DB
|
||||||
|
|
||||||
// so we can verify evidence was from a real validator
|
|
||||||
state types.State
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewEvidenceStore(chainID string, db dbm.DB, state types.State) *EvidenceStore {
|
func NewEvidenceStore(db dbm.DB) *EvidenceStore {
|
||||||
return &EvidenceStore{
|
return &EvidenceStore{
|
||||||
chainID: chainID,
|
|
||||||
db: db,
|
db: db,
|
||||||
state: state,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -93,7 +87,7 @@ func (store *EvidenceStore) PendingEvidence() (evidence []types.Evidence) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// AddNewEvidence adds the given evidence to the database.
|
// AddNewEvidence adds the given evidence to the database.
|
||||||
func (store *EvidenceStore) AddNewEvidence(evidence types.Evidence) (bool, error) {
|
func (store *EvidenceStore) AddNewEvidence(evidence types.Evidence, priority int) (bool, error) {
|
||||||
// check if we already have seen it
|
// check if we already have seen it
|
||||||
key := keyLookup(evidence)
|
key := keyLookup(evidence)
|
||||||
v := store.db.Get(key)
|
v := store.db.Get(key)
|
||||||
@ -101,11 +95,6 @@ func (store *EvidenceStore) AddNewEvidence(evidence types.Evidence) (bool, error
|
|||||||
return false, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
priority, err := store.state.VerifyEvidence(evidence)
|
|
||||||
if err != nil {
|
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
|
|
||||||
ei := evidenceInfo{
|
ei := evidenceInfo{
|
||||||
Committed: false,
|
Committed: false,
|
||||||
Priority: priority,
|
Priority: priority,
|
||||||
|
31
node/node.go
31
node/node.go
@ -19,6 +19,7 @@ import (
|
|||||||
bc "github.com/tendermint/tendermint/blockchain"
|
bc "github.com/tendermint/tendermint/blockchain"
|
||||||
cfg "github.com/tendermint/tendermint/config"
|
cfg "github.com/tendermint/tendermint/config"
|
||||||
"github.com/tendermint/tendermint/consensus"
|
"github.com/tendermint/tendermint/consensus"
|
||||||
|
evidence "github.com/tendermint/tendermint/evidence"
|
||||||
mempl "github.com/tendermint/tendermint/mempool"
|
mempl "github.com/tendermint/tendermint/mempool"
|
||||||
"github.com/tendermint/tendermint/p2p"
|
"github.com/tendermint/tendermint/p2p"
|
||||||
"github.com/tendermint/tendermint/p2p/trust"
|
"github.com/tendermint/tendermint/p2p/trust"
|
||||||
@ -107,6 +108,7 @@ type Node struct {
|
|||||||
mempoolReactor *mempl.MempoolReactor // for gossipping transactions
|
mempoolReactor *mempl.MempoolReactor // for gossipping transactions
|
||||||
consensusState *consensus.ConsensusState // latest consensus state
|
consensusState *consensus.ConsensusState // latest consensus state
|
||||||
consensusReactor *consensus.ConsensusReactor // for participating in the consensus
|
consensusReactor *consensus.ConsensusReactor // for participating in the consensus
|
||||||
|
evidencePool *evidence.EvidencePool // tracking evidence
|
||||||
proxyApp proxy.AppConns // connection to the application
|
proxyApp proxy.AppConns // connection to the application
|
||||||
rpcListeners []net.Listener // rpc servers
|
rpcListeners []net.Listener // rpc servers
|
||||||
txIndexer txindex.TxIndexer
|
txIndexer txindex.TxIndexer
|
||||||
@ -128,9 +130,6 @@ func NewNode(config *cfg.Config,
|
|||||||
}
|
}
|
||||||
blockStore := bc.NewBlockStore(blockStoreDB)
|
blockStore := bc.NewBlockStore(blockStoreDB)
|
||||||
|
|
||||||
consensusLogger := logger.With("module", "consensus")
|
|
||||||
stateLogger := logger.With("module", "state")
|
|
||||||
|
|
||||||
// Get State
|
// Get State
|
||||||
stateDB, err := dbProvider(&DBContext{"state", config})
|
stateDB, err := dbProvider(&DBContext{"state", config})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -149,6 +148,7 @@ func NewNode(config *cfg.Config,
|
|||||||
saveGenesisDoc(stateDB, genDoc)
|
saveGenesisDoc(stateDB, genDoc)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
stateLogger := logger.With("module", "state")
|
||||||
state := sm.LoadState(stateDB)
|
state := sm.LoadState(stateDB)
|
||||||
if state == nil {
|
if state == nil {
|
||||||
state, err = sm.MakeGenesisState(stateDB, genDoc)
|
state, err = sm.MakeGenesisState(stateDB, genDoc)
|
||||||
@ -161,6 +161,7 @@ func NewNode(config *cfg.Config,
|
|||||||
|
|
||||||
// Create the proxyApp, which manages connections (consensus, mempool, query)
|
// Create the proxyApp, which manages connections (consensus, mempool, query)
|
||||||
// and sync tendermint and the app by replaying any necessary blocks
|
// and sync tendermint and the app by replaying any necessary blocks
|
||||||
|
consensusLogger := logger.With("module", "consensus")
|
||||||
handshaker := consensus.NewHandshaker(state, blockStore)
|
handshaker := consensus.NewHandshaker(state, blockStore)
|
||||||
handshaker.SetLogger(consensusLogger)
|
handshaker.SetLogger(consensusLogger)
|
||||||
proxyApp := proxy.NewAppConns(clientCreator, handshaker)
|
proxyApp := proxy.NewAppConns(clientCreator, handshaker)
|
||||||
@ -208,8 +209,22 @@ func NewNode(config *cfg.Config,
|
|||||||
mempool.EnableTxsAvailable()
|
mempool.EnableTxsAvailable()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Make Evidence Reactor
|
||||||
|
evidenceConfig := &cfg.EvidenceConfig{} // TODO
|
||||||
|
evidenceDB, err := dbProvider(&DBContext{"evidence", config})
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
evidenceLogger := logger.With("module", "evidence")
|
||||||
|
evidenceStore := evidence.NewEvidenceStore(evidenceDB)
|
||||||
|
evidencePool := evidence.NewEvidencePool(evidenceConfig, evidenceStore, state)
|
||||||
|
evidencePool.SetLogger(evidenceLogger)
|
||||||
|
evidenceReactor := evidence.NewEvidenceReactor(evidenceConfig, evidencePool)
|
||||||
|
evidenceReactor.SetLogger(evidenceLogger)
|
||||||
|
|
||||||
// Make ConsensusReactor
|
// Make ConsensusReactor
|
||||||
consensusState := consensus.NewConsensusState(config.Consensus, state.Copy(), proxyApp.Consensus(), blockStore, mempool)
|
consensusState := consensus.NewConsensusState(config.Consensus, state.Copy(),
|
||||||
|
proxyApp.Consensus(), blockStore, mempool, evidencePool)
|
||||||
consensusState.SetLogger(consensusLogger)
|
consensusState.SetLogger(consensusLogger)
|
||||||
if privValidator != nil {
|
if privValidator != nil {
|
||||||
consensusState.SetPrivValidator(privValidator)
|
consensusState.SetPrivValidator(privValidator)
|
||||||
@ -224,6 +239,7 @@ func NewNode(config *cfg.Config,
|
|||||||
sw.AddReactor("MEMPOOL", mempoolReactor)
|
sw.AddReactor("MEMPOOL", mempoolReactor)
|
||||||
sw.AddReactor("BLOCKCHAIN", bcReactor)
|
sw.AddReactor("BLOCKCHAIN", bcReactor)
|
||||||
sw.AddReactor("CONSENSUS", consensusReactor)
|
sw.AddReactor("CONSENSUS", consensusReactor)
|
||||||
|
sw.AddReactor("EVIDENCE", evidenceReactor)
|
||||||
|
|
||||||
// Optionally, start the pex reactor
|
// Optionally, start the pex reactor
|
||||||
var addrBook *p2p.AddrBook
|
var addrBook *p2p.AddrBook
|
||||||
@ -323,6 +339,7 @@ func NewNode(config *cfg.Config,
|
|||||||
mempoolReactor: mempoolReactor,
|
mempoolReactor: mempoolReactor,
|
||||||
consensusState: consensusState,
|
consensusState: consensusState,
|
||||||
consensusReactor: consensusReactor,
|
consensusReactor: consensusReactor,
|
||||||
|
evidencePool: evidencePool,
|
||||||
proxyApp: proxyApp,
|
proxyApp: proxyApp,
|
||||||
txIndexer: txIndexer,
|
txIndexer: txIndexer,
|
||||||
indexerService: indexerService,
|
indexerService: indexerService,
|
||||||
@ -416,6 +433,7 @@ func (n *Node) ConfigureRPC() {
|
|||||||
rpccore.SetBlockStore(n.blockStore)
|
rpccore.SetBlockStore(n.blockStore)
|
||||||
rpccore.SetConsensusState(n.consensusState)
|
rpccore.SetConsensusState(n.consensusState)
|
||||||
rpccore.SetMempool(n.mempoolReactor.Mempool)
|
rpccore.SetMempool(n.mempoolReactor.Mempool)
|
||||||
|
rpccore.SetEvidencePool(n.evidencePool)
|
||||||
rpccore.SetSwitch(n.sw)
|
rpccore.SetSwitch(n.sw)
|
||||||
rpccore.SetPubKey(n.privValidator.GetPubKey())
|
rpccore.SetPubKey(n.privValidator.GetPubKey())
|
||||||
rpccore.SetGenesisDoc(n.genesisDoc)
|
rpccore.SetGenesisDoc(n.genesisDoc)
|
||||||
@ -489,6 +507,11 @@ func (n *Node) MempoolReactor() *mempl.MempoolReactor {
|
|||||||
return n.mempoolReactor
|
return n.mempoolReactor
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// EvidencePool returns the Node's EvidencePool.
|
||||||
|
func (n *Node) EvidencePool() *evidence.EvidencePool {
|
||||||
|
return n.evidencePool
|
||||||
|
}
|
||||||
|
|
||||||
// EventBus returns the Node's EventBus.
|
// EventBus returns the Node's EventBus.
|
||||||
func (n *Node) EventBus() *types.EventBus {
|
func (n *Node) EventBus() *types.EventBus {
|
||||||
return n.eventBus
|
return n.eventBus
|
||||||
|
@ -45,6 +45,7 @@ var (
|
|||||||
// interfaces defined in types and above
|
// interfaces defined in types and above
|
||||||
blockStore types.BlockStore
|
blockStore types.BlockStore
|
||||||
mempool types.Mempool
|
mempool types.Mempool
|
||||||
|
evidencePool types.EvidencePool
|
||||||
consensusState Consensus
|
consensusState Consensus
|
||||||
p2pSwitch P2P
|
p2pSwitch P2P
|
||||||
|
|
||||||
@ -67,6 +68,10 @@ func SetMempool(mem types.Mempool) {
|
|||||||
mempool = mem
|
mempool = mem
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func SetEvidencePool(evpool types.EvidencePool) {
|
||||||
|
evidencePool = evpool
|
||||||
|
}
|
||||||
|
|
||||||
func SetConsensusState(cs Consensus) {
|
func SetConsensusState(cs Consensus) {
|
||||||
consensusState = cs
|
consensusState = cs
|
||||||
}
|
}
|
||||||
|
@ -84,7 +84,7 @@ type State interface {
|
|||||||
// UNSTABLE
|
// UNSTABLE
|
||||||
type EvidencePool interface {
|
type EvidencePool interface {
|
||||||
PendingEvidence() []Evidence
|
PendingEvidence() []Evidence
|
||||||
AddEvidence(Evidence)
|
AddEvidence(Evidence) error
|
||||||
}
|
}
|
||||||
|
|
||||||
// MockMempool is an empty implementation of a Mempool, useful for testing.
|
// MockMempool is an empty implementation of a Mempool, useful for testing.
|
||||||
@ -93,4 +93,4 @@ type MockEvidencePool struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (m MockEvidencePool) PendingEvidence() []Evidence { return nil }
|
func (m MockEvidencePool) PendingEvidence() []Evidence { return nil }
|
||||||
func (m MockEvidencePool) AddEvidence(Evidence) {}
|
func (m MockEvidencePool) AddEvidence(Evidence) error { return nil }
|
||||||
|
Reference in New Issue
Block a user