Skip to content

Conversation

@ssd04
Copy link
Contributor

@ssd04 ssd04 commented Sep 11, 2024

Reasoning behind the pull request

  • Added proofs pool holder component
  • removed equivalent proofs for spos worker

Testing procedure

  • TBD

Pre-requisites

Based on the Contributing Guidelines the PR author and the reviewers must check the following requirements are met:

  • was the PR targeted to the correct branch?
  • if this is a larger feature that probably needs more than one PR, is there a feat branch created?
  • if this is a feat branch merging, do all satellite projects have a proper tag inside go.mod?

@ssd04 ssd04 self-assigned this Sep 11, 2024
@ssd04 ssd04 marked this pull request as ready for review September 12, 2024 13:31
@sstanculeanu sstanculeanu self-requested a review September 13, 2024 07:44
dbb.mutHeadersCache.Unlock()

aggSig, bitmap := headerHandler.GetPreviousAggregatedSignatureAndBitmap()
proof := headerHandler.GetPreviousProof()
Copy link
Collaborator

Choose a reason for hiding this comment

The 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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added TODO for this

type EquivalentProofsPool interface {
AddNotarizedProof(headerProof data.HeaderProofHandler) error
GetNotarizedProof(shardID uint32, headerHash []byte) (data.HeaderProofHandler, error)
GetAllNotarizedProofs(shardID uint32) (map[string]data.HeaderProofHandler, error)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like this is not used.. will it be needed in the future?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it was used at some point, not used anymore, it's deleted now

}

prevBlockProof := sr.Blockchain().GetCurrentHeaderProof()
prevBlockProof, err := sr.worker.GetEquivalentProof(sr.GetData())
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the worker will have all the equivalent proofs logic removed(maybe in a different PR). The proof for the prev block should be requested from the newly added equivalentProofsTracker

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kept initially the worker functions, deleted them now

func isProofEmpty(proof data.HeaderProof) bool {
return len(proof.AggregatedSignature) == 0 || len(proof.PubKeysBitmap) == 0
func isProofEmpty(proof data.HeaderProofHandler) bool {
return len(proof.GetAggregatedSignature()) == 0 || len(proof.GetPubKeysBitmap()) == 0
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would also add here a check for len of header hash

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added


proof := sr.Blockchain().GetCurrentHeaderProof()
if !isProofEmpty(proof) {
proof, err := sr.worker.GetEquivalentProof(sr.GetData())
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this can be removed completely L564-576.. reason: it should be saved into the newly added equivalentProofsTracker and this will be done from the interceptor

will be done in a further PR, maybe just save it into equivalentProofsTracker for this one

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

// NewProofsPool creates a new proofs pool component
func NewProofsPool() *proofsPool {
return &proofsPool{
cache: make(map[uint32]*proofsCache),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need to save them by shard?

a node in shard X should have proofs only for X and Meta

Copy link
Contributor Author

@ssd04 ssd04 Sep 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i've added the option to save by shardID in a more general way; indeed, currently i use the proofs only for current shard, i haven't covered the cross shard or meta yet; will analyse this for a next PR

if mp.enableEpochsHandler.IsFlagEnabledInEpoch(common.EquivalentMessagesFlag, shardHdr.GetEpoch()) {
_, shardData.PubKeysBitmap = shardHdr.GetPreviousAggregatedSignatureAndBitmap()
proof := shardHdr.GetPreviousProof()
shardData.PubKeysBitmap = proof.GetPubKeysBitmap()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check proof against nil before this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

func (hsv *HeaderSigVerifier) getPrevHeaderInfo(currentHeader data.HeaderHandler) (data.HeaderHandler, []byte, []byte, []byte, error) {
sig, bitmap := currentHeader.GetPreviousAggregatedSignatureAndBitmap()
previousProof := currentHeader.GetPreviousProof()
sig, bitmap := previousProof.GetAggregatedSignature(), previousProof.GetPubKeysBitmap()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check previousProof against nil before this

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

if vs.enableEpochsHandler.IsFlagEnabledInEpoch(common.EquivalentMessagesFlag, previousHeader.GetEpoch()) {
_, bitmap = previousHeader.GetPreviousAggregatedSignatureAndBitmap()
proof := previousHeader.GetPreviousProof()
bitmap = proof.GetPubKeysBitmap()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check proof against nil

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

)

// ProofsPoolStub -
type ProofsPoolStub struct {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rename to mock.. file as well.. can use scripts/generators/mockGenerator.sh

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

renamed

dbb.mutHeadersCache.Unlock()

aggSig, bitmap := headerHandler.GetPreviousAggregatedSignatureAndBitmap()
// TODO: should be handled from interceptor
Copy link
Contributor

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.


func isProofEmpty(proof data.HeaderProof) bool {
return len(proof.AggregatedSignature) == 0 || len(proof.PubKeysBitmap) == 0
func isProofEmpty(proof data.HeaderProofHandler) bool {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should only be an extra validation right?
I mean we only add proofs to the proof tracker if the proof is valid, so if it is already present, then it should have already been validated.

}

proof := sr.Blockchain().GetCurrentHeaderProof()
proof, err := sr.EquivalentProofsPool().GetProof(sr.ShardCoordinator().SelfId(), sr.GetData())
Copy link
Contributor

Choose a reason for hiding this comment

The 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.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indeed, should not be needed anymore


// TODO: check if this is the best approach. Perhaps we don't want to relay only on the first received message
if sr.worker.HasEquivalentMessage(sr.GetData()) {
if sr.EquivalentProofsPool().HasProof(sr.ShardCoordinator().SelfId(), sr.GetData()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need to adapt the usage of shouldSendFinalInfo, as it should not stop the leader to commit the block if the proof is already received from someone else.

Leader should not send the info, true, but should still continue to commit the block. (otherwise he will try to sync it afterwards)

if sr.EnableEpochsHandler().IsFlagEnabledInEpoch(common.EquivalentMessagesFlag, sr.Header.GetEpoch()) {
sr.worker.SetValidEquivalentProof(sr.GetData(), proof)
sr.Blockchain().SetCurrentHeaderProof(proof)
err = sr.EquivalentProofsPool().AddProof(proof)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it seems after equivalent proofs activation doEndRoundJobByLeader will be called by all nodes in consensus group, so if shouldSendFinalInfo fails (they received from someone the proof), all consensus group participants that did not send the proof will no longer finalize the block during consensus, but will try to sync it afterwards.

AggregatedSignature: cnsDta.AggregateSignature,
proof := &block.HeaderProof{
PubKeysBitmap: cnsDta.PubKeysBitmap,
AggregatedSignature: cnsDta.AggregateSignature,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The saving of the proof here maybe not always required, only if it was created by the participant, otherwise it should already be available in the proofs tracker.

shardData.PubKeysBitmap = shardHdr.GetPubKeysBitmap()
if mp.enableEpochsHandler.IsFlagEnabledInEpoch(common.EquivalentMessagesFlag, shardHdr.GetEpoch()) {
_, shardData.PubKeysBitmap = shardHdr.GetPreviousAggregatedSignatureAndBitmap()
proof := shardHdr.GetPreviousProof()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The data for a notarized shard header should be related to that shard header not the previous.
here the proof for the header should be used not the one included in the header, which is for the previous one.

Also

hasProof = len(previousAggregatedSignature) > 0 && len(previousBitmap) > 0

if len(previousBitmap) > 0 {
hasLeaderSignature = previousBitmap[0]&1 != 0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is no longer valid
with fixed ordering, the leader can have any index in the bitmap, but at the same time it is no longer needed to have its signature in the proof.

Copy link
Contributor

@AdoAdoAdo AdoAdoAdo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes can be taken on the next PR

@AdoAdoAdo AdoAdoAdo merged commit dd4e4d4 into feat/equivalent-messages Sep 19, 2024
@AdoAdoAdo AdoAdoAdo deleted the equivalent-proofs-tracker branch September 19, 2024 12:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants