miner: fix block number extraction for BlockSigner tx#1894
miner: fix block number extraction for BlockSigner tx#1894AnilChinchawale merged 1 commit intoXinFinOrg:dev-upgradefrom
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 |
2c64396 to
a91a0fa
Compare
Previously, the code used binary.BigEndian.Uint64(data[8:40]), which incorrectly read the index and only extracted the highest 8 bytes of the 32-byte left-padded block number, resulting in wrong values (often zero). Now, the code uses new(big.Int).SetBytes(data[4:36]).Uint64() to correctly extract the block number from the proper 32-byte field. This change fixes both the incorrect index and the parsing logic, ensuring accurate block number extraction and correct validation for special transactions.
a91a0fa to
0cc208d
Compare
There was a problem hiding this comment.
Pull request overview
This PR fixes a critical bug in block number extraction for BlockSignersBinary special transactions. The original code was reading from the wrong byte offset and only parsing the first 8 bytes of a 32-byte field, often resulting in incorrect values (typically zero). The fix correctly extracts the full 32-byte block number field and interprets it as a big-endian integer.
Key Changes:
- Corrected byte slice from
data[8:40]todata[4:36]to properly extract the 32-byte block number field - Changed parsing from
binary.BigEndian.Uint64()(8-byte read) tonew(big.Int).SetBytes().Uint64()(full 32-byte interpretation) - Removed unused
encoding/binaryimport
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Proposed changes
Previously, the code used binary.BigEndian.Uint64(data[8:40]), which incorrectly read the index and only extracted the highest 8 bytes of the 32-byte left-padded block number, resulting in wrong values (often zero). Now, the code uses new(big.Int).SetBytes(data[4:36]).Uint64() to correctly extract the block number from the proper 32-byte field. This change fixes both the incorrect index and the parsing logic, ensuring accurate block number extraction and correct validation for special transactions.
eg:
when data is
e341eaa4000000000000000000000000000000000000000000000000000000000000000f077c098bfe0729811df156252455c1debd1a8e4b7e781d8c7384ea32d15e5021old(wrong):
data[8:40]is0000000000000000000000000000000000000000000000000000000f077c098bblkNumber is 0
new(right):
data[4:36]is000000000000000000000000000000000000000000000000000000000000000fblkNumber is 15
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