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

Feat equivalent proofs tmp1 #6609

Draft
wants to merge 52 commits into
base: feat/equivalent-messages
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
85dca04
add proof signature check in header check
ssd04 Sep 25, 2024
712e0da
wait for confirmation block in epoch start block syncer
ssd04 Sep 25, 2024
4bddfce
fix epoch start meta block syncer tests
ssd04 Sep 25, 2024
1eae0e9
now metachain notarizez based on equivalent proofs
sstanculeanu Oct 2, 2024
4197d2b
Merge branch 'feat/equivalent-messages' into adapt_notarization
sstanculeanu Oct 3, 2024
71187d1
Merge branch 'feat/equivalent-messages' into adapt_notarization
sstanculeanu Oct 3, 2024
d398385
Merge branch 'feat/equivalent-messages' into integrate-proof-check-on…
ssd04 Oct 3, 2024
66316b2
added proofs pool in process sync
ssd04 Oct 3, 2024
225945f
integrate proofs pool in interceptors factory
ssd04 Oct 4, 2024
1cc05a0
Merge branch 'feat/equivalent-messages' into integrate-proof-check-on…
ssd04 Oct 4, 2024
c244eca
fix epoch start bootstrap process tests
ssd04 Oct 4, 2024
d2598ff
refactor to use flag activation in epoch start meta block processor
ssd04 Oct 5, 2024
d4886f4
add todo for meta block sync duplicated code
ssd04 Oct 5, 2024
58eeb1e
unit tests for flow with equivalent proofs
ssd04 Oct 7, 2024
3813ce8
process block only if there is a proof
ssd04 Oct 7, 2024
367d1d1
Merge branch 'feat/equivalent-messages' of https://github.com/multive…
sstanculeanu Oct 10, 2024
3df3761
Merge remote-tracking branch 'origin/adapt_notarization' into adapt_n…
sstanculeanu Oct 10, 2024
ed9fbba
fix comment
ssd04 Oct 14, 2024
8236823
fixes after review
sstanculeanu Oct 15, 2024
1e43a57
cleanup and adapting
AdoAdoAdo Oct 16, 2024
b8afd0c
fixes v2 EndRound subround
AdoAdoAdo Oct 16, 2024
d96462a
fixed more tests
sstanculeanu Oct 17, 2024
e970b06
Merge branch 'feat/equivalent-messages' of https://github.com/multive…
sstanculeanu Oct 17, 2024
2e1b145
fix after merge
sstanculeanu Oct 17, 2024
47f4742
fixes v2 EndRound subround
AdoAdoAdo Oct 17, 2024
f34b5cf
Merge branch 'feat/equivalent-messages' into adapt_notarization
sstanculeanu Oct 17, 2024
a5f105e
Merge branch 'feat/equivalent-messages' into refactor-v2-subround-end…
AdoAdoAdo Oct 17, 2024
6aad53b
fix tests
sstanculeanu Oct 17, 2024
4b03649
add log trace check on display
ssd04 Oct 21, 2024
33c5aaa
subround end round refactoring
AdoAdoAdo Oct 21, 2024
72431c3
refactor commit block in consensus
AdoAdoAdo Oct 21, 2024
80f1ca3
remove debug prints
ssd04 Oct 21, 2024
47746d5
Merge branch 'feat/equivalent-messages' into integrate-proof-check-on…
ssd04 Oct 21, 2024
50ba8a1
subround block fixes
sstanculeanu Oct 22, 2024
3fb045b
removed tests for after equivalent messages as they are not valid any…
sstanculeanu Oct 22, 2024
93afc4e
fix linter
sstanculeanu Oct 22, 2024
1158d33
remove one more test
sstanculeanu Oct 22, 2024
bc8fc7b
cleanup tests and adapt worker mock
AdoAdoAdo Oct 23, 2024
450d335
proper proofs verification on notarization
sstanculeanu Oct 23, 2024
12d156a
add proofs pool subscribers
ssd04 Oct 24, 2024
176e9a9
fix linter issue
ssd04 Oct 24, 2024
fd736e6
added nil check unit tests
ssd04 Oct 24, 2024
8334c57
some fixes
AdoAdoAdo Oct 28, 2024
10030d4
remove old tests
ssd04 Nov 12, 2024
81f3225
added unit tests
ssd04 Nov 13, 2024
f283bb3
add worker received proof
ssd04 Nov 13, 2024
94a2069
fix invalid signers broadcast
ssd04 Nov 13, 2024
49f67f6
small refactoring and comments
ssd04 Nov 13, 2024
f9452de
Merge branch 'subround-endround-v2-tests' into feat-equivalent-proofs…
ssd04 Nov 14, 2024
353b9ca
Merge branch 'integrate-proof-check-on-sync' into feat-equivalent-pro…
ssd04 Nov 14, 2024
965a195
temp changes and fixes
ssd04 Nov 14, 2024
d6640e1
fix missing equivalent messages flag checks
ssd04 Nov 14, 2024
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
10 changes: 10 additions & 0 deletions consensus/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,3 +208,13 @@ type EquivalentProofsPool interface {
HasProof(shardID uint32, headerHash []byte) bool
IsInterfaceNil() bool
}

// ProofHandler defines the interface for a proof handler
type ProofHandler interface {
GetPubKeysBitmap() []byte
GetAggregatedSignature() []byte
GetHeaderHash() []byte
GetHeaderEpoch() uint32
GetHeaderNonce() uint64
GetHeaderShardId() uint32
}
3 changes: 1 addition & 2 deletions consensus/spos/bls/v2/blsSubroundsFactory.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,10 +284,9 @@ func (fct *factory) generateEndRoundSubround() error {
return err
}

fct.worker.AddReceivedMessageCall(bls.MtBlockHeaderFinalInfo, subroundEndRoundObject.receivedBlockHeaderFinalInfo)
fct.worker.AddReceivedProofHandler(subroundEndRoundObject.receivedProof)
fct.worker.AddReceivedMessageCall(bls.MtInvalidSigners, subroundEndRoundObject.receivedInvalidSignersInfo)
fct.worker.AddReceivedMessageCall(bls.MtSignature, subroundEndRoundObject.receivedSignature)
fct.worker.AddReceivedHeaderHandler(subroundEndRoundObject.receivedHeader)
fct.consensusCore.Chronology().AddSubround(subroundEndRoundObject)

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

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

// ErrWrongSizeBitmap defines the error for wrong size bitmap
var ErrWrongSizeBitmap = errors.New("wrong size bitmap")

// ErrNotEnoughSignatures defines the error for not enough signatures
var ErrNotEnoughSignatures = errors.New("not enough signatures")
43 changes: 14 additions & 29 deletions consensus/spos/bls/v2/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,39 +256,19 @@
return sr.checkSignaturesValidity(bitmap)
}

// DoEndRoundJobByParticipant calls the unexported doEndRoundJobByParticipant function
func (sr *subroundEndRound) DoEndRoundJobByParticipant(cnsDta *consensus.Message) bool {
return sr.doEndRoundJobByParticipant(cnsDta)
// DoEndRoundJobByLeader calls the unexported doEndRoundJobByNode function
func (sr *subroundEndRound) DoEndRoundJobByNode() bool {
return sr.doEndRoundJobByNode()
}

// DoEndRoundJobByLeader calls the unexported doEndRoundJobByLeader function
func (sr *subroundEndRound) DoEndRoundJobByLeader() bool {
return sr.doEndRoundJobByLeader()
// CreateAndBroadcastProof calls the unexported createAndBroadcastHeaderFinalInfo function
func (sr *subroundEndRound) CreateAndBroadcastProof(signature []byte, bitmap []byte) {
sr.createAndBroadcastProof(signature, bitmap)

Check failure on line 266 in consensus/spos/bls/v2/export_test.go

View workflow job for this annotation

GitHub Actions / golangci linter

Error return value of `sr.createAndBroadcastProof` is not checked (errcheck)
}

// HaveConsensusHeaderWithFullInfo calls the unexported haveConsensusHeaderWithFullInfo function
func (sr *subroundEndRound) HaveConsensusHeaderWithFullInfo(cnsDta *consensus.Message) (bool, data.HeaderHandler) {
return sr.haveConsensusHeaderWithFullInfo(cnsDta)
}

// CreateAndBroadcastHeaderFinalInfo calls the unexported createAndBroadcastHeaderFinalInfo function
func (sr *subroundEndRound) CreateAndBroadcastHeaderFinalInfo(signature []byte, bitmap []byte, leaderSignature []byte, pk []byte) {
sr.createAndBroadcastHeaderFinalInfoForKey(signature, bitmap, leaderSignature, pk)
}

// ReceivedBlockHeaderFinalInfo calls the unexported receivedBlockHeaderFinalInfo function
func (sr *subroundEndRound) ReceivedBlockHeaderFinalInfo(cnsDta *consensus.Message) bool {
return sr.receivedBlockHeaderFinalInfo(context.Background(), cnsDta)
}

// IsBlockHeaderFinalInfoValid calls the unexported isBlockHeaderFinalInfoValid function
func (sr *subroundEndRound) IsBlockHeaderFinalInfoValid(cnsDta *consensus.Message) bool {
return sr.isBlockHeaderFinalInfoValid(cnsDta)
}

// IsConsensusHeaderReceived calls the unexported isConsensusHeaderReceived function
func (sr *subroundEndRound) IsConsensusHeaderReceived() (bool, data.HeaderHandler) {
return sr.isConsensusHeaderReceived()
// ReceivedProof calls the unexported receivedProof function
func (sr *subroundEndRound) ReceivedProof(proof consensus.ProofHandler) {
sr.receivedProof(proof)
}

// IsOutOfTime calls the unexported isOutOfTime function
Expand Down Expand Up @@ -355,3 +335,8 @@
func (sr *subroundSignature) DoSignatureJobForManagedKeys(ctx context.Context) bool {
return sr.doSignatureJobForManagedKeys(ctx)
}

// ReceivedSignature method is called when a signature is received through the signature channel
func (sr *subroundEndRound) ReceivedSignature(cnsDta *consensus.Message) bool {
return sr.receivedSignature(context.Background(), cnsDta)
}
41 changes: 12 additions & 29 deletions consensus/spos/bls/v2/subroundBlock.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import (
"github.com/multiversx/mx-chain-core-go/core"
"github.com/multiversx/mx-chain-core-go/core/check"
"github.com/multiversx/mx-chain-core-go/data"
"github.com/multiversx/mx-chain-core-go/data/block"

"github.com/multiversx/mx-chain-go/common"
"github.com/multiversx/mx-chain-go/consensus"
"github.com/multiversx/mx-chain-go/consensus/spos"
Expand Down Expand Up @@ -361,44 +359,29 @@ func (sr *subroundBlock) createHeader() (data.HeaderHandler, error) {
return hdr, nil
}

func (sr *subroundBlock) isEpochChangeBlockForEquivalentMessagesActivation(header data.HeaderHandler) bool {
isEquivalentMessagesFlagEnabledForHeader := sr.EnableEpochsHandler().IsFlagEnabledInEpoch(common.EquivalentMessagesFlag, header.GetEpoch())
isStartOfEpochBlock := header.IsStartOfEpochBlock()
isBlockInActivationEpoch := header.GetEpoch() == sr.EnableEpochsHandler().GetActivationEpoch(common.EquivalentMessagesFlag)

return isEquivalentMessagesFlagEnabledForHeader && isStartOfEpochBlock && isBlockInActivationEpoch
}

func (sr *subroundBlock) addProofOnHeader(header data.HeaderHandler) bool {
prevBlockProof, err := sr.EquivalentProofsPool().GetProof(sr.ShardCoordinator().SelfId(), sr.GetData())
if err != nil {
return false
// for the first block after activation we won't add the proof
// TODO: fix this on verifications as well
return sr.isEpochChangeBlockForEquivalentMessagesActivation(header)
}

if !isProofEmpty(prevBlockProof) {
header.SetPreviousProof(prevBlockProof)
return true
}

// this may happen in 2 cases:
// 1. on the very first block, after equivalent messages flag activation
// in this case, we set the previous proof as signature and bitmap from the previous header
// 2. current node is leader in the first block after sync
// in this case, we won't set the proof, return false and wait for the next round to receive a proof
prevBlockHeader := sr.Blockchain().GetCurrentBlockHeader()
if check.IfNil(prevBlockHeader) {
log.Debug("addProofOnHeader.GetCurrentBlockHeader, returned nil header")
return false
}

isFlagEnabledForPrevHeader := sr.EnableEpochsHandler().IsFlagEnabledInEpoch(common.EquivalentMessagesFlag, prevBlockHeader.GetEpoch())
if !isFlagEnabledForPrevHeader {
proof := &block.HeaderProof{
PubKeysBitmap: prevBlockHeader.GetSignature(),
AggregatedSignature: prevBlockHeader.GetPubKeysBitmap(),
HeaderHash: sr.Blockchain().GetCurrentBlockHeaderHash(),
HeaderEpoch: prevBlockHeader.GetEpoch(),
HeaderNonce: prevBlockHeader.GetNonce(),
HeaderShardId: prevBlockHeader.GetShardID(),
}

header.SetPreviousProof(proof)
return true
}
log.Debug("addProofOnHeader: no proof found")

log.Debug("addProofOnHeader: leader after sync, no proof for current header, will wait one round")
return false
}

Expand Down
29 changes: 0 additions & 29 deletions consensus/spos/bls/v2/subroundBlock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -554,35 +554,6 @@ func TestSubroundBlock_DoBlockJob(t *testing.T) {
assert.Equal(t, providedSignature, proof.GetAggregatedSignature())
assert.Equal(t, providedBitmap, proof.GetPubKeysBitmap())
})
t.Run("should work, equivalent messages flag not enabled", func(t *testing.T) {
t.Parallel()
container := consensusMocks.InitConsensusCore()
sr := initSubroundBlock(nil, container, &statusHandler.AppStatusHandlerStub{})

container.SetRoundHandler(&testscommon.RoundHandlerMock{
IndexCalled: func() int64 {
return 1
},
})

leader, err := sr.GetLeader()
assert.Nil(t, err)
sr.SetSelfPubKey(leader)
bpm := consensusMocks.InitBlockProcessorMock(container.Marshalizer())
container.SetBlockProcessor(bpm)
bm := &consensusMocks.BroadcastMessengerMock{
BroadcastConsensusMessageCalled: func(message *consensus.Message) error {
return nil
},
}
container.SetBroadcastMessenger(bm)
container.SetRoundHandler(&consensusMocks.RoundHandlerMock{
RoundIndex: 1,
})
r := sr.DoBlockJob()
assert.True(t, r)
assert.Equal(t, uint64(1), sr.GetHeader().GetNonce())
})
}

func TestSubroundBlock_ReceivedBlock(t *testing.T) {
Expand Down
Loading
Loading