diff --git a/cli/src/processor/localnet.rs b/cli/src/processor/localnet.rs index a2edeca03..dd626774d 100644 --- a/cli/src/processor/localnet.rs +++ b/cli/src/processor/localnet.rs @@ -120,8 +120,8 @@ fn create_threads(client: &Client, mint_pubkey: Pubkey) -> Result<()> { client.payer_pubkey(), epoch_thread_id.into(), clockwork_client::network::instruction::registry_epoch_kickoff( - epoch_thread_pubkey, Snapshot::pubkey(0), + epoch_thread_pubkey, ) .into(), client.payer_pubkey(), diff --git a/client/src/network/instruction/registry_epoch_kickoff.rs b/client/src/network/instruction/registry_epoch_kickoff.rs index 9324aab74..cee046838 100644 --- a/client/src/network/instruction/registry_epoch_kickoff.rs +++ b/client/src/network/instruction/registry_epoch_kickoff.rs @@ -9,14 +9,14 @@ use { clockwork_network_program::objects::*, }; -pub fn registry_epoch_kickoff(thread: Pubkey, snapshot: Pubkey) -> Instruction { +pub fn registry_epoch_kickoff(snapshot: Pubkey, thread: Pubkey) -> Instruction { Instruction { program_id: clockwork_network_program::ID, accounts: vec![ AccountMeta::new_readonly(Config::pubkey(), false), - AccountMeta::new_readonly(thread, true), AccountMeta::new(Registry::pubkey(), false), AccountMeta::new_readonly(snapshot, false), + AccountMeta::new_readonly(thread, true), ], data: clockwork_network_program::instruction::RegistryEpochKickoff {}.data(), } diff --git a/client/src/network/instruction/registry_nonce_hash.rs b/client/src/network/instruction/registry_nonce_hash.rs index 474a5bb0b..ccd829221 100644 --- a/client/src/network/instruction/registry_nonce_hash.rs +++ b/client/src/network/instruction/registry_nonce_hash.rs @@ -14,8 +14,8 @@ pub fn registry_nonce_hash(thread: Pubkey) -> Instruction { program_id: clockwork_network_program::ID, accounts: vec![ AccountMeta::new_readonly(Config::pubkey(), false), - AccountMeta::new_readonly(thread, true), AccountMeta::new(Registry::pubkey(), false), + AccountMeta::new_readonly(thread, true), ], data: clockwork_network_program::instruction::RegistryNonceHash {}.data(), } diff --git a/programs/network/src/instructions/delegation_stake.rs b/programs/network/src/instructions/delegation_stake.rs index f2e61df71..eafad9641 100644 --- a/programs/network/src/instructions/delegation_stake.rs +++ b/programs/network/src/instructions/delegation_stake.rs @@ -31,15 +31,15 @@ pub struct DelegationStake<'info> { )] pub delegation_stake: Account<'info, TokenAccount>, - #[account(address = config.epoch_thread)] - pub thread: Signer<'info>, - #[account( address = Registry::pubkey(), constraint = registry.locked )] pub registry: Account<'info, Registry>, + #[account(address = config.epoch_thread)] + pub thread: Signer<'info>, + #[account(address = anchor_spl::token::ID)] pub token_program: Program<'info, Token>, @@ -58,8 +58,8 @@ pub fn handler(ctx: Context) -> Result { let config = &ctx.accounts.config; let delegation = &mut ctx.accounts.delegation; let delegation_stake = &mut ctx.accounts.delegation_stake; - let thread = &ctx.accounts.thread; let registry = &ctx.accounts.registry; + let thread = &ctx.accounts.thread; let token_program = &ctx.accounts.token_program; let worker = &ctx.accounts.worker; let worker_stake = &ctx.accounts.worker_stake; @@ -107,8 +107,8 @@ pub fn handler(ctx: Context) -> Result { get_associated_token_address(&next_delegation_pubkey, &config.mint), false, ), - AccountMetaData::new_readonly(thread.key(), true), AccountMetaData::new_readonly(registry.key(), false), + AccountMetaData::new_readonly(thread.key(), true), AccountMetaData::new_readonly(token_program.key(), false), AccountMetaData::new_readonly(worker.key(), false), AccountMetaData::new(worker_stake.key(), false), @@ -126,8 +126,8 @@ pub fn handler(ctx: Context) -> Result { program_id: crate::ID, accounts: vec![ AccountMetaData::new_readonly(config.key(), false), - AccountMetaData::new_readonly(thread.key(), true), AccountMetaData::new_readonly(registry.key(), false), + AccountMetaData::new_readonly(thread.key(), true), AccountMetaData::new_readonly( Worker::pubkey(worker.id.checked_add(1).unwrap()), false, @@ -142,13 +142,13 @@ pub fn handler(ctx: Context) -> Result { accounts: vec![ AccountMetaData::new_readonly(config.key(), false), AccountMetaData::new(clockwork_utils::PAYER_PUBKEY, true), - AccountMetaData::new_readonly(thread.key(), true), AccountMetaData::new_readonly(registry.key(), false), AccountMetaData::new( Snapshot::pubkey(registry.current_epoch.checked_add(1).unwrap()), false, ), AccountMetaData::new_readonly(system_program::ID, false), + AccountMetaData::new_readonly(thread.key(), true), ], data: anchor_sighash("snapshot_create").to_vec(), }) diff --git a/programs/network/src/instructions/fee_distribute.rs b/programs/network/src/instructions/fee_distribute.rs index 69a76dc76..16d319f0b 100644 --- a/programs/network/src/instructions/fee_distribute.rs +++ b/programs/network/src/instructions/fee_distribute.rs @@ -33,9 +33,6 @@ pub struct FeeDistribute<'info> { )] pub fee: Account<'info, Fee>, - #[account(address = config.epoch_thread)] - pub thread: Signer<'info>, - #[account(address = Registry::pubkey())] pub registry: Account<'info, Registry>, @@ -58,6 +55,9 @@ pub struct FeeDistribute<'info> { )] pub snapshot_entry: Account<'info, SnapshotEntry>, + #[account(address = config.epoch_thread)] + pub thread: Signer<'info>, + #[account(address = worker.pubkey())] pub worker: Account<'info, Worker>, } @@ -67,11 +67,11 @@ pub fn handler(ctx: Context) -> Result { let config = &ctx.accounts.config; let delegation = &mut ctx.accounts.delegation; let fee = &mut ctx.accounts.fee; - let thread = &ctx.accounts.thread; let registry = &ctx.accounts.registry; let snapshot = &ctx.accounts.snapshot; let snapshot_entry = &ctx.accounts.snapshot_entry; let snapshot_frame = &ctx.accounts.snapshot_frame; + let thread = &ctx.accounts.thread; let worker = &ctx.accounts.worker; // Calculate the balance of this particular delegation, based on the weight of its stake with this worker. @@ -123,11 +123,11 @@ pub fn handler(ctx: Context) -> Result { AccountMetaData::new_readonly(config.key(), false), AccountMetaData::new(next_delegation_pubkey, false), AccountMetaData::new(fee.key(), false), - AccountMetaData::new_readonly(thread.key(), true), AccountMetaData::new_readonly(registry.key(), false), AccountMetaData::new_readonly(snapshot.key(), false), AccountMetaData::new_readonly(snapshot_frame.key(), false), AccountMetaData::new_readonly(next_snapshot_entry_pubkey, false), + AccountMetaData::new_readonly(thread.key(), true), AccountMetaData::new_readonly(worker.key(), false), ], data: anchor_sighash("fee_distribute").to_vec(), @@ -147,10 +147,10 @@ pub fn handler(ctx: Context) -> Result { accounts: vec![ AccountMetaData::new_readonly(config.key(), false), AccountMetaData::new(Fee::pubkey(next_worker_pubkey), false), - AccountMetaData::new_readonly(thread.key(), true), AccountMetaData::new_readonly(registry.key(), false), AccountMetaData::new_readonly(snapshot.key(), false), AccountMetaData::new_readonly(next_snapshot_frame_pubkey, false), + AccountMetaData::new_readonly(thread.key(), true), AccountMetaData::new(next_worker_pubkey, false), ], data: anchor_sighash("worker_fees_distribute").to_vec(), @@ -161,8 +161,8 @@ pub fn handler(ctx: Context) -> Result { program_id: crate::ID, accounts: vec![ AccountMetaData::new_readonly(config.key(), false), - AccountMetaData::new_readonly(thread.key(), true), AccountMetaData::new_readonly(registry.key(), false), + AccountMetaData::new_readonly(thread.key(), true), AccountMetaData::new_readonly(Worker::pubkey(0), false), ], data: anchor_sighash("worker_delegations_stake").to_vec(), diff --git a/programs/network/src/instructions/registry_epoch_cutover.rs b/programs/network/src/instructions/registry_epoch_cutover.rs index 5d55489ee..ed079a29a 100644 --- a/programs/network/src/instructions/registry_epoch_cutover.rs +++ b/programs/network/src/instructions/registry_epoch_cutover.rs @@ -7,22 +7,22 @@ pub struct RegistryEpochCutover<'info> { #[account(address = Config::pubkey())] pub config: Account<'info, Config>, - #[account(address = config.epoch_thread)] - pub thread: Signer<'info>, - #[account( mut, seeds = [SEED_REGISTRY], bump, )] pub registry: Account<'info, Registry>, + + #[account(address = config.epoch_thread)] + pub thread: Signer<'info>, } pub fn handler(ctx: Context) -> Result { // Get accounts. let config = &ctx.accounts.config; - let thread = &ctx.accounts.thread; let registry = &mut ctx.accounts.registry; + let thread = &ctx.accounts.thread; // Move the current epoch forward. registry.current_epoch = registry.current_epoch.checked_add(1).unwrap(); @@ -34,12 +34,12 @@ pub fn handler(ctx: Context) -> Result { program_id: crate::ID, accounts: vec![ AccountMetaData::new_readonly(config.key(), false), - AccountMetaData::new(thread.key(), true), AccountMetaData::new_readonly(registry.key(), false), AccountMetaData::new( Snapshot::pubkey(registry.current_epoch.checked_sub(1).unwrap()), false, ), + AccountMetaData::new(thread.key(), true), ], data: anchor_sighash("snapshot_delete").to_vec(), }); diff --git a/programs/network/src/instructions/registry_epoch_kickoff.rs b/programs/network/src/instructions/registry_epoch_kickoff.rs index a71eede47..56024b4b8 100644 --- a/programs/network/src/instructions/registry_epoch_kickoff.rs +++ b/programs/network/src/instructions/registry_epoch_kickoff.rs @@ -27,9 +27,6 @@ pub struct RegistryEpochKickoff<'info> { #[account(address = Config::pubkey())] pub config: Account<'info, Config>, - #[account(address = config.epoch_thread)] - pub thread: Signer<'info>, - #[account( mut, seeds = [SEED_REGISTRY], @@ -42,14 +39,17 @@ pub struct RegistryEpochKickoff<'info> { constraint = snapshot.id.eq(®istry.current_epoch) )] pub snapshot: Account<'info, Snapshot>, + + #[account(address = config.epoch_thread)] + pub thread: Signer<'info>, } pub fn handler(ctx: Context) -> Result { // Get accounts. let config = &ctx.accounts.config; - let thread = &ctx.accounts.thread; let registry = &mut ctx.accounts.registry; let snapshot = &ctx.accounts.snapshot; + let thread = &ctx.accounts.thread; // Lock the registry registry.locked = true; @@ -59,12 +59,12 @@ pub fn handler(ctx: Context) -> Result { program_id: crate::ID, accounts: vec![ AccountMetaData::new_readonly(config.key(), false), - AccountMetaData::new_readonly(thread.key(), true), AccountMetaData::new(registry.key(), false), AccountMetaData::new_readonly( Snapshot::pubkey(snapshot.id.checked_add(1).unwrap()), false, ), + AccountMetaData::new_readonly(thread.key(), true), ], data: anchor_sighash("registry_epoch_kickoff").to_vec(), }); @@ -77,10 +77,10 @@ pub fn handler(ctx: Context) -> Result { accounts: vec![ AccountMetaData::new_readonly(config.key(), false), AccountMetaData::new(Fee::pubkey(Worker::pubkey(0)), false), - AccountMetaData::new_readonly(thread.key(), true), AccountMetaData::new_readonly(registry.key(), false), AccountMetaData::new_readonly(snapshot.key(), false), AccountMetaData::new_readonly(SnapshotFrame::pubkey(snapshot.key(), 0), false), + AccountMetaData::new_readonly(thread.key(), true), AccountMetaData::new(Worker::pubkey(0), false), ], data: anchor_sighash("worker_fees_distribute").to_vec(), @@ -91,8 +91,8 @@ pub fn handler(ctx: Context) -> Result { program_id: crate::ID, accounts: vec![ AccountMetaData::new_readonly(config.key(), false), - AccountMetaData::new_readonly(thread.key(), true), AccountMetaData::new_readonly(registry.key(), false), + AccountMetaData::new_readonly(thread.key(), true), AccountMetaData::new_readonly(Worker::pubkey(0), false), ], data: anchor_sighash("worker_delegations_stake").to_vec(), @@ -103,8 +103,8 @@ pub fn handler(ctx: Context) -> Result { program_id: crate::ID, accounts: vec![ AccountMetaData::new_readonly(config.key(), false), - AccountMetaData::new_readonly(thread.key(), true), AccountMetaData::new(registry.key(), false), + AccountMetaData::new_readonly(thread.key(), true), ], data: anchor_sighash("registry_epoch_cutover").to_vec(), }) diff --git a/programs/network/src/instructions/registry_nonce_hash.rs b/programs/network/src/instructions/registry_nonce_hash.rs index c9df338c6..658bba7c5 100644 --- a/programs/network/src/instructions/registry_nonce_hash.rs +++ b/programs/network/src/instructions/registry_nonce_hash.rs @@ -7,15 +7,15 @@ pub struct RegistryNonceHash<'info> { #[account(address = Config::pubkey())] pub config: Account<'info, Config>, - #[account(address = config.hasher_thread)] - pub thread: Signer<'info>, - #[account( mut, seeds = [SEED_REGISTRY], bump )] pub registry: Account<'info, Registry>, + + #[account(address = config.hasher_thread)] + pub thread: Signer<'info>, } pub fn handler(ctx: Context) -> Result { diff --git a/programs/network/src/instructions/snapshot_create.rs b/programs/network/src/instructions/snapshot_create.rs index 7c5a69426..b5dad824c 100644 --- a/programs/network/src/instructions/snapshot_create.rs +++ b/programs/network/src/instructions/snapshot_create.rs @@ -14,9 +14,6 @@ pub struct SnapshotCreate<'info> { #[account(mut)] pub payer: Signer<'info>, - #[account(address = config.epoch_thread)] - pub thread: Signer<'info>, - #[account( address = Registry::pubkey(), constraint = registry.locked @@ -37,16 +34,19 @@ pub struct SnapshotCreate<'info> { #[account(address = system_program::ID)] pub system_program: Program<'info, System>, + + #[account(address = config.epoch_thread)] + pub thread: Signer<'info>, } pub fn handler(ctx: Context) -> Result { // Get accounts let config = &ctx.accounts.config; let payer = &ctx.accounts.payer; - let thread = &ctx.accounts.thread; let registry = &ctx.accounts.registry; let snapshot = &mut ctx.accounts.snapshot; let system_program = &ctx.accounts.system_program; + let thread = &ctx.accounts.thread; // Start a new snapshot. snapshot.init(registry.current_epoch.checked_add(1).unwrap())?; @@ -61,11 +61,11 @@ pub fn handler(ctx: Context) -> Result { accounts: vec![ AccountMetaData::new_readonly(config.key(), false), AccountMetaData::new(payer.key(), true), - AccountMetaData::new_readonly(thread.key(), true), AccountMetaData::new_readonly(registry.key(), false), AccountMetaData::new(snapshot.key(), false), AccountMetaData::new(snapshot_frame_pubkey, false), AccountMetaData::new_readonly(system_program.key(), false), + AccountMetaData::new_readonly(thread.key(), true), AccountMetaData::new_readonly(worker_pubkey, false), AccountMetaData::new_readonly( get_associated_token_address(&worker_pubkey, &config.mint), @@ -80,8 +80,8 @@ pub fn handler(ctx: Context) -> Result { program_id: crate::ID, accounts: vec![ AccountMetaData::new_readonly(config.key(), false), - AccountMetaData::new_readonly(thread.key(), true), AccountMetaData::new(registry.key(), false), + AccountMetaData::new_readonly(thread.key(), true), ], data: anchor_sighash("registry_epoch_cutover").to_vec(), }) diff --git a/programs/network/src/instructions/snapshot_delete.rs b/programs/network/src/instructions/snapshot_delete.rs index 27a71159d..09b3b1f25 100644 --- a/programs/network/src/instructions/snapshot_delete.rs +++ b/programs/network/src/instructions/snapshot_delete.rs @@ -7,12 +7,6 @@ pub struct SnapshotDelete<'info> { #[account(address = Config::pubkey())] pub config: Account<'info, Config>, - #[account( - mut, - address = config.epoch_thread - )] - pub thread: Signer<'info>, - #[account( address = Registry::pubkey(), constraint = !registry.locked @@ -29,14 +23,21 @@ pub struct SnapshotDelete<'info> { constraint = snapshot.id.lt(®istry.current_epoch) )] pub snapshot: Account<'info, Snapshot>, + + #[account( + mut, + address = config.epoch_thread + )] + pub thread: Signer<'info>, + } pub fn handler(ctx: Context) -> Result { // Get accounts let config = &ctx.accounts.config; - let thread = &mut ctx.accounts.thread; let registry = &ctx.accounts.registry; let snapshot = &mut ctx.accounts.snapshot; + let thread = &mut ctx.accounts.thread; // If this snapshot has no entries, then close immediately if snapshot.total_frames.eq(&0) { @@ -56,10 +57,10 @@ pub fn handler(ctx: Context) -> Result { program_id: crate::ID, accounts: vec![ AccountMetaData::new_readonly(config.key(), false), - AccountMetaData::new(thread.key(), true), AccountMetaData::new_readonly(registry.key(), false), AccountMetaData::new(snapshot.key(), false), AccountMetaData::new(SnapshotFrame::pubkey(snapshot.key(), 0), false), + AccountMetaData::new(thread.key(), true), ], data: anchor_sighash("snapshot_frame_delete").to_vec(), }) diff --git a/programs/network/src/instructions/snapshot_entry_create.rs b/programs/network/src/instructions/snapshot_entry_create.rs index 14aa80f26..074ac1f74 100644 --- a/programs/network/src/instructions/snapshot_entry_create.rs +++ b/programs/network/src/instructions/snapshot_entry_create.rs @@ -27,9 +27,6 @@ pub struct SnapshotEntryCreate<'info> { #[account(mut)] pub payer: Signer<'info>, - #[account(address = config.epoch_thread)] - pub thread: Signer<'info>, - #[account( address = Registry::pubkey(), constraint = registry.locked @@ -71,6 +68,9 @@ pub struct SnapshotEntryCreate<'info> { #[account(address = system_program::ID)] pub system_program: Program<'info, System>, + #[account(address = config.epoch_thread)] + pub thread: Signer<'info>, + #[account( address = worker.pubkey(), constraint = worker.id.eq(&snapshot_frame.id), @@ -84,12 +84,12 @@ pub fn handler(ctx: Context) -> Result { let delegation = &ctx.accounts.delegation; let delegation_stake = &ctx.accounts.delegation_stake; let payer = &ctx.accounts.payer; - let thread = &ctx.accounts.thread; let registry = &ctx.accounts.registry; let snapshot = &mut ctx.accounts.snapshot; let snapshot_entry = &mut ctx.accounts.snapshot_entry; let snapshot_frame = &mut ctx.accounts.snapshot_frame; let system_program = &ctx.accounts.system_program; + let thread = &ctx.accounts.thread; let worker = &ctx.accounts.worker; // Initialize snapshot entry account. @@ -142,11 +142,11 @@ pub fn handler(ctx: Context) -> Result { accounts: vec![ AccountMetaData::new_readonly(config.key(), false), AccountMetaData::new(payer.key(), true), - AccountMetaData::new_readonly(thread.key(), true), AccountMetaData::new_readonly(registry.key(), false), AccountMetaData::new(snapshot.key(), false), AccountMetaData::new(next_snapshot_frame_pubkey, false), AccountMetaData::new_readonly(system_program.key(), false), + AccountMetaData::new_readonly(thread.key(), true), AccountMetaData::new_readonly(next_worker_pubkey, false), AccountMetaData::new_readonly( get_associated_token_address(&next_worker_pubkey, &config.mint), @@ -161,8 +161,8 @@ pub fn handler(ctx: Context) -> Result { program_id: crate::ID, accounts: vec![ AccountMetaData::new_readonly(config.key(), false), - AccountMetaData::new_readonly(thread.key(), true), AccountMetaData::new(registry.key(), false), + AccountMetaData::new_readonly(thread.key(), true), ], data: anchor_sighash("registry_epoch_cutover").to_vec(), }) diff --git a/programs/network/src/instructions/snapshot_entry_delete.rs b/programs/network/src/instructions/snapshot_entry_delete.rs index 4cc90f475..82310a5ee 100644 --- a/programs/network/src/instructions/snapshot_entry_delete.rs +++ b/programs/network/src/instructions/snapshot_entry_delete.rs @@ -7,12 +7,6 @@ pub struct SnapshotEntryDelete<'info> { #[account(address = Config::pubkey())] pub config: Account<'info, Config>, - #[account( - mut, - address = config.epoch_thread - )] - pub thread: Signer<'info>, - #[account( address = Registry::pubkey(), constraint = !registry.locked @@ -53,16 +47,22 @@ pub struct SnapshotEntryDelete<'info> { has_one = snapshot, )] pub snapshot_frame: Account<'info, SnapshotFrame>, + + #[account( + mut, + address = config.epoch_thread + )] + pub thread: Signer<'info>, } pub fn handler(ctx: Context) -> Result { // Get accounts let config = &ctx.accounts.config; - let thread = &mut ctx.accounts.thread; let registry = &ctx.accounts.registry; let snapshot = &mut ctx.accounts.snapshot; let snapshot_entry = &mut ctx.accounts.snapshot_entry; let snapshot_frame = &mut ctx.accounts.snapshot_frame; + let thread = &mut ctx.accounts.thread; // Close the snapshot entry account. let snapshot_entry_lamports = snapshot_entry.to_account_info().lamports(); @@ -103,11 +103,11 @@ pub fn handler(ctx: Context) -> Result { program_id: crate::ID, accounts: vec![ AccountMetaData::new_readonly(config.key(), false), - AccountMetaData::new(thread.key(), true), AccountMetaData::new_readonly(registry.key(), false), AccountMetaData::new(snapshot.key(), false), AccountMetaData::new(SnapshotEntry::pubkey(snapshot_frame.key(), snapshot_entry.id.checked_add(1).unwrap()), false), AccountMetaData::new(snapshot_frame.key(), false), + AccountMetaData::new(thread.key(), true), ], data: anchor_sighash("snapshot_entry_delete").to_vec(), }) @@ -117,10 +117,10 @@ pub fn handler(ctx: Context) -> Result { program_id: crate::ID, accounts: vec![ AccountMetaData::new_readonly(config.key(), false), - AccountMetaData::new(thread.key(), true), AccountMetaData::new_readonly(registry.key(), false), AccountMetaData::new(snapshot.key(), false), AccountMetaData::new(SnapshotFrame::pubkey(snapshot.key(), snapshot_frame.id.checked_add(1).unwrap()), false), + AccountMetaData::new(thread.key(), true), ], data: anchor_sighash("snapshot_frame_delete").to_vec(), }) diff --git a/programs/network/src/instructions/snapshot_frame_create.rs b/programs/network/src/instructions/snapshot_frame_create.rs index 99f4d6d3a..93808c7ad 100644 --- a/programs/network/src/instructions/snapshot_frame_create.rs +++ b/programs/network/src/instructions/snapshot_frame_create.rs @@ -14,9 +14,6 @@ pub struct SnapshotFrameCreate<'info> { #[account(mut)] pub payer: Signer<'info>, - #[account(address = config.epoch_thread)] - pub thread: Signer<'info>, - #[account( address = Registry::pubkey(), constraint = registry.locked @@ -51,6 +48,9 @@ pub struct SnapshotFrameCreate<'info> { #[account(address = system_program::ID)] pub system_program: Program<'info, System>, + #[account(address = config.epoch_thread)] + pub thread: Signer<'info>, + #[account( address = worker.pubkey(), constraint = worker.id.eq(&snapshot.total_frames), @@ -68,11 +68,11 @@ pub fn handler(ctx: Context) -> Result { // Get accounts. let config = &ctx.accounts.config; let payer = &ctx.accounts.payer; - let thread = &ctx.accounts.thread; let registry = &ctx.accounts.registry; let snapshot = &mut ctx.accounts.snapshot; let snapshot_frame = &mut ctx.accounts.snapshot_frame; let system_program = &ctx.accounts.system_program; + let thread = &ctx.accounts.thread; let worker = &ctx.accounts.worker; let worker_stake = &ctx.accounts.worker_stake; @@ -107,12 +107,12 @@ pub fn handler(ctx: Context) -> Result { false, ), AccountMetaData::new(payer.key(), true), - AccountMetaData::new_readonly(thread.key(), true), AccountMetaData::new_readonly(registry.key(), false), AccountMetaData::new_readonly(snapshot.key(), false), AccountMetaData::new(zeroth_snapshot_entry_pubkey, false), AccountMetaData::new(snapshot_frame.key(), false), AccountMetaData::new_readonly(system_program.key(), false), + AccountMetaData::new_readonly(thread.key(), true), AccountMetaData::new_readonly(worker.key(), false), ], data: anchor_sighash("snapshot_entry_create").to_vec(), @@ -127,11 +127,11 @@ pub fn handler(ctx: Context) -> Result { accounts: vec![ AccountMetaData::new_readonly(config.key(), false), AccountMetaData::new(payer.key(), true), - AccountMetaData::new_readonly(thread.key(), true), AccountMetaData::new_readonly(registry.key(), false), AccountMetaData::new(snapshot.key(), false), AccountMetaData::new(next_snapshot_frame_pubkey, false), AccountMetaData::new_readonly(system_program.key(), false), + AccountMetaData::new_readonly(thread.key(), true), AccountMetaData::new_readonly(next_worker_pubkey, false), AccountMetaData::new_readonly( get_associated_token_address(&next_worker_pubkey, &config.mint), @@ -146,8 +146,8 @@ pub fn handler(ctx: Context) -> Result { program_id: crate::ID, accounts: vec![ AccountMetaData::new_readonly(config.key(), false), - AccountMetaData::new_readonly(thread.key(), true), AccountMetaData::new(registry.key(), false), + AccountMetaData::new_readonly(thread.key(), true), ], data: anchor_sighash("registry_epoch_cutover").to_vec(), }) diff --git a/programs/network/src/instructions/snapshot_frame_delete.rs b/programs/network/src/instructions/snapshot_frame_delete.rs index acb1095b7..0fecf075c 100644 --- a/programs/network/src/instructions/snapshot_frame_delete.rs +++ b/programs/network/src/instructions/snapshot_frame_delete.rs @@ -7,12 +7,6 @@ pub struct SnapshotFrameDelete<'info> { #[account(address = Config::pubkey())] pub config: Account<'info, Config>, - #[account( - mut, - address = config.epoch_thread - )] - pub thread: Signer<'info>, - #[account( address = Registry::pubkey(), constraint = !registry.locked @@ -41,15 +35,21 @@ pub struct SnapshotFrameDelete<'info> { has_one = snapshot, )] pub snapshot_frame: Account<'info, SnapshotFrame>, + + #[account( + mut, + address = config.epoch_thread + )] + pub thread: Signer<'info>, } pub fn handler(ctx: Context) -> Result { // Get accounts let config = &ctx.accounts.config; - let thread = &mut ctx.accounts.thread; let registry = &ctx.accounts.registry; let snapshot = &mut ctx.accounts.snapshot; let snapshot_frame = &mut ctx.accounts.snapshot_frame; + let thread = &mut ctx.accounts.thread; // If this frame has no entries, then close the frame account. if snapshot_frame.total_entries.eq(&0) { @@ -81,11 +81,11 @@ pub fn handler(ctx: Context) -> Result { program_id: crate::ID, accounts: vec![ AccountMetaData::new_readonly(config.key(), false), - AccountMetaData::new(thread.key(), true), AccountMetaData::new_readonly(registry.key(), false), AccountMetaData::new(snapshot.key(), false), AccountMetaData::new(SnapshotEntry::pubkey(snapshot_frame.key(), 0), false), AccountMetaData::new(snapshot_frame.key(), false), + AccountMetaData::new(thread.key(), true), ], data: anchor_sighash("snapshot_entry_delete").to_vec(), }) @@ -95,10 +95,10 @@ pub fn handler(ctx: Context) -> Result { program_id: crate::ID, accounts: vec![ AccountMetaData::new_readonly(config.key(), false), - AccountMetaData::new(thread.key(), true), AccountMetaData::new_readonly(registry.key(), false), AccountMetaData::new(snapshot.key(), false), AccountMetaData::new(SnapshotFrame::pubkey(snapshot.key(), snapshot_frame.id.checked_add(1).unwrap()), false), + AccountMetaData::new(thread.key(), true), ], data: anchor_sighash("snapshot_frame_delete").to_vec(), }) diff --git a/programs/network/src/instructions/unstake_preprocess.rs b/programs/network/src/instructions/unstake_preprocess.rs index b912659ed..08eac47fe 100644 --- a/programs/network/src/instructions/unstake_preprocess.rs +++ b/programs/network/src/instructions/unstake_preprocess.rs @@ -11,15 +11,15 @@ pub struct UnstakePreprocess<'info> { #[account(address = Config::pubkey())] pub config: Account<'info, Config>, - #[account(address = config.epoch_thread)] - pub thread: Signer<'info>, - #[account( address = Registry::pubkey(), constraint = registry.locked )] pub registry: Account<'info, Registry>, + #[account(address = config.epoch_thread)] + pub thread: Signer<'info>, + #[account(address = unstake.pubkey())] pub unstake: Account<'info, Unstake>, } @@ -27,8 +27,8 @@ pub struct UnstakePreprocess<'info> { pub fn handler(ctx: Context) -> Result { // Get accounts. let config = &ctx.accounts.config; - let thread = &ctx.accounts.thread; let registry = &ctx.accounts.registry; + let thread = &ctx.accounts.thread; let unstake = &ctx.accounts.unstake; // Return next instruction for thread. @@ -39,8 +39,8 @@ pub fn handler(ctx: Context) -> Result { AccountMetaData::new_readonly(unstake.authority, false), AccountMetaData::new_readonly(config.key(), false), AccountMetaData::new(unstake.delegation, false), - AccountMetaData::new_readonly(thread.key(), true), AccountMetaData::new(registry.key(), false), + AccountMetaData::new_readonly(thread.key(), true), AccountMetaData::new_readonly(anchor_spl::token::ID, false), AccountMetaData::new(unstake.key(), false), AccountMetaData::new_readonly(unstake.worker, false), diff --git a/programs/network/src/instructions/unstake_process.rs b/programs/network/src/instructions/unstake_process.rs index b12249637..89711287d 100644 --- a/programs/network/src/instructions/unstake_process.rs +++ b/programs/network/src/instructions/unstake_process.rs @@ -35,9 +35,6 @@ pub struct UnstakeProcess<'info> { )] pub delegation: Box>, - #[account(address = config.epoch_thread)] - pub thread: Signer<'info>, - #[account( mut, seeds = [SEED_REGISTRY], @@ -45,6 +42,9 @@ pub struct UnstakeProcess<'info> { )] pub registry: Box>, + #[account(address = config.epoch_thread)] + pub thread: Signer<'info>, + #[account(address = anchor_spl::token::ID)] pub token_program: Program<'info, Token>, @@ -77,8 +77,8 @@ pub fn handler(ctx: Context) -> Result { let authority_tokens = &ctx.accounts.authority_tokens; let config = &ctx.accounts.config; let delegation = &mut ctx.accounts.delegation; - let thread = &ctx.accounts.thread; let registry = &mut ctx.accounts.registry; + let thread = &ctx.accounts.thread; let token_program = &ctx.accounts.token_program; let unstake = &ctx.accounts.unstake; let worker = &ctx.accounts.worker; @@ -142,8 +142,8 @@ pub fn handler(ctx: Context) -> Result { program_id: crate::ID, accounts: vec![ AccountMetaData::new_readonly(config.key(), false), - AccountMetaData::new_readonly(thread.key(), true), AccountMetaData::new_readonly(registry.key(), false), + AccountMetaData::new_readonly(thread.key(), true), AccountMetaData::new_readonly(next_unstake_pubkey, false), ], data: anchor_sighash("unstake_preprocess").to_vec(), @@ -157,8 +157,8 @@ pub fn handler(ctx: Context) -> Result { program_id: crate::ID, accounts: vec![ AccountMetaData::new_readonly(config.key(), false), - AccountMetaData::new_readonly(thread.key(), true), AccountMetaData::new_readonly(registry.key(), false), + AccountMetaData::new_readonly(thread.key(), true), AccountMetaData::new_readonly(Worker::pubkey(0), false), ], data: anchor_sighash("worker_delegations_stake").to_vec(), diff --git a/programs/network/src/instructions/worker_delegations_stake.rs b/programs/network/src/instructions/worker_delegations_stake.rs index 77dcdf7e4..a8733f912 100644 --- a/programs/network/src/instructions/worker_delegations_stake.rs +++ b/programs/network/src/instructions/worker_delegations_stake.rs @@ -10,15 +10,15 @@ pub struct WorkerStakeDelegations<'info> { #[account(address = Config::pubkey())] pub config: Account<'info, Config>, - #[account(address = config.epoch_thread)] - pub thread: Signer<'info>, - #[account( address = Registry::pubkey(), constraint = registry.locked )] pub registry: Account<'info, Registry>, + #[account(address = config.epoch_thread)] + pub thread: Signer<'info>, + #[account(address = worker.pubkey())] pub worker: Account<'info, Worker>, } @@ -26,8 +26,8 @@ pub struct WorkerStakeDelegations<'info> { pub fn handler(ctx: Context) -> Result { // Get accounts. let config = &ctx.accounts.config; - let thread = &ctx.accounts.thread; let registry = &ctx.accounts.registry; + let thread = &ctx.accounts.thread; let worker = &ctx.accounts.worker; // Build the next instruction for the thread. @@ -43,8 +43,8 @@ pub fn handler(ctx: Context) -> Result { get_associated_token_address(&delegation_pubkey, &config.mint), false, ), - AccountMetaData::new_readonly(thread.key(), true), AccountMetaData::new_readonly(registry.key(), false), + AccountMetaData::new_readonly(thread.key(), true), AccountMetaData::new_readonly(anchor_spl::token::ID, false), AccountMetaData::new_readonly(worker.key(), false), AccountMetaData::new( @@ -65,8 +65,8 @@ pub fn handler(ctx: Context) -> Result { program_id: crate::ID, accounts: vec![ AccountMetaData::new_readonly(config.key(), false), - AccountMetaData::new_readonly(thread.key(), true), AccountMetaData::new_readonly(registry.key(), false), + AccountMetaData::new_readonly(thread.key(), true), AccountMetaData::new_readonly( Worker::pubkey(worker.id.checked_add(1).unwrap()), false, @@ -81,13 +81,13 @@ pub fn handler(ctx: Context) -> Result { accounts: vec![ AccountMetaData::new_readonly(config.key(), false), AccountMetaData::new(clockwork_utils::PAYER_PUBKEY, true), - AccountMetaData::new_readonly(thread.key(), true), AccountMetaData::new_readonly(registry.key(), false), AccountMetaData::new( Snapshot::pubkey(registry.current_epoch.checked_add(1).unwrap()), false, ), AccountMetaData::new_readonly(system_program::ID, false), + AccountMetaData::new_readonly(thread.key(), true), ], data: anchor_sighash("snapshot_create").to_vec(), }) diff --git a/programs/network/src/instructions/worker_fees_distribute.rs b/programs/network/src/instructions/worker_fees_distribute.rs index 71b08ca9a..b005e3e26 100644 --- a/programs/network/src/instructions/worker_fees_distribute.rs +++ b/programs/network/src/instructions/worker_fees_distribute.rs @@ -20,9 +20,6 @@ pub struct WorkerDistributeFees<'info> { )] pub fee: Account<'info, Fee>, - #[account(address = config.epoch_thread)] - pub thread: Signer<'info>, - #[account(address = Registry::pubkey())] pub registry: Account<'info, Registry>, @@ -39,6 +36,9 @@ pub struct WorkerDistributeFees<'info> { )] pub snapshot_frame: Account<'info, SnapshotFrame>, + #[account(address = config.epoch_thread)] + pub thread: Signer<'info>, + #[account(mut)] pub worker: Account<'info, Worker>, } @@ -47,10 +47,10 @@ pub fn handler(ctx: Context) -> Result { // Get accounts. let config = &ctx.accounts.config; let fee = &mut ctx.accounts.fee; - let thread = &ctx.accounts.thread; let registry = &ctx.accounts.registry; let snapshot = &ctx.accounts.snapshot; let snapshot_frame = &ctx.accounts.snapshot_frame; + let thread = &ctx.accounts.thread; let worker = &mut ctx.accounts.worker; // Calculate the fee account's usuable balance. @@ -98,11 +98,11 @@ pub fn handler(ctx: Context) -> Result { AccountMetaData::new_readonly(config.key(), false), AccountMetaData::new(delegation_pubkey, false), AccountMetaData::new(fee.key(), false), - AccountMetaData::new_readonly(thread.key(), true), AccountMetaData::new_readonly(registry.key(), false), AccountMetaData::new_readonly(snapshot.key(), false), AccountMetaData::new_readonly(snapshot_frame.key(), false), AccountMetaData::new_readonly(snapshot_entry_pubkey.key(), false), + AccountMetaData::new_readonly(thread.key(), true), AccountMetaData::new_readonly(worker.key(), false), ], data: anchor_sighash("fee_distribute").to_vec(), @@ -122,10 +122,10 @@ pub fn handler(ctx: Context) -> Result { accounts: vec![ AccountMetaData::new_readonly(config.key(), false), AccountMetaData::new(Fee::pubkey(next_worker_pubkey), false), - AccountMetaData::new_readonly(thread.key(), true), AccountMetaData::new_readonly(registry.key(), false), AccountMetaData::new_readonly(snapshot.key(), false), AccountMetaData::new_readonly(next_snapshot_frame_pubkey, false), + AccountMetaData::new_readonly(thread.key(), true), AccountMetaData::new(next_worker_pubkey, false), ], data: anchor_sighash("worker_fees_distribute").to_vec(), @@ -136,8 +136,8 @@ pub fn handler(ctx: Context) -> Result { program_id: crate::ID, accounts: vec![ AccountMetaData::new_readonly(config.key(), false), - AccountMetaData::new_readonly(thread.key(), true), AccountMetaData::new_readonly(registry.key(), false), + AccountMetaData::new_readonly(thread.key(), true), AccountMetaData::new_readonly(Unstake::pubkey(0), false), ], data: anchor_sighash("unstake_preprocess").to_vec(), @@ -149,8 +149,8 @@ pub fn handler(ctx: Context) -> Result { program_id: crate::ID, accounts: vec![ AccountMetaData::new_readonly(config.key(), false), - AccountMetaData::new_readonly(thread.key(), true), AccountMetaData::new_readonly(registry.key(), false), + AccountMetaData::new_readonly(thread.key(), true), AccountMetaData::new_readonly(Worker::pubkey(0), false), ], data: anchor_sighash("worker_delegations_stake").to_vec(),