From 6b87b776cc7f0cd9e1b75bbd6cec8a946df6901e Mon Sep 17 00:00:00 2001 From: jesus Date: Thu, 8 Feb 2024 07:33:22 -0500 Subject: [PATCH] updated error message format to match pox-4 messages --- .../stacks/boot/signers-voting.clar | 30 +++++++++---------- .../stacks/boot/signers_voting_tests.rs | 4 +-- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/stackslib/src/chainstate/stacks/boot/signers-voting.clar b/stackslib/src/chainstate/stacks/boot/signers-voting.clar index 9b30c137a..5192386ba 100644 --- a/stackslib/src/chainstate/stacks/boot/signers-voting.clar +++ b/stackslib/src/chainstate/stacks/boot/signers-voting.clar @@ -9,14 +9,14 @@ ;; maps aggregate public keys to rewards cycles and rounds (define-map used-aggregate-public-keys (buff 33) {reward-cycle: uint, round: uint}) -(define-constant err-signer-index-mismatch (err u10000)) -(define-constant err-invalid-signer-index (err u10001)) -(define-constant err-out-of-voting-window (err u10002)) -(define-constant err-old-round (err u10003)) -(define-constant err-ill-formed-aggregate-public-key (err u10004)) -(define-constant err-duplicate-aggregate-public-key (err u10005)) -(define-constant err-duplicate-vote (err u10006)) -(define-constant err-invalid-burn-block-height (err u10007)) +(define-constant ERR_SIGNER_INDEX_MISMATCH 1) +(define-constant ERR_INVALID_SIGNER_INDEX 2) +(define-constant ERR_OUT_OF_VOTING_WINDOW 3) +(define-constant ERR_OLD_ROUND 4) +(define-constant ERR_ILL_FORMED_AGGREGATE_PUBLIC_KEY 5) +(define-constant ERR_DUPLICATE_AGGREGATE_PUBLIC_KEY 6) +(define-constant ERR_DUPLICATE_VOTE 7) +(define-constant ERR_INVALID_BURN_BLOCK_HEIGHT 8) (define-constant pox-info (unwrap-panic (contract-call? .pox-4 get-pox-info))) @@ -47,8 +47,8 @@ (get-signer-slots signer-index cycle))) (define-read-only (get-signer-slots (signer-index uint) (reward-cycle uint)) - (let ((details (unwrap! (try! (contract-call? .signers get-signer-by-index reward-cycle signer-index)) err-invalid-signer-index))) - (asserts! (is-eq (get signer details) tx-sender) err-signer-index-mismatch) + (let ((details (unwrap! (try! (contract-call? .signers get-signer-by-index reward-cycle signer-index)) (err (to-uint ERR_INVALID_SIGNER_INDEX))))) + (asserts! (is-eq (get signer details) tx-sender) (err (to-uint ERR_SIGNER_INDEX_MISMATCH))) (ok (get weight details)))) ;; aggregate public key must be unique and can be used only in a single cycle-round pair @@ -73,11 +73,11 @@ ;; one slot, one vote (num-slots (try! (get-current-signer-slots signer-index))) (new-total (+ num-slots (default-to u0 (map-get? tally tally-key))))) - (asserts! (is-in-voting-window burn-block-height reward-cycle) err-out-of-voting-window) - (asserts! (>= round (default-to u0 (map-get? rounds reward-cycle))) err-old-round) - (asserts! (is-eq (len key) u33) err-ill-formed-aggregate-public-key) - (asserts! (is-valid-aggregated-public-key key {reward-cycle: reward-cycle, round: round}) err-duplicate-aggregate-public-key) - (asserts! (map-insert votes {reward-cycle: reward-cycle, round: round, signer: tx-sender} {aggregate-public-key: key, reward-slots: num-slots}) err-duplicate-vote) + (asserts! (is-in-voting-window burn-block-height reward-cycle) (err (to-uint ERR_OUT_OF_VOTING_WINDOW))) + (asserts! (>= round (default-to u0 (map-get? rounds reward-cycle))) (err (to-uint ERR_OLD_ROUND))) + (asserts! (is-eq (len key) u33) (err (to-uint ERR_ILL_FORMED_AGGREGATE_PUBLIC_KEY))) + (asserts! (is-valid-aggregated-public-key key {reward-cycle: reward-cycle, round: round}) (err (to-uint ERR_DUPLICATE_AGGREGATE_PUBLIC_KEY))) + (asserts! (map-insert votes {reward-cycle: reward-cycle, round: round, signer: tx-sender} {aggregate-public-key: key, reward-slots: num-slots}) (err (to-uint ERR_DUPLICATE_VOTE))) (map-set tally tally-key new-total) (map-set used-aggregate-public-keys key {reward-cycle: reward-cycle, round: round}) (update-last-round reward-cycle round) diff --git a/stackslib/src/chainstate/stacks/boot/signers_voting_tests.rs b/stackslib/src/chainstate/stacks/boot/signers_voting_tests.rs index 9fff91e6b..8766dfc34 100644 --- a/stackslib/src/chainstate/stacks/boot/signers_voting_tests.rs +++ b/stackslib/src/chainstate/stacks/boot/signers_voting_tests.rs @@ -213,7 +213,7 @@ fn vote_for_aggregate_public_key_in_first_block() { tx2.result, Value::Response(ResponseData { committed: false, - data: Box::new(Value::UInt(10006)) // err-duplicate-vote + data: Box::new(Value::UInt(7)) // err-duplicate-vote }) ); } @@ -352,7 +352,7 @@ fn vote_for_aggregate_public_key_in_last_block() { tx2.result, Value::Response(ResponseData { committed: false, - data: Box::new(Value::UInt(10006)) // err-duplicate-vote + data: Box::new(Value::UInt(7)) // err-duplicate-vote }) );