srml-contracts: Avoid unnecessary lookups during call context initialization (#3121)

* srml-contracts: Remove lookups during CallContext initialization.

* Bump node runtime impl_version.
This commit is contained in:
Jim Posen
2019-07-16 22:30:45 +02:00
committed by Sergei Pepyakin
parent 8e09338e27
commit eea9437805
3 changed files with 19 additions and 9 deletions
+2 -2
View File
@@ -69,8 +69,8 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
// and set impl_version to equal spec_version. If only runtime // and set impl_version to equal spec_version. If only runtime
// implementation changes and behavior does not, then leave spec_version as // implementation changes and behavior does not, then leave spec_version as
// is and increment impl_version. // is and increment impl_version.
spec_version: 112, spec_version: 113,
impl_version: 112, impl_version: 113,
apis: RUNTIME_API_VERSIONS, apis: RUNTIME_API_VERSIONS,
}; };
+7 -3
View File
@@ -174,15 +174,19 @@ Assuming marshaled size of a balance value is of the constant size we can neglec
## Initialization ## Initialization
Before a call or create can be performed the execution context must be initialized. This involves Before a call or create can be performed the execution context must be initialized.
two calls:
For the first call or instantiation in the handling of an extrinsic, this involves two calls:
1. `<timestamp::Module<T>>::now()` 1. `<timestamp::Module<T>>::now()`
2. `<system::Module<T>>::block_number()` 2. `<system::Module<T>>::block_number()`
the complexity of initialization depends on the complexity of these functions. In the current The complexity of initialization depends on the complexity of these functions. In the current
implementation they just involve a DB read. implementation they just involve a DB read.
For subsequent calls and instantiations during contract execution, the initialization requires no
expensive operations.
## Call ## Call
This function receives input data for the contract execution. The execution consists of the following steps: This function receives input data for the contract execution. The execution consists of the following steps:
+10 -4
View File
@@ -264,6 +264,8 @@ pub struct ExecutionContext<'a, T: Trait + 'a, V, L> {
pub config: &'a Config<T>, pub config: &'a Config<T>,
pub vm: &'a V, pub vm: &'a V,
pub loader: &'a L, pub loader: &'a L,
pub timestamp: T::Moment,
pub block_number: T::BlockNumber,
} }
impl<'a, T, E, V, L> ExecutionContext<'a, T, V, L> impl<'a, T, E, V, L> ExecutionContext<'a, T, V, L>
@@ -287,6 +289,8 @@ where
config: &cfg, config: &cfg,
vm: &vm, vm: &vm,
loader: &loader, loader: &loader,
timestamp: <timestamp::Module<T>>::now(),
block_number: <system::Module<T>>::block_number(),
} }
} }
@@ -303,6 +307,8 @@ where
config: self.config, config: self.config,
vm: self.vm, vm: self.vm,
loader: self.loader, loader: self.loader,
timestamp: self.timestamp.clone(),
block_number: self.block_number.clone(),
} }
} }
@@ -368,8 +374,8 @@ where
ctx: &mut nested, ctx: &mut nested,
caller: self.self_account.clone(), caller: self.self_account.clone(),
value_transferred: value, value_transferred: value,
timestamp: <timestamp::Module<T>>::now(), timestamp: self.timestamp.clone(),
block_number: <system::Module<T>>::block_number(), block_number: self.block_number.clone(),
}, },
input_data, input_data,
empty_output_buf, empty_output_buf,
@@ -439,8 +445,8 @@ where
ctx: &mut nested, ctx: &mut nested,
caller: self.self_account.clone(), caller: self.self_account.clone(),
value_transferred: endowment, value_transferred: endowment,
timestamp: <timestamp::Module<T>>::now(), timestamp: self.timestamp.clone(),
block_number: <system::Module<T>>::block_number(), block_number: self.block_number.clone(),
}, },
input_data, input_data,
EmptyOutputBuf::new(), EmptyOutputBuf::new(),