Prevent repeated accounts in genesis to avoid breaking account hashing
This commit is contained in:
parent
4870a2cbac
commit
c34cc4918f
|
@ -155,7 +155,12 @@ impl LocalCluster {
|
||||||
storage_contract::create_validator_storage_account(leader_pubkey, 1),
|
storage_contract::create_validator_storage_account(leader_pubkey, 1),
|
||||||
));
|
));
|
||||||
|
|
||||||
// override staking config
|
// Replace staking config
|
||||||
|
genesis_block.accounts = genesis_block
|
||||||
|
.accounts
|
||||||
|
.into_iter()
|
||||||
|
.filter(|(pubkey, _)| *pubkey != stake_config::id())
|
||||||
|
.collect();
|
||||||
genesis_block.accounts.push((
|
genesis_block.accounts.push((
|
||||||
stake_config::id(),
|
stake_config::id(),
|
||||||
stake_config::create_account(
|
stake_config::create_account(
|
||||||
|
|
|
@ -611,11 +611,17 @@ impl Bank {
|
||||||
self.update_fees();
|
self.update_fees();
|
||||||
|
|
||||||
for (pubkey, account) in genesis_block.accounts.iter() {
|
for (pubkey, account) in genesis_block.accounts.iter() {
|
||||||
|
if self.get_account(&pubkey).is_some() {
|
||||||
|
panic!("{} repeated in genesis block", pubkey);
|
||||||
|
}
|
||||||
self.store_account(pubkey, account);
|
self.store_account(pubkey, account);
|
||||||
self.capitalization
|
self.capitalization
|
||||||
.fetch_add(account.lamports, Ordering::Relaxed);
|
.fetch_add(account.lamports, Ordering::Relaxed);
|
||||||
}
|
}
|
||||||
for (pubkey, account) in genesis_block.rewards_pools.iter() {
|
for (pubkey, account) in genesis_block.rewards_pools.iter() {
|
||||||
|
if self.get_account(&pubkey).is_some() {
|
||||||
|
panic!("{} repeated in genesis block", pubkey);
|
||||||
|
}
|
||||||
self.store_account(pubkey, account);
|
self.store_account(pubkey, account);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1637,7 +1643,10 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_bank_capitalization() {
|
fn test_bank_capitalization() {
|
||||||
let bank = Arc::new(Bank::new(&GenesisBlock {
|
let bank = Arc::new(Bank::new(&GenesisBlock {
|
||||||
accounts: vec![(Pubkey::default(), Account::new(42, 0, &Pubkey::default()),); 42],
|
accounts: (0..42)
|
||||||
|
.into_iter()
|
||||||
|
.map(|_| (Pubkey::new_rand(), Account::new(42, 0, &Pubkey::default())))
|
||||||
|
.collect(),
|
||||||
..GenesisBlock::default()
|
..GenesisBlock::default()
|
||||||
}));
|
}));
|
||||||
assert_eq!(bank.capitalization(), 42 * 42);
|
assert_eq!(bank.capitalization(), 42 * 42);
|
||||||
|
@ -1649,13 +1658,15 @@ mod tests {
|
||||||
fn test_bank_update_rewards() {
|
fn test_bank_update_rewards() {
|
||||||
// create a bank that ticks really slowly...
|
// create a bank that ticks really slowly...
|
||||||
let bank = Arc::new(Bank::new(&GenesisBlock {
|
let bank = Arc::new(Bank::new(&GenesisBlock {
|
||||||
accounts: vec![
|
accounts: (0..42)
|
||||||
(
|
.into_iter()
|
||||||
Pubkey::default(),
|
.map(|_| {
|
||||||
Account::new(1_000_000_000, 0, &Pubkey::default()),
|
(
|
||||||
);
|
Pubkey::new_rand(),
|
||||||
42
|
Account::new(1_000_000_000, 0, &Pubkey::default()),
|
||||||
],
|
)
|
||||||
|
})
|
||||||
|
.collect(),
|
||||||
// set it up so the first epoch is a full year long
|
// set it up so the first epoch is a full year long
|
||||||
poh_config: PohConfig {
|
poh_config: PohConfig {
|
||||||
target_tick_duration: Duration::from_secs(
|
target_tick_duration: Duration::from_secs(
|
||||||
|
|
Loading…
Reference in New Issue