Skip to content

Commit

Permalink
refactor: use new getters from SimplifiedMasternodeList
Browse files Browse the repository at this point in the history
Signed-off-by: HashEngineering <[email protected]>
  • Loading branch information
HashEngineering committed Jul 6, 2024
1 parent 0d5c8ae commit f1df0d1
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 50 deletions.
62 changes: 31 additions & 31 deletions core/src/main/java/org/bitcoinj/evolution/QuorumRotationState.java
Original file line number Diff line number Diff line change
Expand Up @@ -174,13 +174,13 @@ public void applyDiff(Peer peer, DualBlockChain blockChain,
isLoadingBootStrap ? "bootstrap" : "requested",
mnListAtH.getHeight(), newHeight, quorumRotationInfo.toString(blockChain), peer);

blockAtTip = blockChain.getBlock(quorumRotationInfo.getMnListDiffTip().blockHash);
blockAtH = blockChain.getBlock(quorumRotationInfo.getMnListDiffAtH().blockHash);
blockMinusC = blockChain.getBlock(quorumRotationInfo.getMnListDiffAtHMinusC().blockHash);
blockMinus2C = blockChain.getBlock(quorumRotationInfo.getMnListDiffAtHMinus2C().blockHash);
blockMinus3C = blockChain.getBlock(quorumRotationInfo.getMnListDiffAtHMinus3C().blockHash);
blockAtTip = blockChain.getBlock(quorumRotationInfo.getMnListDiffTip().getBlockHash());
blockAtH = blockChain.getBlock(quorumRotationInfo.getMnListDiffAtH().getBlockHash());
blockMinusC = blockChain.getBlock(quorumRotationInfo.getMnListDiffAtHMinusC().getBlockHash());
blockMinus2C = blockChain.getBlock(quorumRotationInfo.getMnListDiffAtHMinus2C().getBlockHash());
blockMinus3C = blockChain.getBlock(quorumRotationInfo.getMnListDiffAtHMinus3C().getBlockHash());
if (quorumRotationInfo.hasExtraShare()) {
blockMinus4C = blockChain.getBlock(quorumRotationInfo.getMnListDiffAtHMinus4C().blockHash);
blockMinus4C = blockChain.getBlock(quorumRotationInfo.getMnListDiffAtHMinus4C().getBlockHash());
}

// TODO: this may not be needed
Expand All @@ -190,23 +190,23 @@ public void applyDiff(Peer peer, DualBlockChain blockChain,
if (peer != null && isSyncingHeadersFirst)
peer.queueMasternodeListDownloadedListeners(MasternodeListDownloadedListener.Stage.Processing, quorumRotationInfo.getMnListDiffTip());

if (!mnListAtH.getBlockHash().equals(quorumRotationInfo.getMnListDiffAtH().blockHash)) {
if (!mnListAtH.getBlockHash().equals(quorumRotationInfo.getMnListDiffAtH().getBlockHash())) {

SimplifiedMasternodeList baseMNList;
SimplifiedMasternodeList newMNListAtHMinus4C = null;
if (quorumRotationInfo.hasExtraShare()) {
baseMNList = mnListsCache.get(quorumRotationInfo.getMnListDiffAtHMinus4C().prevBlockHash);
baseMNList = mnListsCache.get(quorumRotationInfo.getMnListDiffAtHMinus4C().getPrevBlockHash());
newMNListAtHMinus4C = baseMNList.applyDiff(quorumRotationInfo.getMnListDiffAtHMinus4C());
mnListsCache.put(newMNListAtHMinus4C.getBlockHash(), newMNListAtHMinus4C);
}

baseMNList = mnListsCache.get(quorumRotationInfo.getMnListDiffAtHMinus3C().prevBlockHash);
baseMNList = mnListsCache.get(quorumRotationInfo.getMnListDiffAtHMinus3C().getPrevBlockHash());
if (baseMNList == null)
throw new MasternodeListDiffException("does not connect to previous lists", true, false, false, false);
SimplifiedMasternodeList newMNListAtHMinus3C = baseMNList.applyDiff(quorumRotationInfo.getMnListDiffAtHMinus3C());
mnListsCache.put(newMNListAtHMinus3C.getBlockHash(), newMNListAtHMinus3C);

baseMNList = mnListsCache.get(quorumRotationInfo.getMnListDiffAtHMinus2C().prevBlockHash);
baseMNList = mnListsCache.get(quorumRotationInfo.getMnListDiffAtHMinus2C().getPrevBlockHash());
if (baseMNList == null)
throw new MasternodeListDiffException("does not connect to previous lists", true, false, false, false);
SimplifiedMasternodeList newMNListAtHMinus2C = baseMNList.applyDiff(quorumRotationInfo.getMnListDiffAtHMinus2C());
Expand All @@ -215,19 +215,19 @@ public void applyDiff(Peer peer, DualBlockChain blockChain,
// TODO: do we actually need to keep track of the blockchain tip mnlist?
// SimplifiedMasternodeList newMNListTip = mnListTip.applyDiff(quorumRotationInfo.getMnListDiffTip());
SimplifiedMasternodeList newMNListAtH = mnListAtH.applyDiff(quorumRotationInfo.getMnListDiffAtH());
baseMNList = mnListsCache.get(quorumRotationInfo.getMnListDiffAtHMinusC().prevBlockHash);
baseMNList = mnListsCache.get(quorumRotationInfo.getMnListDiffAtHMinusC().getPrevBlockHash());
if (baseMNList == null)
throw new MasternodeListDiffException("does not connect to previous lists", true, false, false, false);
StoredBlock prevBlockHMinusC = blockChain.getBlock(quorumRotationInfo.getMnListDiffAtHMinusC().prevBlockHash);
StoredBlock prevBlockHMinusC = blockChain.getBlock(quorumRotationInfo.getMnListDiffAtHMinusC().getPrevBlockHash());

if (baseMNList == null) {
log.info("mnList missing for " + quorumRotationInfo.getMnListDiffAtHMinusC().prevBlockHash + " " + (prevBlockHMinusC != null ? prevBlockHMinusC.getHeight() : -1));
log.info("mnList missing for " + quorumRotationInfo.getMnListDiffAtHMinusC().getPrevBlockHash() + " " + (prevBlockHMinusC != null ? prevBlockHMinusC.getHeight() : -1));
for (Sha256Hash hash : mnListsCache.keySet()) {
StoredBlock block = blockChain.getBlock(hash);
log.info("--> {}: {}: {}", hash, block == null ? -1 : block.getHeight(), mnListsCache.get(hash).getBlockHash());
}
}
checkNotNull(baseMNList, "mnList missing for " + quorumRotationInfo.getMnListDiffAtHMinusC().prevBlockHash + " " + (prevBlockHMinusC != null ? prevBlockHMinusC.getHeight() : -1));
checkNotNull(baseMNList, "mnList missing for " + quorumRotationInfo.getMnListDiffAtHMinusC().getPrevBlockHash() + " " + (prevBlockHMinusC != null ? prevBlockHMinusC.getHeight() : -1));

SimplifiedMasternodeList newMNListAtHMinusC = baseMNList.applyDiff(quorumRotationInfo.getMnListDiffAtHMinusC());
mnListsCache.put(newMNListAtHMinusC.getBlockHash(), newMNListAtHMinusC);
Expand All @@ -252,12 +252,12 @@ public void applyDiff(Peer peer, DualBlockChain blockChain,

// TODO: do we actually need to keep track of the blockchain tip mnlist?
// newMNListTip.setBlock(blockAtTip, blockAtTip != null && blockAtTip.getHeader().getPrevBlockHash().equals(quorumRotationInfo.getMnListDiffTip().prevBlockHash));
newMNListAtH.setBlock(blockAtH, blockAtH != null && blockAtH.getHeader().getPrevBlockHash().equals(quorumRotationInfo.getMnListDiffAtHMinusC().prevBlockHash));
newMNListAtHMinusC.setBlock(blockMinusC, blockMinusC != null && blockMinusC.getHeader().getPrevBlockHash().equals(quorumRotationInfo.getMnListDiffAtHMinusC().prevBlockHash));
newMNListAtHMinus2C.setBlock(blockMinus2C, blockMinus2C != null && blockMinus2C.getHeader().getPrevBlockHash().equals(quorumRotationInfo.getMnListDiffAtHMinus2C().prevBlockHash));
newMNListAtHMinus3C.setBlock(blockMinus3C, blockMinus3C != null && blockMinus3C.getHeader().getPrevBlockHash().equals(quorumRotationInfo.getMnListDiffAtHMinus3C().prevBlockHash));
newMNListAtH.setBlock(blockAtH, blockAtH != null && blockAtH.getHeader().getPrevBlockHash().equals(quorumRotationInfo.getMnListDiffAtHMinusC().getPrevBlockHash()));
newMNListAtHMinusC.setBlock(blockMinusC, blockMinusC != null && blockMinusC.getHeader().getPrevBlockHash().equals(quorumRotationInfo.getMnListDiffAtHMinusC().getPrevBlockHash()));
newMNListAtHMinus2C.setBlock(blockMinus2C, blockMinus2C != null && blockMinus2C.getHeader().getPrevBlockHash().equals(quorumRotationInfo.getMnListDiffAtHMinus2C().getPrevBlockHash()));
newMNListAtHMinus3C.setBlock(blockMinus3C, blockMinus3C != null && blockMinus3C.getHeader().getPrevBlockHash().equals(quorumRotationInfo.getMnListDiffAtHMinus3C().getPrevBlockHash()));
if (quorumRotationInfo.hasExtraShare()) {
newMNListAtHMinus4C.setBlock(blockMinus4C, blockMinus4C != null && blockMinus4C.getHeader().getPrevBlockHash().equals(quorumRotationInfo.getMnListDiffAtHMinus4C().prevBlockHash));
newMNListAtHMinus4C.setBlock(blockMinus4C, blockMinus4C != null && blockMinus4C.getHeader().getPrevBlockHash().equals(quorumRotationInfo.getMnListDiffAtHMinus4C().getPrevBlockHash()));
}

mnListsCache.clear();
Expand All @@ -276,8 +276,8 @@ public void applyDiff(Peer peer, DualBlockChain blockChain,
for (int i = 0; i < oldDiffs.size(); ++i) {
SimplifiedMasternodeList oldList = new SimplifiedMasternodeList(params);
oldList = oldList.applyDiff(oldDiffs.get(i));
mnListsCache.put(oldDiffs.get(i).blockHash, oldList);
quorumSnapshotCache.put(oldDiffs.get(i).blockHash, oldSnapshots.get(i));
mnListsCache.put(oldDiffs.get(i).getBlockHash(), oldList);
quorumSnapshotCache.put(oldDiffs.get(i).getBlockHash(), oldSnapshots.get(i));
}

// TODO: do we actually need to keep track of the blockchain tip mnlist?
Expand Down Expand Up @@ -306,21 +306,21 @@ public void applyDiff(Peer peer, DualBlockChain blockChain,
SimplifiedQuorumList newQuorumListAtHMinus4C = new SimplifiedQuorumList(params);

if (quorumRotationInfo.hasExtraShare()) {
baseQuorumList = quorumsCache.get(quorumRotationInfo.getMnListDiffAtHMinus4C().prevBlockHash);
baseQuorumList = quorumsCache.get(quorumRotationInfo.getMnListDiffAtHMinus4C().getPrevBlockHash());
if (baseQuorumList != null)
newQuorumListAtHMinus4C = baseQuorumList.applyDiff(quorumRotationInfo.getMnListDiffAtHMinus4C(), isLoadingBootStrap, blockChain, true, false);
}

baseQuorumList = quorumsCache.get(quorumRotationInfo.getMnListDiffAtHMinus3C().prevBlockHash);
baseQuorumList = quorumsCache.get(quorumRotationInfo.getMnListDiffAtHMinus3C().getPrevBlockHash());
SimplifiedQuorumList newQuorumListAtHMinus3C = baseQuorumList.applyDiff(quorumRotationInfo.getMnListDiffAtHMinus3C(), isLoadingBootStrap, blockChain, true, false);

baseQuorumList = quorumsCache.get(quorumRotationInfo.getMnListDiffAtHMinus2C().prevBlockHash);
baseQuorumList = quorumsCache.get(quorumRotationInfo.getMnListDiffAtHMinus2C().getPrevBlockHash());
SimplifiedQuorumList newQuorumListAtHMinus2C = baseQuorumList.applyDiff(quorumRotationInfo.getMnListDiffAtHMinus2C(), isLoadingBootStrap, blockChain, true, false);

baseQuorumList = quorumsCache.get(quorumRotationInfo.getMnListDiffAtHMinusC().prevBlockHash);
baseQuorumList = quorumsCache.get(quorumRotationInfo.getMnListDiffAtHMinusC().getPrevBlockHash());
SimplifiedQuorumList newQuorumListAtHMinusC = baseQuorumList.applyDiff(quorumRotationInfo.getMnListDiffAtHMinusC(), isLoadingBootStrap, blockChain, true, false);

baseQuorumList = quorumsCache.get(quorumRotationInfo.getMnListDiffAtH().prevBlockHash);
baseQuorumList = quorumsCache.get(quorumRotationInfo.getMnListDiffAtH().getPrevBlockHash());
SimplifiedQuorumList newQuorumListAtH = baseQuorumList.applyDiff(quorumRotationInfo.getMnListDiffAtH(), isLoadingBootStrap, blockChain, true, false);

if (context.masternodeSync.hasVerifyFlag(MasternodeSync.VERIFY_FLAGS.MNLISTDIFF_QUORUM)) {
Expand Down Expand Up @@ -1268,10 +1268,10 @@ public void processDiff(@Nullable Peer peer, QuorumRotationInfo quorumRotationIn
log.info(toString());
} catch (MasternodeListDiffException x) {
//we already have this qrinfo or doesn't match our current tipBlockHash
if (mnListAtH.getBlockHash().equals(quorumRotationInfo.getMnListDiffAtH().blockHash)) {
if (mnListAtH.getBlockHash().equals(quorumRotationInfo.getMnListDiffAtH().getBlockHash())) {
log.info("heights are the same: " + x.getMessage(), x);
log.info("mnList = {} vs qrinfo {}", mnListTip.getBlockHash(), quorumRotationInfo.getMnListDiffTip().prevBlockHash);
log.info("mnlistdiff {} -> {}", quorumRotationInfo.getMnListDiffTip().prevBlockHash, quorumRotationInfo.getMnListDiffTip().blockHash);
log.info("mnList = {} vs qrinfo {}", mnListTip.getBlockHash(), quorumRotationInfo.getMnListDiffTip().getPrevBlockHash());
log.info("mnlistdiff {} -> {}", quorumRotationInfo.getMnListDiffTip().getPrevBlockHash(), quorumRotationInfo.getMnListDiffTip().getBlockHash());
log.info("lastRequest: {} -> {}", lastRequest.request.getBaseBlockHashes(), lastRequest.request.getBlockRequestHash());
// remove this block from the list
if (!pendingBlocks.isEmpty()) {
Expand All @@ -1281,8 +1281,8 @@ public void processDiff(@Nullable Peer peer, QuorumRotationInfo quorumRotationIn
log.info("heights are different", x);
log.info("qrinfo height = {}; mnListAtTip: {}; mnListAtH: {}; quorumListAtH: {}", newHeight, getMnListTip().getHeight(),
getMnListAtH().getHeight(), getQuorumListAtTip().getHeight());
log.info("mnList = {} vs qrinfo = {}", mnListTip.getBlockHash(), quorumRotationInfo.getMnListDiffTip().prevBlockHash);
log.info("qrinfo {} -> {}", quorumRotationInfo.getMnListDiffTip().prevBlockHash, quorumRotationInfo.getMnListDiffTip().blockHash);
log.info("mnList = {} vs qrinfo = {}", mnListTip.getBlockHash(), quorumRotationInfo.getMnListDiffTip().getPrevBlockHash());
log.info("qrinfo {} -> {}", quorumRotationInfo.getMnListDiffTip().getPrevBlockHash(), quorumRotationInfo.getMnListDiffTip().getBlockHash());
log.info("lastRequest: {} -> {}", lastRequest.request.getBaseBlockHashes(), lastRequest.request.getBlockRequestHash());
log.info("requires reset {}", x.isRequiringReset());
log.info("requires new peer {}", x.isRequiringNewPeer());
Expand Down
22 changes: 11 additions & 11 deletions core/src/main/java/org/bitcoinj/evolution/QuorumState.java
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public void applyDiff(Peer peer, DualBlockChain blockChain,
boolean isSyncingHeadersFirst = context.peerGroup.getSyncStage() == PeerGroup.SyncStage.MNLIST;

long newHeight = ((CoinbaseTx) mnlistdiff.coinBaseTx.getExtraPayloadObject()).getHeight();
block = blockChain.getBlock(mnlistdiff.blockHash);
block = blockChain.getBlock(mnlistdiff.getBlockHash());

if(!isLoadingBootStrap && block.getHeight() != newHeight)
throw new ProtocolException("mnlistdiff blockhash (height="+block.getHeight()+" doesn't match coinbase blockheight: " + newHeight);
Expand All @@ -134,7 +134,7 @@ public void applyDiff(Peer peer, DualBlockChain blockChain,
if(context.masternodeSync.hasVerifyFlag(MasternodeSync.VERIFY_FLAGS.MNLISTDIFF_MNLIST))
newMNList.verify(mnlistdiff.coinBaseTx, mnlistdiff, mnList);
if (peer != null && isSyncingHeadersFirst) peer.queueMasternodeListDownloadedListeners(MasternodeListDownloadedListener.Stage.ProcessedMasternodes, mnlistdiff);
newMNList.setBlock(block, block != null && block.getHeader().getPrevBlockHash().equals(mnlistdiff.prevBlockHash));
newMNList.setBlock(block, block != null && block.getHeader().getPrevBlockHash().equals(mnlistdiff.getPrevBlockHash()));

SimplifiedQuorumList newQuorumList = quorumList;
if (mnlistdiff.coinBaseTx.getExtraPayloadObject().getVersion() >= SimplifiedMasternodeListManager.LLMQ_FORMAT_VERSION) {
Expand Down Expand Up @@ -293,24 +293,24 @@ public void processDiff(@Nullable Peer peer, SimplifiedMasternodeListDiff mnlist
finishDiff(isLoadingBootStrap);
} catch(MasternodeListDiffException x) {
// we already have this mnlistdiff or doesn't match our current tipBlockHash
if(getMnList().getBlockHash().equals(mnlistdiff.blockHash)) {
log.info("heights are the same: " + x.getMessage());
log.info("mnList = {} vs mnlistdiff {}", getMnList().getBlockHash(), mnlistdiff.prevBlockHash);
log.info("mnlistdiff {} -> {}", mnlistdiff.prevBlockHash, mnlistdiff.blockHash);
if(getMnList().getBlockHash().equals(mnlistdiff.getBlockHash())) {
log.info("heights are the same: {}", x.getMessage());
log.info("mnList = {} vs mnlistdiff {}", getMnList().getBlockHash(), mnlistdiff.getPrevBlockHash());
log.info("mnlistdiff {} -> {}", mnlistdiff.getPrevBlockHash(), mnlistdiff.getBlockHash());
log.info("lastRequest {} -> {}", lastRequest.request.baseBlockHash, lastRequest.request.blockHash);
// remove this block from the list
if(!pendingBlocks.isEmpty()) {
StoredBlock thisBlock = pendingBlocks.peek();
if(thisBlock.getHeader().getPrevBlockHash().equals(mnlistdiff.prevBlockHash) &&
thisBlock.getHeader().getHash().equals(mnlistdiff.prevBlockHash)) {
if(thisBlock.getHeader().getPrevBlockHash().equals(mnlistdiff.getPrevBlockHash()) &&
thisBlock.getHeader().getHash().equals(mnlistdiff.getPrevBlockHash())) {
pendingBlocks.pop();
}
}
} else {
log.info("heights are different " + x.getMessage());
log.info("heights are different {}", x.getMessage());
log.info("mnlistdiff height = {}; mnList: {}; quorumList: {}", newHeight, getMnList().getHeight(), quorumList.getHeight());
log.info("mnList = {} vs mnlistdiff = {}", getMnList().getBlockHash(), mnlistdiff.prevBlockHash);
log.info("mnlistdiff {} -> {}", mnlistdiff.prevBlockHash, mnlistdiff.blockHash);
log.info("mnList = {} vs mnlistdiff = {}", getMnList().getBlockHash(), mnlistdiff.getPrevBlockHash());
log.info("mnlistdiff {} -> {}", mnlistdiff.getPrevBlockHash(), mnlistdiff.getBlockHash());
log.info("lastRequest {} -> {}", lastRequest.request.baseBlockHash, lastRequest.request.blockHash);
log.info("requires reset {}", x.isRequiringReset());
log.info("requires new peer {}", x.isRequiringNewPeer());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,15 +152,15 @@ public String toString() {
public SimplifiedMasternodeList applyDiff(SimplifiedMasternodeListDiff diff) throws MasternodeListDiffException
{
CoinbaseTx cbtx = (CoinbaseTx)diff.coinBaseTx.getExtraPayloadObject();
if(!diff.prevBlockHash.equals(blockHash) && !(diff.prevBlockHash.isZero() && blockHash.equals(params.getGenesisBlock().getHash())))
if(!diff.getPrevBlockHash().equals(blockHash) && !(diff.getPrevBlockHash().isZero() && blockHash.equals(params.getGenesisBlock().getHash())))
throw new MasternodeListDiffException("The mnlistdiff does not connect to this list. height: " +
height + " -> " + cbtx.getHeight(), false, false, height == cbtx.getHeight(), false);

lock.lock();
try {
SimplifiedMasternodeList result = new SimplifiedMasternodeList(this, diff.getVersion());

result.blockHash = diff.blockHash;
result.blockHash = diff.getBlockHash();
result.height = cbtx.getHeight();
result.coinbaseTxPayload = cbtx;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,12 @@ public SimplifiedQuorumList applyDiff(SimplifiedMasternodeListDiff diff, boolean
lock.lock();
try {
CoinbaseTx cbtx = (CoinbaseTx) diff.getCoinBaseTx().getExtraPayloadObject();
if(!diff.prevBlockHash.equals(blockHash))
if(!diff.getPrevBlockHash().equals(blockHash))
throw new MasternodeListDiffException("The mnlistdiff does not connect to this quorum. height: " +
height + " vs " + cbtx.getHeight(), false, false, height == cbtx.getHeight(), false);

SimplifiedQuorumList result = new SimplifiedQuorumList(this);
result.blockHash = diff.blockHash;
result.blockHash = diff.getBlockHash();
result.height = cbtx.getHeight();
result.coinbaseTxPayload = cbtx;

Expand Down
Loading

0 comments on commit f1df0d1

Please sign in to comment.