Allow modules to indicate full block. (#1687)

* Add transaction skipping.

* Update runtime.
This commit is contained in:
Tomasz Drwięga
2019-02-08 15:35:48 +01:00
committed by Gav Wood
parent 091e222d99
commit 83f9e1e720
7 changed files with 43 additions and 9 deletions
+3 -1
View File
@@ -16,6 +16,7 @@
use crate::{GasSpent, Module, Trait};
use balances;
use runtime_primitives::BLOCK_FULL;
use runtime_primitives::traits::{As, CheckedMul, CheckedSub, Zero};
use runtime_support::StorageValue;
@@ -206,7 +207,8 @@ pub fn buy_gas<T: Trait>(
// This cannot underflow since `gas_spent` is never greater than `block_gas_limit`.
let gas_available = <Module<T>>::block_gas_limit() - <Module<T>>::gas_spent();
if gas_limit > gas_available {
return Err("block gas limit is reached");
// gas limit reached, revert the transaction and retry again in the future
return Err(BLOCK_FULL);
}
// Buy the specified amount of gas.
+4 -1
View File
@@ -207,7 +207,10 @@ impl<
let r = f.dispatch(s.into());
<system::Module<System>>::note_applied_extrinsic(&r, encoded_len as u32);
r.map(|_| internal::ApplyOutcome::Success).or_else(|e| Ok(internal::ApplyOutcome::Fail(e)))
r.map(|_| internal::ApplyOutcome::Success).or_else(|e| match e {
primitives::BLOCK_FULL => Err(internal::ApplyError::FullBlock),
e => Ok(internal::ApplyOutcome::Fail(e))
})
}
fn final_checks(header: &System::Header) {
+1 -1
View File
@@ -56,8 +56,8 @@ mod double_map;
pub use self::storage::{StorageVec, StorageList, StorageValue, StorageMap};
pub use self::hashable::Hashable;
pub use self::dispatch::{Parameter, Dispatchable, Callable, IsSubType};
pub use self::double_map::StorageDoubleMap;
pub use runtime_io::print;
pub use double_map::StorageDoubleMap;
#[doc(inline)]
pub use srml_support_procedural::decl_storage;