Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

override sysvars from accounts list #61

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
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
5 changes: 4 additions & 1 deletion harness/src/fuzz/firedancer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,13 @@ fn parse_fixture_context(
.map(|(key, acct, _)| (*key, acct.clone()))
.collect::<Vec<_>>();

let mut sysvars = Sysvars::default();
sysvars.fill_from_accounts(&accounts);

let mollusk = Mollusk {
compute_budget,
feature_set: epoch_context.feature_set.clone(),
sysvars: Sysvars::fill_from_accounts(&accounts),
sysvars,
..Default::default()
};

Expand Down
7 changes: 5 additions & 2 deletions harness/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,9 @@ impl Mollusk {
let mut compute_units_consumed = 0;
let mut timings = ExecuteTimings::default();

let mut sysvars = self.sysvars.clone();
sysvars.fill_from_accounts(accounts);

let loader_key = self
.program_cache
.load_program(&instruction.program_id)
Expand All @@ -169,7 +172,7 @@ impl Mollusk {

let mut transaction_context = TransactionContext::new(
transaction_accounts,
self.sysvars.rent.clone(),
sysvars.rent.clone(),
self.compute_budget.max_instruction_stack_depth,
self.compute_budget.max_instruction_trace_length,
);
Expand All @@ -185,7 +188,7 @@ impl Mollusk {
None,
Arc::new(self.feature_set.clone()),
self.fee_structure.lamports_per_signature,
&SysvarCache::from(&self.sysvars),
&SysvarCache::from(&sysvars),
),
None,
self.compute_budget,
Expand Down
36 changes: 24 additions & 12 deletions harness/src/sysvar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,20 @@ pub struct Sysvars {
pub stake_history: StakeHistory,
}

impl Clone for Sysvars {
fn clone(&self) -> Self {
Self {
clock: self.clock.clone(),
epoch_rewards: self.epoch_rewards.clone(),
epoch_schedule: self.epoch_schedule.clone(),
last_restart_slot: self.last_restart_slot.clone(),
rent: self.rent.clone(),
slot_hashes: SlotHashes::new(&self.slot_hashes),
stake_history: self.stake_history.clone(),
}
}
}

impl Default for Sysvars {
fn default() -> Self {
let clock = Clock::default();
Expand Down Expand Up @@ -59,34 +73,32 @@ impl Default for Sysvars {
}

impl Sysvars {
/// Create a `Sysvars` instance from a list of accounts. Any missing
/// sysvars will be filled with default values.
pub fn fill_from_accounts(accounts: &[(Pubkey, AccountSharedData)]) -> Self {
let mut me = Self::default();
/// Update a `Sysvars` instance from a list of accounts. Any sysvars not
/// in the account list will retain their existing values.
pub fn fill_from_accounts(&mut self, accounts: &[(Pubkey, AccountSharedData)]) {
for (key, account) in accounts {
if key == &Clock::id() {
me.clock = bincode::deserialize(account.data()).unwrap();
self.clock = bincode::deserialize(account.data()).unwrap();
}
if key == &EpochRewards::id() {
me.epoch_rewards = bincode::deserialize(account.data()).unwrap();
self.epoch_rewards = bincode::deserialize(account.data()).unwrap();
}
if key == &EpochSchedule::id() {
me.epoch_schedule = bincode::deserialize(account.data()).unwrap();
self.epoch_schedule = bincode::deserialize(account.data()).unwrap();
}
if key == &LastRestartSlot::id() {
me.last_restart_slot = bincode::deserialize(account.data()).unwrap();
self.last_restart_slot = bincode::deserialize(account.data()).unwrap();
}
if key == &Rent::id() {
me.rent = bincode::deserialize(account.data()).unwrap();
self.rent = bincode::deserialize(account.data()).unwrap();
}
if key == &SlotHashes::id() {
me.slot_hashes = bincode::deserialize(account.data()).unwrap();
self.slot_hashes = bincode::deserialize(account.data()).unwrap();
}
if key == &StakeHistory::id() {
me.stake_history = bincode::deserialize(account.data()).unwrap();
self.stake_history = bincode::deserialize(account.data()).unwrap();
}
}
me
}

fn sysvar_account<T: SysvarId + Sysvar>(&self, sysvar: &T) -> (Pubkey, AccountSharedData) {
Expand Down
Loading