Skip to content

Commit 7fa860e

Browse files
committed
Merge branch 'master' into dev
* master: chore: avoid CU budget exceeded for lookup table management (#455)
2 parents 3fef41f + d5c9f6b commit 7fa860e

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

magicblock-table-mania/src/compute_budget.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@ use solana_sdk::{
22
compute_budget::ComputeBudgetInstruction, instruction::Instruction,
33
};
44

5+
/// We multiply the CU values that we determined since we've seen compute budget exceeded errors
6+
/// if we use them as is. The only way to determine CUs for a particular transaction 100% is
7+
/// to simulate that exact transaction.
8+
/// This would make table management even slower, but is an option to consider for the future.
9+
/// The multiplier is based on the observation that [CREATE_AND_EXTEND_TABLE_CUS] were _safe_ at
10+
/// 16K-17K CUs which we slightly exceed if we multiply by this multiplier.
11+
const SAFETY_MULTIPLIER: u32 = 7;
12+
513
/// Compute units required to create and extend a lookup table, with the initial
614
/// pubkeys. This is the same no matter how many pubkeys are added to the table
715
/// initially.
@@ -10,14 +18,14 @@ use solana_sdk::{
1018
/// https://github.com/solana-program/address-lookup-table/blob/main/program/src/processor.rs .
1119
/// This test repo (https://github.com/thlorenz/create-program-address-cus) verified
1220
/// that the variation is around 25 CUs, but to be on the safe side we add 10x that.
13-
pub const CREATE_AND_EXTEND_TABLE_CUS: u32 = 2_400 + 250;
21+
pub const CREATE_AND_EXTEND_TABLE_CUS: u32 = (2_400 + 250) * SAFETY_MULTIPLIER;
1422
/// Compute units required to extend a lookup table with additional pubkeys
1523
/// This is the same no matter how many pubkeys are added to the table.
16-
pub const EXTEND_TABLE_CUS: u32 = 1_200;
24+
pub const EXTEND_TABLE_CUS: u32 = 1_200 * SAFETY_MULTIPLIER;
1725
/// Compute units required to deactivate a lookup table.
18-
pub const DEACTIVATE_TABLE_CUS: u32 = 1_050;
26+
pub const DEACTIVATE_TABLE_CUS: u32 = 1_050 * SAFETY_MULTIPLIER;
1927
/// Compute units required to close a lookup table.
20-
pub const CLOSE_TABLE_CUS: u32 = 1_050;
28+
pub const CLOSE_TABLE_CUS: u32 = 1_050 * SAFETY_MULTIPLIER;
2129

2230
#[derive(Clone)]
2331
pub struct TableManiaComputeBudget {

test-integration/test-table-mania/tests/ix_lookup_table.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ async fn test_lookup_table_ixs_cus_per_pubkey() {
267267
*lookup_table.extend_signatures().unwrap().last().unwrap();
268268
let cus = get_tx_cus(&rpc_client, &extend_sig).await;
269269
debug!("Extend for {i:03} CUs {cus:04}CUs");
270-
assert_eq!(cus, EXTEND_TABLE_CUS as u64);
270+
assert!(cus <= EXTEND_TABLE_CUS as u64);
271271

272272
lookup_table
273273
.deactivate(&rpc_client, &validator_auth, &budgets.deactivate)
@@ -280,7 +280,7 @@ async fn test_lookup_table_ixs_cus_per_pubkey() {
280280
)
281281
.await;
282282
debug!("Deactivate table {cus:03}CUs");
283-
assert_eq!(cus, DEACTIVATE_TABLE_CUS as u64);
283+
assert!(cus <= DEACTIVATE_TABLE_CUS as u64);
284284

285285
#[cfg(feature = "test_table_close")]
286286
{
@@ -305,7 +305,7 @@ async fn test_lookup_table_ixs_cus_per_pubkey() {
305305
assert!(is_closed);
306306
let cus = get_tx_cus(&rpc_client, &close_sig.unwrap()).await;
307307
debug!("Close table {cus:03}CUs",);
308-
assert_eq!(cus, CLOSE_TABLE_CUS as u64);
308+
assert!(cus <= CLOSE_TABLE_CUS as u64);
309309
}
310310
}
311311
}

0 commit comments

Comments
 (0)