Skip to content

Commit

Permalink
tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
EdHastingsCasperAssociation committed Mar 18, 2024
1 parent 4232609 commit 255a548
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 30 deletions.
10 changes: 5 additions & 5 deletions binary_port/src/payload_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,11 +277,11 @@ const NEXT_UPGRADE_TAG: u8 = 25;
const CONSENSUS_STATUS_TAG: u8 = 26;
const CHAINSPEC_RAW_BYTES_TAG: u8 = 27;
const HIGHEST_BLOCK_SEQUENCE_CHECK_RESULT_TAG: u8 = 28;
const SPECULATIVE_EXECUTION_RESULT_TAG: u8 = 29;
const GLOBAL_STATE_QUERY_RESULT_TAG: u8 = 30;
const STORED_VALUES_TAG: u8 = 31;
const GET_TRIE_FULL_RESULT_TAG: u8 = 32;
const NODE_STATUS_TAG: u8 = 33;
const GLOBAL_STATE_QUERY_RESULT_TAG: u8 = 29;
const STORED_VALUES_TAG: u8 = 30;
const GET_TRIE_FULL_RESULT_TAG: u8 = 31;
const NODE_STATUS_TAG: u8 = 32;
const SPECULATIVE_EXECUTION_RESULT_TAG: u8 = 33;
const WASM_V1_RESULT_TAG: u8 = 34;

impl ToBytes for PayloadType {
Expand Down
3 changes: 2 additions & 1 deletion node/src/components/binary_port/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,8 @@ impl From<NetworkInfoRequest> for Event {
}

impl From<StorageRequest> for Event {
fn from(_request: StorageRequest) -> Self {
fn from(request: StorageRequest) -> Self {
println!("{}", request);
unreachable!()
}
}
Expand Down
2 changes: 1 addition & 1 deletion node/src/components/block_synchronizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1141,7 +1141,7 @@ impl BlockSynchronizer {
}
};
return effect_builder
.put_execution_results_to_storage(
.put_execution_artifacts_to_storage(
block_hash,
block_height,
era_id,
Expand Down
38 changes: 21 additions & 17 deletions node/src/components/contract_runtime/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ use crate::{
fatal,
types::{ExecutableBlock, MetaBlock, MetaBlockState},
};

use casper_execution_engine::engine_state::ExecutionEngineV1;
use casper_storage::{
data_access_layer::DataAccessLayer, global_state::state::lmdb::LmdbGlobalState,
};
use casper_types::{Chainspec, EraId, Key};
use once_cell::sync::Lazy;
use std::fmt::Debug;
use std::{
cmp,
collections::{BTreeMap, HashMap},
Expand All @@ -43,13 +45,18 @@ static INTENSIVE_TASKS_SEMAPHORE: Lazy<tokio::sync::Semaphore> =
pub(super) async fn run_intensive_task<T, V>(task: T) -> V
where
T: 'static + Send + FnOnce() -> V,
V: 'static + Send,
V: 'static + Send + Debug,
{
// This will never panic since the semaphore is never closed.
let _permit = INTENSIVE_TASKS_SEMAPHORE.acquire().await.unwrap();
tokio::task::spawn_blocking(task)
.await
.expect("task panicked")
let result = tokio::task::spawn_blocking(task).await;
match result {
Ok(ret) => ret,
Err(err) => {
error!("{:?}", err);
panic!("intensive contract runtime task errored: {:?}", err);
}
}
}

#[allow(clippy::too_many_arguments)]
Expand Down Expand Up @@ -102,8 +109,8 @@ pub(super) async fn exec_or_requeue<REv>(
let BlockAndExecutionArtifacts {
block,
approvals_hashes,
execution_artifacts: execution_results,
step_outcome: maybe_step_effects_and_upcoming_era_validators,
execution_artifacts,
step_outcome: maybe_step_outcome,
} = match run_intensive_task(move || {
debug!("ContractRuntime: execute_finalized_block");
execute_finalized_block(
Expand All @@ -118,7 +125,7 @@ pub(super) async fn exec_or_requeue<REv>(
})
.await
{
Ok(block_and_execution_results) => block_and_execution_results,
Ok(ret) => ret,
Err(error) => {
error!(%error, "failed to execute block");
return fatal!(effect_builder, "{}", error).await;
Expand Down Expand Up @@ -152,7 +159,7 @@ pub(super) async fn exec_or_requeue<REv>(
if let Some(StepOutcome {
step_effects,
mut upcoming_era_validators,
}) = maybe_step_effects_and_upcoming_era_validators
}) = maybe_step_outcome
{
effect_builder
.announce_commit_step_success(current_era_id, step_effects)
Expand Down Expand Up @@ -185,29 +192,26 @@ pub(super) async fn exec_or_requeue<REv>(
"executed block"
);

let execution_results_map: HashMap<_, _> = execution_results
let artifacts_map: HashMap<_, _> = execution_artifacts
.iter()
.cloned()
.map(|artifact| (artifact.transaction_hash, artifact.execution_result))
.collect();

if meta_block_state.register_as_stored().was_updated() {
effect_builder
.put_executed_block_to_storage(
Arc::clone(&block),
approvals_hashes,
execution_results_map,
)
.put_executed_block_to_storage(Arc::clone(&block), approvals_hashes, artifacts_map)
.await;
} else {
effect_builder
.put_approvals_hashes_to_storage(approvals_hashes)
.await;
effect_builder
.put_execution_results_to_storage(
.put_execution_artifacts_to_storage(
*block.hash(),
block.height(),
block.era_id(),
execution_results_map,
artifacts_map,
)
.await;
}
Expand All @@ -223,7 +227,7 @@ pub(super) async fn exec_or_requeue<REv>(
);
}

let meta_block = MetaBlock::new_forward(block, execution_results, meta_block_state);
let meta_block = MetaBlock::new_forward(block, execution_artifacts, meta_block_state);
effect_builder.announce_meta_block(meta_block).await;

// If the child is already finalized, start execution.
Expand Down
2 changes: 1 addition & 1 deletion node/src/effect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1627,7 +1627,7 @@ impl<REv> EffectBuilder<REv> {

/// Stores the given execution results for the transactions in the given block in the linear
/// block store.
pub(crate) async fn put_execution_results_to_storage(
pub(crate) async fn put_execution_artifacts_to_storage(
self,
block_hash: BlockHash,
block_height: u64,
Expand Down
8 changes: 4 additions & 4 deletions storage/src/global_state/state/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ pub trait CommitProvider: StateProvider {
}
};

crate::system::runtime_native::Id::Seed(bytes)
Id::Seed(bytes)
};

let config = request.config();
Expand Down Expand Up @@ -376,7 +376,7 @@ pub trait CommitProvider: StateProvider {
}
};

crate::system::runtime_native::Id::Seed(bytes)
Id::Seed(bytes)
};

// this runtime uses the system's context
Expand Down Expand Up @@ -540,7 +540,7 @@ pub trait CommitProvider: StateProvider {
}
};

crate::system::runtime_native::Id::Seed(bytes)
Id::Seed(bytes)
};

let config = request.config();
Expand Down Expand Up @@ -1376,7 +1376,7 @@ pub trait StateProvider {
}
};

let id = crate::system::runtime_native::Id::Transaction(request.transaction_hash());
let id = Id::Transaction(request.transaction_hash());
// IMPORTANT: this runtime _must_ use the payer's context.
let mut runtime = RuntimeNative::new(
protocol_version,
Expand Down
4 changes: 3 additions & 1 deletion storage/src/system/mint/mint_native.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,9 @@ where
}
let transaction_hash = match self.id() {
Id::Transaction(transaction_hash) => *transaction_hash,
Id::Seed(_) => return Err(Error::RecordTransferFailure),
// we don't write transfer records for systemic transfers (step, fees, rewards, etc)
// so return Ok and move on.
Id::Seed(_) => return Ok(()),
};

let transfer_addr = TransferAddr::new(self.address_generator().create_address());
Expand Down

0 comments on commit 255a548

Please sign in to comment.