aboutsummaryrefslogtreecommitdiffstats
path: root/core/syncer/consensus.go
diff options
context:
space:
mode:
authorMission Liao <mission.liao@dexon.org>2018-12-18 16:51:29 +0800
committerGitHub <noreply@github.com>2018-12-18 16:51:29 +0800
commiteaf271f8e4d16920d8575cf77c65ece2960444d0 (patch)
treef16137dc83613f306278141886a390de94f906a5 /core/syncer/consensus.go
parent9f240d93507cdf03935ba7e4e3a7b226f150736d (diff)
downloadtangerine-consensus-eaf271f8e4d16920d8575cf77c65ece2960444d0.tar
tangerine-consensus-eaf271f8e4d16920d8575cf77c65ece2960444d0.tar.gz
tangerine-consensus-eaf271f8e4d16920d8575cf77c65ece2960444d0.tar.bz2
tangerine-consensus-eaf271f8e4d16920d8575cf77c65ece2960444d0.tar.lz
tangerine-consensus-eaf271f8e4d16920d8575cf77c65ece2960444d0.tar.xz
tangerine-consensus-eaf271f8e4d16920d8575cf77c65ece2960444d0.tar.zst
tangerine-consensus-eaf271f8e4d16920d8575cf77c65ece2960444d0.zip
misc: panic not ready (#374)
* Panic when config/crs not ready For those calls to Governace.Configuration and Governance.CRS without checking returns, replace those calls with these newly added helpers: - utils.GetConfigurationWithPanic - utils.GetCRSWithPanic They would check returns, and panic directly if not ready yet. * Fix a bug that config is not ready when syncing
Diffstat (limited to 'core/syncer/consensus.go')
-rw-r--r--core/syncer/consensus.go17
1 files changed, 10 insertions, 7 deletions
diff --git a/core/syncer/consensus.go b/core/syncer/consensus.go
index eababa0..da9d352 100644
--- a/core/syncer/consensus.go
+++ b/core/syncer/consensus.go
@@ -104,7 +104,9 @@ func NewConsensus(
prv: prv,
logger: logger,
validatedChains: make(map[uint32]struct{}),
- configs: []*types.Config{gov.Configuration(0)},
+ configs: []*types.Config{
+ utils.GetConfigWithPanic(gov, 0, logger),
+ },
roundBeginTimes: []time.Time{dMoment},
receiveChan: make(chan *types.Block, 1000),
pullChan: make(chan common.Hash, 1000),
@@ -560,17 +562,18 @@ func (con *Consensus) setupConfigs(blocks []*types.Block) {
}
}
// Get configs from governance.
- untilRound := maxRound + core.ConfigRoundShift
+ //
+ // In fullnode, the notification of new round is yet another TX, which
+ // needs to be executed after corresponding block delivered. Thus, the
+ // configuration for 'maxRound + core.ConfigRoundShift' won't be ready when
+ // seeing this block.
+ untilRound := maxRound + core.ConfigRoundShift - 1
curMaxNumChains := uint32(0)
func() {
con.lock.Lock()
defer con.lock.Unlock()
for r := uint64(len(con.configs)); r <= untilRound; r++ {
- cfg := con.gov.Configuration(r)
- if cfg == nil {
- panic(fmt.Errorf(
- "unable to get config for round: %v (syncer)", r))
- }
+ cfg := utils.GetConfigWithPanic(con.gov, r, con.logger)
con.configs = append(con.configs, cfg)
con.roundBeginTimes = append(
con.roundBeginTimes,