Have apply return Ok even if calls failed

This ensures fees are paid, and block building isn't interrupted, even for TXs
which error.
This commit is contained in:
Luke Parker
2025-02-26 07:51:28 -05:00
parent 0ac11defcc
commit ed9cbdd8e0

View File

@@ -478,8 +478,7 @@ mod substrate {
match call.dispatch(None.into()) { match call.dispatch(None.into()) {
Ok(res) => Ok(Ok(res)), Ok(res) => Ok(Ok(res)),
// Unsigned transactions should only be included if valid in all regards // Unsigned transactions should only be included if valid in all regards
// This isn't actually a "mandatory" but the intent is the same Err(_err) => Err(TransactionValidityError::Invalid(InvalidTransaction::Custom(0))),
Err(_err) => Err(TransactionValidityError::Invalid(InvalidTransaction::BadMandatory)),
} }
} }
Transaction::Signed { Transaction::Signed {
@@ -490,24 +489,28 @@ mod substrate {
// Start by paying the fee // Start by paying the fee
self.1.pay_fee(&signer, fee)?; self.1.pay_fee(&signer, fee)?;
Ok(frame_support::storage::transactional::with_storage_layer(|| { let _res = frame_support::storage::transactional::with_storage_layer(|| {
for call in calls.0 { for call in calls.0 {
let call = Context::RuntimeCall::from(call); let call = Context::RuntimeCall::from(call);
match call.dispatch(Some(signer).into()) { match call.dispatch(Some(signer).into()) {
Ok(_res) => {} Ok(_res) => {}
// Because this call errored, don't continue and revert all prior calls // Because this call errored, don't continue and revert all prior calls
Err(e) => Err(e)?, Err(e) => return Err(e),
} }
} }
// Since all calls succeeded, return Ok Ok(())
Ok(PostDispatchInfo { });
// `None` stands for the worst case, which is what we want
actual_weight: None, // We don't care if the individual calls succeeded or failed.
// Signed transactions always pay their fee // The transaction was valid for inclusion and the fee was paid.
// TODO: Do we want to handle this so we can not charge fees on removing genesis // Either the calls passed, as desired, or they failed and the storage was reverted.
// liquidity? Ok(Ok(PostDispatchInfo {
pays_fee: Pays::Yes, // `None` stands for the worst case, which is what we want
}) actual_weight: None,
// Signed transactions always pay their fee
// TODO: Do we want to handle this so we can not charge fees on removing genesis
// liquidity?
pays_fee: Pays::Yes,
})) }))
} }
} }