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
@@ -20,7 +20,7 @@
//
use std::{self, time, sync::Arc};
use log::{info, debug, trace};
use log::{info, debug};
use client::{
self, error, Client as SubstrateClient, CallExecutor,
@@ -190,10 +190,17 @@ impl<Block, C, A> Proposer<Block, C, A> where
{
use runtime_primitives::traits::BlakeTwo256;
/// If the block is full we will attempt to push at most
/// this number of transactions before quitting for real.
/// It allows us to increase block utilisation.
const MAX_SKIPPED_TRANSACTIONS: usize = 8;
let block = self.client.build_block(
&self.parent_id,
inherent_data,
|block_builder| {
let mut is_first = true;
let mut skipped = 0;
let mut unqueue_invalid = Vec::new();
let pending_iterator = self.transaction_pool.ready();
@@ -208,14 +215,27 @@ impl<Block, C, A> Proposer<Block, C, A> where
debug!("[{:?}] Pushed to the block.", pending.hash);
}
Err(error::Error(error::ErrorKind::ApplyExtrinsicFailed(ApplyError::FullBlock), _)) => {
debug!("Block is full, proceed with proposing.");
break;
if is_first {
debug!("[{:?}] Invalid transaction: FullBlock on empty block", pending.hash);
unqueue_invalid.push(pending.hash.clone());
} else if skipped < MAX_SKIPPED_TRANSACTIONS {
skipped += 1;
debug!(
"Block seems full, but will try {} more transactions before quitting.",
MAX_SKIPPED_TRANSACTIONS - skipped
);
} else {
debug!("Block is full, proceed with proposing.");
break;
}
}
Err(e) => {
trace!(target: "transaction-pool", "Invalid transaction: {}", e);
debug!("[{:?}] Invalid transaction: {}", pending.hash, e);
unqueue_invalid.push(pending.hash.clone());
}
}
is_first = false;
}
self.transaction_pool.remove_invalid(&unqueue_invalid);
+11 -2
View File
@@ -14,8 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
//! System manager: Handles all of the top-level stuff; executing block/transaction, setting code
//! and depositing logs.
//! Runtime Modules shared primitive types.
#![warn(missing_docs)]
@@ -44,6 +43,16 @@ pub mod traits;
pub mod generic;
pub mod transaction_validity;
/// Full block error message.
///
/// This allows modules to indicate that given transaction is potentially valid
/// in the future, but can't be executed in the current state.
/// Note this error should be returned early in the execution to prevent DoS,
/// cause the fees are not being paid if this error is returned.
///
/// Example: block gas limit is reached (the transaction can be retried in the next block though).
pub const BLOCK_FULL: &str = "block size limit is reached";
/// Justification type.
pub type Justification = Vec<u8>;