openzeppelin_relayer/constants/solana_transaction.rs
1//! Constants for Solana transaction processing.
2//!
3//! This module contains default values used throughout the Solana transaction
4//! handling logic, including validation limits, status check delays, and timeout thresholds.
5
6use chrono::Duration;
7
8/// Default transaction valid timespan for Solana when no explicit valid_until is provided (in milliseconds)
9/// Set to 30 minutes to balance between:
10/// - Preventing infinite resubmission loops
11/// - Allowing reasonable time for transaction processing during network congestion
12/// - Aligning with Solana's fast finality expectations
13pub const SOLANA_DEFAULT_TX_VALID_TIMESPAN: i64 = 30 * 60 * 1000; // 30 minutes in milliseconds
14
15// API request validation limits
16/// Maximum number of instructions allowed in a transaction request
17pub const REQUEST_MAX_INSTRUCTIONS: usize = 64;
18
19/// Maximum number of accounts allowed per instruction in a request
20pub const REQUEST_MAX_ACCOUNTS_PER_INSTRUCTION: usize = 64;
21
22/// Maximum total unique accounts allowed in a transaction request
23pub const REQUEST_MAX_TOTAL_ACCOUNTS: usize = 64;
24
25/// Maximum instruction data size in bytes allowed in a request
26pub const REQUEST_MAX_INSTRUCTION_DATA_SIZE: usize = 1232;
27
28// Status check scheduling
29/// Initial delay before first status check (in seconds)
30pub const SOLANA_STATUS_CHECK_INITIAL_DELAY_SECONDS: i64 = 5;
31
32/// Minimum age before checking for resubmit/expiration (in seconds)
33/// If transaction is younger than this, we don't check blockhash expiration yet
34pub const SOLANA_MIN_AGE_FOR_RESUBMIT_CHECK_SECONDS: i64 = 90;
35
36/// Minimum age before triggering Pending status recovery (in seconds)
37/// Only schedule a recovery job if Pending transaction exceeds this age
38pub const SOLANA_PENDING_RECOVERY_TRIGGER_SECONDS: i64 = 20;
39
40/// Timeout for Pending status: transaction preparation phase (in minutes)
41/// If a transaction stays in Pending for longer than this, mark as Failed
42pub const SOLANA_PENDING_TIMEOUT_MINUTES: i64 = 3;
43
44/// Timeout for Sent status: waiting for submission (in minutes)
45/// If a transaction stays in Sent for longer than this, mark as Failed
46pub const SOLANA_SENT_TIMEOUT_MINUTES: i64 = 3;
47
48/// Maximum number of transaction resubmission attempts before marking as Failed
49/// Each attempt creates a new signature (when blockhash expires and tx is resubmitted)
50/// Similar to EVM's MAXIMUM_TX_ATTEMPTS but tailored for Solana's resubmission behavior
51pub const MAXIMUM_SOLANA_TX_ATTEMPTS: usize = 20;
52
53/// Get status check initial delay duration
54pub fn get_solana_status_check_initial_delay() -> Duration {
55 Duration::seconds(SOLANA_STATUS_CHECK_INITIAL_DELAY_SECONDS)
56}