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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
}

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
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
Loading