aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMission Liao <mission.liao@dexon.org>2018-12-27 11:00:13 +0800
committerGitHub <noreply@github.com>2018-12-27 11:00:13 +0800
commit3ef65533cf0624adf6b09b133ff50c88fdf1303f (patch)
tree7b143301dd436456699868101b0e6787e59d2139
parent2a8254195f56cc10252753f828458b6efe222558 (diff)
downloaddexon-consensus-3ef65533cf0624adf6b09b133ff50c88fdf1303f.tar
dexon-consensus-3ef65533cf0624adf6b09b133ff50c88fdf1303f.tar.gz
dexon-consensus-3ef65533cf0624adf6b09b133ff50c88fdf1303f.tar.bz2
dexon-consensus-3ef65533cf0624adf6b09b133ff50c88fdf1303f.tar.lz
dexon-consensus-3ef65533cf0624adf6b09b133ff50c88fdf1303f.tar.xz
dexon-consensus-3ef65533cf0624adf6b09b133ff50c88fdf1303f.tar.zst
dexon-consensus-3ef65533cf0624adf6b09b133ff50c88fdf1303f.zip
Fix: consensusTimestamp panic when numChains increased at round 1(#382)
-rw-r--r--core/consensus-timestamp.go9
-rw-r--r--core/consensus-timestamp_test.go12
-rw-r--r--integration_test/consensus_test.go11
3 files changed, 29 insertions, 3 deletions
diff --git a/core/consensus-timestamp.go b/core/consensus-timestamp.go
index a1ace97..d7ce8e2 100644
--- a/core/consensus-timestamp.go
+++ b/core/consensus-timestamp.go
@@ -80,6 +80,15 @@ func (ct *consensusTimestamp) appendConfig(
if round != uint64(len(ct.numChainsOfRounds))+ct.numChainsBase {
return ErrRoundNotIncreasing
}
+ // This segment is to handle the corner case for config checking logic in
+ // processBlock method.
+ if len(ct.numChainsOfRounds) == 1 {
+ if ct.numChainsOfRounds[0] > config.NumChains {
+ ct.resizeTimetamps(ct.numChainsOfRounds[0])
+ } else {
+ ct.resizeTimetamps(config.NumChains)
+ }
+ }
ct.numChainsOfRounds = append(ct.numChainsOfRounds, config.NumChains)
return nil
}
diff --git a/core/consensus-timestamp_test.go b/core/consensus-timestamp_test.go
index bbc58a2..9d199fe 100644
--- a/core/consensus-timestamp_test.go
+++ b/core/consensus-timestamp_test.go
@@ -189,6 +189,18 @@ func (s *ConsensusTimestampTest) TestTimestampRoundInterleave() {
s.Require().NoError(err)
}
+func (s *ConsensusTimestampTest) TestNumChainsChangeAtSecondAppendedRound() {
+ now := time.Now().UTC()
+ ct := newConsensusTimestamp(now, 1, 4)
+ s.Require().NoError(ct.appendConfig(2, &types.Config{NumChains: 5}))
+ // We should be able to handle a block from the second appended round.
+ s.Require().NoError(ct.processBlocks([]*types.Block{
+ &types.Block{
+ Position: types.Position{Round: 2},
+ Timestamp: now.Add(1 * time.Second),
+ }}))
+}
+
func (s *ConsensusTimestampTest) TestTimestampSync() {
chainNum := 19
sigma := 100 * time.Millisecond
diff --git a/integration_test/consensus_test.go b/integration_test/consensus_test.go
index 23a4b3c..c68028f 100644
--- a/integration_test/consensus_test.go
+++ b/integration_test/consensus_test.go
@@ -258,19 +258,24 @@ func (s *ConsensusTestSuite) TestNumChainsChange() {
pubKeys, 100*time.Millisecond, &common.NullLogger{}, true),
core.ConfigRoundShift)
req.NoError(err)
- // Setup configuration for round 0 and round 1.
req.NoError(seedGov.State().RequestChange(
test.StateChangeRoundInterval, 45*time.Second))
+ seedGov.CatchUpWithRound(0)
+ // Setup configuration for round 0 and round 1.
+ req.NoError(seedGov.State().RequestChange(
+ test.StateChangeNumChains, uint32(5)))
+ req.NoError(seedGov.State().RequestChange(
+ test.StateChangeRoundInterval, 55*time.Second))
seedGov.CatchUpWithRound(1)
// Setup configuration for round 2.
req.NoError(seedGov.State().RequestChange(
- test.StateChangeNumChains, uint32(5)))
+ test.StateChangeNumChains, uint32(6)))
req.NoError(seedGov.State().RequestChange(
test.StateChangeRoundInterval, 55*time.Second))
seedGov.CatchUpWithRound(2)
// Setup configuration for round 3.
req.NoError(seedGov.State().RequestChange(
- test.StateChangeNumChains, uint32(6)))
+ test.StateChangeNumChains, uint32(5)))
req.NoError(seedGov.State().RequestChange(
test.StateChangeRoundInterval, 75*time.Second))
seedGov.CatchUpWithRound(3)