-
Notifications
You must be signed in to change notification settings - Fork 135
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
perf(state-transition): Skip double payload verification on verified and finalized blocks #2145
base: main
Are you sure you want to change the base?
Changes from 2 commits
33f42fe
aed28ab
1e120b3
5d2cd2c
675abd4
d32eae0
73b7780
94e55ee
103be19
66a8ca1
30d5272
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 | ||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -221,6 +221,7 @@ func (h *ABCIMiddleware[ | |||||||||||||||||||||||
blk, | ||||||||||||||||||||||||
req.GetProposerAddress(), | ||||||||||||||||||||||||
req.GetTime().Add(h.minPayloadDelay), | ||||||||||||||||||||||||
true, // verify payload | ||||||||||||||||||||||||
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. 🧹 Nitpick (assertive) Consider making payload verification configurable Instead of hardcoding 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. 🧹 Nitpick (assertive) Add documentation for the payload verification parameter The addition of - true, // verify payload
+ true, // Always verify payload during proposal processing to ensure block validity 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||
) | ||||||||||||||||||||||||
blkEvent := async.NewEvent(ctx, async.BeaconBlockReceived, consensusBlk) | ||||||||||||||||||||||||
if err = h.dispatcher.Publish(blkEvent); err != nil { | ||||||||||||||||||||||||
|
@@ -346,6 +347,11 @@ func (h *ABCIMiddleware[ | |||||||||||||||||||||||
blk, | ||||||||||||||||||||||||
req.GetProposerAddress(), | ||||||||||||||||||||||||
req.GetTime().Add(h.minPayloadDelay), | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
// Finalize may be called while syncing. In such a case | ||||||||||||||||||||||||
// we can skip payload verification since block is guaranteed | ||||||||||||||||||||||||
// to have been accepted by a super majority of validators. | ||||||||||||||||||||||||
req.SyncingToHeight == req.Height, | ||||||||||||||||||||||||
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. 🧹 Nitpick (assertive) Enhance error handling for payload verification control The current implementation would benefit from explicit error handling when payload verification is skipped or fails. Consider:
This would improve observability and debugging capabilities. Also applies to: 224-224 🧹 Nitpick (assertive) Consider additional safety checks for sync detection While the current condition
This would make the sync detection more robust and aid in debugging. Example enhancement: - req.SyncingToHeight == req.Height,
+ func() bool {
+ isSyncing := req.SyncingToHeight > 0 && req.Height > 0 &&
+ req.SyncingToHeight == req.Height
+ if isSyncing {
+ h.logger.Debug("Skipping payload verification during sync",
+ "height", req.Height,
+ "syncingToHeight", req.SyncingToHeight)
+ }
+ return isSyncing
+ }(),
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. 🧹 Nitpick (assertive) LGTM! Consider extracting the sync check to a named variable The logic for skipping payload verification during syncing is correct and well-documented. However, consider extracting the comparison to a named variable for better readability. + isSyncing := req.SyncingToHeight == req.Height
// Finalize may be called while syncing. In such a case
// we can skip payload verification since block is guaranteed
// to have been accepted by a super majority of validators.
- req.SyncingToHeight == req.Height,
+ isSyncing, 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||
) | ||||||||||||||||||||||||
blkEvent := async.NewEvent( | ||||||||||||||||||||||||
ctx, | ||||||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -31,24 +31,32 @@ type ConsensusBlock[BeaconBlockT any] struct { | |||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
// some consensus data useful to build and verify the block | ||||||||||||||||||||||||||||||
*commonConsensusData | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
verifyPayload bool | ||||||||||||||||||||||||||||||
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. 🧹 Nitpick (assertive) Add documentation for the verifyPayload field Consider adding a comment explaining the purpose of this field and its relationship to payload verification during block replay. *commonConsensusData
+ // verifyPayload determines whether payload verification should be performed
+ // during block processing. This is typically false during block replay.
verifyPayload bool 📝 Committable suggestion
Suggested change
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. 🧹 Nitpick (assertive) Add documentation for the verifyPayload field Consider adding a comment explaining the purpose and usage of this field, particularly its role in controlling payload verification during block processing. *commonConsensusData
+ // verifyPayload determines whether the payload should be verified during block processing.
+ // When false, payload verification is skipped (e.g., during block replay).
verifyPayload bool 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
// New creates a new ConsensusBlock instance. | ||||||||||||||||||||||||||||||
func (b *ConsensusBlock[BeaconBlockT]) New( | ||||||||||||||||||||||||||||||
beaconBlock BeaconBlockT, | ||||||||||||||||||||||||||||||
proposerAddress []byte, | ||||||||||||||||||||||||||||||
nextPayloadTimestamp time.Time, | ||||||||||||||||||||||||||||||
verifyPayload bool, | ||||||||||||||||||||||||||||||
) *ConsensusBlock[BeaconBlockT] { | ||||||||||||||||||||||||||||||
b = &ConsensusBlock[BeaconBlockT]{ | ||||||||||||||||||||||||||||||
blk: beaconBlock, | ||||||||||||||||||||||||||||||
commonConsensusData: &commonConsensusData{ | ||||||||||||||||||||||||||||||
proposerAddress: proposerAddress, | ||||||||||||||||||||||||||||||
nextPayloadTimestamp: math.U64(nextPayloadTimestamp.Unix()), | ||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||
verifyPayload: verifyPayload, | ||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
return b | ||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
func (b *ConsensusBlock[BeaconBlockT]) GetBeaconBlock() BeaconBlockT { | ||||||||||||||||||||||||||||||
return b.blk | ||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
func (b *ConsensusBlock[BeaconBlockT]) GetVerifyPayload() bool { | ||||||||||||||||||||||||||||||
return b.verifyPayload | ||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
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. 🧹 Nitpick (assertive) Add documentation for the GetVerifyPayload method Consider adding a comment explaining the method's purpose and return value semantics. +// GetVerifyPayload returns whether payload verification should be performed during
+// block processing. A return value of false typically indicates that the block
+// is being replayed.
func (b *ConsensusBlock[BeaconBlockT]) GetVerifyPayload() bool {
return b.verifyPayload
} 📝 Committable suggestion
Suggested change
|
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.
Critical: Remove hardcoded skip of payload verification
Hardcoding
SkipPayloadVerification
totrue
with a TODO comment is concerning:Replace the hardcoded value with the intended implementation:
This change:
GetVerifyPayload
method as intended📝 Committable suggestion