Skip to content
This repository was archived by the owner on Jan 22, 2025. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 50 additions & 1 deletion runtime/src/bank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -597,10 +597,15 @@ impl Bank {
old_account.as_ref().map(|a| a.lamports).unwrap_or(1)
}

/// Unused conversion
pub fn get_unused_from_slot(rooted_slot: Slot, unused: u64) -> u64 {
(rooted_slot + (unused - 1)) / unused
}

pub fn clock(&self) -> sysvar::clock::Clock {
sysvar::clock::Clock {
slot: self.slot,
unused: 0,
unused: Self::get_unused_from_slot(self.slot, self.unused),
epoch: self.epoch_schedule.get_epoch(self.slot),
leader_schedule_epoch: self.epoch_schedule.get_leader_schedule_epoch(self.slot),
unix_timestamp: self.unix_timestamp(),
Expand Down Expand Up @@ -7005,4 +7010,48 @@ mod tests {
}
info!("results: {:?}", results);
}

#[test]
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ryoqun how about this test? I ran it across different scenarios (with the owner in the hash, without, with my archiver's removed w and w/o this PR) and it looks like it accomplishes what we need. Let me know what you think.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perfect! That's what I'm looking for. :)

fn test_bank_hash_consistency() {
let mut genesis_config = GenesisConfig::new(
&[(
Pubkey::new(&[42; 32]),
Account::new(1_000_000_000_000, 0, &system_program::id()),
)],
&[],
);
genesis_config.creation_time = 0;
let mut bank = Arc::new(Bank::new(&genesis_config));
// Check a few slots, cross an epoch boundary
assert_eq!(bank.get_slots_in_epoch(0), 32);
loop {
goto_end_of_slot(Arc::get_mut(&mut bank).unwrap());
if bank.slot == 0 {
assert_eq!(
bank.hash().to_string(),
"7MKHH6P7J5aQNN29Cr6aZQbEpQcXe8KTgchd4Suk9NCG"
);
}
if bank.slot == 32 {
assert_eq!(
bank.hash().to_string(),
"3AxuV6GGcoqRi6pksN6btNEmeJCTesLbjgA88QZt9a8Q"
);
}
if bank.slot == 64 {
assert_eq!(
bank.hash().to_string(),
"B32ZLAzeCW5FueeauiGYnujh8Efmxvpeac74W9JU68oB"
);
}
if bank.slot == 128 {
assert_eq!(
bank.hash().to_string(),
"A2tCz2EqryRZ7tHpw9H2918RZLCbqnSGzRWUqbnnESGz"
);
break;
}
bank = Arc::new(new_from_parent(&bank));
}
}
}