Skip to content

Commit 50584f6

Browse files
committed
feat: add checks to make sure indexes are set
1 parent 0e2563d commit 50584f6

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

runtime/src/bank/pyth_accumulator.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,10 @@ pub fn update_v1(
139139
let v1_messages = if use_message_buffers {
140140
let mut measure = Measure::start("update_v1_load_program_accounts");
141141

142+
assert!(
143+
bank.account_indexes_include_key(&*MESSAGE_BUFFER_PID),
144+
"MessageBuffer program account index missing"
145+
);
142146
message_buffer_accounts = bank
143147
.get_filtered_indexed_accounts(
144148
&IndexKey::ProgramId(*MESSAGE_BUFFER_PID),
@@ -384,6 +388,11 @@ fn post_accumulator_attestation(
384388
pub fn update_v2(bank: &Bank) -> std::result::Result<(), AccumulatorUpdateErrorV1> {
385389
let mut measure = Measure::start("update_v2_load_program_accounts");
386390

391+
assert!(
392+
bank.account_indexes_include_key(&*ORACLE_PID),
393+
"Oracle program account index missing"
394+
);
395+
387396
let accounts = bank
388397
.get_filtered_indexed_accounts(
389398
&IndexKey::ProgramId(*ORACLE_PID),

validator/src/main.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ use {
5252
AccountIndex, AccountSecondaryIndexes, AccountSecondaryIndexesIncludeExclude,
5353
AccountsIndexConfig, IndexLimitMb,
5454
},
55+
bank::pyth_accumulator::{MESSAGE_BUFFER_PID, ORACLE_PID},
5556
hardened_unpack::MAX_GENESIS_ARCHIVE_UNPACKED_SIZE,
5657
runtime_config::RuntimeConfig,
5758
snapshot_config::SnapshotConfig,
@@ -3193,6 +3194,24 @@ fn process_account_indexes(matches: &ArgMatches) -> AccountSecondaryIndexes {
31933194
let exclude_keys = !account_indexes_exclude_keys.is_empty();
31943195
let include_keys = !account_indexes_include_keys.is_empty();
31953196

3197+
if include_keys {
3198+
if !account_indexes_include_keys.contains(&*ORACLE_PID) || !account_indexes_include_keys.contains(&*MESSAGE_BUFFER_PID) {
3199+
panic!(
3200+
"The oracle program id and message buffer program id must be included in the account index. Add the following flags\n\
3201+
--account-index program-id\n\
3202+
--account-index-include-key {}\n\
3203+
--account-index-include-key {}\n",
3204+
&*ORACLE_PID, &*MESSAGE_BUFFER_PID
3205+
);
3206+
}
3207+
}
3208+
3209+
if exclude_keys {
3210+
if account_indexes_exclude_keys.contains(&*ORACLE_PID) || account_indexes_exclude_keys.contains(&*MESSAGE_BUFFER_PID) {
3211+
panic!("The oracle program id and message buffer program id must *not* be excluded from the account index.");
3212+
}
3213+
}
3214+
31963215
let keys = if !account_indexes.is_empty() && (exclude_keys || include_keys) {
31973216
let account_indexes_keys = AccountSecondaryIndexesIncludeExclude {
31983217
exclude: exclude_keys,

0 commit comments

Comments
 (0)