-
Notifications
You must be signed in to change notification settings - Fork 647
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
PoX-4 Signer Set Structs, Getters & Setters [wip] #4164
PoX-4 Signer Set Structs, Getters & Setters [wip] #4164
Conversation
…nlock to /new_block events
Signed-off-by: Jacinta Ferrant <jacinta@trustmachines.co>
…le file descriptors
- Address type mismatch in POX 4 signer set retrieval - Update variable and function usage for type compatibility
a171c84
to
3d98bfd
Compare
- Address type mismatch in PoX-4 signer set retrieval - Update variable and function usage for type compatibility
214d72d
to
81273b6
Compare
sim.execute_next_block(|_env| {}); | ||
sim.execute_next_block(|_env| {}); | ||
|
||
sim.execute_next_block(|env| { |
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 verify that this actually catches syntax errors in pox-4
? Because, it hadn't in the past.
@@ -34,6 +34,7 @@ use clarity::vm::types::{ | |||
}; | |||
use clarity::vm::{ClarityVersion, Environment, SymbolicExpression}; | |||
use lazy_static::lazy_static; | |||
use libc::sem_t; |
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.
What's this?
@@ -1735,6 +1765,38 @@ pub mod test { | |||
make_tx(key, nonce, 0, payload) | |||
} | |||
|
|||
// Get the current signer set |
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.
Please don't commit commented-out code
vec![ | ||
Value::UInt(lock_period), | ||
addr_tuple, | ||
Value::Optional(OptionalData { data: None }), |
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.
The make_pox_4_extend()
function needs to also take an Option<StacksPublicKey>
so it can be added into this call to stack-extend
.
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.
Generally speaking, you shouldn't put in default values to PoX-4 callers like make_pox_4_extend
. Anything you pass into .pox-4
should be a Rust argument.
@@ -1165,6 +1166,37 @@ impl StacksChainState { | |||
}); | |||
Ok(aggregate_public_key) | |||
} | |||
|
|||
// Get the current signer set | |||
pub fn get_current_signer_set_pox_4( |
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.
I don't think you currently have the means of testing this, because there isn't any logic written to write state into reward-cycle-signing-keys
. So, I think one of two things need to happen:
-
You can add the logic to insert state into
reward-cycle-signing-keys
, e.g. via a private function inpox-4
that the node can call. If you take this route, then you should also add some code to actually populate this data map so you can proceed to test this function in a unit test. -
You can delete this function for now, and we'll add it back in once it's possible to populate
reward-cycle-signing-keys
.
;; Map that tracks the signing-key & cycle to a list of key-ids | ||
(define-map reward-cycle-signing-key-ids | ||
{cycle: uint, signer: (buff 33)} | ||
{key-ids: (list 4000 uint)}) |
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 add a comment explaining what a key-id
is supposed to be, and why it's necessary in addition to the signer-address
in reward-cycle-signing-keys
and signer
in reward-cycle-signing-key-ids
? Also, why have both the signing key and the address?
@@ -576,13 +603,14 @@ | |||
|
|||
;; Lock up some uSTX for stacking! Note that the given amount here is in micro-STX (uSTX). | |||
;; The STX will be locked for the given number of reward cycles (lock-period). | |||
;; This is the self-service interface. tx-sender will be the Stacker. | |||
;; This is the self-service interface. tx-sender will be the Stacker. Stacker is responsible for providing a valid signing 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.
Please word-wrap, and also it's The Stacker is responsible ...
.
;; | ||
;; * The given stacker cannot currently be stacking. | ||
;; * You will need the minimum uSTX threshold. This will be determined by (get-stacking-minimum) | ||
;; at the time this method is called. | ||
;; * You may need to increase the amount of uSTX locked up later, since the minimum uSTX threshold | ||
;; may increase between reward cycles. | ||
;; * You need to provide a signing-key used to allocate signature-weight to a valid signer |
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.
signature weight
(asserts! (is-none next-signer-set-map) (err ERR_NEXT_SIGNER_SET_ALREADY_REGISTERED)) | ||
|
||
;; Assert in prepare phase (height equal to / greater than start of prepare phase) | ||
(asserts! (>= block-height (- next-reward-cycle-burn-height u100)) (err ERR_NOT_IN_PREPARE_PHASE_EARLY)) |
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 should be a define-read-only
function called is-in-prepare-phase
. I think one of @friedger's PRs has this?
@@ -67,6 +67,7 @@ use crate::chainstate::stacks::index::marf::MarfConnection; | |||
use crate::chainstate::stacks::index::MarfTrieId; | |||
use crate::chainstate::stacks::tests::make_coinbase; | |||
use crate::chainstate::stacks::*; | |||
use crate::chainstate::{self}; |
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 is a nonsensical import
let reward_cycle = burnchain | ||
.block_height_to_reward_cycle(tip.block_height) | ||
.unwrap() as u64; | ||
peer.chainstate() |
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 doesn't test anything. There's nothing in this data map, so there's nothing to check. Please actually add data to the data map and verify that you can read it out.
|
||
;; return the lock-up information, so the node can actually carry out the lock. | ||
(ok { stacker: stacker, | ||
unlock-burn-height: new-unlock-ht })))) | ||
|
||
;; This function allows a node to register a new 'current-signer-set' during the prepare phase | ||
(define-private (set-current-signer-set (new-signer-set (list 4000 {signer: (buff 33)}))) |
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.
There is currently no test coverage for this. There should be a unit test in pox_4_tests.rs
that calls this function with some synthetic data, and reads it back out again.
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.
Your tests should hit not only the happy path, but also each of the failure paths (and verify that the right error code is returned).
|
||
;; This function allows a node to register a list of key-ids to the current-signer-set | ||
;; This work is done one-at-a-time by the node & could require up to 4000 individual writes | ||
(define-private (set-current-signer (signer (buff 33)) (key-ids (list 4000 uint))) |
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.
There is currently no test coverage for this. Please add it to pox_4_tests.rs
. As before, test each error path as well as the happy path.
;; Gets the signer-set for a given reward cycle | ||
(define-read-only (get-signer-set-by-reward-cycle (cycle uint)) | ||
(let ((cycle-to-burn-height (reward-cycle-to-burn-height cycle)) | ||
(burn-height-to-id-header-hash (get-block-info? id-header-hash cycle-to-burn-height))) |
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 doesn't type-check, since get-block-info?
returns an (optional ..)
. Again, please type-check your code before asking for a review. Use clarity-cli check
or have your unit tests run an analysis pass.
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.
Hey @setzeus, there's still lots of work to do here. In particular, it seems that your unit tests don't verify that pox-4
even type-checks. Please fix this, and please add the unit tests described in the above comments. Thanks!
81273b6
to
72ca439
Compare
Should be re-based to next or closed. |
@friedger waiting for @MarvinJanssen to complete his .Signers work to see which of the maps created in this PR will stay here (aka will re-base off of his branch once published or will close). |
PoX-4 Signer Set Structs, Getters, & Setters
Summary of Changes
This PR is WIP addition to #4092 that addresses the PoX-4/Argon epic #3970 with the specific issue #4164. As titled, this specific PR introduces the data structures, getters & setters for the current & next-cycle signer set.
Each cycle signer set can hold up to 4096 signers (identified by a (buff 33)), each with a list of 4096 key-ids (represented as a uint). The following functions were introduced:
Testing
How were these changes tested?
This was only tested locally for instantiation. Unit tests will be address in #4092 prior to merging into Next.
What future testing should occur?
The logic here should have corresponding unit tests in both Rust & Clarinet/Clarity. I'll be working with @moodmosaic to address these tests correctly.
Checklist: