Skip to content

Commit

Permalink
Merge pull request #2872 from rsksmart/add-32-byte-chainwork-support
Browse files Browse the repository at this point in the history
Add 32 byte chainwork support
  • Loading branch information
marcos-iov authored Dec 5, 2024
2 parents 7f46c0e + 3f4cde5 commit 85a9cba
Show file tree
Hide file tree
Showing 7 changed files with 2,089 additions and 180 deletions.
2 changes: 1 addition & 1 deletion rskj-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ ext {
jaxwsRtVer : '2.3.5',
picocliVer : '4.6.3',

bitcoinjThinVer: '0.14.4-rsk-16',
bitcoinjThinVer: '0.14.4-rsk-17-SNAPSHOT',
rskjNativeVer: '1.3.0',
]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@

package co.rsk.peg;

import static co.rsk.bitcoinj.core.StoredBlock.deserializeCompactLegacy;
import static co.rsk.bitcoinj.core.StoredBlock.deserializeCompactV2;

import co.rsk.bitcoinj.core.BtcBlock;
import co.rsk.bitcoinj.core.NetworkParameters;
import co.rsk.bitcoinj.core.Sha256Hash;
Expand Down Expand Up @@ -307,17 +310,36 @@ public StoredBlock getStoredBlockAtMainChainDepth(int depth) throws BlockStoreEx
}

private byte[] storedBlockToByteArray(StoredBlock block) {
ByteBuffer byteBuffer = ByteBuffer.allocate(128);
block.serializeCompact(byteBuffer);
ByteBuffer byteBuffer = serializeBlock(block);
byte[] ba = new byte[byteBuffer.position()];
byteBuffer.flip();
byteBuffer.get(ba);
return ba;
}

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.
return byteBuffer;
}

ByteBuffer byteBuffer = ByteBuffer.allocate(StoredBlock.COMPACT_SERIALIZED_SIZE_V2);
block.serializeCompactV2(byteBuffer);
return byteBuffer;
}

private boolean shouldUseLegacy12ByteChainworkFormat() {
return !activations.isActive(ConsensusRule.RSKIP454);
}

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.
}

return deserializeCompactV2(btcNetworkParams, byteBuffer);
}

private void checkIfInitialized() {
Expand Down
Loading

0 comments on commit 85a9cba

Please sign in to comment.