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

Implementation of local signer state machine #5933

Open
wants to merge 11 commits into
base: develop
Choose a base branch
from

Conversation

kantai
Copy link
Contributor

@kantai kantai commented Mar 17, 2025

This PR contains an initial implementation (and the beginning of testing) for the local state machine work (#5915)

@kantai kantai requested a review from a team as a code owner March 17, 2025 16:34
@kantai kantai removed the request for review from a team March 17, 2025 18:26
@kantai kantai marked this pull request as draft March 17, 2025 18:26
@aldur aldur requested a review from fdefelici March 18, 2025 15:38
Copy link

codecov bot commented Mar 19, 2025

Codecov Report

Attention: Patch coverage is 64.44233% with 373 lines in your changes missing coverage. Please review.

Project coverage is 81.13%. Comparing base (9937c41) to head (f853597).
Report is 20 commits behind head on develop.

Files with missing lines Patch % Lines
testnet/stacks-node/src/tests/signer/v0.rs 16.26% 206 Missing ⚠️
testnet/stacks-node/src/tests/signer/mod.rs 66.47% 119 Missing ⚠️
stacks-signer/src/v0/signer_state.rs 89.19% 31 Missing ⚠️
stacks-signer/src/monitoring/mod.rs 0.00% 6 Missing ⚠️
stacks-signer/src/v0/signer.rs 89.83% 6 Missing ⚠️
stacks-signer/src/signerdb.rs 90.00% 3 Missing ⚠️
stacks-signer/src/lib.rs 50.00% 1 Missing ⚠️
stacks-signer/src/runloop.rs 94.73% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##           develop    #5933       +/-   ##
============================================
+ Coverage    68.14%   81.13%   +12.99%     
============================================
  Files          521      522        +1     
  Lines       382814   383513      +699     
  Branches       323      323               
============================================
+ Hits        260884   311182    +50298     
+ Misses      121922    72323    -49599     
  Partials         8        8               
Files with missing lines Coverage Δ
libsigner/src/events.rs 90.73% <100.00%> (+10.83%) ⬆️
libsigner/src/v0/messages.rs 84.58% <ø> (+16.03%) ⬆️
stacks-signer/src/chainstate.rs 91.65% <100.00%> (+0.77%) ⬆️
stacks-signer/src/client/stacks_client.rs 86.70% <100.00%> (+16.15%) ⬆️
stacks-signer/src/monitoring/prometheus.rs 100.00% <ø> (ø)
stacks-signer/src/tests/chainstate.rs 100.00% <100.00%> (+42.36%) ⬆️
...tacks-node/src/nakamoto_node/signer_coordinator.rs 87.38% <100.00%> (+1.84%) ⬆️
stacks-signer/src/lib.rs 90.00% <50.00%> (ø)
stacks-signer/src/runloop.rs 87.57% <94.73%> (+14.79%) ⬆️
stacks-signer/src/signerdb.rs 93.44% <90.00%> (+9.74%) ⬆️
... and 5 more

... and 307 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e21c0dd...f853597. Read the comment docs.

🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@kantai kantai changed the title Draft: initial implementation of local signer state machine Initial implementation of local signer state machine Mar 20, 2025
@kantai kantai marked this pull request as ready for review March 20, 2025 14:45
@kantai kantai changed the title Initial implementation of local signer state machine Implementation of local signer state machine Mar 20, 2025
@aldur aldur requested review from rdeioris, obycode and jferrant March 20, 2025 15:38
Comment on lines +583 to +591
let consensus_hash = burn_block_event
.consensus_hash
.get(2..)
.ok_or_else(|| EventError::Deserialize("Hex string should be 0x prefixed".into()))
.and_then(|hex| {
ConsensusHash::from_hex(hex)
.map_err(|e| EventError::Deserialize(format!("Invalid hex string: {e}")))
})?;

Choose a reason for hiding this comment

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

This code pattern is repeated for different data (consensus_hash, burn_header_hash, signer_sighash, block_id) . Also the check for "0x" doesn't seem really strong.

What about put this kind of conversion in dedicated function, or eventually even creating a Type::from_hex_0x(...) for each data type? So it could become also testable with a simple unit test and eventually reusable for the future.


/// The local signer state machine
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum LocalStateMachine {

Choose a reason for hiding this comment

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

Interesting choice to represent the state machine as an enum.

I would appreciate if you could share whether you evaluated the possibility to make the state machine like a struct (currently with a field that represent the current state, but with the possibility have more fields if needed) and, if so, the reasoning behind the choice of this solution.

};

let current_miner = match state_machine.current_miner {
MinerState::ActiveMiner {
Copy link
Contributor

@jferrant jferrant Mar 20, 2025

Choose a reason for hiding this comment

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

Just a nit, but might be cleaner to implement a From for StateMachineUpdateMinerState

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.

3 participants