Skip to content

Commit

Permalink
Alphabetize accounts and args in network program (#84)
Browse files Browse the repository at this point in the history
* Rename 'crank' to 'exec'

* Rename crank to exec

* Alphabetize accounts and function args

Co-authored-by: Nick Garfield <[email protected]>
  • Loading branch information
nickgarfield and Nick Garfield authored Oct 26, 2022
1 parent 3b85069 commit 018cadd
Show file tree
Hide file tree
Showing 18 changed files with 106 additions and 105 deletions.
2 changes: 1 addition & 1 deletion cli/src/processor/localnet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
4 changes: 2 additions & 2 deletions client/src/network/instruction/registry_epoch_kickoff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
}
Expand Down
2 changes: 1 addition & 1 deletion client/src/network/instruction/registry_nonce_hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
}
Expand Down
14 changes: 7 additions & 7 deletions programs/network/src/instructions/delegation_stake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>,

Expand All @@ -58,8 +58,8 @@ pub fn handler(ctx: Context<DelegationStake>) -> Result<ExecResponse> {
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;
Expand Down Expand Up @@ -107,8 +107,8 @@ pub fn handler(ctx: Context<DelegationStake>) -> Result<ExecResponse> {
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),
Expand All @@ -126,8 +126,8 @@ pub fn handler(ctx: Context<DelegationStake>) -> Result<ExecResponse> {
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,
Expand All @@ -142,13 +142,13 @@ pub fn handler(ctx: Context<DelegationStake>) -> Result<ExecResponse> {
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(),
})
Expand Down
14 changes: 7 additions & 7 deletions programs/network/src/instructions/fee_distribute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>,

Expand All @@ -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>,
}
Expand All @@ -67,11 +67,11 @@ pub fn handler(ctx: Context<FeeDistribute>) -> Result<ExecResponse> {
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.
Expand Down Expand Up @@ -123,11 +123,11 @@ pub fn handler(ctx: Context<FeeDistribute>) -> Result<ExecResponse> {
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(),
Expand All @@ -147,10 +147,10 @@ pub fn handler(ctx: Context<FeeDistribute>) -> Result<ExecResponse> {
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(),
Expand All @@ -161,8 +161,8 @@ pub fn handler(ctx: Context<FeeDistribute>) -> Result<ExecResponse> {
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(),
Expand Down
10 changes: 5 additions & 5 deletions programs/network/src/instructions/registry_epoch_cutover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<RegistryEpochCutover>) -> Result<ExecResponse> {
// 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();
Expand All @@ -34,12 +34,12 @@ pub fn handler(ctx: Context<RegistryEpochCutover>) -> Result<ExecResponse> {
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(),
});
Expand Down
16 changes: 8 additions & 8 deletions programs/network/src/instructions/registry_epoch_kickoff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand All @@ -42,14 +39,17 @@ pub struct RegistryEpochKickoff<'info> {
constraint = snapshot.id.eq(&registry.current_epoch)
)]
pub snapshot: Account<'info, Snapshot>,

#[account(address = config.epoch_thread)]
pub thread: Signer<'info>,
}

pub fn handler(ctx: Context<RegistryEpochKickoff>) -> Result<ExecResponse> {
// 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;
Expand All @@ -59,12 +59,12 @@ pub fn handler(ctx: Context<RegistryEpochKickoff>) -> Result<ExecResponse> {
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(),
});
Expand All @@ -77,10 +77,10 @@ pub fn handler(ctx: Context<RegistryEpochKickoff>) -> Result<ExecResponse> {
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(),
Expand All @@ -91,8 +91,8 @@ pub fn handler(ctx: Context<RegistryEpochKickoff>) -> Result<ExecResponse> {
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(),
Expand All @@ -103,8 +103,8 @@ pub fn handler(ctx: Context<RegistryEpochKickoff>) -> Result<ExecResponse> {
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(),
})
Expand Down
6 changes: 3 additions & 3 deletions programs/network/src/instructions/registry_nonce_hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<RegistryNonceHash>) -> Result<ExecResponse> {
Expand Down
12 changes: 6 additions & 6 deletions programs/network/src/instructions/snapshot_create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<SnapshotCreate>) -> Result<ExecResponse> {
// 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())?;
Expand All @@ -61,11 +61,11 @@ pub fn handler(ctx: Context<SnapshotCreate>) -> Result<ExecResponse> {
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),
Expand All @@ -80,8 +80,8 @@ pub fn handler(ctx: Context<SnapshotCreate>) -> Result<ExecResponse> {
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(),
})
Expand Down
Loading

0 comments on commit 018cadd

Please sign in to comment.