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

feat: Sortition tracking in signer binary #4905

Merged

Conversation

jbencin
Copy link
Contributor

@jbencin jbencin commented Jun 24, 2024

Description

Fetch and cache sortition state as needed, and use it to validate incoming BlockProposals

Applicable issues

Additional info (benefits, drawbacks, caveats)

Since this is my first time contributing to the signer binary, there are some things I'm unsure of that reviewers should check:

  • This adds some blocking i/o in handle_block_proposal()
  • I think it's correct to do these checks before submit_block_for_validation(), since that takes longer
  • I only implemented this in signer v0. I didn't touch v1
  • Is the public key passed to check_proposal() the correct one?
  • I used inspect_err(), which was introduced a few months ago in Rust 1.76. Is this okay, and what's our MSRV policy in general?

Checklist

  • Test coverage for new or modified code paths
  • Changelog is updated
  • Required documentation changes (e.g., docs/rpc/openapi.yaml and rpc-endpoints.md for v2 endpoints, event-dispatcher.md for new events)
  • New clarity functions have corresponding PR in clarity-benchmarking repo
  • New integration test(s) added to bitcoin-tests.yml

@jbencin jbencin requested a review from a team as a code owner June 24, 2024 19:14
@jbencin jbencin requested review from kantai and jferrant June 24, 2024 19:14
@jbencin jbencin force-pushed the feat/sortition-tracking-in-signer branch from 0fdbb7d to dc4582e Compare June 24, 2024 19:15
@jbencin jbencin marked this pull request as draft June 24, 2024 19:36
@jbencin jbencin force-pushed the feat/sortition-tracking-in-signer branch from dc4582e to 48ff7dd Compare June 24, 2024 20:13
@jbencin jbencin marked this pull request as ready for review June 24, 2024 20:16
Copy link
Member

@kantai kantai left a comment

Choose a reason for hiding this comment

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

This LGTM -- the existing (and future) signer integration tests should do a good job covering this integration (the rest is covered via the prior SortitionsView tests).

One of the signer::.. integration tests does seem to be failing though, so that needs to be investigated.

@jbencin
Copy link
Contributor Author

jbencin commented Jun 26, 2024

The signer::v0::block_proposal_rejection test is failing because fetch_view() fails to get the sortition view:

INFO [1719421727.355629] [stacks-signer/src/chainstate.rs:358] [signer_runloop] Latest state wasn't a sortition: SortitionInfo { burn_block_hash: 3ca9273766f766477b5ebcdb030742d4b17ae778085d75f6a4d4b99b291f180c, burn_block_height: 231, sortition_id: bdbe3ab31d9768df001ea1aee878b617eece9eed464b44540d6019b2aabb9ecd, parent_sortition_id: 3e241e6177a8bd1de1b999d0d047873f18fbb67822b1f44a7f715f2efb03f8ff, consensus_hash: 219ec7a59ae13212a06b2efa1b18d6b484836a98, was_sortition: false, miner_pk_hash160: None, stacks_parent_ch: None, last_sortition_ch: None, committed_block_hash: None }
WARN [1719421727.355646] [stacks-signer/src/v0/signer.rs:261] [signer_runloop] Cycle #11 Signer #1: Failed to update sortition view: NoSortitionOnChain, signer_sighash: ced4ed4e61eef9b2859ae1053bc5df414e7b3a901c927107ea7c66d1a81a7f28, block_id: d6ac3d6bdcb993b0b3d73961d891d06a118a77e611e8018c63818f900bbf7d1d
WARN [1719421727.355655] [stacks-signer/src/v0/signer.rs:271] [signer_runloop] Cycle #11 Signer #1: Cannot validate block, no sortition view, signer_sighash: ced4ed4e61eef9b2859ae1053bc5df414e7b3a901c927107ea7c66d1a81a7f28, block_id: d6ac3d6bdcb993b0b3d73961d891d06a118a77e611e8018c63818f900bbf7d1d

I am going to refactor this PR a bit, and change how I handle the case when we don't have a sortition view, so it doesn't fail

@jbencin
Copy link
Contributor Author

jbencin commented Jun 26, 2024

I've refactored this so that signer::v0::block_proposal_rejection passes. The basic flow now in handle_block_proposal() is:

  • Try to fetch a sortition view if we don't have one
    • If proposal fails check_proposal(), mark BlockInfo struct as invalid
    • If we can't get sortition view or there is some other error, print a warning and continue
  • Call submit_block_for_validation() if BlockInfo hasn't been marked as invalid
  • Insert BlockInfo into SignerDB

@kantai @jferrant please let me know if this is the desired behavior

@jbencin jbencin force-pushed the feat/sortition-tracking-in-signer branch from 3e987c6 to 50b52d7 Compare June 26, 2024 19:21
jferrant
jferrant previously approved these changes Jun 27, 2024
@saralab saralab requested a review from obycode June 28, 2024 15:44
@jbencin jbencin force-pushed the feat/sortition-tracking-in-signer branch from 0e4f664 to e605610 Compare July 2, 2024 14:27
@jbencin jbencin requested a review from a team as a code owner July 2, 2024 14:27
@jbencin
Copy link
Contributor Author

jbencin commented Jul 2, 2024

I fixed the failing integration test be removing the call to wait_for_validate_reject_response(), which waits for a BlockValidateResponse from the node. Instead, we just check for a BlockResponse from the signer

Copy link
Member

@kantai kantai left a comment

Choose a reason for hiding this comment

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

This LGTM, but I agree with Jacinta's comment in the test: the check at the end should be in a loop, with a longer timeout (like a minute).

kantai
kantai previously approved these changes Jul 2, 2024
Copy link
Member

@kantai kantai left a comment

Choose a reason for hiding this comment

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

LGTM, but it looks like you'll have to resolve a merge conflict

@jbencin jbencin force-pushed the feat/sortition-tracking-in-signer branch from de2cf48 to 18702eb Compare July 2, 2024 20:15
@jbencin jbencin requested a review from kantai July 2, 2024 20:15
@jbencin jbencin added this pull request to the merge queue Jul 3, 2024
Merged via the queue into stacks-network:develop with commit b6b096e Jul 3, 2024
1 check passed
@jbencin jbencin deleted the feat/sortition-tracking-in-signer branch July 3, 2024 14:28
@blockstack-devops
Copy link
Contributor

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@stacks-network stacks-network locked as resolved and limited conversation to collaborators Oct 30, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants