Skip to content

feat: other core 21 updates #257

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

Merged
merged 31 commits into from
Aug 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
e38ea77
chore: update checkpoints for mainnet and testnet
HashEngineering Jun 28, 2024
f2dd686
refactor: move merkle root calculation to MerkleRoot
HashEngineering Jul 6, 2024
3d4a98e
refactor: add and modify getters for SimplifiedMasternodeList
HashEngineering Jul 6, 2024
a12d1c3
refactor: use new getters from SimplifiedMasternodeList
HashEngineering Jul 6, 2024
f3209d3
chore: update seed lists for mainnet and testnet from Core 21
HashEngineering Jul 9, 2024
18a9712
refactor: improve the BLS Lazy classes
HashEngineering Jul 12, 2024
59f3ef1
refactor: improve the AbstractDiffMessage class
HashEngineering Jul 12, 2024
b21d913
refactor: make all constructors abstract in AbstractQuorumRequest
HashEngineering Jul 12, 2024
36b3b59
refactor: remove unused fields in ChainLocksHandler
HashEngineering Jul 12, 2024
a8c9fa3
refactor: add @Override and license to ChainLockSignature
HashEngineering Jul 12, 2024
d7953b6
refactor: use diamond <> for implied template parameters
HashEngineering Jul 12, 2024
2726331
refactor: remove deprecated methods in InstantSendManager
HashEngineering Jul 12, 2024
1467ffa
tests: fix and simplify some tests in DnsDiscoveryTest and ChainLocks…
HashEngineering Jul 12, 2024
e336419
refactor: make all fields private in MasternodeListDiffException
HashEngineering Jul 12, 2024
873a1a6
refactor: remove deprecated methods and simplify some getters in Quor…
HashEngineering Jul 12, 2024
2204cb1
fix: fix equals in FinalCommitment and refactor some
HashEngineering Jul 12, 2024
313b581
refactor: make one field final in GetSimplifiedMasternodeListDiff
HashEngineering Jul 12, 2024
ec3191d
refactor: remove deprecated methods and simplify getters in Simplifie…
HashEngineering Jul 12, 2024
7b25bea
refactor: make atomic fields final in QuorumUpdateRequest
HashEngineering Jul 12, 2024
887f08a
refactor: simplify some code in QuorumState
HashEngineering Jul 12, 2024
62794f8
chore: remove commented code and deprecated methods in QuorumRotation…
HashEngineering Jul 12, 2024
27ab88b
refactor: remove deprecated methods and constants and simplify Simpli…
HashEngineering Jul 12, 2024
6be4827
refactor: remove deprecated methods and constants and simplify Simpli…
HashEngineering Jul 12, 2024
711ecb1
refactor: make field final in SimplifiedMasternodeListEntry
HashEngineering Jul 12, 2024
8d498e6
refactor: use lamdas and simplify SimplifiedQuorumList
HashEngineering Jul 12, 2024
9439bb7
refactor: make constructors protected in SpecialTxPayload
HashEngineering Jul 12, 2024
b6e2633
tests: update mnlistdiff related tests
HashEngineering Jul 12, 2024
d622b2c
refactor: use <> in MasternodeMetaDataManager
HashEngineering Jul 12, 2024
2c8bd40
refactor: use <> in GovernanceObject
HashEngineering Jul 12, 2024
a559bca
refactor: make bootStrapLoaded private and add a getter
HashEngineering Jul 12, 2024
ea5dfa5
fix: log and remove a deadlock when logging a diff message using the …
HashEngineering Jul 24, 2024
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 core/src/main/java/org/bitcoinj/core/Peer.java
Original file line number Diff line number Diff line change
Expand Up @@ -1501,7 +1501,7 @@ protected void processInv(InventoryMessage inv) {
}

// The New InstantSendLock (ISLOCK)
if(context.instantSendManager != null && context.instantSendManager.isNewInstantSendEnabled() &&
if(context.instantSendManager != null && context.instantSendManager.isInstantSendEnabled() &&
context.masternodeSync != null && context.masternodeSync.hasSyncFlag(MasternodeSync.SYNC_FLAGS.SYNC_INSTANTSENDLOCKS)) {
it = instantSendLocks.iterator();
while (it.hasNext()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

import java.io.IOException;
import java.io.OutputStream;

import java.util.Arrays;

public abstract class BLSAbstractLazyObject extends Message {

Expand Down Expand Up @@ -59,4 +59,11 @@
public boolean isInitialized() {
return initialized;
}

public abstract byte[] getBuffer();

@Override
public int hashCode() {
return Arrays.hashCode(getBuffer());

Check warning on line 67 in core/src/main/java/org/bitcoinj/crypto/BLSAbstractLazyObject.java

View check run for this annotation

Codecov / codecov/patch

core/src/main/java/org/bitcoinj/crypto/BLSAbstractLazyObject.java#L67

Added line #L67 was not covered by tests
}
}
6 changes: 5 additions & 1 deletion core/src/main/java/org/bitcoinj/crypto/BLSLazyPublicKey.java
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@
if (that.isInitialized())
return Objects.equals(publicKey, that.publicKey);
else
return Objects.equals(publicKey.getBuffer(), that.buffer);
return Arrays.equals(publicKey.getBuffer(), that.buffer);

Check warning on line 139 in core/src/main/java/org/bitcoinj/crypto/BLSLazyPublicKey.java

View check run for this annotation

Codecov / codecov/patch

core/src/main/java/org/bitcoinj/crypto/BLSLazyPublicKey.java#L139

Added line #L139 was not covered by tests
} else {
if (that.isInitialized())
return Arrays.equals(buffer, that.publicKey.getBuffer());
Expand All @@ -157,4 +157,8 @@
return buffer != null;
}
}

public byte [] getBuffer() {
return buffer != null ? buffer : publicKey.getBuffer();
}
}
27 changes: 24 additions & 3 deletions core/src/main/java/org/bitcoinj/crypto/BLSLazySignature.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@

import java.io.IOException;
import java.io.OutputStream;
import java.util.Arrays;
import java.util.concurrent.locks.ReentrantLock;

public class BLSLazySignature extends BLSAbstractLazyObject {
ReentrantLock lock = Threading.lock("BLSLazySignature");
Logger log = LoggerFactory.getLogger(BLSLazySignature.class);
BLSSignature signature;
private static final Logger log = LoggerFactory.getLogger(BLSLazySignature.class);
private BLSSignature signature;

@Deprecated
public BLSLazySignature() {
Expand Down Expand Up @@ -80,6 +81,7 @@
}
}

@Deprecated
public BLSLazySignature assign(BLSLazySignature blsLazySignature) {
lock.lock();
try {
Expand Down Expand Up @@ -135,7 +137,11 @@

@Override
public String toString() {
return initialized ? signature.toString() : (buffer == null ? invalidSignature.toString() : Utils.HEX.encode(buffer));
if (initialized) {
return signature.toString();
} else {
return buffer == null ? invalidSignature.toString() : Utils.HEX.encode(buffer);
}
}

public boolean isValid() {
Expand All @@ -145,4 +151,19 @@
return buffer != null;
}
}

public byte [] getBuffer() {
return buffer != null ? buffer : signature.getBuffer();
}

@Override
public final boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof BLSLazySignature)) return false;

BLSLazySignature that = (BLSLazySignature) o;
byte[] thisBuffer = getBuffer();
byte[] thatBuffer = that.getBuffer();

Check warning on line 166 in core/src/main/java/org/bitcoinj/crypto/BLSLazySignature.java

View check run for this annotation

Codecov / codecov/patch

core/src/main/java/org/bitcoinj/crypto/BLSLazySignature.java#L164-L166

Added lines #L164 - L166 were not covered by tests
return legacy == that.legacy && Arrays.equals(thisBuffer, thatBuffer);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,23 +39,21 @@
public abstract class AbstractDiffMessage extends Message {
private static final Logger log = LoggerFactory.getLogger(AbstractDiffMessage.class);

public AbstractDiffMessage(NetworkParameters params) {
protected AbstractDiffMessage(NetworkParameters params) {
super(params);
}

public AbstractDiffMessage(NetworkParameters params, byte [] payload, int offset, int protocolVersion) {
protected AbstractDiffMessage(NetworkParameters params, byte [] payload, int offset, int protocolVersion) {
super(params, payload, offset, protocolVersion);
}

protected abstract String getShortName();

public void dump(long startHeight, long endHeight) {
if (!Utils.isAndroidRuntime() && Context.get().isDebugMode()) {
try {
File dumpFile = new File(getShortName() + "-" + params.getNetworkName() + "-" + startHeight + "-" + endHeight + ".dat");
OutputStream stream = new FileOutputStream(dumpFile);
File dumpFile = new File(getShortName() + "-" + params.getNetworkName() + "-" + startHeight + "-" + endHeight + ".dat");
try (OutputStream stream = new FileOutputStream(dumpFile)) {
stream.write(bitcoinSerialize());
stream.close();
log.info("dump successful");
} catch (FileNotFoundException x) {
log.warn("could not dump {} - file not found.", getShortName(), x);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@

public abstract class AbstractQuorumRequest extends Message {

public AbstractQuorumRequest() {
protected AbstractQuorumRequest() {
super();
}

public AbstractQuorumRequest(NetworkParameters params) {
protected AbstractQuorumRequest(NetworkParameters params) {
super(params);
}

public AbstractQuorumRequest(NetworkParameters params, byte [] payload, int offset) {
protected AbstractQuorumRequest(NetworkParameters params, byte [] payload, int offset) {
super(params, payload, offset);
}

Expand Down
26 changes: 17 additions & 9 deletions core/src/main/java/org/bitcoinj/evolution/AbstractQuorumState.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import org.bitcoinj.quorums.SimplifiedQuorumList;
import org.bitcoinj.store.BlockStoreException;
import org.bitcoinj.utils.ContextPropagatingThreadFactory;
import org.bitcoinj.utils.DebugReentrantLock;
import org.bitcoinj.utils.Threading;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -89,7 +90,8 @@
public static final int MIN_CACHE_SIZE = 1;

private static final Logger log = LoggerFactory.getLogger(AbstractQuorumState.class);
protected final ReentrantLock lock = Threading.lock("AbstractQuorumState");
// TODO: Revert to ReentrantLock with 21.0.1
protected final DebugReentrantLock lock = Threading.debugLock("AbstractQuorumState");

Context context;
DualBlockChain blockChain;
Expand Down Expand Up @@ -119,19 +121,19 @@
String bootstrapFilePath = null;
InputStream bootstrapStream = null;
int bootStrapFileFormat = 0;
public SettableFuture<Boolean> bootStrapLoaded;
private SettableFuture<Boolean> bootStrapLoaded;

boolean isLoadingBootstrap = false;
protected static Random random = new Random();

public AbstractQuorumState(Context context) {
protected AbstractQuorumState(Context context) {
super(context.getParams());
this.context = context;
initializeOnce();
initialize();
}

public AbstractQuorumState(NetworkParameters params, byte[] payload, int offset, int protocolVersion) {
protected AbstractQuorumState(NetworkParameters params, byte[] payload, int offset, int protocolVersion) {
super(params, payload, offset, protocolVersion);
initialize();
}
Expand Down Expand Up @@ -200,6 +202,10 @@
return failedAttempts > MAX_ATTEMPTS;
}

public SettableFuture<Boolean> getBootStrapLoadedFuture() {
return bootStrapLoaded;
}

abstract int getBlockHeightOffset();

public abstract int getUpdateInterval();
Expand All @@ -218,6 +224,7 @@
public abstract void requestUpdate(Peer peer, StoredBlock block);

public void retryLastUpdate(Peer peer) {
log.info("retryLastUpdate: {}", lastRequest.getRequestMessage());

Check warning on line 227 in core/src/main/java/org/bitcoinj/evolution/AbstractQuorumState.java

View check run for this annotation

Codecov / codecov/patch

core/src/main/java/org/bitcoinj/evolution/AbstractQuorumState.java#L227

Added line #L227 was not covered by tests
if (peer != null) {
peer.sendMessage(lastRequest.getRequestMessage());
} else {
Expand All @@ -231,13 +238,13 @@

public abstract SimplifiedMasternodeList getMasternodeListAtTip();

public abstract LinkedHashMap<Sha256Hash, SimplifiedMasternodeList> getMasternodeListCache();
public abstract Map<Sha256Hash, SimplifiedMasternodeList> getMasternodeListCache();

public abstract LinkedHashMap<Sha256Hash, SimplifiedQuorumList> getQuorumsCache();
public abstract Map<Sha256Hash, SimplifiedQuorumList> getQuorumsCache();

public abstract SimplifiedQuorumList getQuorumListAtTip();

public abstract ArrayList<Masternode> getAllQuorumMembers(LLMQParameters.LLMQType llmqType, Sha256Hash blockHash);
public abstract List<Masternode> getAllQuorumMembers(LLMQParameters.LLMQType llmqType, Sha256Hash blockHash);

public void resetMNList() {
resetMNList(false, true);
Expand Down Expand Up @@ -405,7 +412,8 @@
log.info("sending {} from {} to {}; \n From {}\n To {}", lastRequest.request.getClass().getSimpleName(),
getMasternodeListAtTip().getHeight(), nextBlock.getHeight(), getMasternodeListAtTip().getBlockHash(), nextBlock.getHeader().getHash());
requestUpdate(downloadPeer, nextBlock);
log.info("message = {}", lastRequest.getRequestMessage().toString(blockChain));
// This was causing a dead lock when using toString(DualBlockchain). Use toString() instead.
log.info("message = {}", lastRequest.getRequestMessage());

Check warning on line 416 in core/src/main/java/org/bitcoinj/evolution/AbstractQuorumState.java

View check run for this annotation

Codecov / codecov/patch

core/src/main/java/org/bitcoinj/evolution/AbstractQuorumState.java#L416

Added line #L416 was not covered by tests
Comment on lines -408 to +416
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was causing the stuck at 30-31%, a log.info call.

The lastRequest.getRequestMessage().toString(blockChain) was taking a long time searching through blockChain to find the block header to link a block hash to a height.

Now, we won't get the heights by calling the default toString().

waitingForMNListDiff = true;
return true;
} else {
Expand Down Expand Up @@ -741,7 +749,7 @@
try {
if (isLocked) {
downloadPeer = context.peerGroup.getDownloadPeer();
log.info("{}: lock acquired, obtaining downloadPeer from peerGroup: {}",
log.info("{}: peergroup lock acquired, obtaining downloadPeer from peerGroup: {}",

Check warning on line 752 in core/src/main/java/org/bitcoinj/evolution/AbstractQuorumState.java

View check run for this annotation

Codecov / codecov/patch

core/src/main/java/org/bitcoinj/evolution/AbstractQuorumState.java#L752

Added line #L752 was not covered by tests
Thread.currentThread().getName(), downloadPeer);
if (downloadPeer == null) {
chooseRandomDownloadPeer();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
this.blockHash = other.blockHash;
this.height = other.height;

mnMap = new HashMap<Sha256Hash, DeterministicMasternode>(other.mnMap.size());
mnMap = new HashMap<>(other.mnMap.size());

Check warning on line 27 in core/src/main/java/org/bitcoinj/evolution/DeterministicMasternodeList.java

View check run for this annotation

Codecov / codecov/patch

core/src/main/java/org/bitcoinj/evolution/DeterministicMasternodeList.java#L27

Added line #L27 was not covered by tests
for(Map.Entry<Sha256Hash, DeterministicMasternode> entry : mnMap.entrySet()) {
mnMap.put(entry.getKey(), new DeterministicMasternode(entry.getValue()));
}
Expand All @@ -35,7 +35,7 @@
blockHash = readHash();
height = (int)readUint32();
int size = (int)readVarInt();
mnMap = new HashMap<Sha256Hash, DeterministicMasternode>(size);
mnMap = new HashMap<>(size);

Check warning on line 38 in core/src/main/java/org/bitcoinj/evolution/DeterministicMasternodeList.java

View check run for this annotation

Codecov / codecov/patch

core/src/main/java/org/bitcoinj/evolution/DeterministicMasternodeList.java#L38

Added line #L38 was not covered by tests
for(int i = 0; i < size; ++i)
{
Sha256Hash hash = readHash();
Expand All @@ -45,13 +45,13 @@
}

size = (int)readVarInt();
mnUniquePropertyMap = new HashMap<Sha256Hash, Pair<Sha256Hash, Integer>>(size);
mnUniquePropertyMap = new HashMap<>(size);

Check warning on line 48 in core/src/main/java/org/bitcoinj/evolution/DeterministicMasternodeList.java

View check run for this annotation

Codecov / codecov/patch

core/src/main/java/org/bitcoinj/evolution/DeterministicMasternodeList.java#L48

Added line #L48 was not covered by tests
for(long i = 0; i < size; ++i)
{
Sha256Hash hash = readHash();
Sha256Hash first = readHash();
int second = (int)readUint32();
mnUniquePropertyMap.put(hash, new Pair<Sha256Hash, Integer>(first, second));
mnUniquePropertyMap.put(hash, new Pair<>(first, second));

Check warning on line 54 in core/src/main/java/org/bitcoinj/evolution/DeterministicMasternodeList.java

View check run for this annotation

Codecov / codecov/patch

core/src/main/java/org/bitcoinj/evolution/DeterministicMasternodeList.java#L54

Added line #L54 was not covered by tests
}
}

Expand Down Expand Up @@ -158,7 +158,7 @@
if (p.getSecond() == 1) {
mnUniquePropertyMap.remove(oldHash);
} else {
mnUniquePropertyMap.put(oldHash, new Pair<Sha256Hash, Integer>(dmn.proRegTxHash, p.getSecond() - 1));
mnUniquePropertyMap.put(oldHash, new Pair<>(dmn.proRegTxHash, p.getSecond() - 1));

Check warning on line 161 in core/src/main/java/org/bitcoinj/evolution/DeterministicMasternodeList.java

View check run for this annotation

Codecov / codecov/patch

core/src/main/java/org/bitcoinj/evolution/DeterministicMasternodeList.java#L161

Added line #L161 was not covered by tests
}
}
@Deprecated
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class GetSimplifiedMasternodeListDiff extends AbstractQuorumRequest {
Sha256Hash baseBlockHash;
Sha256Hash blockHash;

public static int MESSAGE_SIZE = 64;
public static final int MESSAGE_SIZE = 64;

public GetSimplifiedMasternodeListDiff(Sha256Hash baseBlockHash, Sha256Hash blockHash) {
super();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package org.bitcoinj.evolution;

public class MasternodeListDiffException extends Exception {
boolean requireReset;
boolean findNewPeer;
private final boolean requireReset;
private final boolean findNewPeer;

boolean sameHeight;
boolean merkleRootMismatch;
private final boolean sameHeight;
private final boolean merkleRootMismatch;
public MasternodeListDiffException(String message, boolean requireReset, boolean findNewPeer, boolean sameHeight, boolean merkleRootMismatch) {
super(message);
this.requireReset = requireReset;
Expand All @@ -25,4 +25,8 @@
public boolean hasMerkleRootMismatch() {
return merkleRootMismatch;
}

public boolean isSameHeight() {
return sameHeight;

Check warning on line 30 in core/src/main/java/org/bitcoinj/evolution/MasternodeListDiffException.java

View check run for this annotation

Codecov / codecov/patch

core/src/main/java/org/bitcoinj/evolution/MasternodeListDiffException.java#L30

Added line #L30 was not covered by tests
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package org.bitcoinj.evolution;

import org.bitcoinj.core.*;
import org.bitcoinj.governance.GovernanceObject;

import java.util.ArrayList;
import java.util.List;

public class MasternodeMetaDataManager extends AbstractManager {

Expand All @@ -19,8 +19,8 @@

}

public ArrayList<Sha256Hash> getAndClearDirtyGovernanceObjectHashes() {
return new ArrayList<Sha256Hash>();
public List<Sha256Hash> getAndClearDirtyGovernanceObjectHashes() {
return new ArrayList<>();

Check warning on line 23 in core/src/main/java/org/bitcoinj/evolution/MasternodeMetaDataManager.java

View check run for this annotation

Codecov / codecov/patch

core/src/main/java/org/bitcoinj/evolution/MasternodeMetaDataManager.java#L23

Added line #L23 was not covered by tests
}

@Override
Expand Down
Loading
Loading