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

chore: update predicate scanning status on every trigger #603

Merged
merged 2 commits into from
Jun 18, 2024
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
9 changes: 8 additions & 1 deletion components/chainhook-cli/src/scan/bitcoin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,14 @@ pub async fn scan_bitcoin_chainstate_via_rpc_using_predicate(
let mut last_scanned_block_confirmations = 0;
let http_client = build_http_client();

let mut loop_did_trigger = false;
while let Some(current_block_height) = block_heights_to_scan.pop_front() {
if let Some(ref mut predicates_db_conn) = predicates_db_conn {
if number_of_blocks_scanned % 10 == 0 || number_of_blocks_scanned == 0 {
if number_of_blocks_scanned % 100 == 0
|| number_of_blocks_scanned == 0
// if the last loop did trigger a predicate, update the status
|| loop_did_trigger
MicaiahReid marked this conversation as resolved.
Show resolved Hide resolved
{
set_predicate_scanning_status(
&predicate_spec.key(),
number_of_blocks_to_scan,
Expand All @@ -112,6 +117,7 @@ pub async fn scan_bitcoin_chainstate_via_rpc_using_predicate(
);
}
}
loop_did_trigger = false;

if current_block_height > chain_tip {
let prev_chain_tip = chain_tip;
Expand Down Expand Up @@ -177,6 +183,7 @@ pub async fn scan_bitcoin_chainstate_via_rpc_using_predicate(
Ok(actions) => {
if actions > 0 {
number_of_times_triggered += 1;
loop_did_trigger = true
Copy link
Contributor

@csgui csgui Jun 11, 2024

Choose a reason for hiding this comment

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

Related to my previous comment: aren't these variables interchangeable?

}
actions_triggered += actions;
Ok(())
Expand Down
10 changes: 9 additions & 1 deletion components/chainhook-cli/src/scan/stacks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,9 +224,14 @@ pub async fn scan_stacks_chainstate_via_rocksdb_using_predicate(
}
};

let mut loop_did_trigger = false;
while let Some(current_block_height) = block_heights_to_scan.pop_front() {
if let Some(ref mut predicates_db_conn) = predicates_db_conn {
if number_of_blocks_scanned % 10 == 0 || number_of_blocks_scanned == 0 {
if number_of_blocks_scanned % 1000 == 0
|| number_of_blocks_scanned == 0
// if the last loop did trigger a predicate, update the status
|| loop_did_trigger
{
set_predicate_scanning_status(
&predicate_spec.key(),
number_of_blocks_to_scan,
Expand All @@ -238,6 +243,8 @@ pub async fn scan_stacks_chainstate_via_rocksdb_using_predicate(
);
}
}
loop_did_trigger = false;

if current_block_height > chain_tip {
let prev_chain_tip = chain_tip;
// we've scanned up to the chain tip as of the start of this scan
Expand Down Expand Up @@ -316,6 +323,7 @@ pub async fn scan_stacks_chainstate_via_rocksdb_using_predicate(
}
Ok(action) => {
number_of_times_triggered += 1;
loop_did_trigger = true;
let res = match action {
StacksChainhookOccurrence::Http(request, _) => {
send_request(request, 3, 1, &ctx).await
Expand Down
Loading