16
16
17
17
#![ cfg_attr( not( feature = "std" ) , no_std) ]
18
18
19
- use bp_messages:: * ;
20
19
pub use bp_polkadot_core:: {
21
20
AccountId , AccountInfoStorageMapKeyProvider , AccountPublic , Balance , BlockNumber , Hash , Hasher ,
22
21
Hashing , Header , Index , Nonce , Perbill , Signature , SignedBlock , UncheckedExtrinsic ,
23
22
EXTRA_STORAGE_PROOF_SIZE , TX_EXTRA_BYTES ,
24
23
} ;
24
+
25
+ use bp_messages:: * ;
26
+ use bp_runtime:: extensions:: {
27
+ BridgeRejectObsoleteHeadersAndMessages , ChargeTransactionPayment , CheckEra , CheckGenesis ,
28
+ CheckNonZeroSender , CheckNonce , CheckSpecVersion , CheckTxVersion , CheckWeight ,
29
+ GenericSignedExtension , RefundBridgedParachainMessagesSchema ,
30
+ } ;
25
31
use frame_support:: {
26
32
dispatch:: DispatchClass ,
27
33
parameter_types,
@@ -94,8 +100,6 @@ pub type AccountSigner = MultiSigner;
94
100
/// The address format for describing accounts.
95
101
pub type Address = MultiAddress < AccountId , ( ) > ;
96
102
97
- pub use bp_polkadot_core:: BridgeSignedExtension as SignedExtension ;
98
-
99
103
// Note about selecting values of two following constants:
100
104
//
101
105
// Normal transactions have limit of 75% of 1/2 second weight for Cumulus parachains. Let's keep
@@ -125,37 +129,54 @@ pub const MAX_UNREWARDED_RELAYERS_IN_CONFIRMATION_TX: MessageNonce = 1024;
125
129
/// Maximal number of unconfirmed messages at inbound lane for Cumulus-based parachains.
126
130
pub const MAX_UNCONFIRMED_MESSAGES_IN_CONFIRMATION_TX : MessageNonce = 4096 ;
127
131
128
- /// Module with rewarding bridge signed extension support
129
- pub mod rewarding_bridge_signed_extension {
130
- use super :: * ;
131
- use bp_polkadot_core:: PolkadotLike ;
132
- use bp_runtime:: extensions:: * ;
133
-
134
- type RewardingBridgeSignedExtra = (
135
- CheckNonZeroSender ,
136
- CheckSpecVersion ,
137
- CheckTxVersion ,
138
- CheckGenesis < PolkadotLike > ,
139
- CheckEra < PolkadotLike > ,
140
- CheckNonce < Nonce > ,
141
- CheckWeight ,
142
- ChargeTransactionPayment < PolkadotLike > ,
143
- BridgeRejectObsoleteHeadersAndMessages ,
144
- RefundBridgedParachainMessagesSchema ,
145
- ) ;
132
+ /// Extra signed extension data that is used by all bridge hubs.
133
+ pub type SignedExtra = (
134
+ CheckNonZeroSender ,
135
+ CheckSpecVersion ,
136
+ CheckTxVersion ,
137
+ CheckGenesis < Hash > ,
138
+ CheckEra < Hash > ,
139
+ CheckNonce < Index > ,
140
+ CheckWeight ,
141
+ ChargeTransactionPayment < Balance > ,
142
+ BridgeRejectObsoleteHeadersAndMessages ,
143
+ RefundBridgedParachainMessagesSchema ,
144
+ ) ;
145
+
146
+ /// Signed extension that is used by all bridge hubs.
147
+ pub type SignedExtension = GenericSignedExtension < SignedExtra > ;
148
+
149
+ /// Helper trait to define some extra methods on bridge hubs signed extension (and
150
+ /// overcome Rust limitations).
151
+ pub trait BridgeHubSignedExtension {
152
+ /// Create signed extension from its components.
153
+ fn from_params (
154
+ spec_version : u32 ,
155
+ transaction_version : u32 ,
156
+ era : bp_runtime:: TransactionEra < BlockNumber , Hash > ,
157
+ genesis_hash : Hash ,
158
+ nonce : Index ,
159
+ tip : Balance ,
160
+ ) -> Self ;
146
161
147
- /// The signed extension used by Cumulus and Cumulus-like parachain with bridging and rewarding.
148
- pub type RewardingBridgeSignedExtension = GenericSignedExtension < RewardingBridgeSignedExtra > ;
162
+ /// Return transaction nonce.
163
+ fn nonce ( & self ) -> Index ;
164
+
165
+ /// Return transaction tip.
166
+ fn tip ( & self ) -> Balance ;
167
+ }
149
168
150
- pub fn from_params (
169
+ impl BridgeHubSignedExtension for SignedExtension {
170
+ /// Create signed extension from its components.
171
+ fn from_params (
151
172
spec_version : u32 ,
152
173
transaction_version : u32 ,
153
- era : bp_runtime:: TransactionEraOf < PolkadotLike > ,
174
+ era : bp_runtime:: TransactionEra < BlockNumber , Hash > ,
154
175
genesis_hash : Hash ,
155
- nonce : Nonce ,
176
+ nonce : Index ,
156
177
tip : Balance ,
157
- ) -> RewardingBridgeSignedExtension {
158
- GenericSignedExtension :: < RewardingBridgeSignedExtra > :: new (
178
+ ) -> Self {
179
+ GenericSignedExtension :: new (
159
180
(
160
181
( ) , // non-zero sender
161
182
( ) , // spec version
@@ -166,7 +187,7 @@ pub mod rewarding_bridge_signed_extension {
166
187
( ) , // Check weight
167
188
tip. into ( ) , // transaction payment / tip (compact encoding)
168
189
( ) , // bridge reject obsolete headers and msgs
169
- ( ) , // bridge register reward to relayer for message passing
190
+ ( ) , // bridge reward to relayer for message passing
170
191
) ,
171
192
Some ( (
172
193
( ) ,
@@ -183,13 +204,13 @@ pub mod rewarding_bridge_signed_extension {
183
204
)
184
205
}
185
206
186
- /// Return signer nonce, used to craft transaction .
187
- pub fn nonce ( sign_ext : & RewardingBridgeSignedExtension ) -> Nonce {
188
- sign_ext . payload . 5 . into ( )
207
+ /// Return transaction nonce.
208
+ fn nonce ( & self ) -> Index {
209
+ self . payload . 5 . 0
189
210
}
190
211
191
212
/// Return transaction tip.
192
- pub fn tip ( sign_ext : & RewardingBridgeSignedExtension ) -> Balance {
193
- sign_ext . payload . 7 . into ( )
213
+ fn tip ( & self ) -> Balance {
214
+ self . payload . 7 . 0
194
215
}
195
216
}
0 commit comments