diff options
-rw-r--r-- | core/agreement-mgr.go | 21 | ||||
-rw-r--r-- | core/consensus.go | 5 | ||||
-rw-r--r-- | core/utils.go | 8 |
3 files changed, 23 insertions, 11 deletions
diff --git a/core/agreement-mgr.go b/core/agreement-mgr.go index a88e74a..9790452 100644 --- a/core/agreement-mgr.go +++ b/core/agreement-mgr.go @@ -106,7 +106,6 @@ type agreementMgr struct { signer *utils.Signer bcModule *blockChain ctx context.Context - initRound uint64 configs []agreementMgrConfig baModule *agreement recv *consensusBAReceiver @@ -117,7 +116,7 @@ type agreementMgr struct { lock sync.RWMutex } -func newAgreementMgr(con *Consensus, initRound uint64, +func newAgreementMgr(con *Consensus, initConfig agreementMgrConfig) (mgr *agreementMgr, err error) { mgr = &agreementMgr{ con: con, @@ -130,7 +129,6 @@ func newAgreementMgr(con *Consensus, initRound uint64, signer: con.signer, bcModule: con.bcModule, ctx: con.ctx, - initRound: initRound, processedBAResult: make(map[types.Position]struct{}, maxResultCache), configs: []agreementMgrConfig{initConfig}, voteFilter: utils.NewVoteFilter(), @@ -143,19 +141,24 @@ func newAgreementMgr(con *Consensus, initRound uint64, } mgr.recv.updateRound(uint64(0)) mgr.recv.changeNotaryHeightValue.Store(uint64(0)) + return mgr, nil +} + +func (mgr *agreementMgr) prepare() { + round := mgr.bcModule.tipRound() agr := newAgreement( mgr.ID, mgr.recv, newLeaderSelector(genValidLeader(mgr), mgr.logger), mgr.signer, mgr.logger) - // Hacky way to initialize first notarySet. - nodes, err := mgr.cache.GetNodeSet(initRound) + nodes, err := mgr.cache.GetNodeSet(round) if err != nil { return } agr.notarySet = nodes.GetSubSet( - int(initConfig.notarySetSize), types.NewNotarySetTarget(initConfig.crs)) + int(mgr.config(round).notarySetSize), + types.NewNotarySetTarget(mgr.config(round).crs)) // Hacky way to make agreement module self contained. mgr.recv.agreementModule = agr mgr.baModule = agr @@ -172,17 +175,17 @@ func (mgr *agreementMgr) run() { mgr.waitGroup.Add(1) go func() { defer mgr.waitGroup.Done() - mgr.runBA(mgr.initRound) + mgr.runBA(mgr.bcModule.tipRound()) }() } func (mgr *agreementMgr) config(round uint64) *agreementMgrConfig { mgr.lock.RLock() defer mgr.lock.RUnlock() - if round < mgr.initRound { + if round < mgr.configs[0].RoundID() { panic(ErrRoundOutOfRange) } - roundIndex := round - mgr.initRound + roundIndex := round - mgr.configs[0].RoundID() if roundIndex >= uint64(len(mgr.configs)) { return nil } diff --git a/core/consensus.go b/core/consensus.go index 4210c09..4a95eac 100644 --- a/core/consensus.go +++ b/core/consensus.go @@ -734,7 +734,7 @@ func newConsensusForRound( baConfig := agreementMgrConfig{} baConfig.from(initRound, initConfig, initCRS) baConfig.SetRoundBeginHeight(gov.GetRoundHeight(initRound)) - con.baMgr, err = newAgreementMgr(con, initRound, baConfig) + con.baMgr, err = newAgreementMgr(con, baConfig) if err != nil { panic(err) } @@ -985,6 +985,7 @@ func (con *Consensus) prepare(initBlock *types.Block) (err error) { if initBlock != nil { con.event.NotifyHeight(initBlock.Finalization.Height) } + con.baMgr.prepare() return } @@ -1334,10 +1335,12 @@ func (con *Consensus) ProcessAgreementResult( return err } if err := con.bcModule.processAgreementResult(rand); err != nil { + con.baMgr.untouchAgreementResult(rand) return err } // Syncing BA Module. if err := con.baMgr.processAgreementResult(rand); err != nil { + con.baMgr.untouchAgreementResult(rand) return err } diff --git a/core/utils.go b/core/utils.go index bd31701..0250cf2 100644 --- a/core/utils.go +++ b/core/utils.go @@ -159,6 +159,12 @@ func HashConfigurationBlock( // instance. func VerifyAgreementResult( res *types.AgreementResult, cache *utils.NodeSetCache) error { + if res.Position.Round >= DKGDelayRound { + if len(res.Randomness) == 0 { + return ErrMissingRandomness + } + return nil + } notarySet, err := cache.GetNotarySet(res.Position.Round) if err != nil { return err @@ -203,7 +209,7 @@ func VerifyAgreementResult( } voted[vote.ProposerID] = struct{}{} } - if len(voted) < len(notarySet)/3*2+1 { + if len(voted) < len(notarySet)*2/3+1 { return ErrNotEnoughVotes } return nil |