Skip to content

Commit

Permalink
ChainData: update account InsertAfter bug
Browse files Browse the repository at this point in the history
  • Loading branch information
farnyser authored and grooviegermanikus committed Aug 15, 2024
1 parent 5a92d1f commit 0721cda
Showing 1 changed file with 54 additions and 1 deletion.
55 changes: 54 additions & 1 deletion connector/src/chain_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {}
}
Expand Down Expand Up @@ -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);
}
}

0 comments on commit 0721cda

Please sign in to comment.