mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 05:51:02 +00:00
Don't remove invalid transactions when skipping. (#5121)
* Don't remove invalid transactions when skipping. * Use a special kind of extrinsic instead of arbitrary limit. * Fix txpool tests. * Attempt to create more blocks. * Bump lock Co-authored-by: Gavin Wood <github@gavwood.com> Co-authored-by: Nikolay Volf <nikvolf@gmail.com>
This commit is contained in:
@@ -101,7 +101,25 @@ impl Transfer {
|
||||
pub fn into_signed_tx(self) -> Extrinsic {
|
||||
let signature = sp_keyring::AccountKeyring::from_public(&self.from)
|
||||
.expect("Creates keyring from public key.").sign(&self.encode()).into();
|
||||
Extrinsic::Transfer(self, signature)
|
||||
Extrinsic::Transfer {
|
||||
transfer: self,
|
||||
signature,
|
||||
exhaust_resources_when_not_first: false,
|
||||
}
|
||||
}
|
||||
|
||||
/// Convert into a signed extrinsic, which will only end up included in the block
|
||||
/// if it's the first transaction. Otherwise it will cause `ResourceExhaustion` error
|
||||
/// which should be considered as block being full.
|
||||
#[cfg(feature = "std")]
|
||||
pub fn into_resources_exhausting_tx(self) -> Extrinsic {
|
||||
let signature = sp_keyring::AccountKeyring::from_public(&self.from)
|
||||
.expect("Creates keyring from public key.").sign(&self.encode()).into();
|
||||
Extrinsic::Transfer {
|
||||
transfer: self,
|
||||
signature,
|
||||
exhaust_resources_when_not_first: true,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -109,7 +127,11 @@ impl Transfer {
|
||||
#[derive(Clone, PartialEq, Eq, Encode, Decode, RuntimeDebug)]
|
||||
pub enum Extrinsic {
|
||||
AuthoritiesChange(Vec<AuthorityId>),
|
||||
Transfer(Transfer, AccountSignature),
|
||||
Transfer {
|
||||
transfer: Transfer,
|
||||
signature: AccountSignature,
|
||||
exhaust_resources_when_not_first: bool,
|
||||
},
|
||||
IncludeData(Vec<u8>),
|
||||
StorageChange(Vec<u8>, Option<Vec<u8>>),
|
||||
ChangesTrieConfigUpdate(Option<ChangesTrieConfiguration>),
|
||||
@@ -130,9 +152,9 @@ impl BlindCheckable for Extrinsic {
|
||||
fn check(self, _signature: CheckSignature) -> Result<Self, TransactionValidityError> {
|
||||
match self {
|
||||
Extrinsic::AuthoritiesChange(new_auth) => Ok(Extrinsic::AuthoritiesChange(new_auth)),
|
||||
Extrinsic::Transfer(transfer, signature) => {
|
||||
Extrinsic::Transfer { transfer, signature, exhaust_resources_when_not_first } => {
|
||||
if sp_runtime::verify_encoded_lazy(&signature, &transfer, &transfer.from) {
|
||||
Ok(Extrinsic::Transfer(transfer, signature))
|
||||
Ok(Extrinsic::Transfer { transfer, signature, exhaust_resources_when_not_first })
|
||||
} else {
|
||||
Err(InvalidTransaction::BadProof.into())
|
||||
}
|
||||
@@ -165,7 +187,7 @@ impl ExtrinsicT for Extrinsic {
|
||||
impl Extrinsic {
|
||||
pub fn transfer(&self) -> &Transfer {
|
||||
match self {
|
||||
Extrinsic::Transfer(ref transfer, _) => transfer,
|
||||
Extrinsic::Transfer { ref transfer, .. } => transfer,
|
||||
_ => panic!("cannot convert to transfer ref"),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -192,7 +192,7 @@ pub fn validate_transaction(utx: Extrinsic) -> TransactionValidity {
|
||||
/// This doesn't attempt to validate anything regarding the block.
|
||||
pub fn execute_transaction(utx: Extrinsic) -> ApplyExtrinsicResult {
|
||||
let extrinsic_index: u32 = storage::unhashed::get(well_known_keys::EXTRINSIC_INDEX).unwrap();
|
||||
let result = execute_transaction_backend(&utx);
|
||||
let result = execute_transaction_backend(&utx, extrinsic_index);
|
||||
ExtrinsicData::insert(extrinsic_index, utx.encode());
|
||||
storage::unhashed::put(well_known_keys::EXTRINSIC_INDEX, &(extrinsic_index + 1));
|
||||
result
|
||||
@@ -237,7 +237,7 @@ pub fn finalize_block() -> Header {
|
||||
extrinsics_root,
|
||||
state_root: storage_root,
|
||||
parent_hash,
|
||||
digest: digest,
|
||||
digest,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -247,13 +247,18 @@ fn check_signature(utx: &Extrinsic) -> Result<(), TransactionValidityError> {
|
||||
utx.clone().check(CheckSignature::Yes).map_err(|_| InvalidTransaction::BadProof.into()).map(|_| ())
|
||||
}
|
||||
|
||||
fn execute_transaction_backend(utx: &Extrinsic) -> ApplyExtrinsicResult {
|
||||
fn execute_transaction_backend(utx: &Extrinsic, extrinsic_index: u32) -> ApplyExtrinsicResult {
|
||||
check_signature(utx)?;
|
||||
match utx {
|
||||
Extrinsic::Transfer(ref transfer, _) => execute_transfer_backend(transfer),
|
||||
Extrinsic::AuthoritiesChange(ref new_auth) => execute_new_authorities_backend(new_auth),
|
||||
Extrinsic::Transfer { exhaust_resources_when_not_first: true, .. } if extrinsic_index != 0 =>
|
||||
Err(InvalidTransaction::ExhaustsResources.into()),
|
||||
Extrinsic::Transfer { ref transfer, .. } =>
|
||||
execute_transfer_backend(transfer),
|
||||
Extrinsic::AuthoritiesChange(ref new_auth) =>
|
||||
execute_new_authorities_backend(new_auth),
|
||||
Extrinsic::IncludeData(_) => Ok(Ok(())),
|
||||
Extrinsic::StorageChange(key, value) => execute_storage_change(key, value.as_ref().map(|v| &**v)),
|
||||
Extrinsic::StorageChange(key, value) =>
|
||||
execute_storage_change(key, value.as_ref().map(|v| &**v)),
|
||||
Extrinsic::ChangesTrieConfigUpdate(ref new_config) =>
|
||||
execute_changes_trie_config_update(new_config.clone()),
|
||||
}
|
||||
|
||||
@@ -265,7 +265,7 @@ pub fn uxt(who: AccountKeyring, nonce: Index) -> Extrinsic {
|
||||
nonce,
|
||||
amount: 1,
|
||||
};
|
||||
let signature = transfer.using_encoded(|e| who.sign(e));
|
||||
Extrinsic::Transfer(transfer, signature.into())
|
||||
let signature = transfer.using_encoded(|e| who.sign(e)).into();
|
||||
Extrinsic::Transfer { transfer, signature, exhaust_resources_when_not_first: false }
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user