From 0721cda9a84d1126cc63bedc317479bc451ddd0a Mon Sep 17 00:00:00 2001 From: Serge Farny Date: Thu, 15 Aug 2024 15:06:22 +0200 Subject: [PATCH] ChainData: update account InsertAfter bug --- connector/src/chain_data.rs | 55 ++++++++++++++++++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) diff --git a/connector/src/chain_data.rs b/connector/src/chain_data.rs index 2e27b8c..20cc79d 100644 --- a/connector/src/chain_data.rs +++ b/connector/src/chain_data.rs @@ -198,7 +198,7 @@ impl ChainData { InsertAfter(pos) => { self.account_versions_stored += 1; self.account_bytes_stored += account.account.data().len(); - v.insert(pos, account); + v.insert(pos + 1, account); } DoNothing => {} } @@ -648,4 +648,57 @@ mod tests { }, ] } + #[test] + pub fn test_loosing_account_write() { + 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 { + slot: 123, + write_version: 1, + account: AccountSharedData::new(100, 100 /*space*/, &owner), + }, + ); + + chain_data.update_slot(SlotData { + slot: 123, + parent: None, + status: SlotStatus::Rooted, // =finalized + chain: 0, + }); + + chain_data.update_account( + my_account, + AccountData { + slot: 128, + write_version: 1, + account: AccountSharedData::new(101, 101 /*space*/, &owner), + }, + ); + + chain_data.update_slot(SlotData { + slot: 128, + parent: Some(123), + status: SlotStatus::Processed, + chain: 0, + }); + + assert_eq!(chain_data.newest_rooted_slot(), 123); + assert_eq!(chain_data.best_chain_slot(), 128); + assert_eq!(chain_data.account(&my_account).unwrap().slot, 128); + + chain_data.update_slot(SlotData { + slot: 129, + parent: Some(128), + status: SlotStatus::Processed, + chain: 0, + }); + + assert_eq!(chain_data.newest_rooted_slot(), 123); + assert_eq!(chain_data.best_chain_slot(), 129); + assert_eq!(chain_data.account(&my_account).unwrap().slot, 128); + } }