mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 23:21:02 +00:00
Reject too large transactions (#558)
* Fix is_valid condition when removing transactions from the pool. * Less verbosity. * Reject too large transctions from the pool. * Bring back the warning level. * Fix link.
This commit is contained in:
@@ -770,12 +770,6 @@ impl<C> CreateProposal<C> where C: PolkadotApi {
|
|||||||
let result = self.transaction_pool.cull_and_get_pending(BlockId::hash(self.parent_hash), |pending_iterator| {
|
let result = self.transaction_pool.cull_and_get_pending(BlockId::hash(self.parent_hash), |pending_iterator| {
|
||||||
let mut pending_size = 0;
|
let mut pending_size = 0;
|
||||||
for pending in pending_iterator {
|
for pending in pending_iterator {
|
||||||
// skip and cull transactions which are too large.
|
|
||||||
if pending.encoded_size() > MAX_TRANSACTIONS_SIZE {
|
|
||||||
unqueue_invalid.push(pending.hash().clone());
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
if pending_size + pending.encoded_size() >= MAX_TRANSACTIONS_SIZE { break }
|
if pending_size + pending.encoded_size() >= MAX_TRANSACTIONS_SIZE { break }
|
||||||
|
|
||||||
match block_builder.push_extrinsic(pending.primitive_extrinsic()) {
|
match block_builder.push_extrinsic(pending.primitive_extrinsic()) {
|
||||||
|
|||||||
@@ -55,6 +55,11 @@ error_chain! {
|
|||||||
description("Unrecognised address in extrinsic"),
|
description("Unrecognised address in extrinsic"),
|
||||||
display("Unrecognised address in extrinsic: {}", who),
|
display("Unrecognised address in extrinsic: {}", who),
|
||||||
}
|
}
|
||||||
|
/// Extrinsic too large
|
||||||
|
TooLarge(got: usize, max: usize) {
|
||||||
|
description("Extrinsic too large"),
|
||||||
|
display("Extrinsic is too large ({} > {})", got, max),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -59,6 +59,11 @@ use substrate_runtime_primitives::traits::{Bounded, Checkable, Hash as HashT, Bl
|
|||||||
pub use extrinsic_pool::txpool::{Options, Status, LightStatus, VerifiedTransaction as VerifiedTransactionOps};
|
pub use extrinsic_pool::txpool::{Options, Status, LightStatus, VerifiedTransaction as VerifiedTransactionOps};
|
||||||
pub use error::{Error, ErrorKind, Result};
|
pub use error::{Error, ErrorKind, Result};
|
||||||
|
|
||||||
|
/// Maximal size of a single encoded extrinsic.
|
||||||
|
///
|
||||||
|
/// See also polkadot-consensus::MAX_TRANSACTIONS_SIZE
|
||||||
|
const MAX_TRANSACTION_SIZE: usize = 4 * 1024 * 1024;
|
||||||
|
|
||||||
/// Type alias for convenience.
|
/// Type alias for convenience.
|
||||||
pub type CheckedExtrinsic = <UncheckedExtrinsic as Checkable<fn(Address) -> std::result::Result<AccountId, &'static str>>>::Checked;
|
pub type CheckedExtrinsic = <UncheckedExtrinsic as Checkable<fn(Address) -> std::result::Result<AccountId, &'static str>>>::Checked;
|
||||||
|
|
||||||
@@ -279,14 +284,18 @@ impl<'a, A> txpool::Verifier<UncheckedExtrinsic> for Verifier<'a, A> where
|
|||||||
type Error = Error;
|
type Error = Error;
|
||||||
|
|
||||||
fn verify_transaction(&self, uxt: UncheckedExtrinsic) -> Result<Self::VerifiedTransaction> {
|
fn verify_transaction(&self, uxt: UncheckedExtrinsic) -> Result<Self::VerifiedTransaction> {
|
||||||
|
|
||||||
if !uxt.is_signed() {
|
if !uxt.is_signed() {
|
||||||
bail!(ErrorKind::IsInherent(uxt))
|
bail!(ErrorKind::IsInherent(uxt))
|
||||||
}
|
}
|
||||||
|
|
||||||
let encoded = uxt.encode();
|
let encoded = uxt.encode();
|
||||||
let (encoded_size, hash) = (encoded.len(), BlakeTwo256::hash(&encoded));
|
let encoded_size = encoded.len();
|
||||||
|
|
||||||
|
if encoded_size > MAX_TRANSACTION_SIZE {
|
||||||
|
bail!(ErrorKind::TooLarge(encoded_size, MAX_TRANSACTION_SIZE));
|
||||||
|
}
|
||||||
|
|
||||||
|
let hash = BlakeTwo256::hash(&encoded);
|
||||||
debug!(target: "transaction-pool", "Transaction submitted: {}", ::substrate_primitives::hexdisplay::HexDisplay::from(&encoded));
|
debug!(target: "transaction-pool", "Transaction submitted: {}", ::substrate_primitives::hexdisplay::HexDisplay::from(&encoded));
|
||||||
|
|
||||||
let inner = match uxt.clone().check_with(|a| self.lookup(a)) {
|
let inner = match uxt.clone().check_with(|a| self.lookup(a)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user