Skip to content
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

Add 32 byte chainwork support #2884

Merged
merged 8 commits into from
Dec 12, 2024

Conversation

nathanieliov
Copy link
Contributor

@nathanieliov nathanieliov commented Dec 9, 2024

Description

  • Add RSKIP454 activation
  • Bump bitcoinjThinVer version to 0.14.4-rsk-17-SNAPSHOT
  • Add the use of serializeCompactV2 method in RepositoryBtcBlockStoreWithCache
  • Add the use of deserializeCompactV2 method in RepositoryBtcBlockStoreWithCache
  • Add tests validating 32-byte chainwork checkpoints can be processed once RSKIP454 is activated

How Has This Been Tested?

Unit tests

Types of changes

  • Bug fix (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)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • Tests for the changes have been added (for bug fixes / features)
  • Requires Activation Code (Hard Fork)

@nathanieliov nathanieliov requested a review from a team as a code owner December 9, 2024 14:51
Copy link

github-actions bot commented Dec 9, 2024

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

OpenSSF Scorecard

PackageVersionScoreDetails

Scanned Manifest Files

private ByteBuffer serializeBlock(StoredBlock block) {
if (shouldUseLegacy12ByteChainworkFormat()) {
ByteBuffer byteBuffer = ByteBuffer.allocate(StoredBlock.COMPACT_SERIALIZED_SIZE_LEGACY);
block.serializeCompactLegacy(byteBuffer);

Check notice

Code scanning / CodeQL

Deprecated method or constructor invocation Note

Invoking
StoredBlock.serializeCompactLegacy
should be avoided because it has been deprecated.
private StoredBlock byteArrayToStoredBlock(byte[] ba) {
ByteBuffer byteBuffer = ByteBuffer.wrap(ba);
return StoredBlock.deserializeCompact(btcNetworkParams, byteBuffer);
if (ba.length == StoredBlock.COMPACT_SERIALIZED_SIZE_LEGACY) {
return deserializeCompactLegacy(btcNetworkParams, byteBuffer);

Check notice

Code scanning / CodeQL

Deprecated method or constructor invocation Note

Invoking
StoredBlock.deserializeCompactLegacy
should be avoided because it has been deprecated.
BridgeConstants bridgeConstants) throws IOException {
String checkpointToCreate = "/rskbitcoincheckpoints/" + bridgeConstants.getBtcParams().getId() + ".checkpoints";

Path target = Paths.get(getClass().getResource(checkpointToCreate).getPath());

Check warning

Code scanning / CodeQL

Unsafe use of getResource Warning test

The idiom getClass().getResource() is unsafe for classes that may be extended.

Path target = Paths.get(getClass().getResource(checkpointToCreate).getPath());

Path source = Paths.get(getClass().getResource("/checkpoints/" + checkpointFileName).getPath());

Check warning

Code scanning / CodeQL

Unsafe use of getResource Warning test

The idiom getClass().getResource() is unsafe for classes that may be extended.
for (BtcBlock block : checkpoints) {
storedBlock = storedBlock.build(block);
storedBlock.serializeCompact(buffer);
storedBlock.serializeCompactLegacy(buffer);

Check notice

Code scanning / CodeQL

Deprecated method or constructor invocation Note test

Invoking
StoredBlock.serializeCompactLegacy
should be avoided because it has been deprecated.

int expectedCompactSerializedSize = COMPACT_SERIALIZED_SIZE_LEGACY;
ByteBuffer byteBufferForExpectedBlock = ByteBuffer.allocate(expectedCompactSerializedSize);
storedBlock.serializeCompactLegacy(byteBufferForExpectedBlock);

Check notice

Code scanning / CodeQL

Deprecated method or constructor invocation Note test

Invoking
StoredBlock.serializeCompactLegacy
should be avoided because it has been deprecated.
private void arrangeRepositoryWithExpectedStoredBlock(StoredBlock expectedStoreBlock) {
Sha256Hash expectedHash = expectedStoreBlock.getHeader().getHash();
ByteBuffer byteBuffer = ByteBuffer.allocate(COMPACT_SERIALIZED_SIZE_LEGACY);
expectedStoreBlock.serializeCompactLegacy(byteBuffer);

Check notice

Code scanning / CodeQL

Deprecated method or constructor invocation Note test

Invoking
StoredBlock.serializeCompactLegacy
should be avoided because it has been deprecated.

private void arrangeRepositoryWithExpectedChainHead(StoredBlock expectedStoreBlock) {
ByteBuffer byteBuffer = ByteBuffer.allocate(COMPACT_SERIALIZED_SIZE_LEGACY);
expectedStoreBlock.serializeCompactLegacy(byteBuffer);

Check notice

Code scanning / CodeQL

Deprecated method or constructor invocation Note test

Invoking
StoredBlock.serializeCompactLegacy
should be avoided because it has been deprecated.

// assert
ByteBuffer byteBuffer = ByteBuffer.allocate(COMPACT_SERIALIZED_SIZE_LEGACY);
expectedStoreBlock.serializeCompactLegacy(byteBuffer);

Check notice

Code scanning / CodeQL

Deprecated method or constructor invocation Note test

Invoking
StoredBlock.serializeCompactLegacy
should be avoided because it has been deprecated.
@nathanieliov nathanieliov changed the title 32 byte chainwork support integration Add 32 byte chainwork support Dec 9, 2024
@marcos-iov marcos-iov force-pushed the 32-byte-chainwork-support-integration branch from 85a9cba to b8aff0c Compare December 12, 2024 13:11
// Just an arbitrary block
private static final String BLOCK_HEADER = "00e00820925b77c9ff4d0036aa29f3238cde12e9af9d55c34ed30200000000000000000032a9fa3e12ef87a2327b55db6a16a1227bb381db8b269d90aa3a6e38cf39665f91b47766255d0317c1b1575f";
private static final int BLOCK_HEIGHT = 849137;
private static final BtcBlock BLOCK = new BtcBlock(mainneNetworkParameters, Hex.decode(BLOCK_HEADER));

Check notice

Code scanning / CodeQL

Deprecated method or constructor invocation Note test

Invoking
BtcBlock.BtcBlock
should be avoided because it has been deprecated.
Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
B Maintainability Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

@josedahlquist josedahlquist merged commit 1cf9ad6 into master Dec 12, 2024
12 of 13 checks passed
@marcos-iov marcos-iov deleted the 32-byte-chainwork-support-integration branch December 12, 2024 15:21
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