Skip to content

Commit

Permalink
Merge pull request #54 from dashpay/fix/core-20-test-additional
Browse files Browse the repository at this point in the history
core 20: fix cl signatures caching
  • Loading branch information
pankcuf authored Nov 7, 2023
2 parents a6cc177 + df36d48 commit af54d15
Show file tree
Hide file tree
Showing 17 changed files with 805 additions and 546 deletions.
2 changes: 1 addition & 1 deletion DashSharedCore.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'DashSharedCore'
s.version = '0.4.13'
s.version = '0.4.14'
s.summary = 'Dash Core SPV written in Rust'
s.author = 'Dash'
s.description = "C-bindings for Dash Core SPV that can be used in projects for Apple platform"
Expand Down
2 changes: 1 addition & 1 deletion dash-spv-apple-bindings/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "dash_spv_apple_bindings"
version = "0.4.13"
version = "0.4.14"
description = "C-bindings for using and interoperating with Dash SPV"
readme = "README.md"
edition = "2021"
Expand Down
2 changes: 1 addition & 1 deletion dash-spv-masternode-processor/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "dash-spv-masternode-processor"
version = "0.4.13"
version = "0.4.14"
description = "Library for processing masternodes and quorums (SPV)"

edition = "2021"
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
10 changes: 3 additions & 7 deletions dash-spv-masternode-processor/scripts/load_insight_blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,25 @@
parser = argparse.ArgumentParser(description='Script so useful.')
parser.add_argument("--root", type=int, default=0)
parser.add_argument("--head", type=int, default=1)
parser.add_argument("--step", type=int, default=1)
parser.add_argument("--chain", type=str, default='testnet')

args = parser.parse_args()

root = args.root
head = args.head
step = args.step
chain = Chain.from_string(args.chain)

blocks = []
for i in range(root, head):
for i in range(root, head, step):
r = requests.get(f'https://{chain.api_base}/insight-api-dash/block/{i}')
block = r.json()
# print('{}'.format(i))
block_hash = block["hash"]
block_height = block["height"]
merkle_root = block["merkleroot"]
# print('store.put(new StoredBlock(new Block(params, {}, '
# 'Sha256Hash.wrap(Sha256Hash.wrap("{}").getReversedBytes()), '
# 'Sha256Hash.wrap("{}"), {}, {}, {}, new ArrayList<>()), new BigInteger(Hex.decode("{}")), {}));'
# .format(block["version"], block["previousblockhash"], merkle_root, block["time"], 0, block["nonce"], block["chainwork"], block_height))
print('MerkleBlock::reversed({}, "{}", "{}"), '.format(block_height, block_hash, merkle_root))
blocks.append(block)

# print('{}'.format(blocks))
with open('scripts/{}.json'.format(chain.name), 'w', encoding='utf-8') as f:
json.dump(blocks, f, ensure_ascii=False, indent=4)
4 changes: 0 additions & 4 deletions dash-spv-masternode-processor/src/lib_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,6 @@ pub mod tests {
processor.use_insight_as_backup = use_insight_as_backup;
processor.chain_type = chain_type;
let cache = unsafe { &mut *cache };
// println!(
// "process_qrinfo_from_message --: {:?} {:?} {:?}",
// processor, processor.opaque_context, cache
// );
let offset = &mut 0;
let read_list_diff =
|offset: &mut usize| processor.read_list_diff_from_message(message, offset, protocol_version);
Expand Down
39 changes: 14 additions & 25 deletions dash-spv-masternode-processor/src/processing/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,24 +130,18 @@ impl MasternodeProcessor {
}

pub fn llmq_modifier_type_for(&self, llmq_type: LLMQType, work_block_hash: UInt256, work_block_height: u32, cached_cl_signatures: &BTreeMap<UInt256, UInt768>) -> LLMQModifierType {
if let Some(best_cl_signature) = self.find_cl_signature_if_need(work_block_height, cached_cl_signatures) {
LLMQModifierType::CoreV20(llmq_type, work_block_height, best_cl_signature)
} else {
LLMQModifierType::PreCoreV20(llmq_type, work_block_hash)
}
}

pub(crate) fn find_cl_signature_if_need(&self, block_height: u32, cached_cl_signatures: &BTreeMap<UInt256, UInt768>) -> Option<UInt768> {
if self.chain_type.core20_is_active_at(block_height) {
if let Some(work_block_hash) = self.lookup_block_hash_by_height(block_height) {
self.find_cl_signature(work_block_hash, cached_cl_signatures)
if self.chain_type.core20_is_active_at(work_block_height) {
if let Some(work_block_hash) = self.lookup_block_hash_by_height(work_block_height) {
if let Some(best_cl_signature) = self.find_cl_signature(work_block_hash, cached_cl_signatures) {
return LLMQModifierType::CoreV20(llmq_type, work_block_height, best_cl_signature);
} else {
println!("llmq_modifier_type: clsig not found for block hash: {} ({})", work_block_hash, work_block_hash.reversed());
}
} else {
println!("find_cl_signature_if_need: core 20 is active at {} but block is not fetched", block_height);
None
println!("llmq_modifier_type: block not found for height: {}", work_block_height);
}
} else {
None
}
LLMQModifierType::PreCoreV20(llmq_type, work_block_hash)
}

pub(crate) fn find_cl_signature(
Expand Down Expand Up @@ -222,15 +216,6 @@ impl MasternodeProcessor {
// self.save_masternode_list(block_hash, &masternode_list);
}

fn cache_cl_signatures(
&self,
block_hash: UInt256,
cl_signature: UInt768,
cache: &mut MasternodeProcessorCache,
) {
cache.cl_signatures.insert(block_hash, cl_signature);
}

pub(crate) fn get_list_diff_result_internal(
&self,
base_list: Option<models::MasternodeList>,
Expand Down Expand Up @@ -269,7 +254,6 @@ impl MasternodeProcessor {
verification_context,
cache,
);
cache.cl_signatures.extend(cl_signatures.clone());
let masternode_list = models::MasternodeList::new(
masternodes,
quorums,
Expand Down Expand Up @@ -389,7 +373,12 @@ impl MasternodeProcessor {
if llmq_height != u32::MAX {
if let Some(llmq_hash_minus_8) = self.lookup_block_hash_by_height(llmq_height - 8) {
signatures.insert(llmq_hash_minus_8, signature.clone());
cache.cl_signatures.insert(llmq_hash_minus_8, signature.clone());
} else {
println!("unknown hash for {}", llmq_height - 8);
}
} else {
println!("unknown height for {}", quorum.llmq_hash);
}
}
if verification_context.should_validate_quorum_of_type(quorum.llmq_type, self.chain_type) {
Expand Down
Loading

0 comments on commit af54d15

Please sign in to comment.