Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

thread: Add maximum instruction size for thread space calculation #83

Merged
merged 1 commit into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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