Skip to content

Commit

Permalink
remove unnecessary lookup
Browse files Browse the repository at this point in the history
  • Loading branch information
EdHastingsCasperAssociation committed Feb 16, 2024
1 parent faec088 commit 37a3149
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 58 deletions.
102 changes: 52 additions & 50 deletions node/src/components/contract_runtime/operations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ pub fn execute_finalized_block(
.map(|approval| approval.signer().to_account_hash())
.collect();
let transfer_req = TransferRequest::with_runtime_args(
TransferConfig::Unadministered, // TODO: check chainspec & handle administered possibility
TransferConfig::Unadministered, /* TODO: check chainspec & handle
* administered possibility */
state_root_hash,
block_time,
protocol_version,
Expand Down Expand Up @@ -204,58 +205,59 @@ pub fn execute_finalized_block(

// If the finalized block has an era report, run the auction contract and get the upcoming era
// validators.
let maybe_step_effects_and_upcoming_era_validators =
if let Some(era_report) = &executable_block.era_report {
let StepSuccess {
post_state_hash: _, // ignore the post-state-hash returned from scratch
effects: step_effects,
} = commit_step(
&scratch_state, // engine_state
metrics,
protocol_version,
state_root_hash,
era_report.clone(),
executable_block.timestamp.millis(),
executable_block.era_id.successor(),
)?;

state_root_hash =
engine_state.write_scratch_to_db(state_root_hash, scratch_state.into_inner())?;

// state_root_hash = data_access_layer.write_scratch_to_db(state_root_hash, scratch_state)?;

let era_validators_req = EraValidatorsRequest::new(state_root_hash, protocol_version);
let era_validators_result = data_access_layer.era_validators(era_validators_req);

let upcoming_era_validators = match era_validators_result {
EraValidatorsResult::AuctionNotFound => {
panic!("auction not found");
}
EraValidatorsResult::RootNotFound => {
panic!("root not found");
}
EraValidatorsResult::ValueNotFound(msg) => {
panic!("validator snapshot not found: {}", msg);
}
EraValidatorsResult::Failure(tce) => {
return Err(BlockExecutionError::GetEraValidators(tce));
}
EraValidatorsResult::Success { era_validators } => era_validators,
};
let maybe_step_effects_and_upcoming_era_validators = if let Some(era_report) =
&executable_block.era_report
{
let StepSuccess {
post_state_hash: _, // ignore the post-state-hash returned from scratch
effects: step_effects,
} = commit_step(
&scratch_state, // engine_state
metrics,
protocol_version,
state_root_hash,
era_report.clone(),
executable_block.timestamp.millis(),
executable_block.era_id.successor(),
)?;

Some(StepEffectsAndUpcomingEraValidators {
step_effects,
upcoming_era_validators,
})
} else {
// Finally, the new state-root-hash from the cumulative changes to global state is
// returned when they are written to LMDB.
state_root_hash =
engine_state.write_scratch_to_db(state_root_hash, scratch_state.into_inner())?;
// state_root_hash = data_access_layer.write_scratch_to_db(state_root_hash, scratch_state)?;
None
state_root_hash =
engine_state.write_scratch_to_db(state_root_hash, scratch_state.into_inner())?;

// state_root_hash = data_access_layer.write_scratch_to_db(state_root_hash, scratch_state)?;

let era_validators_req = EraValidatorsRequest::new(state_root_hash, protocol_version);
let era_validators_result = data_access_layer.era_validators(era_validators_req);

let upcoming_era_validators = match era_validators_result {
EraValidatorsResult::AuctionNotFound => {
panic!("auction not found");
}
EraValidatorsResult::RootNotFound => {
panic!("root not found");
}
EraValidatorsResult::ValueNotFound(msg) => {
panic!("validator snapshot not found: {}", msg);
}
EraValidatorsResult::Failure(tce) => {
return Err(BlockExecutionError::GetEraValidators(tce));
}
EraValidatorsResult::Success { era_validators } => era_validators,
};

Some(StepEffectsAndUpcomingEraValidators {
step_effects,
upcoming_era_validators,
})
} else {
// Finally, the new state-root-hash from the cumulative changes to global state is
// returned when they are written to LMDB.
state_root_hash =
engine_state.write_scratch_to_db(state_root_hash, scratch_state.into_inner())?;
// state_root_hash = data_access_layer.write_scratch_to_db(state_root_hash, scratch_state)?;
None
};

// Flush once, after all deploys have been executed.
engine_state.flush_environment()?;

Expand Down
8 changes: 1 addition & 7 deletions storage/src/global_state/state/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,15 +274,9 @@ pub trait CommitProvider: StateProvider {
.extract_access_rights(AddressableEntityHash::new(entity_addr.value()), &named_keys);

let transfer_args = {
let entity_named_keys = match tc.borrow_mut().get_named_keys(entity_addr) {
Ok(named_keys) => named_keys,
Err(tce) => {
return TransferResult::Failure(tce.into());
}
};
match runtime_args_builder.build(
&entity,
entity_named_keys,
named_keys.clone(),
protocol_version,
Rc::clone(&tc),
) {
Expand Down
3 changes: 2 additions & 1 deletion storage/src/system/transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,8 @@ impl TransferRuntimeArgsBuilder {
fn resolve_source_uref<R>(
&self,
account: &AddressableEntity,
named_keys: NamedKeys,
named_keys: NamedKeys, /* TODO: consider passing in URef values inside named keys
* instead of entire named keys */
tracking_copy: Rc<RefCell<TrackingCopy<R>>>,
) -> Result<URef, TransferError>
where
Expand Down

0 comments on commit 37a3149

Please sign in to comment.