Skip to content

Commit

Permalink
trigger consensus version change as validator
Browse files Browse the repository at this point in the history
  • Loading branch information
AdoAdoAdo committed Dec 19, 2024
1 parent be02d30 commit 97b9e06
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 2 deletions.
3 changes: 1 addition & 2 deletions cmd/node/config/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@

# ChainParametersByEpoch defines chain operation configurable values that can be modified based on epochs
ChainParametersByEpoch = [
{ EnableEpoch = 0, RoundDuration = 6000, ShardConsensusGroupSize = 2, ShardMinNumNodes = 2, MetachainConsensusGroupSize = 2, MetachainMinNumNodes = 2, Hysteresis = 0.2, Adaptivity = false },
{ EnableEpoch = 4, RoundDuration = 6000, ShardConsensusGroupSize = 2, ShardMinNumNodes = 2, MetachainConsensusGroupSize = 2, MetachainMinNumNodes = 2, Hysteresis = 0.2, Adaptivity = false }
{ EnableEpoch = 0, RoundDuration = 6000, ShardConsensusGroupSize = 2, ShardMinNumNodes = 2, MetachainConsensusGroupSize = 2, MetachainMinNumNodes = 2, Hysteresis = 0.2, Adaptivity = false }
]

[HardwareRequirements]
Expand Down
1 change: 1 addition & 0 deletions consensus/spos/bls/v1/blsSubroundsFactory.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ func (fct *factory) generateBlockSubround() error {
fct.worker.AddReceivedMessageCall(bls.MtBlockBodyAndHeader, subroundBlockInstance.receivedBlockBodyAndHeader)
fct.worker.AddReceivedMessageCall(bls.MtBlockBody, subroundBlockInstance.receivedBlockBody)
fct.worker.AddReceivedMessageCall(bls.MtBlockHeader, subroundBlockInstance.receivedBlockHeader)
fct.worker.AddReceivedHeaderHandler(subroundBlockInstance.receivedFullHeader)
fct.consensusCore.Chronology().AddSubround(subroundBlockInstance)

return nil
Expand Down
3 changes: 3 additions & 0 deletions consensus/spos/bls/v1/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@ import "errors"

// ErrNilSentSignatureTracker defines the error for setting a nil SentSignatureTracker
var ErrNilSentSignatureTracker = errors.New("nil sent signature tracker")

// ErrEquivalentMessagesFlagEnabledWithConsensusV1 defines the error for running with the equivalent messages flag enabled under v1 consensus
var ErrEquivalentMessagesFlagEnabledWithConsensusV1 = errors.New("equivalent messages flag enabled with consensus v1")
21 changes: 21 additions & 0 deletions consensus/spos/bls/v1/subroundBlock.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package v1

import (
"bytes"
"context"
"time"

Expand Down Expand Up @@ -334,6 +335,10 @@ func (sr *subroundBlock) createHeader() (data.HeaderHandler, error) {
return nil, err
}

if sr.EnableEpochsHandler().IsFlagEnabledInEpoch(common.EquivalentMessagesFlag, hdr.GetEpoch()) {
return nil, ErrEquivalentMessagesFlagEnabledWithConsensusV1
}

err = hdr.SetPrevHash(prevHash)
if err != nil {
return nil, err
Expand Down Expand Up @@ -491,6 +496,22 @@ func (sr *subroundBlock) receivedBlockBody(ctx context.Context, cnsDta *consensu
return blockProcessedWithSuccess
}

func (sr *subroundBlock) receivedFullHeader(headerHandler data.HeaderHandler) {
if sr.ShardCoordinator().SelfId() != headerHandler.GetShardID() {
return
}

if !sr.EnableEpochsHandler().IsFlagEnabledInEpoch(common.EquivalentMessagesFlag, headerHandler.GetEpoch()) {
return
}

lastCommittedBlockHash := sr.Blockchain().GetCurrentBlockHeaderHash()
if bytes.Compare(lastCommittedBlockHash, headerHandler.GetPrevHash()) == 0 {

Check failure on line 509 in consensus/spos/bls/v1/subroundBlock.go

View workflow job for this annotation

GitHub Actions / golangci linter

S1004: should use bytes.Equal(lastCommittedBlockHash, headerHandler.GetPrevHash()) instead (gosimple)
// Need to switch to consensus v2
sr.EpochNotifier().CheckEpoch(headerHandler)
}
}

// receivedBlockHeader method is called when a block header is received through the block header channel.
// If the block header is valid, then the validatorRoundStates map corresponding to the node which sent it,
// is set on true for the subround Block
Expand Down
3 changes: 3 additions & 0 deletions process/block/interceptedBlocks/interceptedBlockHeader.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ func (inHdr *InterceptedHeader) processFields(txBuff []byte) {

// CheckValidity checks if the received header is valid (not nil fields, valid sig and so on)
func (inHdr *InterceptedHeader) CheckValidity() error {
// TODO: remove this log after debugging
log.Debug("CheckValidity for header with", "epoch", inHdr.hdr.GetEpoch(), "hash", logger.DisplayByteSlice(inHdr.hash))

err := inHdr.integrityVerifier.Verify(inHdr.hdr)
if err != nil {
return err
Expand Down

0 comments on commit 97b9e06

Please sign in to comment.