Skip to content

Commit

Permalink
Switch to classic math
Browse files Browse the repository at this point in the history
  • Loading branch information
Aursen committed Jan 16, 2024
1 parent df4a894 commit 4aff4e0
Show file tree
Hide file tree
Showing 10 changed files with 14 additions and 23 deletions.
2 changes: 1 addition & 1 deletion programs/network/src/instructions/pool_rotate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub struct PoolRotate<'info> {

#[account(
address = snapshot.pubkey(),
constraint = snapshot.id.eq(&registry.current_epoch)
constraint = snapshot.id == registry.current_epoch
)]
pub snapshot: Account<'info, Snapshot>,

Expand Down
2 changes: 1 addition & 1 deletion programs/network/src/instructions/worker_create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ pub struct WorkerCreate<'info> {
)]
pub registry: Account<'info, Registry>,

#[account(constraint = signatory.key().ne(&authority.key()) @ ClockworkError::InvalidSignatory)]
#[account(constraint = signatory.key() != authority.key() @ ClockworkError::InvalidSignatory)]
pub signatory: Signer<'info>,

pub system_program: Program<'info, System>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ pub fn handler(ctx: Context<DeleteSnapshotProcessSnapshot>) -> Result<ThreadResp
}

// Build next instruction the thread.
let dynamic_instruction = if snapshot.total_frames.gt(&0) {
let dynamic_instruction = if snapshot.total_frames > 0 {
// There are frames in this snapshot. Delete them.
Some(
Instruction {
Expand Down
2 changes: 1 addition & 1 deletion programs/network/src/jobs/distribute_fees/process_frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub struct DistributeFeesProcessFrame<'info> {

#[account(
address = snapshot.pubkey(),
constraint = snapshot.id.eq(&registry.current_epoch)
constraint = snapshot.id == registry.current_epoch
)]
pub snapshot: Account<'info, Snapshot>,

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub struct DistributeFeesProcessSnapshot<'info> {

#[account(
address = snapshot.pubkey(),
constraint = snapshot.id.eq(&registry.current_epoch)
constraint = snapshot.id == registry.current_epoch
)]
pub snapshot: Account<'info, Snapshot>,

Expand Down
11 changes: 3 additions & 8 deletions programs/network/src/jobs/stake_delegations/process_worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub fn handler(ctx: Context<StakeDelegationsProcessWorker>) -> Result<ThreadResp
let worker = &ctx.accounts.worker;

// Build the next instruction for the thread.
let dynamic_instruction = if worker.total_delegations.gt(&0) {
let dynamic_instruction = if worker.total_delegations > 0 {
// This worker has delegations. Stake their deposits.
let delegation_pubkey = Delegation::pubkey(worker.key(), 0);
Some(
Expand All @@ -54,12 +54,7 @@ pub fn handler(ctx: Context<StakeDelegationsProcessWorker>) -> Result<ThreadResp
}
.into(),
)
} else if worker
.id
.checked_add(1)
.unwrap()
.lt(&registry.total_workers)
{
} else if (worker.id + 1) < registry.total_workers {
// This worker has no delegations. Move on to the next worker.
Some(
Instruction {
Expand All @@ -68,7 +63,7 @@ pub fn handler(ctx: Context<StakeDelegationsProcessWorker>) -> Result<ThreadResp
config: config.key(),
registry: registry.key(),
thread: thread.key(),
worker: Worker::pubkey(worker.id.checked_add(1).unwrap()),
worker: Worker::pubkey(worker.id + 1),
}
.to_account_metas(Some(true)),
data: crate::instruction::StakeDelegationsProcessWorker {}.data(),
Expand Down
6 changes: 3 additions & 3 deletions programs/network/src/jobs/take_snapshot/create_entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub struct TakeSnapshotCreateEntry<'info> {

#[account(
address = delegation.pubkey(),
constraint = delegation.id.eq(&snapshot_frame.total_entries),
constraint = delegation.id == snapshot_frame.total_entries,
has_one = worker,
)]
pub delegation: Box<Account<'info, Delegation>>,
Expand All @@ -27,7 +27,7 @@ pub struct TakeSnapshotCreateEntry<'info> {

#[account(
address = snapshot.pubkey(),
constraint = registry.current_epoch.checked_add(1).unwrap().eq(&snapshot.id)
constraint = (registry.current_epoch + 1) == snapshot.id
)]
pub snapshot: Box<Account<'info, Snapshot>>,

Expand Down Expand Up @@ -64,7 +64,7 @@ pub struct TakeSnapshotCreateEntry<'info> {

#[account(
address = worker.pubkey(),
constraint = worker.id.eq(&snapshot_frame.id),
constraint = worker.id == snapshot_frame.id,
)]
pub worker: Box<Account<'info, Worker>>,
}
Expand Down
2 changes: 1 addition & 1 deletion programs/network/src/jobs/take_snapshot/job.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub fn handler(ctx: Context<TakeSnapshotJob>) -> Result<ThreadResponse> {
config: config.key(),
payer: PAYER_PUBKEY,
registry: registry.key(),
snapshot: Snapshot::pubkey(registry.current_epoch.checked_add(1).unwrap()),
snapshot: Snapshot::pubkey(registry.current_epoch + 1),
system_program: system_program::ID,
thread: thread.key(),
}
Expand Down
7 changes: 1 addition & 6 deletions programs/thread/src/instructions/thread_exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,12 +176,7 @@ pub fn handler(ctx: Context<ThreadExec>) -> Result<()> {
thread.exec_context = Some(ExecContext {
exec_index,
execs_since_slot: if clock.slot == thread.exec_context.unwrap().last_exec_at {
thread
.exec_context
.unwrap()
.execs_since_slot
.checked_add(1)
.unwrap()
thread.exec_context.unwrap().execs_since_slot + 1
} else {
1
},
Expand Down
1 change: 1 addition & 0 deletions programs/thread/src/state/thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ pub use clockwork_utils::thread::Equality;
use crate::constants::{NEXT_INSTRUCTION_SIZE, SEED_THREAD};

/// Tracks the current state of a transaction thread on Solana.
// TODO Wait for the next version of Anchor to implement InitSpace macro
#[account]
#[derive(Debug)]
pub struct Thread {
Expand Down

0 comments on commit 4aff4e0

Please sign in to comment.