Skip to content

Give tests unique bank_ids - #15749

Closed
roryharr wants to merge 1 commit into
anza-xyz:masterfrom
roryharr:harness_bank_ids
Closed

roryharr wants to merge 1 commit into
anza-xyz:masterfrom
roryharr:harness_bank_ids

Conversation

@roryharr

@roryharr roryharr commented Oct 2, 2026 •

Copy link
Copy Markdown

Problem

Some tests currently create an accounts_db, store some accounts and then wrap it a bank. This will cause issues when bankId is used as the write cache index, as both slots will use the same bankId.

Summary of Changes

  • Add a new API to create a bank with a given root slot
  • store accounts on the new bank
  • Root the bank and generate a bank used for the test on the new slot

Testing

Fixes #

@codecov-commenter

codecov-commenter commented Oct 2, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 43.24324% with 21 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.6%. Comparing base (e903501) to head (b15df0c).
⚠️ Report is 31 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #15749   +/-   ##
=======================================
  Coverage    82.6%    82.6%           
=======================================
  Files         935      935           
  Lines      373761   373743   -18     
=======================================
  Hits       309048   309048           
+ Misses      64713    64695   -18     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@roryharr
roryharr force-pushed the harness_bank_ids branch 2 times, most recently from c04623c to cc2c9b6 Compare October 2, 2026 19:57
@roryharr
roryharr marked this pull request as ready for review October 2, 2026 21:50
@roryharr

roryharr commented Oct 2, 2026 •

Copy link
Copy Markdown
Author

Joe, you were recommended by github. I'm not sure why. feel free to remove yourself if this isn't relevant.

@buffalojoec

Copy link
Copy Markdown

Joe, you were recommended by github. I'm not sure why. feel free to remove yourself if this isn't relevant.

certified Banker

Comment thread runtime/src/bank.rs
Comment on lines +6995 to +7005
/// A bank at `slot` over an empty accounts db, with no parent. Store a chain's pre-state
/// through it, then build the bank under test on it. Leave it unfrozen: freezing writes
/// slot history into the pre-state.
pub fn new_at_slot_for_tests(slot: Slot, accounts_db_config: AccountsDbConfig) -> Self {
let accounts_db = AccountsDb::new_for_tests_with_config(Vec::new(), accounts_db_config);
let mut bank = Self::default_with_accounts(Accounts::new(Arc::new(accounts_db)));
bank.slot = slot;
bank.epoch = bank.epoch_schedule.get_epoch(slot);
bank.ancestors = Ancestors::from(vec![slot]);
bank
}

@brooksprumo brooksprumo Oct 5, 2026 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please no more Bank constructors. We can already create Banks with an AccountsDbConfig via Bank::new_with_paths_for_tests() and its BankTestConfig parameter.

E.g.

        let accounts_db_config = AccountsDbConfig { .. };
        let bank = Bank::new_with_paths_for_tests(
            genesis_config,
            Some(BankTestConfig {
                accounts_db_config,
            }),
            vec![],
            None,
        );
Suggested change
/// A bank at `slot` over an empty accounts db, with no parent. Store a chain's pre-state
/// through it, then build the bank under test on it. Leave it unfrozen: freezing writes
/// slot history into the pre-state.
pub fn new_at_slot_for_tests(slot: Slot, accounts_db_config: AccountsDbConfig) -> Self {
let accounts_db = AccountsDb::new_for_tests_with_config(Vec::new(), accounts_db_config);
let mut bank = Self::default_with_accounts(Accounts::new(Arc::new(accounts_db)));
bank.slot = slot;
bank.epoch = bank.epoch_schedule.get_epoch(slot);
bank.ancestors = Ancestors::from(vec![slot]);
bank
}

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was trying to largely keep the conformance tests state consistent with the current state.
They create an accountsDb at slotN-1, and then create a new slot at SlotN to test things such as leader schedule.

This was the best way I saw to not change the output bank.

The other tests could use new_with_paths, but the function would still need to live in bank.rs unless some fields moved to public.

Another option is modifying the new_for_tests_with_config API to allow for a slot to be passed in.

@brooksprumo brooksprumo Oct 5, 2026 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I'm intending to convey is to inline changes to the Bank as needed. E.g. make the bank mut and set slot/epoch/ancestors as needed.

Although I'm thinking this can be simplified further.

E.g. in:

    // Populate the accounts DB with the input accounts at the parent slot.
    let bank_accounts = new_accounts_for_tests_single_threaded();
    let ancestors = Ancestors::from(vec![parent_slot]);
    bank_accounts.store_accounts(
        (parent_slot, &accounts[..]),
        BankId::default(),
        None,
        &ancestors,
    );
    bank_accounts.accounts_db.add_root(parent_slot);
    let bank_rc = BankRc::new(bank_accounts);

Can we create the BankRc earlier, and use its bank id generator, thus ensuring the next Bank that is created later--which uses the same BankRc--gets a unique BankId via the generator's call to next()?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, one option would be creating the BankRc and working directly on the BankRc.

eg:

// Accounts DB config and initialization
    let bank_rc = BankRc::new(new_accounts_for_tests_single_threaded());
    let bank_id = bank_rc.bank_id_generator.next(),
    bank_rc.accounts.store_accounts(
        (parent_slot, &accounts_to_store[..]),
        bank_rc.bank_id_generator.next(),
        None,
        &Ancestors::default(),
    );

@brooksprumo brooksprumo Oct 5, 2026 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yah, I like that way better.

@brooksprumo brooksprumo left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My understanding is that this PR will rebase on top of #15796 once merged.

Commenting so this PR isn't in my 'awaiting review' queue. Please re-request review once ready though!

@roryharr

roryharr commented Oct 7, 2026

Copy link
Copy Markdown
Author

Closing in favor of #15830

@roryharr roryharr closed this Oct 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants