Skip to content

Commit

Permalink
style: Move ApplyState over to node-runtime (#10424)
Browse files Browse the repository at this point in the history
This type does not appear to be particularly useful outside of
`node-runtime` (`node-runtime` is its only consumer, so the only good
reason to construct it is for `node-runtime` to use) and it introduces a
dependency edge from near-primitives to near-vm-runner which we might as
well avoid.
  • Loading branch information
nagisa authored Jan 15, 2024
1 parent 0e94443 commit 32cf373
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 57 deletions.
45 changes: 0 additions & 45 deletions core/primitives/src/runtime/apply_state.rs

This file was deleted.

1 change: 0 additions & 1 deletion core/primitives/src/runtime/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
pub mod apply_state;
pub mod migration_data;
49 changes: 41 additions & 8 deletions runtime/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ use near_primitives::hash::CryptoHash;
use near_primitives::receipt::{
ActionReceipt, DataReceipt, DelayedReceiptIndices, Receipt, ReceiptEnum, ReceivedData,
};
pub use near_primitives::runtime::apply_state::ApplyState;
use near_primitives::runtime::migration_data::{MigrationData, MigrationFlags};
use near_primitives::sandbox::state_patch::SandboxStatePatch;
use near_primitives::state_record::StateRecord;
Expand All @@ -30,8 +29,8 @@ use near_primitives::transaction::{
};
use near_primitives::trie_key::TrieKey;
use near_primitives::types::{
validator_stake::ValidatorStake, AccountId, Balance, Compute, EpochInfoProvider, Gas,
RawStateChangesWithTrieKey, StateChangeCause, StateRoot,
validator_stake::ValidatorStake, AccountId, Balance, BlockHeight, Compute, EpochHeight,
EpochId, EpochInfoProvider, Gas, RawStateChangesWithTrieKey, StateChangeCause, StateRoot,
};
use near_primitives::utils::{
create_action_hash, create_receipt_id_from_receipt, create_receipt_id_from_transaction,
Expand All @@ -44,6 +43,7 @@ use near_store::{
};
use near_store::{set_access_key, set_code};
use near_vm_runner::logic::types::PromiseResult;
use near_vm_runner::logic::CompiledContractCache;
use near_vm_runner::logic::ReturnData;
pub use near_vm_runner::with_ext_cost_counter;
use near_vm_runner::ContractCode;
Expand All @@ -66,6 +66,42 @@ mod verifier;

const EXPECT_ACCOUNT_EXISTS: &str = "account exists, checked above";

#[derive(Debug)]
pub struct ApplyState {
/// Currently building block height.
pub block_height: BlockHeight,
/// Prev block hash
pub prev_block_hash: CryptoHash,
/// Current block hash
pub block_hash: CryptoHash,
/// Current epoch id
pub epoch_id: EpochId,
/// Current epoch height
pub epoch_height: EpochHeight,
/// Price for the gas.
pub gas_price: Balance,
/// The current block timestamp (number of non-leap-nanoseconds since January 1, 1970 0:00:00 UTC).
pub block_timestamp: u64,
/// Gas limit for a given chunk.
/// If None is given, assumes there is no gas limit.
pub gas_limit: Option<Gas>,
/// Current random seed (from current block vrf output).
pub random_seed: CryptoHash,
/// Current Protocol version when we apply the state transition
pub current_protocol_version: ProtocolVersion,
/// The Runtime config to use for the current transition.
pub config: Arc<RuntimeConfig>,
/// Cache for compiled contracts.
pub cache: Option<Box<dyn CompiledContractCache>>,
/// Whether the chunk being applied is new.
pub is_new_chunk: bool,
/// Data for migrations that may need to be applied at the start of an epoch when protocol
/// version changes
pub migration_data: Arc<MigrationData>,
/// Flags for migrations indicating whether they can be applied at this block
pub migration_flags: MigrationFlags,
}

/// Contains information to update validators accounts at the first block of a new epoch.
#[derive(Debug)]
pub struct ValidatorAccountsUpdate {
Expand Down Expand Up @@ -2610,18 +2646,15 @@ mod tests {

/// Interface provided for gas cost estimations.
pub mod estimator {
use super::Runtime;
use crate::{ApplyState, ApplyStats};
use near_primitives::errors::RuntimeError;
use near_primitives::receipt::Receipt;
use near_primitives::runtime::apply_state::ApplyState;
use near_primitives::transaction::ExecutionOutcomeWithId;
use near_primitives::types::validator_stake::ValidatorStake;
use near_primitives::types::EpochInfoProvider;
use near_store::TrieUpdate;

use crate::ApplyStats;

use super::Runtime;

pub fn apply_action_receipt(
state_update: &mut TrieUpdate,
apply_state: &ApplyState,
Expand Down
7 changes: 4 additions & 3 deletions runtime/runtime/src/state_viewer/mod.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
use crate::near_primitives::version::PROTOCOL_VERSION;
use crate::actions::execute_function_call;
use crate::ext::RuntimeExt;
use crate::receipt_manager::ReceiptManager;
use crate::{actions::execute_function_call, ext::RuntimeExt};
use crate::ApplyState;
use near_crypto::{KeyType, PublicKey};
use near_parameters::RuntimeConfigStore;
use near_primitives::account::{AccessKey, Account};
use near_primitives::borsh::BorshDeserialize;
use near_primitives::hash::CryptoHash;
use near_primitives::receipt::ActionReceipt;
use near_primitives::runtime::apply_state::ApplyState;
use near_primitives::runtime::migration_data::{MigrationData, MigrationFlags};
use near_primitives::transaction::FunctionCallAction;
use near_primitives::trie_key::trie_key_parsers;
use near_primitives::types::{AccountId, EpochInfoProvider, Gas};
use near_primitives::version::PROTOCOL_VERSION;
use near_primitives::views::{StateItem, ViewApplyState, ViewStateResult};
use near_primitives_core::config::ViewConfig;
use near_store::{get_access_key, get_account, get_code, TrieUpdate};
Expand Down

0 comments on commit 32cf373

Please sign in to comment.