diff options
Diffstat (limited to 'core')
-rw-r--r-- | core/consensus-timestamp.go | 9 | ||||
-rw-r--r-- | core/consensus-timestamp_test.go | 12 |
2 files changed, 21 insertions, 0 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 |