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

Feat: support absinthe v20 #225

Closed
wants to merge 2 commits into from
Closed
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
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
16 changes: 10 additions & 6 deletions core/src/main/java/org/bitcoinj/core/PeerGroup.java
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ public int compare(PeerAddress a, PeerAddress b) {
try {
this.headerChain = new BlockChain(params, new MemoryBlockStore(params));
StoredBlock cursor = chain.getChainHead();
while (cursor != null) {
while (cursor != null && !cursor.getHeader().equals(params.getGenesisBlock())) {
this.headerChain.getBlockStore().put(cursor);
cursor = cursor.getPrev(chain.getBlockStore());
}
Expand Down Expand Up @@ -2555,12 +2555,16 @@ public void onSuccess(Transaction transaction) {

if(transaction.getConfidence().numBroadcastPeers() == 0) {
// TODO: this tx was sent to a single peer, should we send it again to make sure or see if there are more connections?
int sentCount = pendingTxSendCounts.get(transaction.getTxId());
Integer sentCount = pendingTxSendCounts.get(transaction.getTxId());

if(sentCount <= 2) {
log.info("resending tx {} since it was only sent to 1 peer", tx.getHash());
broadcastTransaction(tx);
} else pendingTxSendCounts.put(tx.getHash(), sentCount + MAX_ATTEMPTS);
if (sentCount != null) {
if (sentCount <= 2) {
log.info("resending tx {} since it was only sent to 1 peer", tx.getHash());
broadcastTransaction(tx);
} else {
pendingTxSendCounts.put(tx.getHash(), sentCount + MAX_ATTEMPTS);
}
}
}
pendingTxSendCounts.remove(tx.getHash());
}
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
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.UnknownHostException;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

/**
Expand All @@ -36,13 +37,19 @@ public class MasternodeSeedPeers implements PeerDiscovery {
private String[] seedAddrs;
private int pnseedIndex;

private static String[] mergeArrays(String[] array1, String[] array2) {
String[] result = Arrays.copyOf(array1, array1.length + array2.length);
System.arraycopy(array2, 0, result, array1.length, array2.length);
return result;
}

/**
* Supports finding peers by IP addresses
*
* @param params Network parameters to be used for port information.
*/
public MasternodeSeedPeers(NetworkParameters params) {
this(params.getDefaultMasternodeList(), params);
this(mergeArrays(params.getDefaultMasternodeList(), params.getDefaultHPMasternodeList()), params);
}

/**
Expand Down
43 changes: 26 additions & 17 deletions core/src/main/java/org/bitcoinj/params/AbsintheDevNetParams.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,31 @@ public class AbsintheDevNetParams extends DevNetParams {
private static final String DEVNET_NAME = "absinthe";

private static final String[] MASTERNODES = new String[]{
"34.217.90.41",
"34.219.142.157",
"54.203.57.163",
"54.189.147.138",
"35.87.141.100",
"52.24.16.52",
"18.237.105.25",
"34.219.194.54",
"35.165.169.209",
"34.219.134.212",
"54.201.12.128",
"35.88.132.125",
"54.213.67.58",
"35.166.147.71",
"35.92.129.119",
"35.91.168.157",
"54.203.248.31",
"54.244.207.116",
};

private static final String[] HP_MASTERNODES = new String[]{
"52.12.65.230",
"35.88.162.148",
"35.87.149.127",
"34.216.109.34",
"52.40.57.30",
"54.245.53.222",
"54.244.210.173",
"34.215.201.219",
"35.91.255.242",
"54.245.169.72",
"54.184.78.233",
"35.88.21.135",
"52.36.206.44",
"34.218.253.121",

};

public AbsintheDevNetParams() {
super(DEVNET_NAME, "yQaxrDEMJ7t2d4eDTugn3FY87T78j3fJX3", 20001,
MASTERNODES, true, -1);
MASTERNODES, true, 70227);
dnsSeeds = MASTERNODES;
dropPeersAfterBroadcast = false; // this network is too small
DIP0024BlockHeight = 300;
Expand Down Expand Up @@ -71,4 +75,9 @@ public static AbsintheDevNetParams get() {
public String[] getDefaultMasternodeList() {
return MASTERNODES;
}

@Override
public String[] getDefaultHPMasternodeList() {
return HP_MASTERNODES;
}
}
2 changes: 2 additions & 0 deletions core/src/main/java/org/bitcoinj/quorums/InstantSendLock.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public class InstantSendLock extends Message {
public InstantSendLock(NetworkParameters params, List<TransactionOutPoint> inputs, Sha256Hash txid, BLSLazySignature signature) {
super(params);
this.version = ISLOCK_VERSION;
this.protocolVersion = NetworkParameters.ProtocolVersion.ISDLOCK.getBitcoinProtocolVersion() - 1;
this.inputs = inputs;
this.txid = txid;
this.signature = signature;
Expand All @@ -55,6 +56,7 @@ public InstantSendLock(NetworkParameters params, List<TransactionOutPoint> input
public InstantSendLock(NetworkParameters params, List<TransactionOutPoint> inputs, Sha256Hash txid, Sha256Hash cycleHash, BLSLazySignature signature) {
this(params, inputs, txid, signature);
this.version = ISDLOCK_VERSION;
this.protocolVersion = NetworkParameters.ProtocolVersion.ISDLOCK.getBitcoinProtocolVersion();
this.cycleHash = cycleHash;
}

Expand Down
Loading