chore: rename pox-4-vote to signers-voting

This commit is contained in:
friedger
2024-01-30 09:56:16 +01:00
parent 070a3ea444
commit f243be052a
6 changed files with 51 additions and 50 deletions

View File

@@ -22,8 +22,8 @@ depends_on = []
clarity = 2
epoch = 2.4
[contracts.pox-4-vote]
path = "../../stackslib/src/chainstate/stacks/boot/pox-4-vote.clar"
[contracts.signers-voting]
path = "../../stackslib/src/chainstate/stacks/boot/signers-voting.clar"
depends_on = []
clarity = 2
epoch = 2.4

View File

@@ -17,12 +17,12 @@ const ERR_INVALID_BURN_BLOCK_HEIGHT = 10006
const KEY_1 = "123456789a123456789a123456789a123456789a123456789a123456789a010203";
const KEY_2 = "123456789a123456789a123456789a123456789a123456789a123456789ab0b1b2";
describe("test pox-4-vote contract voting rounds", () => {
describe("test signers-voting contract voting rounds", () => {
describe("test get-last-round", () => {
it("should return none before any vote", () => {
const { result: resultRound } = simnet.callReadOnlyFn(
"pox-4-vote",
"signers-voting",
"get-last-round",
[Cl.uint(0)],
alice,
@@ -31,12 +31,12 @@ describe("test pox-4-vote contract voting rounds", () => {
})
it("should return none after invalid vote", () => {
const { result: resultVote } = simnet.callPublicFn("pox-4-vote", "vote-for-aggregate-public-key",
const { result: resultVote } = simnet.callPublicFn("signers-voting", "vote-for-aggregate-public-key",
[Cl.bufferFromHex("12"), Cl.uint(0), Cl.uint(0),], alice);
expect(resultVote).toEqual(Cl.error(Cl.uint(ERR_INVALID_AGGREGATE_PUBLIC_KEY)));
const { result: resultRound } = simnet.callReadOnlyFn(
"pox-4-vote",
"signers-voting",
"get-last-round",
[Cl.uint(0)],
alice,
@@ -46,12 +46,12 @@ describe("test pox-4-vote contract voting rounds", () => {
})
it("should return round after valid vote", () => {
const { result: resultVote } = simnet.callPublicFn("pox-4-vote", "vote-for-aggregate-public-key",
const { result: resultVote } = simnet.callPublicFn("signers-voting", "vote-for-aggregate-public-key",
[Cl.bufferFromHex(KEY_1), Cl.uint(0), Cl.uint(0),], alice);
expect(resultVote).toEqual(Cl.ok(Cl.bool(true)));
const { result: resultRound } = simnet.callReadOnlyFn(
"pox-4-vote",
"signers-voting",
"get-last-round",
[Cl.uint(0)],
alice,
@@ -62,17 +62,17 @@ describe("test pox-4-vote contract voting rounds", () => {
it("should return last round after valid votes for two rounds", () => {
// Alice votes for cycle 0, round 0
const { result: resultVoteAlice } = simnet.callPublicFn("pox-4-vote", "vote-for-aggregate-public-key",
const { result: resultVoteAlice } = simnet.callPublicFn("signers-voting", "vote-for-aggregate-public-key",
[Cl.bufferFromHex(KEY_1), Cl.uint(0), Cl.uint(0),], alice);
expect(resultVoteAlice).toEqual(Cl.ok(Cl.bool(true)));
// Bob votes for cycle 0, round 1
const { result: resultVoteBob } = simnet.callPublicFn("pox-4-vote", "vote-for-aggregate-public-key",
const { result: resultVoteBob } = simnet.callPublicFn("signers-voting", "vote-for-aggregate-public-key",
[Cl.bufferFromHex(KEY_2), Cl.uint(0), Cl.uint(1),], bob);
expect(resultVoteBob).toEqual(Cl.ok(Cl.bool(true)));
const { result: resultLastRound0 } = simnet.callReadOnlyFn(
"pox-4-vote",
"signers-voting",
"get-last-round",
[Cl.uint(0)],
alice,
@@ -82,7 +82,7 @@ describe("test pox-4-vote contract voting rounds", () => {
it("should return last round after valid votes for different cycles", () => {
// Alice votes for cycle 0, round 1
const { result: resultVoteAlice } = simnet.callPublicFn("pox-4-vote", "vote-for-aggregate-public-key",
const { result: resultVoteAlice } = simnet.callPublicFn("signers-voting", "vote-for-aggregate-public-key",
[Cl.bufferFromHex(KEY_1), Cl.uint(0), Cl.uint(1),], alice);
expect(resultVoteAlice).toEqual(Cl.ok(Cl.bool(true)));
@@ -90,12 +90,12 @@ describe("test pox-4-vote contract voting rounds", () => {
simnet.mineEmptyBlocks(1050);
// Bob votes for cycle 1, round 0
const { result: resultVoteBob } = simnet.callPublicFn("pox-4-vote", "vote-for-aggregate-public-key",
const { result: resultVoteBob } = simnet.callPublicFn("signers-voting", "vote-for-aggregate-public-key",
[Cl.bufferFromHex(KEY_2), Cl.uint(1), Cl.uint(0),], bob);
expect(resultVoteBob).toEqual(Cl.ok(Cl.bool(true)));
const { result: resultLastRound0 } = simnet.callReadOnlyFn(
"pox-4-vote",
"signers-voting",
"get-last-round",
[Cl.uint(0)],
alice,
@@ -104,7 +104,7 @@ describe("test pox-4-vote contract voting rounds", () => {
const { result: resultLastRound1 } = simnet.callReadOnlyFn(
"pox-4-vote",
"signers-voting",
"get-last-round",
[Cl.uint(1)],
alice,
@@ -119,12 +119,12 @@ describe("test pox-4-vote contract voting rounds", () => {
it("should fail on same key for different round", () => {
// Alice votes for cycle 0, round 0
const { result: resultVoteAlice } = simnet.callPublicFn("pox-4-vote", "vote-for-aggregate-public-key",
const { result: resultVoteAlice } = simnet.callPublicFn("signers-voting", "vote-for-aggregate-public-key",
[Cl.bufferFromHex(KEY_1), Cl.uint(0), Cl.uint(0),], alice);
expect(resultVoteAlice).toEqual(Cl.ok(Cl.bool(true)));
// Bob votes for cycle 0, round 1
const { result: resultVoteBob } = simnet.callPublicFn("pox-4-vote", "vote-for-aggregate-public-key",
const { result: resultVoteBob } = simnet.callPublicFn("signers-voting", "vote-for-aggregate-public-key",
[Cl.bufferFromHex(KEY_1), Cl.uint(0), Cl.uint(1),], bob);
expect(resultVoteBob).toEqual(Cl.error(Cl.uint(ERR_DUPLICATE_AGGREGATE_PUBLIC_KEY)));
@@ -132,7 +132,7 @@ describe("test pox-4-vote contract voting rounds", () => {
it("should fail on same key for different cycles", () => {
// Alice votes for cycle 0, round 0
const { result: resultVoteAlice } = simnet.callPublicFn("pox-4-vote", "vote-for-aggregate-public-key",
const { result: resultVoteAlice } = simnet.callPublicFn("signers-voting", "vote-for-aggregate-public-key",
[Cl.bufferFromHex(KEY_1), Cl.uint(0), Cl.uint(0),], alice);
expect(resultVoteAlice).toEqual(Cl.ok(Cl.bool(true)));
@@ -140,7 +140,7 @@ describe("test pox-4-vote contract voting rounds", () => {
simnet.mineEmptyBlocks(1050);
// Bob votes for cycle 1, round 0
const { result: resultVoteBob } = simnet.callPublicFn("pox-4-vote", "vote-for-aggregate-public-key",
const { result: resultVoteBob } = simnet.callPublicFn("signers-voting", "vote-for-aggregate-public-key",
[Cl.bufferFromHex(KEY_1), Cl.uint(1), Cl.uint(0),], bob);
expect(resultVoteBob).toEqual(Cl.error(Cl.uint(ERR_DUPLICATE_AGGREGATE_PUBLIC_KEY)));
@@ -148,7 +148,7 @@ describe("test pox-4-vote contract voting rounds", () => {
it("should fail on same key for different cycles", () => {
// Alice votes for cycle 0, round 0
const { result: resultVoteAlice } = simnet.callPublicFn("pox-4-vote", "vote-for-aggregate-public-key",
const { result: resultVoteAlice } = simnet.callPublicFn("signers-voting", "vote-for-aggregate-public-key",
[Cl.bufferFromHex(KEY_1), Cl.uint(0), Cl.uint(0),], alice);
expect(resultVoteAlice).toEqual(Cl.ok(Cl.bool(true)));
@@ -156,7 +156,7 @@ describe("test pox-4-vote contract voting rounds", () => {
simnet.mineEmptyBlocks(1050);
// Bob votes for cycle 1, round 0
const { result: resultVoteBob } = simnet.callPublicFn("pox-4-vote", "vote-for-aggregate-public-key",
const { result: resultVoteBob } = simnet.callPublicFn("signers-voting", "vote-for-aggregate-public-key",
[Cl.bufferFromHex(KEY_1), Cl.uint(1), Cl.uint(0),], bob);
expect(resultVoteBob).toEqual(Cl.error(Cl.uint(ERR_DUPLICATE_AGGREGATE_PUBLIC_KEY)));
@@ -164,12 +164,12 @@ describe("test pox-4-vote contract voting rounds", () => {
it("should fail on second vote for same cycle and round", () => {
// Alice votes for cycle 0, round 0
const { result: resultVoteAlice } = simnet.callPublicFn("pox-4-vote", "vote-for-aggregate-public-key",
const { result: resultVoteAlice } = simnet.callPublicFn("signers-voting", "vote-for-aggregate-public-key",
[Cl.bufferFromHex(KEY_1), Cl.uint(0), Cl.uint(0),], alice);
expect(resultVoteAlice).toEqual(Cl.ok(Cl.bool(true)));
// Alice votes for cycle 0, round 0 again
const { result: resultVoteAlice2 } = simnet.callPublicFn("pox-4-vote", "vote-for-aggregate-public-key",
const { result: resultVoteAlice2 } = simnet.callPublicFn("signers-voting", "vote-for-aggregate-public-key",
[Cl.bufferFromHex(KEY_1), Cl.uint(0), Cl.uint(0),], alice);
expect(resultVoteAlice2).toEqual(Cl.error(Cl.uint(ERR_DUPLICATE_VOTE)));
@@ -177,7 +177,7 @@ describe("test pox-4-vote contract voting rounds", () => {
it("should fail on early vote", () => {
// Alice votes for cycle 1, round 0 during cycle 0
const { result: resultVoteAlice } = simnet.callPublicFn("pox-4-vote", "vote-for-aggregate-public-key",
const { result: resultVoteAlice } = simnet.callPublicFn("signers-voting", "vote-for-aggregate-public-key",
[Cl.bufferFromHex(KEY_1), Cl.uint(1), Cl.uint(0),], alice);
expect(resultVoteAlice).toEqual(Cl.error(Cl.uint(ERR_INCORRECT_REWARD_CYCLE)));
@@ -185,12 +185,12 @@ describe("test pox-4-vote contract voting rounds", () => {
it("should fail on late round", () => {
// Alice votes for cycle 0, round 1
const { result: resultVoteAlice } = simnet.callPublicFn("pox-4-vote", "vote-for-aggregate-public-key",
const { result: resultVoteAlice } = simnet.callPublicFn("signers-voting", "vote-for-aggregate-public-key",
[Cl.bufferFromHex(KEY_1), Cl.uint(0), Cl.uint(1),], alice);
expect(resultVoteAlice).toEqual(Cl.ok(Cl.bool(true)));
// Bob votes for cycle 0, round 0
const { result: resultVoteBob } = simnet.callPublicFn("pox-4-vote", "vote-for-aggregate-public-key",
const { result: resultVoteBob } = simnet.callPublicFn("signers-voting", "vote-for-aggregate-public-key",
[Cl.bufferFromHex(KEY_1), Cl.uint(0), Cl.uint(0),], bob);
expect(resultVoteBob).toEqual(Cl.error(Cl.uint(ERR_OLD_ROUND)));
})
@@ -199,12 +199,12 @@ describe("test pox-4-vote contract voting rounds", () => {
describe("test get-vote", () => {
it("should return correct aggregate-public-key and shared", () => {
// Alice votes for cycle 0, round 0
const { result: resultVoteAlice } = simnet.callPublicFn("pox-4-vote", "vote-for-aggregate-public-key",
const { result: resultVoteAlice } = simnet.callPublicFn("signers-voting", "vote-for-aggregate-public-key",
[Cl.bufferFromHex(KEY_1), Cl.uint(0), Cl.uint(0),], alice);
expect(resultVoteAlice).toEqual(Cl.ok(Cl.bool(true)));
const { result: vote } = simnet.callReadOnlyFn(
"pox-4-vote",
"signers-voting",
"get-vote",
[Cl.uint(0), Cl.uint(0), Cl.standardPrincipal(alice)],
alice,
@@ -219,7 +219,7 @@ describe("test pox-4-vote contract voting rounds", () => {
it("should return none when not yet voted", () => {
const { result: vote } = simnet.callReadOnlyFn(
"pox-4-vote",
"signers-voting",
"get-vote",
[Cl.uint(0), Cl.uint(0), Cl.standardPrincipal(alice)],
alice,

View File

@@ -78,8 +78,8 @@ pub const POX_1_NAME: &'static str = "pox";
pub const POX_2_NAME: &'static str = "pox-2";
pub const POX_3_NAME: &'static str = "pox-3";
pub const POX_4_NAME: &'static str = "pox-4";
pub const POX_4_VOTE_NAME: &'static str = "pox-4-vote";
pub const SIGNERS_NAME: &'static str = "signers";
pub const SIGNERS_VOTING_NAME: &'static str = "signers-voting";
/// This is the name of a variable in the `.signers` contract which tracks the most recently updated
/// reward cycle number.
pub const SIGNERS_UPDATE_STATE: &'static str = "last-set-cycle";
@@ -90,7 +90,7 @@ const POX_2_BODY: &'static str = std::include_str!("pox-2.clar");
const POX_3_BODY: &'static str = std::include_str!("pox-3.clar");
const POX_4_BODY: &'static str = std::include_str!("pox-4.clar");
pub const SIGNERS_BODY: &'static str = std::include_str!("signers.clar");
const POX_4_VOTE_BODY: &'static str = std::include_str!("pox-4-vote.clar");
const SIGNERS_VOTING_BODY: &'static str = std::include_str!("signers-voting.clar");
pub const COSTS_1_NAME: &'static str = "costs";
pub const COSTS_2_NAME: &'static str = "costs-2";
@@ -119,7 +119,7 @@ lazy_static! {
pub static ref POX_3_TESTNET_CODE: String =
format!("{}\n{}", BOOT_CODE_POX_TESTNET_CONSTS, POX_3_BODY);
pub static ref POX_4_CODE: String = format!("{}", POX_4_BODY);
pub static ref POX_4_VOTE_CODE: String = format!("{}", POX_4_VOTE_BODY);
pub static ref SIGNER_VOTING_CODE: String = format!("{}", SIGNERS_VOTING_BODY);
pub static ref BOOT_CODE_COST_VOTING_TESTNET: String = make_testnet_cost_voting();
pub static ref STACKS_BOOT_CODE_MAINNET: [(&'static str, &'static str); 6] = [
("pox", &BOOT_CODE_POX_MAINNET),
@@ -1309,9 +1309,9 @@ pub mod pox_3_tests;
#[cfg(test)]
pub mod pox_4_tests;
#[cfg(test)]
pub mod pox_4_vote_tests;
#[cfg(test)]
mod signers_tests;
#[cfg(test)]
pub mod signers_voting_tests;
#[cfg(test)]
pub mod test {
@@ -1881,7 +1881,7 @@ pub mod test {
make_tx(key, nonce, 0, payload)
}
pub fn make_pox_4_vote_for_aggregate_public_key(
pub fn make_signers_vote_for_aggregate_public_key(
key: &StacksPrivateKey,
nonce: u64,
aggregate_public_key: &Point,
@@ -1892,7 +1892,7 @@ pub mod test {
.expect("Failed to serialize aggregate public key");
let payload = TransactionPayload::new_contract_call(
boot_code_test_addr(),
POX_4_VOTE_NAME,
SIGNERS_VOTING_NAME,
"vote-for-aggregate-public-key",
vec![
aggregate_public_key,

View File

@@ -60,7 +60,8 @@ use crate::chainstate::stacks::boot::pox_4_tests::{
assert_latest_was_burn, get_last_block_sender_transactions, get_tip, make_test_epochs_pox,
};
use crate::chainstate::stacks::boot::{
BOOT_CODE_COST_VOTING_TESTNET as BOOT_CODE_COST_VOTING, BOOT_CODE_POX_TESTNET, POX_4_VOTE_NAME,
BOOT_CODE_COST_VOTING_TESTNET as BOOT_CODE_COST_VOTING, BOOT_CODE_POX_TESTNET,
SIGNERS_VOTING_NAME,
};
use crate::chainstate::stacks::db::{
MinerPaymentSchedule, StacksChainState, StacksHeaderInfo, MINER_REWARD_MATURITY,

View File

@@ -48,8 +48,8 @@ use crate::chainstate::stacks::boot::{
BOOT_CODE_COST_VOTING_TESTNET as BOOT_CODE_COST_VOTING, BOOT_CODE_POX_TESTNET,
BOOT_TEST_POX_4_AGG_KEY_CONTRACT, BOOT_TEST_POX_4_AGG_KEY_FNAME, COSTS_2_NAME, COSTS_3_NAME,
MINERS_NAME, POX_2_MAINNET_CODE, POX_2_NAME, POX_2_TESTNET_CODE, POX_3_MAINNET_CODE,
POX_3_NAME, POX_3_TESTNET_CODE, POX_4_CODE, POX_4_NAME, POX_4_VOTE_CODE, POX_4_VOTE_NAME,
SIGNERS_BODY, SIGNERS_NAME,
POX_3_NAME, POX_3_TESTNET_CODE, POX_4_CODE, POX_4_NAME, SIGNERS_BODY, SIGNERS_NAME,
SIGNERS_VOTING_NAME, SIGNER_VOTING_CODE,
};
use crate::chainstate::stacks::db::{StacksAccount, StacksChainState};
use crate::chainstate::stacks::events::{StacksTransactionEvent, StacksTransactionReceipt};
@@ -1450,13 +1450,13 @@ impl<'a, 'b> ClarityBlockConnection<'a, 'b> {
);
}
let pox_4_vote_code = &*POX_4_VOTE_CODE;
let pox_4_vote_contract_id = boot_code_id(POX_4_VOTE_NAME, mainnet);
let signers_voting_code = &*SIGNER_VOTING_CODE;
let signers_voting_contract_id = boot_code_id(SIGNERS_VOTING_NAME, mainnet);
let payload = TransactionPayload::SmartContract(
TransactionSmartContract {
name: ContractName::try_from(POX_4_VOTE_NAME)
name: ContractName::try_from(SIGNERS_VOTING_NAME)
.expect("FATAL: invalid boot-code contract name"),
code_body: StacksString::from_str(pox_4_vote_code)
code_body: StacksString::from_str(signers_voting_code)
.expect("FATAL: invalid boot code body"),
},
Some(ClarityVersion::Clarity2),
@@ -1465,25 +1465,25 @@ impl<'a, 'b> ClarityBlockConnection<'a, 'b> {
let signers_contract_tx =
StacksTransaction::new(tx_version.clone(), boot_code_auth.clone(), payload);
let pox_4_vote_initialization_receipt = self.as_transaction(|tx_conn| {
let signers_voting_initialization_receipt = self.as_transaction(|tx_conn| {
// initialize with a synthetic transaction
debug!("Instantiate {} contract", &pox_4_vote_contract_id);
debug!("Instantiate {} contract", &signers_voting_contract_id);
let receipt = StacksChainState::process_transaction_payload(
tx_conn,
&signers_contract_tx,
&boot_code_account,
ASTRules::PrecheckSize,
)
.expect("FATAL: Failed to process .pox-4-vote contract initialization");
.expect("FATAL: Failed to process .signers-voting contract initialization");
receipt
});
if pox_4_vote_initialization_receipt.result != Value::okay_true()
|| pox_4_vote_initialization_receipt.post_condition_aborted
if signers_voting_initialization_receipt.result != Value::okay_true()
|| signers_voting_initialization_receipt.post_condition_aborted
{
panic!(
"FATAL: Failure processing pox-4-vote contract initialization: {:#?}",
&pox_4_vote_initialization_receipt
"FATAL: Failure processing signers-voting contract initialization: {:#?}",
&signers_voting_initialization_receipt
);
}