Skip to content

Commit

Permalink
thread: Add maximum instruction size for thread space calculation (#83)
Browse files Browse the repository at this point in the history
  • Loading branch information
Aursen authored Oct 21, 2024
1 parent 6a0c081 commit 90aa507
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
4 changes: 4 additions & 0 deletions programs/thread/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,7 @@ pub const POOL_ID: u64 = 0;
/// The number of lamports to reimburse the worker with after they've submitted a transaction's worth of exec instructions.
#[constant]
pub const TRANSACTION_BASE_FEE_REIMBURSEMENT: u64 = 5_000;

/// Static space for next_instruction field.
#[constant]
pub const NEXT_INSTRUCTION_SIZE: usize = 1232;
9 changes: 2 additions & 7 deletions programs/thread/src/state/thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use sablier_utils::{
MinSpace, Space,
};

use crate::constants::SEED_THREAD;
use crate::constants::{NEXT_INSTRUCTION_SIZE, SEED_THREAD};

/// Tracks the current state of a transaction thread on Solana.
#[account]
Expand Down Expand Up @@ -72,11 +72,6 @@ pub trait ThreadAccount {
impl Thread {
pub fn min_space(instructions: &[SerializableInstruction]) -> Result<usize> {
let ins_space = instructions.try_to_vec()?.len();
let max_ins_size = instructions
.iter()
.map(|ins| ins.try_to_vec().map(|v| v.len()).unwrap_or(0))
.max()
.unwrap_or(0);

Ok(
8
Expand All @@ -88,7 +83,7 @@ impl Thread {
+ u64::MIN_SPACE // fee
+ (4 + 32) // id
+ (4 + ins_space) // instructions
+ (1 + max_ins_size) // next_instruction
+ (1 + NEXT_INSTRUCTION_SIZE) // next_instruction
+ bool::MIN_SPACE // paused
+ u64::MIN_SPACE // rate_limit
+ Trigger::MIN_SPACE, // trigger
Expand Down

0 comments on commit 90aa507

Please sign in to comment.