-
Notifications
You must be signed in to change notification settings - Fork 69
consensus: skip gas limit verification for genesis block #1968
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
base: dev-upgrade
Are you sure you want to change the base?
Conversation
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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.
Pull request overview
This PR fixes a sync issue by skipping gas limit verification when processing the first block after genesis (block 1). The genesis block may have non-standard gas limit settings that would otherwise cause verification failures and prevent sync from progressing past the genesis block.
Changes:
- Added conditional logic to skip
VerifyGaslimiterrors when the parent block is the genesis block (block 0) - Applied consistently across three locations:
verifyHeader,Prepare, andFinalizefunctions
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| consensus/XDPoS/engines/engine_v2/verifyHeader.go | Added genesis block check to skip gas limit verification when parent is block 0 |
| consensus/XDPoS/engines/engine_v2/engine.go | Added genesis block checks in both Prepare and Finalize functions to skip gas limit verification when parent is block 0 |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if err != nil && parent.Number.Uint64() != 0 { // skip genesis block | ||
| return err | ||
| } | ||
|
|
Copilot
AI
Jan 20, 2026
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 line contains only whitespace. Remove the trailing whitespace for consistency with coding standards.
| // Ensure gas settings are bounded | ||
| if err := misc.VerifyGaslimit(parent.GasLimit, header.GasLimit); err != nil { | ||
| err = misc.VerifyGaslimit(parent.GasLimit, header.GasLimit) | ||
| if err != nil && parent.Number.Uint64() != 0 { // skip genesis block |
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.
parent.Number.Sign() != 0 is better than parent.Number.Uint64() != 0,
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.
Please explain why is .Sign() better, do you mean better performance?
I think parent.Number.Uint64() != 0 is more direct condition for skip (as a person would understand, I know it has no difference to the machine)
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.
Yes, Sign() has better performance than Uint64():
// Sign returns:
// - -1 if x < 0;
// - 0 if x == 0;
// - +1 if x > 0.
func (x *Int) Sign() int {
// This function is used in cryptographic operations. It must not leak
// anything but the Int's sign and bit size through side-channels. Any
// changes must be reviewed by a security expert.
if len(x.abs) == 0 {
return 0
}
if x.neg {
return -1
}
return 1
}// Uint64 returns the uint64 representation of x.
// If x cannot be represented in a uint64, the result is undefined.
func (x *Int) Uint64() uint64 {
return low64(x.abs)
}
// low64 returns the least significant 64 bits of x.
func low64(x nat) uint64 {
if len(x) == 0 {
return 0
}
v := uint64(x[0])
if _W == 32 && len(x) > 1 {
return uint64(x[1])<<32 | v
}
return v
}
Proposed changes
skip gas limit verification for genesis block, fix sync stuck at genesis block
ref: #1646, #1619
ref audit ticket: XFN-07
Types of changes
What types of changes does your code introduce to XDC network?
Put an
✅in the boxes that applyImpacted Components
Which part of the codebase this PR will touch base on,
Put an
✅in the boxes that applyChecklist
Put an
✅in the boxes once you have confirmed below actions (or provide reasons on not doing so) that