Skip to content

Commit

Permalink
basic rooting flow
Browse files Browse the repository at this point in the history
  • Loading branch information
grooviegermanikus committed Aug 7, 2024
1 parent 423bf25 commit 31c0eaf
Showing 1 changed file with 63 additions and 1 deletion.
64 changes: 63 additions & 1 deletion connector/src/chain_data.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
use std::str::FromStr;

Check warning on line 1 in connector/src/chain_data.rs

View workflow job for this annotation

GitHub Actions / test

Diff in /home/runner/work/mango-feeds/mango-feeds/connector/src/chain_data.rs
use itertools::chain;
use solana_sdk::clock::Slot;
use {
solana_sdk::account::{AccountSharedData, ReadableAccount},
solana_sdk::pubkey::Pubkey,
Expand All @@ -18,7 +21,9 @@ pub struct SlotData {
pub slot: u64,
pub parent: Option<u64>,
pub status: SlotStatus,
pub chain: u64, // the top slot that this is in a chain with. uncles will have values < tip
// the top slot that this is in a chain with. uncles will have values < tip
// this field gets progressively rewritten as new successor slots are added
pub chain: u64,
}

#[derive(Clone, Debug)]
Expand Down Expand Up @@ -348,3 +353,60 @@ impl ChainDataMetrics {
});
}

Check warning on line 354 in connector/src/chain_data.rs

View workflow job for this annotation

GitHub Actions / test

Diff in /home/runner/work/mango-feeds/mango-feeds/connector/src/chain_data.rs
}


#[test]
pub fn test_overwrite() {
const SLOT: Slot = 42_000_000;
const SOME_LAMPORTS: u64 = 99000;

let owner = Pubkey::from_str("675kPX9MHTjS2zt1qfr1NYHuzeLXfQM9H24wFSUt1Mp8").unwrap();
let my_account = Pubkey::new_unique();
let mut chain_data = ChainData::new();

chain_data.update_account(
my_account,
AccountData {

Check warning on line 369 in connector/src/chain_data.rs

View workflow job for this annotation

GitHub Actions / test

Diff in /home/runner/work/mango-feeds/mango-feeds/connector/src/chain_data.rs
slot: SLOT,
write_version: 2000,
account: AccountSharedData::new(SOME_LAMPORTS, 100/*space*/, &owner),
}
);

// note: this is initial state
assert_eq!(chain_data.newest_rooted_slot(), 0);

// assume no rooted slot yet
assert_eq!(chain_data.iter_accounts_rooted().count(), 0);

chain_data.update_slot(SlotData {
slot: SLOT,
parent: None,
status: SlotStatus::Processed,
chain: 0,
});

assert_eq!(chain_data.newest_rooted_slot(), 0);

chain_data.update_slot(SlotData {
slot: SLOT - 2,
parent: None,
status: SlotStatus::Rooted, // =finalized
chain: 0,
});

assert_eq!(chain_data.newest_rooted_slot(), SLOT - 2);

assert_eq!(chain_data.iter_accounts_rooted().count(), 0);

// GIVEN: finalized slot SLOT
chain_data.update_slot(SlotData {
slot: SLOT,
parent: None,
status: SlotStatus::Rooted, // =finalized
chain: 0,
});

assert_eq!(chain_data.iter_accounts_rooted().count(), 1);

}

0 comments on commit 31c0eaf

Please sign in to comment.