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

Paging in StackerDB and update to .signers #4323

Merged
merged 68 commits into from
Feb 10, 2024
Merged

Conversation

kantai
Copy link
Member

@kantai kantai commented Feb 1, 2024

Description

This adds paging to StackerDB (it also converts a lot of expects() to guarded errors: I'm pretty sure those weren't reachable, but easy enough to be a little paranoid with those).

It also updates the .signers (and the downstream .signer-voting) contracts to use paging to store the alternate signers sets. As part of this, the .signers contract changed some: the StackerDB slots are stored separately from the signer voting weights: the prior implementation incorrectly conflated the two.

EDIT (@jcnelson): I'll be taking over this PR. The system will implement multiple StackerDBs for signers -- one per message type -- and will support running two signer-sets at once.

This implements #4307 and #4315

* expand e2e correct_burns test to invoke the new RPC endpoint
* fix reward-set storage information to write correct coinbase height
Paging supports larger StackerDB instances
* make signer-slots a const in stacks-common
* update the .signers maintenance to separate voting share from StackerDB slots
* update .signers to use and alternate 2 pages of signers
Copy link

codecov bot commented Feb 1, 2024

Codecov Report

Attention: 234 lines in your changes are missing coverage. Please review.

Comparison is base (efbef05) 76.73% compared to head (0772e75) 83.03%.

Files Patch % Lines
stacks-signer/src/runloop.rs 55.31% 84 Missing ⚠️
stackslib/src/chainstate/stacks/db/mod.rs 0.00% 36 Missing ⚠️
stacks-signer/src/utils.rs 0.00% 22 Missing ⚠️
stacks-signer/src/client/stackerdb.rs 81.44% 18 Missing ⚠️
stackslib/src/net/stackerdb/config.rs 78.31% 18 Missing ⚠️
testnet/stacks-node/src/nakamoto_node/miner.rs 0.00% 15 Missing ⚠️
testnet/stacks-node/src/config.rs 38.09% 13 Missing ⚠️
clarity/src/vm/database/clarity_db.rs 0.00% 10 Missing ⚠️
testnet/stacks-node/src/tests/signer.rs 87.67% 9 Missing ⚠️
stackslib/src/net/api/poststackerdbchunk.rs 64.28% 5 Missing ⚠️
... and 1 more
Additional details and impacted files
@@            Coverage Diff             @@
##             next    #4323      +/-   ##
==========================================
+ Coverage   76.73%   83.03%   +6.29%     
==========================================
  Files         446      446              
  Lines      318774   319256     +482     
==========================================
+ Hits       244607   265088   +20481     
+ Misses      74167    54168   -19999     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Collaborator

@friedger friedger left a comment

Choose a reason for hiding this comment

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

I just have some nits and questions. Lgtm

Copy link
Member

@jcnelson jcnelson left a comment

Choose a reason for hiding this comment

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

Thanks for this! Just two blockers:

  • I don't think the signer-set contract's StackerDB is correct
  • I think we want a hard cap on the number of pages

Copy link
Member

@jcnelson jcnelson left a comment

Choose a reason for hiding this comment

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

We need the maximum page size to be 24, since each signer needs 12 slots and there are two signer sets.

@jcnelson jcnelson self-requested a review February 2, 2024 18:47
Copy link
Member

@jcnelson jcnelson left a comment

Choose a reason for hiding this comment

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

LGTM. Was confused about the way in which the signer list was translating into chunk inventories. What you have here is good.

@kantai kantai force-pushed the feat/reward-set-endpoint branch from cda02b1 to c6a54db Compare February 3, 2024 03:17
@jcnelson jcnelson self-requested a review February 3, 2024 05:23
Copy link
Member

@jcnelson jcnelson left a comment

Choose a reason for hiding this comment

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

Temporarily rejecting this because I think there's a simpler way to do this.

@jferrant
Copy link
Collaborator

jferrant commented Feb 7, 2024

This will help me so much for cast aggregate vote PR...have been struggling with making things work the way they were and seeing all these changes makes me realize why lol :P

@@ -2511,7 +2511,7 @@ impl NakamotoChainState {
Self::calculate_matured_miner_rewards(
&mut clarity_tx,
sortition_dbconn.sqlite_conn(),
coinbase_height,
coinbase_height + 1,
Copy link
Member

Choose a reason for hiding this comment

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

@kantai Can you explain why this change needed to be made?

@@ -2511,6 +2511,7 @@ impl NakamotoChainState {
Self::calculate_matured_miner_rewards(
&mut clarity_tx,
sortition_dbconn.sqlite_conn(),
// coinbase_height + 1,
Copy link
Member

Choose a reason for hiding this comment

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

@kantai I had to comment this out because it was causing the chain to crash in some of the integration tests. Can you please help me understand why this change was here in the first place?

Copy link
Member Author

Choose a reason for hiding this comment

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

There were some tests where the coordinator panicked without this change (I think they were signers tests that used mockamoto, or some configuration where nakamoto was active during very early Stacks block heights). This was because of some assumptions about the block height, maturation windows, and the size of the matured rewards. I don't think +1 here is correct, but I do think that the height used for calculated miner rewards maturation in nakamoto needs another look.

The coinbase_height parameter of NakamotoChainState::setup_block includes the block being set up. The chain_tip parameter of StacksChainState::setup_block, however, is the parent tip, so that the stacks height used in this function is logically -1. This is why StacksChainState uses +1 when invoking handle_prepare_phase_start(). This was discovered in trying to test that method, but I didn't try to completely test all of the behavior around these height parameters. It may be that the first block of a tenure has the parent's height passed in, but subsequent blocks in that tenure have the new coinbase height (where we could see something like #4333).

@jcnelson jcnelson self-requested a review February 8, 2024 02:57
@jcnelson jcnelson requested a review from jferrant February 8, 2024 03:40
Copy link
Member Author

@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, just some superficial comments. But also, a response to the coinbase_height argument for reward maturation probably deserves more attention.

@@ -2511,6 +2511,7 @@ impl NakamotoChainState {
Self::calculate_matured_miner_rewards(
&mut clarity_tx,
sortition_dbconn.sqlite_conn(),
// coinbase_height + 1,
Copy link
Member Author

Choose a reason for hiding this comment

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

There were some tests where the coordinator panicked without this change (I think they were signers tests that used mockamoto, or some configuration where nakamoto was active during very early Stacks block heights). This was because of some assumptions about the block height, maturation windows, and the size of the matured rewards. I don't think +1 here is correct, but I do think that the height used for calculated miner rewards maturation in nakamoto needs another look.

The coinbase_height parameter of NakamotoChainState::setup_block includes the block being set up. The chain_tip parameter of StacksChainState::setup_block, however, is the parent tip, so that the stacks height used in this function is logically -1. This is why StacksChainState uses +1 when invoking handle_prepare_phase_start(). This was discovered in trying to test that method, but I didn't try to completely test all of the behavior around these height parameters. It may be that the first block of a tenure has the parent's height passed in, but subsequent blocks in that tenure have the new coinbase height (where we could see something like #4333).

Copy link
Collaborator

@friedger friedger left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Collaborator

@jferrant jferrant left a comment

Choose a reason for hiding this comment

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

LGTM! Has greatly improved my cast aggregate dkg vote PR so am excited to see this merged.

@jcnelson jcnelson merged commit 606838d into next Feb 10, 2024
2 checks passed
@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 Nov 5, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
5 participants