-
Notifications
You must be signed in to change notification settings - Fork 678
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
Reward set calculation and RPC endpoint #4311
Conversation
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## next #4311 +/- ##
===========================================
+ Coverage 44.92% 76.67% +31.74%
===========================================
Files 443 445 +2
Lines 316901 317161 +260
===========================================
+ Hits 142370 243184 +100814
+ Misses 174531 73977 -100554 ☔ View full report in Codecov by Sentry. |
105860f
to
b92dcdd
Compare
@@ -611,6 +611,22 @@ impl<'a> ClarityDatabase<'a> { | |||
self.store.insert_metadata(contract_identifier, key, data); | |||
} | |||
|
|||
/// Set a metadata entry if it hasn't already been set, yielding | |||
/// a runtime error if it was. This should only be called by post-nakamoto | |||
/// contexts. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you help me understand how this error could be triggered?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, this function should just be removed -- at first I was going to try to store the computed reward set as metadata, in which case, this function might have been needed. But metadata storage in Clarity is very closely tied to contract instantiation, so it would be really cumbersome to have done things this way.
// | ||
// Data **cannot** be read from `.signers` in epoch 2.5 because the write occurs | ||
// in the first block of the prepare phase, but the PoX anchor block is *before* | ||
// the prepare phase. Therefore |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unfinished thought?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I think I completed the thought in my latest commit, but it's hard to know exactly where I was planning to go with that sentence.
.expect_optional() | ||
.map(|x| u64::try_from(x.expect_u128()).expect("FATAL: block height exceeded u64")) | ||
else { | ||
if debug_log { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a way to DRY this up? Perhaps a custom logging function?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, a new macro definition would be necessary. I can add.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a local macro for this.
"checked_block" => %reward_set_block.index_block_hash() | ||
); | ||
} else { | ||
error!( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got a log discrepancy (needs to be DRY'ed up)
@@ -0,0 +1,387 @@ | |||
// Copyright (C) 2013-2020 Blockstack PBC, a public benefit corporation | |||
// Copyright (C) 2020-2023 Stacks Open Internet Foundation |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2024
stackslib/src/net/api/mod.rs
Outdated
@@ -114,6 +115,7 @@ impl StacksHttp { | |||
self.register_rpc_endpoint(postmicroblock::RPCPostMicroblockRequestHandler::new()); | |||
self.register_rpc_endpoint(poststackerdbchunk::RPCPostStackerDBChunkRequestHandler::new()); | |||
self.register_rpc_endpoint(posttransaction::RPCPostTransactionRequestHandler::new()); | |||
self.register_rpc_endpoint(getstackers::GetStackersRequestHandler::default()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Miner code aesthetic: can you place the call to self.register_rpc_endpoint()
in alphabetical order with the other RPC endpoints? So, after the one for getstackerdbmetadata
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, but are we sure it shouldn't be after getstackerdbchunk
and before getpoxinfo
;) ?
@@ -68,13 +68,19 @@ fn advance_to_nakamoto( | |||
) | |||
.unwrap(); | |||
|
|||
// use the signing key of addr, otherwise the test stackers | |||
// will not stack enough for any single signing key | |||
// let signing_key = StacksPublicKey::from_private(&private_key); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Commented code
LGTM; just fix merge conflicts and make sure CI passes. Thanks! |
* expand e2e correct_burns test to invoke the new RPC endpoint * fix reward-set storage information to write correct coinbase height
cda02b1
to
c6a54db
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM :D
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good. I just had two minor comments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
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. |
Description
Implement #4295 and #4298
4295: Reading the reward set data from
.signers
Implementation of #4295 is kind of subtle, and will have to impose additional constraints on Epoch-2.5 (one of which isn't implemented in this PR, but could be added, I suppose).
Reading the reward set state from the calculation performed for
.signers
is only possible after that calculation is performed (due to the general nature of causality and the linear passage of time). This calculation is performed during the first block of a prepare phase. This does not pose a challenge for nakamoto, because that's the block it chooses as the PoX anchor block anyways, so, of course it can read that data. For Epoch 2.5, however, this is a challenge: the PoX anchor block always comes before the prepare phase.To deal with this, this PR splits the reward set loading by epoch -- in Nakamoto, it reads from the
.signers
, but in Epoch 2.5, it continues to use the 2.x reward set routine. However, we still want to ensure that the calculation done by the 2.x reward set routine at the PoX anchor block and the calculation performed by.signers
work out to the same result. The PoX anchor block (if one is chosen) in any given fork is the last block before the prepare phase. This means that the.signers
calculation will always occur with the PoX anchor block as its anchor block parent. Because the 2.x reward set routine uses the state at the end of block processing, we can ensure that the reward set calculations are the same if:
.signers
calculation occurs before any burn operation processing.This PR implements the first step there. For the second step, I'd propose to disable microblocks in Epoch 2.5.
4298: New RPC endpoint `/v2/stacker_set/{cycle_number}
This endpoint returns the same
RewardSet
JSON data propagated over the event observer interface. Callers must supply a cycle number to query for. It will return 400 if the set hasn't been calculated yet or if the requested cycle wasn't a PoX-4 cycle.