aboutsummaryrefslogtreecommitdiffstats
path: root/core/agreement-mgr.go
diff options
context:
space:
mode:
authorJimmy Hu <jimmy.hu@dexon.org>2019-03-27 18:11:57 +0800
committerGitHub <noreply@github.com>2019-03-27 18:11:57 +0800
commite41fcf0bb3f5fe6d473ef2056b6143b92c65faf3 (patch)
tree42242a643d54c089fd4ddf8452d48ef5fc633c33 /core/agreement-mgr.go
parentf848ee5128563138b1757034ea7d387c77679728 (diff)
downloaddexon-consensus-e41fcf0bb3f5fe6d473ef2056b6143b92c65faf3.tar
dexon-consensus-e41fcf0bb3f5fe6d473ef2056b6143b92c65faf3.tar.gz
dexon-consensus-e41fcf0bb3f5fe6d473ef2056b6143b92c65faf3.tar.bz2
dexon-consensus-e41fcf0bb3f5fe6d473ef2056b6143b92c65faf3.tar.lz
dexon-consensus-e41fcf0bb3f5fe6d473ef2056b6143b92c65faf3.tar.xz
dexon-consensus-e41fcf0bb3f5fe6d473ef2056b6143b92c65faf3.tar.zst
dexon-consensus-e41fcf0bb3f5fe6d473ef2056b6143b92c65faf3.zip
core: fix issues (#522)
* required vote calculation * fix agreement result * core: fix initRound issue of BA
Diffstat (limited to 'core/agreement-mgr.go')
-rw-r--r--core/agreement-mgr.go21
1 files changed, 12 insertions, 9 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
}