Skip to content

Commit

Permalink
fix: support absinthe devnet v20
Browse files Browse the repository at this point in the history
* some changes are not compatible with v19.2
  • Loading branch information
HashEngineering committed Jul 29, 2023
1 parent 7c927e5 commit 5b380f4
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,7 @@ public static enum ProtocolVersion {
COINJOIN_PROTX_HASH(70226),
DMN_TYPE(70227),
SMNLE_VERSIONED(70228),
CURRENT(70228);
CURRENT(70227);

private final int bitcoinProtocol;

Expand Down
33 changes: 30 additions & 3 deletions core/src/main/java/org/bitcoinj/evolution/CoinbaseTx.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,25 @@


import org.bitcoinj.core.*;
import org.bitcoinj.crypto.BLSSignature;
import org.json.JSONObject;

import java.io.IOException;
import java.io.OutputStream;
import java.math.BigInteger;

public class CoinbaseTx extends SpecialTxPayload {
public static final int CURRENT_VERSION = 2;
public static final int CB_V19_VERSION = 2;
public static final int CB_V20_VERSION = 3;
public static final int CURRENT_VERSION = CB_V19_VERSION;
private static final int PAYLOAD_SIZE = 2 + 4 + 32 + 32;

long height;
Sha256Hash merkleRootMasternodeList;
Sha256Hash merkleRootQuorums; //v2
long bestCLHeightDiff;
BLSSignature bestCLSignature;
Coin assetLockedAmount;

public CoinbaseTx(long height, Sha256Hash merkleRootMasternodeList, Sha256Hash merkleRootQuorums) {
super(CURRENT_VERSION);
Expand All @@ -32,8 +39,15 @@ protected void parse() throws ProtocolException {
super.parse();
height = readUint32();
merkleRootMasternodeList = readHash();
if(version >= 2)
if(version >= CB_V19_VERSION) {
merkleRootQuorums = readHash();
if (version >= CB_V20_VERSION) {
bestCLHeightDiff = readVarInt();
bestCLSignature = new BLSSignature(params, payload, cursor);
cursor += bestCLSignature.getMessageSize();
assetLockedAmount = Coin.valueOf(readInt64());
}
}
length = cursor - offset;
}

Expand All @@ -42,8 +56,14 @@ protected void bitcoinSerializeToStream(OutputStream stream) throws IOException
super.bitcoinSerializeToStream(stream);
Utils.uint32ToByteStreamLE(height, stream);
stream.write(merkleRootMasternodeList.getReversedBytes());
if(version >= 2)
if(version >= CB_V19_VERSION) {
stream.write(merkleRootQuorums.getReversedBytes());
if (version >= CB_V20_VERSION) {
stream.write(new VarInt(bestCLHeightDiff).encode());
bestCLSignature.bitcoinSerialize(stream);
Utils.uint64ToByteStreamLE(BigInteger.valueOf(assetLockedAmount.getValue()), stream);
}
}
}

public int getCurrentVersion() {
Expand Down Expand Up @@ -71,6 +91,13 @@ public JSONObject toJson() {
result.append("height", height);
result.append("merkleRootMNList", merkleRootMasternodeList);
result.append("merkleRootQuorums", merkleRootQuorums);
if (version >= CB_V19_VERSION) {
result.append("merkleRootQuorums", merkleRootQuorums);
if (version >= CB_V20_VERSION) {
result.append("bestCLHeightDiff", bestCLHeightDiff);
result.append("bestCLSignature", bestCLSignature.toString());
}
}
return result;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.google.common.collect.Sets;
import org.bitcoinj.core.*;
import org.bitcoinj.crypto.BLSScheme;
import org.bitcoinj.crypto.LazyECPoint;
import org.bitcoinj.quorums.FinalCommitment;
import org.bitcoinj.store.BlockStore;
import org.bitcoinj.utils.Pair;
Expand Down Expand Up @@ -78,7 +79,7 @@ protected void parse() throws ProtocolException {
if (protocolVersion >= NetworkParameters.ProtocolVersion.BLS_SCHEME.getBitcoinProtocolVersion()) {
version = (short) readUint16();
} else {
version = CURRENT_VERSION;
version = LEGACY_BLS_VERSION;
}

int size = (int)readVarInt();
Expand All @@ -89,9 +90,12 @@ protected void parse() throws ProtocolException {

size = (int)readVarInt();
mnList = new ArrayList<SimplifiedMasternodeListEntry>(size);
int protocolVersionSMLE = version == BASIC_BLS_VERSION ?
NetworkParameters.ProtocolVersion.DMN_TYPE.getBitcoinProtocolVersion() :
NetworkParameters.ProtocolVersion.BLS_LEGACY.getBitcoinProtocolVersion();
for(int i = 0; i < size; ++i)
{
SimplifiedMasternodeListEntry mn = new SimplifiedMasternodeListEntry(params, payload, cursor, protocolVersion);
SimplifiedMasternodeListEntry mn = new SimplifiedMasternodeListEntry(params, payload, cursor, protocolVersionSMLE);
cursor += mn.getMessageSize();
mnList.add(mn);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ public SimplifiedMasternodeListEntry(NetworkParameters params, SimplifiedMastern

@Override
protected void parse() throws ProtocolException {
if (protocolVersion >= NetworkParameters.ProtocolVersion.SMNLE_VERSIONED.getBitcoinProtocolVersion()) {
version = (short) readUint16();
if (protocolVersion >= NetworkParameters.ProtocolVersion.BLS_SCHEME.getBitcoinProtocolVersion()) {
version = BASIC_BLS_VERSION;
} else {
version = LEGACY_BLS_VERSION;
}
Expand Down

0 comments on commit 5b380f4

Please sign in to comment.