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

fix: masternode list sync and block reward #240

Merged
merged 5 commits into from
Dec 19, 2023
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
3 changes: 2 additions & 1 deletion core/src/main/java/org/bitcoinj/core/Block.java
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,8 @@ public static Coin getBlockInflation(NetworkParameters params, int height, long
}

// Hard fork to reduce the block reward by 10 extra percent (allowing budget/superblocks)
Coin nSuperblockPart = (nPrevHeight > params.getBudgetPaymentsStartBlock()) ? nSubsidy.div(10) : Coin.ZERO;
int treasuryPart = params.isV20Active(nPrevHeight) ? 20 : 10; // parts per 100, 20 is 20%
Coin nSuperblockPart = (nPrevHeight > params.getBudgetPaymentsStartBlock()) ? nSubsidy.multiply(treasuryPart).div(100) : Coin.ZERO;
Comment on lines +270 to +271
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 updates for the new Treasury size of 20% once v20 is active.


return fSuperblockPartOnly ? nSuperblockPart : nSubsidy.minus(nSuperblockPart);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -856,4 +856,10 @@ Sha256Hash getHashModifier(LLMQParameters llmqParams, StoredBlock quorumBaseBloc
}
return LLMQUtils.buildLLMQBlockHash(llmqParams.getType(), quorumBaseBlock.getHeader().getHash());
}

public void close() {
// reset the state of any sync operation
initChainTipSyncComplete = false;
waitingForMNListDiff = false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,22 @@ public Sha256Hash getConfirmedHashWithProRegTxHash() {
return confirmedHashWithProRegTxHash;
}

public int getType() {
return type;
}

public boolean isHPMN() {
return type == MasternodeType.HIGHPERFORMANCE.index;
}
Comment on lines +201 to +203
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 is required by Dash Wallet for Masternode APY.


public int getPlatformHTTPPort() {
return platformHTTPPort;
}

public KeyId getPlatformNodeId() {
return platformNodeId;
}

void updateConfirmedHashWithProRegTxHash() {
try {
UnsafeByteArrayOutputStream bos = new UnsafeByteArrayOutputStream(64);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -411,8 +411,8 @@ public void close() {
quorumState.removeEventListeners(blockChain.getBlockChain(), peerGroup);
quorumRotationState.removeEventListeners(blockChain.getBlockChain(), peerGroup);
// reset state of chain sync
quorumState.initChainTipSyncComplete = false;
quorumRotationState.initChainTipSyncComplete = false;
quorumState.close();
quorumRotationState.close();
Comment on lines -414 to +415
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

need to reset more of the sync state than this one value.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

One reason for "Syncing..." was that it was waiting for a reply to a message sent before the network was completely disconnected. After starting up, the wait flag was still set to true. While waiting, we don't request again.


try {
threadPool.shutdown();
Expand Down Expand Up @@ -450,12 +450,14 @@ public boolean isQuorumRotationEnabled(LLMQParameters.LLMQType type) {
return params.getLlmqDIP0024InstantSend() == type && quorumRotationActive;
}

// TODO: this needs an argument for LLMQType
public SimplifiedMasternodeList getListAtChainTip() {
return getMasternodeList();
if (quorumState.getMasternodeListAtTip() != null) {
return quorumState.getMasternodeListAtTip();
} else {
return quorumRotationState.getMnListAtH();
}
}
Comment on lines 453 to 459
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 helps fix a sync issue. When checking if mnlistdiff needs to be requested, we were actually checking the wrong list from qrinfo. Additionally in Dash Wallet, the block height used for the CrowdNode APY was from qrinfo which could be up to 12 hours old, rather than the most recent masternode list block height.


// TODO: this needs an argument for LLMQType
public SimplifiedQuorumList getQuorumListAtTip(LLMQParameters.LLMQType llmqType) {
if (!isQuorumRotationEnabled(llmqType)) {
return quorumState.quorumList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,14 @@ public void readBytesV1Test() {
byte[] smle = Utils.HEX.decode("318c32ec1598fa8f38dc76e28d15c00c20553c7020161a4c64742524a18465c39b2d789571a3b223a5365fbde69b3fe7143c4f9ebc6293afb84d340f0000000000000000000000000000ffff23a3e2204e1f08b4c1a8b9c1402ea84afe7c47f7e98d657df873b9747a0e4a497120ec62c81f314ad91a6f3384648e7e60f2734554f7f4c0fe75eec22907d6b043edb0df74ccc7b85a4500");
SimplifiedMasternodeListEntry entry = new SimplifiedMasternodeListEntry(UNITTEST, smle, 0, NetworkParameters.ProtocolVersion.BLS_LEGACY.getBitcoinProtocolVersion());
assertEquals(1, entry.version);
assertEquals(0, entry.type);
assertEquals(0, entry.getType());
assertEquals("c36584a1242574644c1a1620703c55200cc0158de276dc388ffa9815ec328c31", entry.proRegTxHash.toString());
assertEquals("000000000f344db8af9362bc9e4f3c14e73f9be6bd5f36a523b2a37195782d9b", entry.confirmedHash.toString());
assertEquals(new MasternodeAddress("35.163.226.32", 19999), entry.service);
assertEquals("yidavU3B2BUNzaUv3gW6nmV4ojLNwPeazt", Address.fromPubKeyHash(UNITTEST, entry.keyIdVoting.getBytes()).toString());
assertEquals(new BLSLazyPublicKey(UNITTEST, Utils.HEX.decode("08b4c1a8b9c1402ea84afe7c47f7e98d657df873b9747a0e4a497120ec62c81f314ad91a6f3384648e7e60f2734554f7"), 0, false), entry.pubKeyOperator);
assertFalse(entry.isValid); // this masternode is not valid
assertFalse(entry.isHPMN());
assertEquals(Sha256Hash.wrap("a7fc065ab65f453c4b57c597467f4d126188d5807f08cfab6b1f6d52e30e067e"), entry.getHash());
}

Expand All @@ -53,13 +54,15 @@ public void readBytesV2Test() {
byte[] smle = Utils.HEX.decode("0200e7aef4f585df3def44b855219ae93d6e8cc49a8c96658c5cc0813c48f5384c33e2999069d702d61d852a74b1e07d6f58101e0352d84043e866ff7946bdf5987f00000000000000000000ffff7f0000012f3197fe8172fd3207d71125a053ff32266e11110c06c1184d5be0a8118d0131d6119b138ec4d0398e7eacc5e16a75f718ed796c3a4cab668936c1f6d0945a7b97d7c0fee7cf0101002caa114755a4648d422a5caa5c915597f8c733b8e146");
SimplifiedMasternodeListEntry entry = new SimplifiedMasternodeListEntry(UNITTEST, smle, 0, NetworkParameters.ProtocolVersion.CURRENT.getBitcoinProtocolVersion());
assertEquals(2, entry.version);
assertEquals(1, entry.type);
assertEquals(1, entry.getType());
assertEquals("334c38f5483c81c05c8c65968c9ac48c6e3de99a2155b844ef3ddf85f5f4aee7", entry.proRegTxHash.toString());
assertEquals("7f98f5bd4679ff66e84340d852031e10586f7de0b1742a851dd602d7699099e2", entry.confirmedHash.toString());
assertEquals(new MasternodeAddress("127.0.0.1", 12081), entry.service);
assertEquals("yXPUGD63qih1Hzgxy7gY9LFKof2KqBf3hU", Address.fromPubKeyHash(UNITTEST, entry.keyIdVoting.getBytes()).toString());
assertEquals(new BLSLazyPublicKey(UNITTEST, Utils.HEX.decode("97fe8172fd3207d71125a053ff32266e11110c06c1184d5be0a8118d0131d6119b138ec4d0398e7eacc5e16a75f718ed"), 0, false), entry.pubKeyOperator);
assertEquals(KeyId.fromString("46e1b833c7f89755915caa5c2a428d64a4554711"), entry.platformNodeId);
assertEquals(KeyId.fromString("46e1b833c7f89755915caa5c2a428d64a4554711"), entry.getPlatformNodeId());
assertEquals(43564, entry.getPlatformHTTPPort());
assertTrue(entry.isHPMN());
assertTrue(entry.isValid);
}
}
Loading