Skip to content

feat: support core 20 - #230

Merged
HashEngineering merged 35 commits into
feature-core-20from
feature-core-20-phase-1
Sep 26, 2023
Merged

HashEngineering merged 35 commits into
feature-core-20from
feature-core-20-phase-1

Conversation

@HashEngineering

Copy link
Copy Markdown
Collaborator

Issue being fixed or feature implemented

What was done?

How Has This Been Tested?

Breaking Changes

Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added or updated relevant unit/integration/functional/e2e tests
  • I have made corresponding changes to the documentation

For repository code-owners and collaborators only

  • I have assigned this pull request to a milestone

Signed-off-by: HashEngineering <[email protected]>
fix: toJson method
Signed-off-by: HashEngineering <[email protected]>
Signed-off-by: HashEngineering <[email protected]>
Signed-off-by: HashEngineering <[email protected]>
* Signatures and Keys are not a child objects

Signed-off-by: HashEngineering <[email protected]>
* chore: deprecate default constructor

Signed-off-by: HashEngineering <[email protected]>
Signed-off-by: HashEngineering <[email protected]>
Signed-off-by: HashEngineering <[email protected]>
* set current protocol to 70230

Signed-off-by: HashEngineering <[email protected]>
* set v20 activation height in TestNet3Params

Signed-off-by: HashEngineering <[email protected]>
Signed-off-by: HashEngineering <[email protected]>
* This will help with masternode and quorum list sync when receiving transactions

Signed-off-by: HashEngineering <[email protected]>
@HashEngineering HashEngineering self-assigned this Sep 15, 2023
@codecov

codecov Bot commented Sep 15, 2023 •

Copy link
Copy Markdown

Codecov Report

Patch coverage: 68.30% and project coverage change: +0.38% 🎉

Comparison is base (7773c1f) 47.11% compared to head (01c4e3c) 47.50%.

Additional details and impacted files
@@                  Coverage Diff                  @@
##             feature-core-20     #230      +/-   ##
=====================================================
+ Coverage              47.11%   47.50%   +0.38%     
- Complexity              6472     6580     +108     
=====================================================
  Files                    408      408              
  Lines                  45879    46144     +265     
  Branches                6481     6518      +37     
=====================================================
+ Hits                   21618    21919     +301     
+ Misses                 21891    21843      -48     
- Partials                2370     2382      +12     
Files Changed Coverage Δ
...n/java/org/bitcoinj/core/TransactionBroadcast.java 10.23% <0.00%> (-0.25%) ⬇️
...rc/main/java/org/bitcoinj/core/VersionMessage.java 59.23% <ø> (ø)
...ava/org/bitcoinj/crypto/BLSAbstractLazyObject.java 66.66% <ø> (ø)
...g/bitcoinj/evolution/SimplifiedMasternodeList.java 59.04% <0.00%> (ø)
...tcoinj/net/discovery/ThreeMethodPeerDiscovery.java 0.00% <0.00%> (ø)
.../java/org/bitcoinj/params/BinTangDevNetParams.java 0.00% <ø> (ø)
...ain/java/org/bitcoinj/params/OuzoDevNetParams.java 0.00% <0.00%> (ø)
.../org/bitcoinj/params/WhiteRussianDevNetParams.java 94.11% <ø> (-0.33%) ⬇️
...ain/java/org/bitcoinj/quorums/InstantSendLock.java 53.33% <0.00%> (-1.47%) ⬇️
.../main/java/org/bitcoinj/evolution/QuorumState.java 54.06% <44.00%> (+4.36%) ⬆️
... and 30 more

... and 15 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Comment on lines +891 to +914
Sha256Hash getHashModifier(LLMQParameters llmqParams, StoredBlock quorumBaseBlock) {
StoredBlock workBlock = getBlockAncestor(quorumBaseBlock, quorumBaseBlock.getHeight() - 8);

if (params.isV20Active(workBlock.getHeight())) {
// v20 is active: calculate modifier using the new way.
BLSSignature bestCLSignature = getCoinbaseChainlock(workBlock);
log.info("getHashModifier(..., {})\n work: {}\n sig: {}", quorumBaseBlock.getHeader().getHash(), workBlock.getHeader().getHash(), bestCLSignature);
if (bestCLSignature != null) {
// We have a non-null CL signature: calculate modifier using this CL signature

return LLMQUtils.buildLLMQBlockHash(llmqParams.getType(), workBlock.getHeight(), bestCLSignature);
} else {
log.info("cannot find CL for block {}", workBlock.getHeader().getHash());
}
// No non-null CL signature found in coinbase: calculate modifier using block hash only
return LLMQUtils.buildLLMQBlockHash(llmqParams.getType(), workBlock.getHeader().getHash());
}

// v20 isn't active yet: calculate modifier using the usual way
if (llmqParams.useRotation()) {
return LLMQUtils.buildLLMQBlockHash(llmqParams.getType(), workBlock.getHeader().getHash());
}
return LLMQUtils.buildLLMQBlockHash(llmqParams.getType(), quorumBaseBlock.getHeader().getHash());
}

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This method calculates the hash value used to determine quorum membership.

Comment on lines -99 to -100
//0.14 format include quorum information
if(payload.length > cursor - offset) {

@HashEngineering HashEngineering Sep 15, 2023 •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This if statement is removed because we don't need to support Dash Core 0.13 protocols



public abstract class SpecialTxPayload extends Message {
public abstract class SpecialTxPayload extends ChildMessage {

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

ChildMessage contains a parent field.

Comment on lines +77 to +82
LinkedHashMap<Sha256Hash, ChainLockSignature> coinbaseChainlockMap = new LinkedHashMap<Sha256Hash, ChainLockSignature>() {
@Override
protected boolean removeEldestEntry(Map.Entry entry) {
return size() > 5000;
}
};

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This will be an in-memory-only hash table that associates a block with the coinbase chainlock signature.

Comment on lines +581 to +583
if (cursor < payload.length) {
// TODO: parse the chainlockMap here
}

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This should be removed if there is no plan to save the chainlock maps.

Comment on lines +139 to +143
if (tx.getVersionShort() > Transaction.MAX_STANDARD_VERSION || tx.getVersionShort() < Transaction.MIN_STANDARD_VERSION ||
tx.getType().getValue() >= Transaction.Type.TRANSACTION_TYPE_MAX.getValue()) {
log.warn("TX considered non-standard due to unknown version number {} or type {}", tx.getVersionShort(), tx.getType());
return RuleViolation.VERSION;
}

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

without this change, a version 3 transaction with a type other than 0 would be counted as non-standard. One such example would be a coinbase transaction (type = 5).

Comment on lines -932 to +928
Sha256Hash modifier = LLMQUtils.buildLLMQBlockHash(llmqParameters.getType(), workBlock.getHeader().getHash());
Sha256Hash modifier = getHashModifier(llmqParameters, cycleQuorumBaseBlock);

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Any place where getHashModifier is used is a v20 change for DIP29.

final StoredBlock workBlock = quorumBaseBlock.getAncestor(store, quorumBaseBlock.getHeight() - 8);
final Sha256Hash modifier = LLMQUtils.buildLLMQBlockHash(llmqType, workBlock.getHeader().getHash());
final StoredBlock workBlock = cycleQuorumBaseBlock.getAncestor(store, cycleQuorumBaseBlock.getHeight() - 8);
final Sha256Hash modifier = getHashModifier(llmqParameters, cycleQuorumBaseBlock);

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Another v20 change in getMNUsageBySnapshot

Comment on lines -186 to +209
public ArrayList<Masternode> getAllQuorumMembers(LLMQParameters.LLMQType llmqType, Sha256Hash blockHash) {
public ArrayList<Masternode> getAllQuorumMembers(LLMQParameters.LLMQType llmqType, Sha256Hash quorumBaseBlockHash) {
StoredBlock quorumBaseBlock = getBlockFromHash(quorumBaseBlockHash);
return computeQuorumMembers(llmqType, quorumBaseBlock);
}

protected ArrayList<Masternode> computeQuorumMembers(LLMQParameters.LLMQType llmqType, StoredBlock quorumBaseBlock) {
boolean evoOnly = (params.getLlmqPlatform() == llmqType) && params.isV19Active(quorumBaseBlock);
LLMQParameters llmqParameters = params.getLlmqs().get(llmqType);
SimplifiedMasternodeList allMns = getListForBlock(blockHash);
if (allMns != null) {
Sha256Hash modifier = LLMQUtils.buildLLMQBlockHash(llmqType, blockHash);
boolean hmpnOnly = (params.getLlmqPlatform() == llmqType) && params.isV19Active(allMns.getStoredBlock());
return allMns.calculateQuorum(llmqParameters.getSize(), modifier, hmpnOnly);
checkNotNull(llmqParameters);
if (llmqParameters.useRotation() || quorumBaseBlock.getHeight() % llmqParameters.getDkgInterval() != 0) {
return Lists.newArrayList();
}
return null;
}

StoredBlock workBlock = params.isV20Active(quorumBaseBlock) ?
getBlockAncestor(quorumBaseBlock, quorumBaseBlock.getHeight() - 8) :
quorumBaseBlock;

Sha256Hash modifier = getHashModifier(llmqParameters, quorumBaseBlock);
SimplifiedMasternodeList allMns = getListForBlock(workBlock.getHeader().getHash());
return allMns != null ? allMns.calculateQuorum(llmqParameters.getSize(), modifier, evoOnly) : null;
}

@HashEngineering HashEngineering Sep 18, 2023 •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

this is a refactor or non-rotated quorum membership calculation to match more closely to Core v20's code, but it also includes the update for v20 Change for DIP29 with getHashModifier..

Comment on lines -707 to +704
final StoredBlock workBlock = quorumBaseBlock.getAncestor(store, quorumBaseBlock.getHeight() - 8);

Sha256Hash modifier = LLMQUtils.buildLLMQBlockHash(llmqParameters.getType(), workBlock.getHeader().getHash());
final StoredBlock workBlock = cycleQuorumBaseBlock.getAncestor(store, cycleQuorumBaseBlock.getHeight() - 8);
final Sha256Hash modifier = getHashModifier(llmqParameters, cycleQuorumBaseBlock);

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

v20 Change for DIP29.

@HashEngineering
HashEngineering marked this pull request as ready for review September 20, 2023 14:12

@Syn-McJ Syn-McJ left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good

llmqTypePlatform = LLMQParameters.LLMQType.LLMQ_25_67;
llmqTypeDIP0024InstantSend = LLMQParameters.LLMQType.LLMQ_60_75;
llmqTypeMnhf = LLMQParameters.LLMQType.LLMQ_50_60;
llmqTypeAssetLocks = LLMQParameters.LLMQType.LLMQ_50_60;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Same type as llmqTypeMnhf?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Yes, it is the same quorum type. This is the code from Dash Core.

consensus.llmqTypeMnhf = Consensus::LLMQType::LLMQ_50_60;
consensus.llmqTypeAssetLocks = Consensus::LLMQType::LLMQ_50_60;

@HashEngineering
HashEngineering merged commit 1f64d0e into feature-core-20 Sep 26, 2023
@HashEngineering
HashEngineering deleted the feature-core-20-phase-1 branch October 30, 2023 04:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants