Skip to content

Commit

Permalink
Merge pull request #2884 from rsksmart/32-byte-chainwork-support-inte…
Browse files Browse the repository at this point in the history
…gration

Add 32 byte chainwork support
  • Loading branch information
josedahlquist authored Dec 12, 2024
2 parents 7b32a15 + ab2a578 commit 1cf9ad6
Show file tree
Hide file tree
Showing 12 changed files with 2,090 additions and 182 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);
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);
}

return deserializeCompactV2(btcNetworkParams, byteBuffer);
}

private void checkIfInitialized() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ public enum ConsensusRule {
RSKIP427("rskip427"),
RSKIP428("rskip428"),
RSKIP434("rskip434"),
RSKIP438("rskip438")
RSKIP438("rskip438"),
RSKIP454("rskip454"),
;

private final String configKey;
Expand Down
1 change: 1 addition & 0 deletions rskj-core/src/main/resources/expected.conf
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ blockchain = {
rskip428 = <hardforkName>
rskip434 = <hardforkName>
rskip438 = <hardforkName>
rskip454 = <hardforkName>
}
}
gc = {
Expand Down
1 change: 1 addition & 0 deletions rskj-core/src/main/resources/reference.conf
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ blockchain = {
rskip428 = lovell700
rskip434 = arrowhead631
rskip438 = lovell700
rskip454 = lovell700
}
}
gc = {
Expand Down
Loading

0 comments on commit 1cf9ad6

Please sign in to comment.