ChainData: update account InsertAfter bug
This commit is contained in:
parent
e993e2cc4f
commit
98f05abc6a
|
@ -201,7 +201,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 => {}
|
||||
}
|
||||
|
@ -416,6 +416,109 @@ mod tests {
|
|||
use solana_sdk::pubkey::Pubkey;
|
||||
use std::str::FromStr;
|
||||
|
||||
#[test]
|
||||
#[ignore]
|
||||
pub fn test_try_to_reproduce_weird_thing() {
|
||||
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: 283573414,
|
||||
write_version: 1,
|
||||
account: AccountSharedData::new(100, 100 /*space*/, &owner),
|
||||
},
|
||||
);
|
||||
|
||||
chain_data.update_slot(SlotData {
|
||||
slot: 283574172,
|
||||
parent: None,
|
||||
status: SlotStatus::Rooted, // =finalized
|
||||
chain: 0,
|
||||
});
|
||||
|
||||
chain_data.update_slot(SlotData {
|
||||
slot: 283574209,
|
||||
parent: Some(283574172),
|
||||
status: SlotStatus::Processed,
|
||||
chain: 0,
|
||||
});
|
||||
|
||||
assert_eq!(chain_data.newest_rooted_slot(), 283574172);
|
||||
assert_eq!(chain_data.best_chain_slot(), 283574209);
|
||||
assert_eq!(chain_data.account(&my_account).unwrap().slot, 283573414);
|
||||
|
||||
chain_data.update_account(
|
||||
my_account,
|
||||
AccountData {
|
||||
slot: 283574185,
|
||||
write_version: 1,
|
||||
account: AccountSharedData::new(101, 101 /*space*/, &owner),
|
||||
},
|
||||
);
|
||||
|
||||
assert_eq!(chain_data.newest_rooted_slot(), 283574172);
|
||||
assert_eq!(chain_data.best_chain_slot(), 283574209);
|
||||
assert_eq!(chain_data.account(&my_account).unwrap().slot, 283574185);
|
||||
assert_eq!(chain_data.account(&my_account).unwrap().account.lamports(), 101);
|
||||
}
|
||||
|
||||
#[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);
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn test_move_slot_to_finalized() {
|
||||
const SLOT: Slot = 42_000_000;
|
||||
|
|
Loading…
Reference in New Issue