Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions blockchain/v0/bls_reactor.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type BLSBlockchainReactor struct {
// immutable
initialState sm.State

blockExec *sm.BlockExecutor
blockExec *sm.BLSBlockExecutor
store *store.BlockStore
pool *BlockPool
fastSync bool
Expand All @@ -32,7 +32,7 @@ type BLSBlockchainReactor struct {
}

// NewBLSBlockchainReactor returns new reactor instance.
func NewBLSBlockchainReactor(state sm.State, blockExec *sm.BlockExecutor, store *store.BlockStore, verifier dkgtypes.Verifier,
func NewBLSBlockchainReactor(state sm.State, blockExec *sm.BLSBlockExecutor, store *store.BlockStore, verifier dkgtypes.Verifier,
fastSync bool) *BLSBlockchainReactor {

if state.LastBlockHeight != store.Height() {
Expand Down
27 changes: 20 additions & 7 deletions consensus/BLSState.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ import (
"fmt"
"runtime/debug"

"github.com/dgamingfoundation/tendermint/evidence"

"github.com/dgamingfoundation/tendermint/state"

dkgtypes "github.com/dgamingfoundation/dkglib/lib/types"
cfg "github.com/tendermint/tendermint/config"
cstypes "github.com/tendermint/tendermint/consensus/types"
Expand All @@ -18,7 +22,9 @@ import (

type BLSConsensusState struct {
ConsensusState
dkg dkgtypes.DKG
dkg dkgtypes.DKG
blockExec *sm.BLSBlockExecutor
evpool *evidence.BLSEvidencePool
}

type BLSStateOption func(*BLSConsensusState)
Expand All @@ -28,16 +34,19 @@ var _ StateInterface = &BLSConsensusState{}
func NewBLSConsensusState(
config *cfg.ConsensusConfig,
state sm.State,
blockExec *sm.BlockExecutor,
blockExec *sm.BLSBlockExecutor,
blockStore sm.BlockStore,
txNotifier txNotifier,
evpool evidencePool,
options ...BLSStateOption,
) *BLSConsensusState {
blsCS := &BLSConsensusState{}
blsCS := &BLSConsensusState{
blockExec: blockExec,
evpool: evpool.(*evidence.BLSEvidencePool),
}
blsCS.ConsensusState = ConsensusState{
config: config,
blockExec: blockExec,
blockExec: blockExec.BlockExecutor,
blockStore: blockStore,
txNotifier: txNotifier,
peerMsgQueue: make(chan msgInfo, msgQueueSize),
Expand Down Expand Up @@ -66,6 +75,7 @@ func NewBLSConsensusState(
// Don't call scheduleRound0 yet.
// We do that upon Start().
blsCS.reconstructLastCommit(state)
blsCS.evpool.SetDKGInstance(blsCS.dkg)

return blsCS
}
Expand Down Expand Up @@ -300,10 +310,13 @@ func (cs *BLSConsensusState) finalizeCommit(height int64) {
// TODO: Currently we lack a lot of relevant information about the failed node,
// TODO: including the height at which we had a misbehavior. We should address
// TODO: this as soon as possible.
if err := cs.evpool.AddEvidence(&DKGEvidenceMissingData{
pubkey: dkgLoser.PubKey,
if err := cs.evpool.AddEvidence(&state.DKGEvidenceCorruptData{
DKGEvidence: state.DKGEvidence{
Loser: dkgLoser,
ValidatorPubKey: dkgLoser.Validator.PubKey,
},
}); err != nil {
panic(fmt.Sprintf("failed to add dkg evidence for validator %s: %v", dkgLoser.Address.String(), err))
panic(fmt.Sprintf("failed to add dkg evidence for validator %s: %v", dkgLoser.Validator.String(), err))
}
}

Expand Down
143 changes: 0 additions & 143 deletions consensus/dkg_evidence.go

This file was deleted.

4 changes: 3 additions & 1 deletion consensus/reactor.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"sync"
"time"

"github.com/dgamingfoundation/tendermint/state"

"github.com/pkg/errors"

amino "github.com/tendermint/go-amino"
Expand Down Expand Up @@ -1395,7 +1397,7 @@ func RegisterConsensusMessages(cdc *amino.Codec) {
cdc.RegisterConcrete(&VoteSetMaj23Message{}, "tendermint/VoteSetMaj23", nil)
cdc.RegisterConcrete(&VoteSetBitsMessage{}, "tendermint/VoteSetBits", nil)
cdc.RegisterConcrete(&dkgtypes.DKGDataMessage{}, "tendermint/DKGData", nil)
cdc.RegisterConcrete(&DKGEvidenceMissingData{}, "tendermint/DKGEvidenceMissingData", nil)
cdc.RegisterConcrete(&state.DKGEvidenceMissingData{}, "tendermint/DKGEvidenceMissingData", nil)
}

func decodeMsg(bz []byte) (msg ConsensusMessage, err error) {
Expand Down
4 changes: 2 additions & 2 deletions consensus/wal_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@ func WALGenerateNBlocks(t *testing.T, wr io.Writer, numBlocks int) (err error) {
defer eventBus.Stop()
mempool := mock.Mempool{}
evpool := sm.MockEvidencePool{}
blockExec := sm.NewBlockExecutor(stateDB, log.TestingLogger(), proxyApp.Consensus(), mempool, evpool)

evsw := events.NewEventSwitch()
dkg := dkgOffChain.NewOffChainDKG(evsw, "localchain", dkgOffChain.WithVerifier(dkgOffChain.GetVerifier(1, 1)("wal_generator", 0)), dkgOffChain.WithLogger(logger.With("dkg")))
blockExec := sm.NewBLSBlockExecutor(stateDB, log.TestingLogger(), proxyApp.Consensus(), mempool, evpool)
blockExec.SetDKGInstance(dkg)

consensusState := NewBLSConsensusState(config.Consensus, state.Copy(), blockExec, blockStore, mempool, evpool, BLSWithDKG(dkg), BLSWithEVSW(evsw))
consensusState.SetLogger(logger)
Expand Down
63 changes: 63 additions & 0 deletions evidence/bls_pool.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package evidence

import (
dkgTypes "github.com/dgamingfoundation/dkglib/lib/types"
clist "github.com/tendermint/tendermint/libs/clist"
"github.com/tendermint/tendermint/libs/log"
sm "github.com/tendermint/tendermint/state"
"github.com/tendermint/tendermint/types"
dbm "github.com/tendermint/tm-db"
)

type BLSEvidencePool struct {
*BaseEvidencePool
dkgInstance dkgTypes.DKG
}

func NewBLSEvidencePool(stateDB, evidenceDB dbm.DB) *BLSEvidencePool {
evidenceStore := NewEvidenceStore(evidenceDB)
evpool := &BaseEvidencePool{
stateDB: stateDB,
state: sm.LoadState(stateDB),
logger: log.NewNopLogger(),
evidenceStore: evidenceStore,
evidenceList: clist.New(),
}
return &BLSEvidencePool{
BaseEvidencePool: evpool,
}
}

func (evpool *BLSEvidencePool) SetDKGInstance(dkgInstance dkgTypes.DKG) {
evpool.dkgInstance = dkgInstance
}

// AddEvidence checks the evidence is valid and adds it to the pool.
func (evpool *BLSEvidencePool) AddEvidence(evidence types.Evidence) (err error) {

// TODO: check if we already have evidence for this
// validator at this height so we dont get spammed

if err := sm.BLSVerifyEvidence(evpool.stateDB, evpool.State(), evpool.dkgInstance, evidence); err != nil {
return err
}

// fetch the validator and return its voting power as its priority
// TODO: something better ?
valset, _ := sm.LoadValidators(evpool.stateDB, evidence.Height())
_, val := valset.GetByAddress(evidence.Address())
priority := val.VotingPower

added := evpool.evidenceStore.AddNewEvidence(evidence, priority)
if !added {
// evidence already known, just ignore
return
}

evpool.logger.Info("Verified new evidence of byzantine behaviour", "evidence", evidence)

// add evidence to clist
evpool.evidenceList.PushBack(evidence)

return nil
}
Loading