Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/skip waiting 100 sign with lock free message validation #4740

Draft
wants to merge 9 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Moved spawn into finalCommit.
  • Loading branch information
Frozen committed Aug 19, 2024
commit 998a636eb07d65436b0c19ef280af9c5ea7a8213
17 changes: 16 additions & 1 deletion consensus/consensus_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,22 @@ func (consensus *Consensus) HandleMessageUpdate(ctx context.Context, peer libp2p
return nil
}

func (consensus *Consensus) finalCommit() {
// finalCommit uses locks, not suited to be called internally
func (consensus *Consensus) finalCommit(viewID uint64) {
waitTime := 1000 * time.Millisecond
maxWaitTime := time.Until(consensus.NextBlockDue) - 200*time.Millisecond
if maxWaitTime > waitTime {
waitTime = maxWaitTime
}
consensus.GetLogger().Info().Str("waitTime", waitTime.String()).
Msg("[OnCommit] Starting Grace Period")
time.Sleep(waitTime)

consensus.mutex.Lock()
defer consensus.mutex.Unlock()
if viewID != consensus.getCurBlockViewID() {
return
}
numCommits := consensus.decider.SignersCount(quorum.Commit)

consensus.getLogger().Info().
Expand Down
25 changes: 6 additions & 19 deletions consensus/leader.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package consensus

import (
"time"

"github.com/harmony-one/harmony/consensus/signature"
"github.com/harmony-one/harmony/crypto/bls"
"github.com/harmony-one/harmony/internal/common"
Expand Down Expand Up @@ -199,6 +197,7 @@ func (consensus *Consensus) onCommit(recvMsg *FBFTMessage) {
if !consensus.isRightBlockNumAndViewID(recvMsg) {
return
}
currentHeader := consensus.Blockchain().CurrentHeader()
// proceed only when the message is not received before
for _, signer := range recvMsg.SenderPubkeys {
signed := consensus.decider.ReadBallot(quorum.Commit, signer.Bytes)
Expand Down Expand Up @@ -299,23 +298,11 @@ func (consensus *Consensus) onCommit(recvMsg *FBFTMessage) {
consensus.preCommitAndPropose(blockObj)
}

go func(viewID uint64) {
waitTime := 1000 * time.Millisecond
maxWaitTime := time.Until(consensus.NextBlockDue) - 200*time.Millisecond
if maxWaitTime > waitTime {
waitTime = maxWaitTime
}
consensus.getLogger().Info().Str("waitTime", waitTime.String()).
Msg("[OnCommit] Starting Grace Period")
time.Sleep(waitTime)
logger.Info().Msg("[OnCommit] Commit Grace Period Ended")

consensus.mutex.Lock()
defer consensus.mutex.Unlock()
if viewID == consensus.getCurBlockViewID() {
consensus.finalCommit()
}
}(viewID)
if consensus.Blockchain().Config().IsOneSecond(currentHeader.Epoch()) {
go consensus.finalCommit(viewID)
} else {
go consensus.finalCommit(viewID)
}

consensus.msgSender.StopRetry(msg_pb.MessageType_PREPARED)
}
Expand Down
3 changes: 3 additions & 0 deletions core/blockchain_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -1711,6 +1711,9 @@ func (bc *BlockChainImpl) insertChain(chain types.Blocks, verifyHeaders bool) (i
if len(chain) == 0 {
return 0, nil, nil, ErrEmptyChain
}
if first := chain[0]; true {
fmt.Println(utils.GetPort(), first.ShardID(), first.Epoch().Uint64(), first.NumberU64())
}
// Do a sanity check that the provided chain is actually ordered and linked
for i := 1; i < len(chain); i++ {
if chain[i].NumberU64() != chain[i-1].NumberU64()+1 || chain[i].ParentHash() != chain[i-1].Hash() {
Expand Down
2 changes: 1 addition & 1 deletion internal/params/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ var (
MaxRateEpoch: EpochTBD,
DevnetExternalEpoch: EpochTBD,
TestnetExternalEpoch: EpochTBD,
IsOneSecondEpoch: EpochTBD,
IsOneSecondEpoch: big.NewInt(2),
}

// AllProtocolChanges ...
Expand Down