-
Notifications
You must be signed in to change notification settings - Fork 215
Equivalent proofs tracker #6456
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
Changes from all commits
11f7ffb
5d86307
bf8a938
f25d57f
541d170
a1ebf33
c52089f
ff82998
a7e735b
fe022ea
f9ea993
66d40f1
7a0e55b
631cbc8
41cf564
2a6e05b
340b17f
7095589
e292002
4354927
61cd94f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -54,27 +54,26 @@ type headerDataForValidator struct { | |
| } | ||
|
|
||
| type delayedBlockBroadcaster struct { | ||
| alarm timersScheduler | ||
| interceptorsContainer process.InterceptorsContainer | ||
| shardCoordinator sharding.Coordinator | ||
| headersSubscriber consensus.HeadersPoolSubscriber | ||
| valHeaderBroadcastData []*shared.ValidatorHeaderBroadcastData | ||
| valBroadcastData []*shared.DelayedBroadcastData | ||
| delayedBroadcastData []*shared.DelayedBroadcastData | ||
| maxDelayCacheSize uint32 | ||
| maxValidatorDelayCacheSize uint32 | ||
| mutDataForBroadcast sync.RWMutex | ||
| broadcastMiniblocksData func(mbData map[uint32][]byte, pkBytes []byte) error | ||
| broadcastTxsData func(txData map[string][][]byte, pkBytes []byte) error | ||
| broadcastHeader func(header data.HeaderHandler, pkBytes []byte) error | ||
| alarm timersScheduler | ||
| interceptorsContainer process.InterceptorsContainer | ||
| shardCoordinator sharding.Coordinator | ||
| headersSubscriber consensus.HeadersPoolSubscriber | ||
| valHeaderBroadcastData []*shared.ValidatorHeaderBroadcastData | ||
| valBroadcastData []*shared.DelayedBroadcastData | ||
| delayedBroadcastData []*shared.DelayedBroadcastData | ||
| maxDelayCacheSize uint32 | ||
| maxValidatorDelayCacheSize uint32 | ||
| mutDataForBroadcast sync.RWMutex | ||
| broadcastMiniblocksData func(mbData map[uint32][]byte, pkBytes []byte) error | ||
| broadcastTxsData func(txData map[string][][]byte, pkBytes []byte) error | ||
| broadcastHeader func(header data.HeaderHandler, pkBytes []byte) error | ||
| broadcastConsensusMessage func(message *consensus.Message) error | ||
| cacheHeaders storage.Cacher | ||
| mutHeadersCache sync.RWMutex | ||
| cacheHeaders storage.Cacher | ||
| mutHeadersCache sync.RWMutex | ||
| config config.ConsensusGradualBroadcastConfig | ||
| mutBroadcastConsensusMessage sync.RWMutex | ||
| valBroadcastConsensusMessage map[string]*consensus.Message | ||
| cacheConsensusMessages storage.Cacher | ||
|
|
||
| } | ||
|
|
||
| // NewDelayedBlockBroadcaster create a new instance of a delayed block data broadcaster | ||
|
|
@@ -103,19 +102,19 @@ func NewDelayedBlockBroadcaster(args *ArgsDelayedBlockBroadcaster) (*delayedBloc | |
| } | ||
|
|
||
| dbb := &delayedBlockBroadcaster{ | ||
| alarm: args.AlarmScheduler, | ||
| shardCoordinator: args.ShardCoordinator, | ||
| interceptorsContainer: args.InterceptorsContainer, | ||
| headersSubscriber: args.HeadersSubscriber, | ||
| valHeaderBroadcastData: make([]*shared.ValidatorHeaderBroadcastData, 0), | ||
| valBroadcastData: make([]*shared.DelayedBroadcastData, 0), | ||
| delayedBroadcastData: make([]*shared.DelayedBroadcastData, 0), | ||
| alarm: args.AlarmScheduler, | ||
| shardCoordinator: args.ShardCoordinator, | ||
| interceptorsContainer: args.InterceptorsContainer, | ||
| headersSubscriber: args.HeadersSubscriber, | ||
| valHeaderBroadcastData: make([]*shared.ValidatorHeaderBroadcastData, 0), | ||
| valBroadcastData: make([]*shared.DelayedBroadcastData, 0), | ||
| delayedBroadcastData: make([]*shared.DelayedBroadcastData, 0), | ||
| valBroadcastConsensusMessage: make(map[string]*consensus.Message, 0), | ||
| maxDelayCacheSize: args.LeaderCacheSize, | ||
| maxValidatorDelayCacheSize: args.ValidatorCacheSize, | ||
| mutDataForBroadcast: sync.RWMutex{}, | ||
| cacheHeaders: cacheHeaders, | ||
| mutHeadersCache: sync.RWMutex{}, | ||
| maxDelayCacheSize: args.LeaderCacheSize, | ||
| maxValidatorDelayCacheSize: args.ValidatorCacheSize, | ||
| mutDataForBroadcast: sync.RWMutex{}, | ||
| cacheHeaders: cacheHeaders, | ||
| mutHeadersCache: sync.RWMutex{}, | ||
| config: args.Config, | ||
| cacheConsensusMessages: cacheConsensusMessages, | ||
| } | ||
|
|
@@ -674,7 +673,15 @@ func (dbb *delayedBlockBroadcaster) interceptedHeader(_ string, headerHash []byt | |
| dbb.cacheHeaders.Put(headerHash, struct{}{}, 0) | ||
| dbb.mutHeadersCache.Unlock() | ||
|
|
||
| aggSig, bitmap := headerHandler.GetPreviousAggregatedSignatureAndBitmap() | ||
| // TODO: should be handled from interceptor | ||
| proof := headerHandler.GetPreviousProof() | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. note for further PRs(probably for myself): this method should be either called from interceptor, either the logic should be moved on the header interceptor, as the header will be broadcast on a new topic
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. added TODO for this |
||
|
|
||
| var aggSig, bitmap []byte | ||
| if proof != nil { | ||
| aggSig, bitmap = proof.GetAggregatedSignature(), proof.GetPubKeysBitmap() | ||
| } | ||
|
|
||
| // TODO: add common check for verifying proof validity | ||
| isFinalInfo := len(aggSig) > 0 && len(bitmap) > 0 | ||
| if isFinalInfo { | ||
| dbb.cacheConsensusMessages.Put(headerHash, struct{}{}, 0) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,6 +7,7 @@ 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" | ||
|
|
@@ -472,9 +473,13 @@ func (sr *subroundBlock) addProofOnHeader(header data.HeaderHandler) bool { | |
| return true | ||
| } | ||
|
|
||
| prevBlockProof := sr.Blockchain().GetCurrentHeaderProof() | ||
| prevBlockProof, err := sr.EquivalentProofsPool().GetProof(sr.ShardCoordinator().SelfId(), sr.GetData()) | ||
| if err != nil { | ||
| return false | ||
| } | ||
|
|
||
| if !isProofEmpty(prevBlockProof) { | ||
| header.SetPreviousAggregatedSignatureAndBitmap(prevBlockProof.AggregatedSignature, prevBlockProof.PubKeysBitmap) | ||
| header.SetPreviousProof(prevBlockProof) | ||
| return true | ||
| } | ||
|
|
||
|
|
@@ -491,16 +496,26 @@ func (sr *subroundBlock) addProofOnHeader(header data.HeaderHandler) bool { | |
|
|
||
| isFlagEnabledForCurrentHeader := sr.EnableEpochsHandler().IsFlagEnabledInEpoch(common.EquivalentMessagesFlag, currentHeader.GetEpoch()) | ||
| if !isFlagEnabledForCurrentHeader { | ||
| header.SetPreviousAggregatedSignatureAndBitmap(currentHeader.GetSignature(), currentHeader.GetPubKeysBitmap()) | ||
| proof := &block.HeaderProof{ | ||
| PubKeysBitmap: currentHeader.GetSignature(), | ||
| AggregatedSignature: currentHeader.GetPubKeysBitmap(), | ||
| HeaderHash: sr.Blockchain().GetCurrentBlockHeaderHash(), | ||
| HeaderEpoch: currentHeader.GetEpoch(), | ||
| HeaderNonce: currentHeader.GetNonce(), | ||
| HeaderShardId: currentHeader.GetShardID(), | ||
| } | ||
| header.SetPreviousProof(proof) | ||
| return true | ||
| } | ||
|
|
||
| log.Debug("leader after sync, no proof for current header, will wait one round") | ||
| return false | ||
| } | ||
|
|
||
| func isProofEmpty(proof data.HeaderProof) bool { | ||
| return len(proof.AggregatedSignature) == 0 || len(proof.PubKeysBitmap) == 0 | ||
| func isProofEmpty(proof data.HeaderProofHandler) bool { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this should only be an extra validation right? |
||
| return len(proof.GetAggregatedSignature()) == 0 || | ||
| len(proof.GetPubKeysBitmap()) == 0 || | ||
| len(proof.GetHeaderHash()) == 0 | ||
| } | ||
|
|
||
| // receivedBlockBodyAndHeader method is called when a block body and a block header is received | ||
|
|
@@ -587,17 +602,23 @@ func (sr *subroundBlock) saveProofForPreviousHeaderIfNeeded() { | |
| return | ||
| } | ||
|
|
||
| proof := sr.Blockchain().GetCurrentHeaderProof() | ||
| proof, err := sr.EquivalentProofsPool().GetProof(sr.ShardCoordinator().SelfId(), sr.GetData()) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think this method - saveProofForPreviousHeaderIfNeeded is required here, as it is already saved on the regular interceptor.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. indeed, should not be needed anymore |
||
| if err != nil { | ||
| log.Debug("saveProofForPreviousHeaderIfNeeded: do not set proof since it was not found") | ||
| return | ||
| } | ||
|
|
||
| if !isProofEmpty(proof) { | ||
| log.Debug("saveProofForPreviousHeaderIfNeeded: no need to set proof since it is already saved") | ||
| return | ||
| } | ||
|
|
||
| prevAggSig, prevBitmap := sr.Header.GetPreviousAggregatedSignatureAndBitmap() | ||
| proof = data.HeaderProof{ | ||
| AggregatedSignature: prevAggSig, | ||
| PubKeysBitmap: prevBitmap, | ||
| proof = sr.Header.GetPreviousProof() | ||
| err = sr.EquivalentProofsPool().AddProof(proof) | ||
| if err != nil { | ||
| log.Debug("saveProofForPreviousHeaderIfNeeded: failed to add proof, %w", err) | ||
| return | ||
| } | ||
| sr.Blockchain().SetCurrentHeaderProof(proof) | ||
| } | ||
|
|
||
| func (sr *subroundBlock) saveLeaderSignature(nodeKey []byte, signature []byte) error { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method was previously used by validators in consensus to find out if the leader propagates the block with final data on, and if not to do the propagation themselves in the predefined order.
This won't be needed anymore as the block in its final form is propagated at the beginning of the round, and if not propagated, then there is nothing to do.
So after equivalent proofs activation, this method will not be needed.