Skip to content

Commit

Permalink
Applied CR remarks
Browse files Browse the repository at this point in the history
  • Loading branch information
Jakub Zajkowski committed Nov 21, 2024
1 parent 69a6b46 commit 983beba
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 20 deletions.
9 changes: 6 additions & 3 deletions node/src/components/contract_runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ use casper_execution_engine::engine_state::{EngineConfigBuilder, ExecutionEngine
use casper_storage::{
data_access_layer::{
AddressableEntityRequest, AddressableEntityResult, BlockStore, DataAccessLayer,
EntryPointsRequest, ExecutionResultsChecksumRequest, FlushRequest, FlushResult,
EntryPointExistsRequest, ExecutionResultsChecksumRequest, FlushRequest, FlushResult,
GenesisRequest, GenesisResult, TrieRequest,
},
global_state::{
Expand Down Expand Up @@ -463,8 +463,11 @@ impl ContractRuntime {
let data_access_layer = Arc::clone(&self.data_access_layer);
async move {
let start = Instant::now();
let request =
EntryPointsRequest::new(state_root_hash, entry_point_name, contract_hash);
let request = EntryPointExistsRequest::new(
state_root_hash,
entry_point_name,
contract_hash,
);
let result = data_access_layer.entry_point_exists(request);
metrics.entry_points.observe(start.elapsed().as_secs_f64());
trace!(?result, "get addressable entity");
Expand Down
4 changes: 2 additions & 2 deletions node/src/components/contract_runtime/operations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use casper_storage::{
mint::BalanceIdentifierTransferArgs,
AuctionMethod, BalanceHoldKind, BalanceHoldRequest, BalanceIdentifier, BalanceRequest,
BiddingRequest, BlockGlobalRequest, BlockGlobalResult, BlockRewardsRequest,
BlockRewardsResult, DataAccessLayer, EntryPointResult, EntryPointsRequest,
BlockRewardsResult, DataAccessLayer, EntryPointRequest, EntryPointResult,
EraValidatorsRequest, EraValidatorsResult, EvictItem, FeeRequest, FeeResult, FlushRequest,
HandleFeeMode, HandleFeeRequest, HandleRefundMode, HandleRefundRequest,
InsufficientBalanceHandling, ProofHandling, PruneRequest, PruneResult, StepRequest,
Expand Down Expand Up @@ -1249,7 +1249,7 @@ fn invoked_contract_will_pay(
Some((hash_addr, entry_point_name)) => (hash_addr, entry_point_name),
};
let entity_addr = EntityAddr::new_smart_contract(hash_addr);
let entry_point_request = EntryPointsRequest::new(state_root_hash, entry_point_name, hash_addr);
let entry_point_request = EntryPointRequest::new(state_root_hash, entry_point_name, hash_addr);
let entry_point_response = state_provider.entry_point(entry_point_request);
match entry_point_response {
EntryPointResult::RootNotFound => Err(StateResultError::RootNotFound),
Expand Down
10 changes: 6 additions & 4 deletions node/src/components/contract_runtime/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ mod test_mod {
use tempfile::tempdir;

use casper_storage::{
data_access_layer::{EntryPointExistsResult, EntryPointsRequest},
data_access_layer::{EntryPointExistsRequest, EntryPointExistsResult},
global_state::{
state::{CommitProvider, StateProvider},
trie::Trie,
Expand Down Expand Up @@ -605,7 +605,8 @@ mod test_mod {
ProtocolVersion::V2_0_0,
);
let (contract_runtime, state_hash) = create_test_state(rng, initial_state);
let request = EntryPointsRequest::new(state_hash, entry_point_name.to_string(), hash_addr);
let request =
EntryPointExistsRequest::new(state_hash, entry_point_name.to_string(), hash_addr);
let res = contract_runtime
.data_access_layer()
.entry_point_exists(request);
Expand All @@ -620,7 +621,8 @@ mod test_mod {
let entry_point_name = "ep1";
let initial_state = create_entry_point(entity_addr, entry_point_name);
let (contract_runtime, state_hash) = create_test_state(rng, initial_state);
let request = EntryPointsRequest::new(state_hash, entry_point_name.to_string(), hash_addr);
let request =
EntryPointExistsRequest::new(state_hash, entry_point_name.to_string(), hash_addr);
let res = contract_runtime
.data_access_layer()
.entry_point_exists(request);
Expand All @@ -634,7 +636,7 @@ mod test_mod {
let entity_addr = EntityAddr::new_smart_contract(hash_addr);
let initial_state = create_entry_point(entity_addr, "ep1");
let (contract_runtime, state_hash) = create_test_state(rng, initial_state);
let request = EntryPointsRequest::new(state_hash, "ep2".to_string(), hash_addr);
let request = EntryPointExistsRequest::new(state_hash, "ep2".to_string(), hash_addr);
let res = contract_runtime
.data_access_layer()
.entry_point_exists(request);
Expand Down
4 changes: 3 additions & 1 deletion storage/src/data_access_layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ pub use bids::{BidsRequest, BidsResult};
pub use block_global::{BlockGlobalKind, BlockGlobalRequest, BlockGlobalResult};
pub use block_rewards::{BlockRewardsError, BlockRewardsRequest, BlockRewardsResult};
pub use contract::{ContractRequest, ContractResult};
pub use entry_points::{EntryPointExistsResult, EntryPointResult, EntryPointsRequest};
pub use entry_points::{
EntryPointExistsRequest, EntryPointExistsResult, EntryPointRequest, EntryPointResult,
};
pub use era_validators::{EraValidatorsRequest, EraValidatorsResult};
pub use execution_results_checksum::{
ExecutionResultsChecksumRequest, ExecutionResultsChecksumResult,
Expand Down
54 changes: 49 additions & 5 deletions storage/src/data_access_layer/entry_points.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
use crate::tracking_copy::TrackingCopyError;
use casper_types::{Digest, EntryPointValue, HashAddr};

/// Represents a request to obtain entry points.
/// Represents a request to obtain entry point.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct EntryPointsRequest {
pub struct EntryPointRequest {
state_hash: Digest,
entry_point_name: String,
contract_hash: HashAddr,
}

impl EntryPointsRequest {
impl EntryPointRequest {
/// ctor
pub fn new(state_hash: Digest, entry_point_name: String, contract_hash: HashAddr) -> Self {
EntryPointsRequest {
EntryPointRequest {
state_hash,
entry_point_name,
contract_hash,
Expand All @@ -35,7 +35,17 @@ impl EntryPointsRequest {
}
}

/// Represents a result of a `entry_points` request.
impl From<EntryPointExistsRequest> for EntryPointRequest {
fn from(value: EntryPointExistsRequest) -> Self {
EntryPointRequest {
state_hash: value.state_hash,
entry_point_name: value.entry_point_name,
contract_hash: value.contract_hash,
}
}
}

/// Represents a result of a `entry_point` request.
#[derive(Debug)]
pub enum EntryPointResult {
/// Invalid state root hash.
Expand All @@ -51,6 +61,40 @@ pub enum EntryPointResult {
Failure(TrackingCopyError),
}

/// Represents a request to check entry point existence.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct EntryPointExistsRequest {
state_hash: Digest,
entry_point_name: String,
contract_hash: HashAddr,
}

impl EntryPointExistsRequest {
/// ctor
pub fn new(state_hash: Digest, entry_point_name: String, contract_hash: HashAddr) -> Self {
EntryPointExistsRequest {
state_hash,
entry_point_name,
contract_hash,
}
}

/// Returns state root hash.
pub fn state_hash(&self) -> Digest {
self.state_hash
}

/// Returns entry_point_name.
pub fn entry_point_name(&self) -> &str {
&self.entry_point_name
}

/// Returns contract_hash.
pub fn contract_hash(&self) -> HashAddr {
self.contract_hash
}
}

/// Represents a result of `entry_point_exists` request.
#[derive(Debug)]
pub enum EntryPointExistsResult {
Expand Down
10 changes: 5 additions & 5 deletions storage/src/global_state/state/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ use crate::{
BalanceHoldKind, BalanceHoldMode, BalanceHoldRequest, BalanceHoldResult, BalanceIdentifier,
BalanceRequest, BalanceResult, BidsRequest, BidsResult, BlockGlobalKind,
BlockGlobalRequest, BlockGlobalResult, BlockRewardsError, BlockRewardsRequest,
BlockRewardsResult, ContractRequest, ContractResult, EntryPointExistsResult,
EntryPointResult, EntryPointsRequest, EraValidatorsRequest,
BlockRewardsResult, ContractRequest, ContractResult, EntryPointExistsRequest,
EntryPointExistsResult, EntryPointRequest, EntryPointResult, EraValidatorsRequest,
ExecutionResultsChecksumRequest, ExecutionResultsChecksumResult, FeeError, FeeRequest,
FeeResult, FlushRequest, FlushResult, GenesisRequest, GenesisResult, HandleRefundMode,
HandleRefundRequest, HandleRefundResult, InsufficientBalanceHandling, MessageTopicsRequest,
Expand Down Expand Up @@ -1887,7 +1887,7 @@ pub trait StateProvider: Send + Sync + Sized {
}

/// Gets an entry point value.
fn entry_point(&self, request: EntryPointsRequest) -> EntryPointResult {
fn entry_point(&self, request: EntryPointRequest) -> EntryPointResult {
let state_root_hash = request.state_hash();
let contract_hash = request.contract_hash();
let entry_point_name = request.entry_point_name();
Expand Down Expand Up @@ -1966,8 +1966,8 @@ pub trait StateProvider: Send + Sync + Sized {
}

/// Gets an entry point value.
fn entry_point_exists(&self, request: EntryPointsRequest) -> EntryPointExistsResult {
match self.entry_point(request) {
fn entry_point_exists(&self, request: EntryPointExistsRequest) -> EntryPointExistsResult {
match self.entry_point(request.into()) {
EntryPointResult::RootNotFound => EntryPointExistsResult::RootNotFound,
EntryPointResult::ValueNotFound(msg) => EntryPointExistsResult::ValueNotFound(msg),
EntryPointResult::Success { .. } => EntryPointExistsResult::Success,
Expand Down

0 comments on commit 983beba

Please sign in to comment.