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

PoX-4 Signer Set Structs, Getters & Setters [wip] #4164

Closed

Conversation

setzeus
Copy link
Collaborator

@setzeus setzeus commented Dec 13, 2023

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:

  1. Update-current-signer
  2. Update-current-signer-set
  3. Get-signer-set-by-reward-cycle
  4. Get-signer-key-ids-by-reward-cycle

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:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

setzeus and others added 30 commits November 23, 2023 13:37
Signed-off-by: Jacinta Ferrant <jacinta@trustmachines.co>
@friedger friedger mentioned this pull request Dec 18, 2023
5 tasks
setzeus and others added 2 commits December 18, 2023 07:44
- Address type mismatch in POX 4 signer set retrieval
- Update variable and function usage for type compatibility
@moodmosaic moodmosaic force-pushed the feat/pox-4-signer-set-getter-and-setters branch from a171c84 to 3d98bfd Compare December 18, 2023 16:52
- Address type mismatch in PoX-4 signer set retrieval
- Update variable and function usage for type compatibility
sim.execute_next_block(|_env| {});
sim.execute_next_block(|_env| {});

sim.execute_next_block(|env| {
Copy link
Member

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;
Copy link
Member

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
Copy link
Member

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 }),
Copy link
Member

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.

Copy link
Member

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(
Copy link
Member

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 in pox-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)})
Copy link
Member

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.
Copy link
Member

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
Copy link
Member

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))
Copy link
Member

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};
Copy link
Member

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()
Copy link
Member

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)})))
Copy link
Member

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.

Copy link
Member

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)))
Copy link
Member

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)))
Copy link
Member

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.

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.

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!

@jcnelson jcnelson mentioned this pull request Dec 19, 2023
8 tasks
@setzeus setzeus changed the title PoX-4 Signer Set Structs, Getters & Setters PoX-4 Signer Set Structs, Getters & Setters [wip] Dec 21, 2023
@friedger
Copy link
Collaborator

Should be re-based to next or closed.

@setzeus
Copy link
Collaborator Author

setzeus commented Jan 10, 2024

@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).

@friedger friedger marked this pull request as draft January 10, 2024 16:56
@saralab saralab closed this Jan 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Status: ✅ Done
Development

Successfully merging this pull request may close these issues.

None yet