From 7c927e58b633b6028e44159a08d98bdaaedbb886 Mon Sep 17 00:00:00 2001 From: HashEngineering Date: Sat, 29 Jul 2023 12:51:27 -0700 Subject: [PATCH 1/2] chore: upgrade protobuf-javalite to 3.17 to support M1 CPU --- .../java/org/bitcoinj/core/PeerGroup.java | 16 ++++--- .../net/discovery/MasternodeSeedPeers.java | 9 +++- .../bitcoinj/params/AbsintheDevNetParams.java | 43 +++++++++++-------- .../org/bitcoinj/quorums/InstantSendLock.java | 2 + 4 files changed, 46 insertions(+), 24 deletions(-) diff --git a/core/src/main/java/org/bitcoinj/core/PeerGroup.java b/core/src/main/java/org/bitcoinj/core/PeerGroup.java index 94939947ab..786870b777 100644 --- a/core/src/main/java/org/bitcoinj/core/PeerGroup.java +++ b/core/src/main/java/org/bitcoinj/core/PeerGroup.java @@ -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()); } @@ -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()); } diff --git a/core/src/main/java/org/bitcoinj/net/discovery/MasternodeSeedPeers.java b/core/src/main/java/org/bitcoinj/net/discovery/MasternodeSeedPeers.java index 964059b6af..8149cd7b7f 100644 --- a/core/src/main/java/org/bitcoinj/net/discovery/MasternodeSeedPeers.java +++ b/core/src/main/java/org/bitcoinj/net/discovery/MasternodeSeedPeers.java @@ -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; /** @@ -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); } /** diff --git a/core/src/main/java/org/bitcoinj/params/AbsintheDevNetParams.java b/core/src/main/java/org/bitcoinj/params/AbsintheDevNetParams.java index fbe044cb9d..336a7fa88e 100644 --- a/core/src/main/java/org/bitcoinj/params/AbsintheDevNetParams.java +++ b/core/src/main/java/org/bitcoinj/params/AbsintheDevNetParams.java @@ -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; @@ -71,4 +75,9 @@ public static AbsintheDevNetParams get() { public String[] getDefaultMasternodeList() { return MASTERNODES; } + + @Override + public String[] getDefaultHPMasternodeList() { + return HP_MASTERNODES; + } } diff --git a/core/src/main/java/org/bitcoinj/quorums/InstantSendLock.java b/core/src/main/java/org/bitcoinj/quorums/InstantSendLock.java index fe51dcce51..920cfa8805 100644 --- a/core/src/main/java/org/bitcoinj/quorums/InstantSendLock.java +++ b/core/src/main/java/org/bitcoinj/quorums/InstantSendLock.java @@ -47,6 +47,7 @@ public class InstantSendLock extends Message { public InstantSendLock(NetworkParameters params, List 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; @@ -55,6 +56,7 @@ public InstantSendLock(NetworkParameters params, List input public InstantSendLock(NetworkParameters params, List 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; } From 5b380f438cf8dfce5f8661c0bec875b1e1c337bb Mon Sep 17 00:00:00 2001 From: HashEngineering Date: Sat, 29 Jul 2023 12:51:52 -0700 Subject: [PATCH 2/2] fix: support absinthe devnet v20 * some changes are not compatible with v19.2 --- .../org/bitcoinj/core/NetworkParameters.java | 2 +- .../org/bitcoinj/evolution/CoinbaseTx.java | 33 +++++++++++++++++-- .../SimplifiedMasternodeListDiff.java | 8 +++-- .../SimplifiedMasternodeListEntry.java | 4 +-- 4 files changed, 39 insertions(+), 8 deletions(-) diff --git a/core/src/main/java/org/bitcoinj/core/NetworkParameters.java b/core/src/main/java/org/bitcoinj/core/NetworkParameters.java index d97dd568cf..3a23ae26bd 100644 --- a/core/src/main/java/org/bitcoinj/core/NetworkParameters.java +++ b/core/src/main/java/org/bitcoinj/core/NetworkParameters.java @@ -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; diff --git a/core/src/main/java/org/bitcoinj/evolution/CoinbaseTx.java b/core/src/main/java/org/bitcoinj/evolution/CoinbaseTx.java index 1ce6d26314..4e349be83a 100644 --- a/core/src/main/java/org/bitcoinj/evolution/CoinbaseTx.java +++ b/core/src/main/java/org/bitcoinj/evolution/CoinbaseTx.java @@ -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); @@ -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; } @@ -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() { @@ -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; } diff --git a/core/src/main/java/org/bitcoinj/evolution/SimplifiedMasternodeListDiff.java b/core/src/main/java/org/bitcoinj/evolution/SimplifiedMasternodeListDiff.java index 3cb0ceb735..bd300b2e8e 100644 --- a/core/src/main/java/org/bitcoinj/evolution/SimplifiedMasternodeListDiff.java +++ b/core/src/main/java/org/bitcoinj/evolution/SimplifiedMasternodeListDiff.java @@ -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; @@ -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(); @@ -89,9 +90,12 @@ protected void parse() throws ProtocolException { size = (int)readVarInt(); mnList = new ArrayList(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); } diff --git a/core/src/main/java/org/bitcoinj/evolution/SimplifiedMasternodeListEntry.java b/core/src/main/java/org/bitcoinj/evolution/SimplifiedMasternodeListEntry.java index e8ca5c0cca..c154ac2a17 100644 --- a/core/src/main/java/org/bitcoinj/evolution/SimplifiedMasternodeListEntry.java +++ b/core/src/main/java/org/bitcoinj/evolution/SimplifiedMasternodeListEntry.java @@ -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; }