Transactions resubmitter (#1083)

* resubmit transactions: start

* resubmit transactions: continue

* enable resubmitter in deployments

* clippy

* spellcheck

* Update relays/client-substrate/src/chain.rs

Co-authored-by: Tomasz Drwięga <tomusdrw@users.noreply.github.com>

* fix compilation

* fix compilation

Co-authored-by: Tomasz Drwięga <tomusdrw@users.noreply.github.com>
This commit is contained in:
Svyatoslav Nikolsky
2021-09-09 10:26:10 +03:00
committed by Bastian Köcher
parent d59d442e93
commit 1df7076c4f
28 changed files with 682 additions and 151 deletions
+54 -6
View File
@@ -14,7 +14,8 @@
// You should have received a copy of the GNU General Public License
// along with Parity Bridges Common. If not, see <http://www.gnu.org/licenses/>.
use bp_runtime::Chain as ChainBase;
use bp_runtime::{Chain as ChainBase, TransactionEraOf};
use codec::{Codec, Encode};
use frame_support::{weights::WeightToFeePolynomial, Parameter};
use jsonrpsee_ws_client::{DeserializeOwned, Serialize};
use num_traits::{Bounded, CheckedSub, SaturatingAdd, Zero};
@@ -58,7 +59,7 @@ pub trait Chain: ChainBase + Clone {
/// Block type.
type SignedBlock: Member + Serialize + DeserializeOwned + BlockWithJustification<Self::Header>;
/// The aggregated `Call` type.
type Call: Dispatchable + Debug;
type Call: Clone + Dispatchable + Debug;
/// Balance of an account in native tokens.
///
/// The chain may support multiple tokens, but this particular type is for token that is used
@@ -96,14 +97,47 @@ pub trait ChainWithBalances: Chain {
fn account_info_storage_key(account_id: &Self::AccountId) -> StorageKey;
}
/// SCALE-encoded extrinsic.
pub type EncodedExtrinsic = Vec<u8>;
/// Block with justification.
pub trait BlockWithJustification<Header> {
/// Return block header.
fn header(&self) -> Header;
/// Return encoded block extrinsics.
fn extrinsics(&self) -> Vec<EncodedExtrinsic>;
/// Return block justification, if known.
fn justification(&self) -> Option<&EncodedJustification>;
}
/// Transaction before it is signed.
#[derive(Clone, Debug)]
pub struct UnsignedTransaction<C: Chain> {
/// Runtime call of this transaction.
pub call: C::Call,
/// Transaction nonce.
pub nonce: C::Index,
/// Tip included into transaction.
pub tip: C::Balance,
}
impl<C: Chain> UnsignedTransaction<C> {
/// Create new unsigned transaction with given call, nonce and zero tip.
pub fn new(call: C::Call, nonce: C::Index) -> Self {
Self {
call,
nonce,
tip: Zero::zero(),
}
}
/// Set transaction tip.
pub fn tip(mut self, tip: C::Balance) -> Self {
self.tip = tip;
self
}
}
/// Substrate-based chain transactions signing scheme.
pub trait TransactionSignScheme {
/// Chain that this scheme is to be used.
@@ -111,16 +145,26 @@ pub trait TransactionSignScheme {
/// Type of key pairs used to sign transactions.
type AccountKeyPair: Pair;
/// Signed transaction.
type SignedTransaction;
type SignedTransaction: Clone + Debug + Codec + Send + 'static;
/// Create transaction for given runtime call, signed by given account.
fn sign_transaction(
genesis_hash: <Self::Chain as ChainBase>::Hash,
signer: &Self::AccountKeyPair,
era: bp_runtime::TransactionEraOf<Self::Chain>,
signer_nonce: <Self::Chain as Chain>::Index,
call: <Self::Chain as Chain>::Call,
era: TransactionEraOf<Self::Chain>,
unsigned: UnsignedTransaction<Self::Chain>,
) -> Self::SignedTransaction;
/// Returns true if transaction is signed.
fn is_signed(tx: &Self::SignedTransaction) -> bool;
/// Returns true if transaction is signed by given signer.
fn is_signed_by(signer: &Self::AccountKeyPair, tx: &Self::SignedTransaction) -> bool;
/// Parse signed transaction into its unsigned part.
///
/// Returns `None` if signed transaction has unsupported format.
fn parse_transaction(tx: Self::SignedTransaction) -> Option<UnsignedTransaction<Self::Chain>>;
}
impl<Block: BlockT> BlockWithJustification<Block::Header> for SignedBlock<Block> {
@@ -128,6 +172,10 @@ impl<Block: BlockT> BlockWithJustification<Block::Header> for SignedBlock<Block>
self.block.header().clone()
}
fn extrinsics(&self) -> Vec<EncodedExtrinsic> {
self.block.extrinsics().iter().map(Encode::encode).collect()
}
fn justification(&self) -> Option<&EncodedJustification> {
self.justifications
.as_ref()