Skip to content

Commit 90aa507

Browse files
authored
thread: Add maximum instruction size for thread space calculation (#83)
1 parent 6a0c081 commit 90aa507

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

programs/thread/src/constants.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,7 @@ pub const POOL_ID: u64 = 0;
1414
/// The number of lamports to reimburse the worker with after they've submitted a transaction's worth of exec instructions.
1515
#[constant]
1616
pub const TRANSACTION_BASE_FEE_REIMBURSEMENT: u64 = 5_000;
17+
18+
/// Static space for next_instruction field.
19+
#[constant]
20+
pub const NEXT_INSTRUCTION_SIZE: usize = 1232;

programs/thread/src/state/thread.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use sablier_utils::{
55
MinSpace, Space,
66
};
77

8-
use crate::constants::SEED_THREAD;
8+
use crate::constants::{NEXT_INSTRUCTION_SIZE, SEED_THREAD};
99

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

8176
Ok(
8277
8
@@ -88,7 +83,7 @@ impl Thread {
8883
+ u64::MIN_SPACE // fee
8984
+ (4 + 32) // id
9085
+ (4 + ins_space) // instructions
91-
+ (1 + max_ins_size) // next_instruction
86+
+ (1 + NEXT_INSTRUCTION_SIZE) // next_instruction
9287
+ bool::MIN_SPACE // paused
9388
+ u64::MIN_SPACE // rate_limit
9489
+ Trigger::MIN_SPACE, // trigger

0 commit comments

Comments
 (0)