Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 441c65a

Browse files
committedDec 23, 2024
Merge branch 'fix/excess-propose-signals' into feature/fix-excess-plus-1-sec
2 parents b17d14c + a893edd commit 441c65a

File tree

7 files changed

+30
-13
lines changed

7 files changed

+30
-13
lines changed
 

‎consensus/consensus.go

+9-4
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,18 @@ const (
3333
var errLeaderPriKeyNotFound = errors.New("leader private key not found locally")
3434

3535
type Proposal struct {
36-
Type ProposalType
37-
Caller string
36+
Type ProposalType
37+
Caller string
38+
blockNum uint64
3839
}
3940

4041
// NewProposal creates a new proposal
41-
func NewProposal(t ProposalType) Proposal {
42-
return Proposal{Type: t, Caller: utils.GetCallStackInfo(2)}
42+
func NewProposal(t ProposalType, blockNum uint64) Proposal {
43+
return Proposal{
44+
Type: t,
45+
Caller: utils.GetCallStackInfo(2),
46+
blockNum: blockNum,
47+
}
4348
}
4449

4550
// ProposalType is to indicate the type of signal for new block proposal

‎consensus/consensus_service.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,7 @@ func (consensus *Consensus) updateConsensusInformation(reason string) Mode {
498498
consensus.GetLogger().Info().
499499
Str("myKey", myPubKeys.SerializeToHexStr()).
500500
Msg("[UpdateConsensusInformation] I am the New Leader")
501-
consensus.ReadySignal(NewProposal(SyncProposal), "updateConsensusInformation", "leader changed and I am the new leader")
501+
consensus.ReadySignal(NewProposal(SyncProposal, curHeader.NumberU64()+1), "updateConsensusInformation", "leader changed and I am the new leader")
502502
}()
503503
}
504504
return Normal

‎consensus/consensus_v2.go

+15-4
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ func (consensus *Consensus) _finalCommit(isLeader bool) {
292292
// No pipelining
293293
go func() {
294294
consensus.getLogger().Info().Msg("[finalCommit] sending block proposal signal")
295-
consensus.ReadySignal(NewProposal(SyncProposal), "finalCommit", "I am leader and it's the last block in epoch")
295+
consensus.ReadySignal(NewProposal(SyncProposal, block.NumberU64()+1), "finalCommit", "I am leader and it's the last block in epoch")
296296
}()
297297
} else {
298298
// pipelining
@@ -368,7 +368,7 @@ func (consensus *Consensus) StartChannel() {
368368
consensus.start = true
369369
consensus.getLogger().Info().Time("time", time.Now()).Msg("[ConsensusMainLoop] Send ReadySignal")
370370
consensus.mutex.Unlock()
371-
consensus.ReadySignal(NewProposal(SyncProposal), "StartChannel", "consensus channel is started")
371+
consensus.ReadySignal(NewProposal(SyncProposal, consensus.Blockchain().CurrentHeader().NumberU64()+1), "StartChannel", "consensus channel is started")
372372
return
373373
}
374374
consensus.mutex.Unlock()
@@ -620,12 +620,23 @@ func (consensus *Consensus) preCommitAndPropose(blk *types.Block) error {
620620
// Send signal to Node to propose the new block for consensus
621621
consensus.getLogger().Info().Msg("[preCommitAndPropose] sending block proposal signal")
622622
consensus.mutex.Unlock()
623-
consensus.ReadySignal(NewProposal(AsyncProposal), "preCommitAndPropose", "proposing new block which will wait on the full commit signatures to finish")
623+
if !consensus.isRotation(blk.Epoch()) {
624+
consensus.ReadySignal(NewProposal(AsyncProposal, blk.NumberU64()+1), "preCommitAndPropose, before rotation", "proposing new block which will wait on the full commit signatures to finish")
625+
} else {
626+
next := consensus.rotateLeader(blk.Epoch(), consensus.getLeaderPubKey())
627+
if consensus.isMyKey(next) {
628+
consensus.ReadySignal(NewProposal(AsyncProposal, blk.NumberU64()+1), "preCommitAndPropose rotation", "proposing new block which will wait on the full commit signatures to finish")
629+
}
630+
}
624631
}()
625632

626633
return nil
627634
}
628635

636+
func (consensus *Consensus) isRotation(epoch *big.Int) bool {
637+
return consensus.Blockchain().Config().IsLeaderRotationInternalValidators(epoch)
638+
}
639+
629640
func (consensus *Consensus) verifyLastCommitSig(lastCommitSig []byte, blk *types.Block) error {
630641
if len(lastCommitSig) < bls.BLSSignatureSizeInBytes {
631642
return errors.New("lastCommitSig not have enough length")
@@ -873,7 +884,7 @@ func (consensus *Consensus) setupForNewConsensus(blk *types.Block, committedMsg
873884
blockPeriod := consensus.BlockPeriod
874885
go func() {
875886
<-time.After(blockPeriod)
876-
consensus.ReadySignal(NewProposal(SyncProposal), "setupForNewConsensus", "I am the new leader")
887+
consensus.ReadySignal(NewProposal(SyncProposal, blk.NumberU64()+1), "setupForNewConsensus", "I am the new leader")
877888
}()
878889
}
879890
}

‎consensus/leader.go

+1
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,7 @@ func (consensus *Consensus) onCommit(recvMsg *FBFTMessage) {
330330
// only do early commit if it's not epoch block to avoid problems
331331
consensus.preCommitAndPropose(blockObj)
332332
}
333+
333334
consensus.transitions.finalCommit = true
334335
waitTime := 1000 * time.Millisecond
335336
maxWaitTime := time.Until(consensus.NextBlockDue) - 200*time.Millisecond

‎consensus/proposer.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func (p *Proposer) WaitForConsensusReadyV2(stopChan chan struct{}, stoppedChan c
4343
for retryCount := 0; retryCount < 3 && consensus.IsLeader(); retryCount++ {
4444
time.Sleep(SleepPeriod)
4545
utils.Logger().Info().
46-
Uint64("blockNum", consensus.Blockchain().CurrentBlock().NumberU64()+1).
46+
Uint64("blockNum", proposal.blockNum).
4747
Bool("asyncProposal", proposal.Type == AsyncProposal).
4848
Str("called", proposal.Caller).
4949
Msg("PROPOSING NEW BLOCK ------------------------------------------------")

‎consensus/view_change.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ func (consensus *Consensus) onViewChange(recvMsg *FBFTMessage) {
440440
consensus.getLogger().Error().Err(err).Msg("[onViewChange] startNewView failed")
441441
return
442442
}
443-
go consensus.ReadySignal(NewProposal(SyncProposal), "onViewChange", "quorum is achieved by mask and is view change mode and M1 payload is empty")
443+
go consensus.ReadySignal(NewProposal(SyncProposal, consensus.Blockchain().CurrentHeader().NumberU64()+1), "onViewChange", "quorum is achieved by mask and is view change mode and M1 payload is empty")
444444
return
445445
}
446446

‎internal/params/config.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -312,8 +312,8 @@ var (
312312
SlotsLimitedEpoch: EpochTBD, // epoch to enable HIP-16
313313
CrossShardXferPrecompileEpoch: big.NewInt(1),
314314
AllowlistEpoch: EpochTBD,
315-
LeaderRotationInternalValidatorsEpoch: big.NewInt(5),
316-
LeaderRotationExternalValidatorsEpoch: big.NewInt(6),
315+
LeaderRotationInternalValidatorsEpoch: big.NewInt(3),
316+
LeaderRotationExternalValidatorsEpoch: big.NewInt(3),
317317
LeaderRotationV2Epoch: EpochTBD,
318318
FeeCollectEpoch: big.NewInt(2),
319319
ValidatorCodeFixEpoch: big.NewInt(2),

0 commit comments

Comments
 (0)
Please sign in to comment.