Skip to content

Conversation

@wanwiset25
Copy link
Collaborator

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 apply

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation Update (if none of the other choices apply)
  • Regular KTLO or any of the maintaince work. e.g code style
  • CICD Improvement

Impacted Components

Which part of the codebase this PR will touch base on,

Put an in the boxes that apply

  • Consensus
  • Account
  • Network
  • Geth
  • Smart Contract
  • External components
  • Not sure (Please specify below)

Checklist

Put an in the boxes once you have confirmed below actions (or provide reasons on not doing so) that

  • This PR has sufficient test coverage (unit/integration test) OR I have provided reason in the PR description for not having test coverage
  • Provide an end-to-end test plan in the PR description on how to manually test it on the devnet/testnet.
  • Tested the backwards compatibility.
  • Tested with XDC nodes running this version co-exist with those running the previous version.
  • Relevant documentation has been updated as part of this PR
  • N/A

Copilot AI review requested due to automatic review settings January 20, 2026 00:05
@coderabbitai
Copy link

coderabbitai bot commented Jan 20, 2026

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

Copilot AI left a 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 VerifyGaslimit errors when the parent block is the genesis block (block 0)
  • Applied consistently across three locations: verifyHeader, Prepare, and Finalize functions

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
}

Copy link

Copilot AI Jan 20, 2026

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.

Suggested change

Copilot uses AI. Check for mistakes.
// 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
Copy link
Collaborator

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,

Copy link
Collaborator Author

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)

Copy link
Collaborator

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
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants