Skip to content

Commit

Permalink
feat: parse /stackerdb_chunks Stacks node event (#653)
Browse files Browse the repository at this point in the history
Starts listening to the new `/stackerdb_chunks` Stacks node event and
parses the incoming message. Parsers are taken from the `stacks_codec`
crate, which has been updated with the latest serializers.

For future PRs:
* Start integrating the signer messages into the predicates framework
* Store signer messages in a local SQLite DB for replay
* Expand unit tests to include full Stacks node integration tests

---------

Co-authored-by: Matthew Little <[email protected]>
  • Loading branch information
rafaelcr and zone117x authored Oct 16, 2024
1 parent 0a722b3 commit e44d84a
Show file tree
Hide file tree
Showing 16 changed files with 504 additions and 37 deletions.
8 changes: 6 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ jobs:
strategy:
fail-fast: false
matrix:
suite: [cli, sdk]
include:
- suite: cli
features: redis_tests
- suite: sdk
features: stacks-signers
defaults:
run:
working-directory: ./components/chainhook-${{ matrix.suite }}
Expand Down Expand Up @@ -62,7 +66,7 @@ jobs:

- name: Run tests
run: |
cargo tarpaulin --skip-clean --out lcov ${{ env.TARPAULIN_FLAGS }} -- --test-threads=1
cargo tarpaulin --skip-clean --out lcov --features ${{ matrix.features }} -- --test-threads=1
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v4
Expand Down
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ default-members = ["components/chainhook-cli", "components/chainhook-sdk"]
resolver = "2"

[patch.crates-io]
stacks-codec = { git = "https://github.com/hirosystems/clarinet.git" }
stacks-codec = { git = "https://github.com/hirosystems/clarinet.git", rev = "3a2f9136abd85b265e538fbe51c808e9c09a06cb" }
2 changes: 1 addition & 1 deletion components/chainhook-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ serde-redis = "0.12.0"
hex = "0.4.3"
rand = "0.8.5"
chainhook-sdk = { version = "0.12.6", default-features = false, features = [
"zeromq",
"zeromq", "stacks-signers"
], path = "../chainhook-sdk" }
hiro-system-kit = "0.3.4"
# hiro-system-kit = { path = "../../../clarinet/components/hiro-system-kit" }
Expand Down
10 changes: 8 additions & 2 deletions components/chainhook-cli/src/service/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,10 @@ impl Service {
};
}
StacksChainEvent::ChainUpdatedWithMicroblocks(_)
| StacksChainEvent::ChainUpdatedWithMicroblocksReorg(_) => {}
| StacksChainEvent::ChainUpdatedWithMicroblocksReorg(_) => {},
StacksChainEvent::ChainUpdatedWithStackerDbChunks(data) => {
// TODO(rafaelcr): Store signer data.
}
},
Err(e) => {
error!(
Expand Down Expand Up @@ -615,7 +618,10 @@ impl Service {
}
}
StacksChainEvent::ChainUpdatedWithMicroblocks(_)
| StacksChainEvent::ChainUpdatedWithMicroblocksReorg(_) => {}
| StacksChainEvent::ChainUpdatedWithMicroblocksReorg(_) => {},
StacksChainEvent::ChainUpdatedWithStackerDbChunks(data) => {
// TODO(rafaelcr): Send via HTTP payload.
},
};
update_status_from_report(
Chain::Stacks,
Expand Down
1 change: 1 addition & 0 deletions components/chainhook-sdk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,6 @@ test-case = "3.1.0"
[features]
default = ["hiro-system-kit/log"]
zeromq = ["zmq"]
stacks-signers = []
debug = ["hiro-system-kit/debug"]
release = ["hiro-system-kit/release_debug", "hiro-system-kit/full_log_level_prefix"]
5 changes: 4 additions & 1 deletion components/chainhook-sdk/src/chainhooks/stacks/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -721,7 +721,10 @@ pub fn evaluate_stacks_chainhooks_on_chain_event<'a>(
})
}
}
}
},
StacksChainEvent::ChainUpdatedWithStackerDbChunks(data) => {
// TODO: Support predicates to send this data
},
}
(
triggered_predicates,
Expand Down
26 changes: 25 additions & 1 deletion components/chainhook-sdk/src/indexer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ impl Indexer {
header: BlockHeader,
ctx: &Context,
) -> Result<Option<BlockchainEvent>, String> {

self.bitcoin_blocks_pool.process_header(header, ctx)
}

Expand Down Expand Up @@ -167,6 +166,31 @@ impl Indexer {
pub fn get_pox_config(&mut self) -> PoxConfig {
self.stacks_context.pox_config.clone()
}

#[cfg(feature = "stacks-signers")]
pub fn handle_stacks_marshalled_stackerdb_chunk(
&mut self,
marshalled_stackerdb_chunks: JsonValue,
receipt_time: u64,
ctx: &Context,
) -> Result<Option<StacksChainEvent>, String> {
use chainhook_types::StacksChainUpdatedWithStackerDbChunksData;

let chunks = stacks::standardize_stacks_marshalled_stackerdb_chunks(
&self.config,
marshalled_stackerdb_chunks,
receipt_time,
&mut self.stacks_context,
ctx,
)?;
if chunks.len() > 0 {
Ok(Some(StacksChainEvent::ChainUpdatedWithStackerDbChunks(
StacksChainUpdatedWithStackerDbChunksData { chunks },
)))
} else {
Ok(None)
}
}
}

#[derive(Clone, Debug, PartialEq, Eq)]
Expand Down
Loading

0 comments on commit e44d84a

Please sign in to comment.