Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
Squashed 'bridges/' changes from 78e3357c0..5b5627e90
Browse files Browse the repository at this point in the history
5b5627e90 Rewards refund for relaying BridgeHubRococo/BridgeHubWococo (#1894)

git-subtree-dir: bridges
git-subtree-split: 5b5627e9081640ed5691eb2891182843563fb99a
  • Loading branch information
bkontur committed Feb 21, 2023
1 parent d6149f2 commit 1afb13d
Show file tree
Hide file tree
Showing 8 changed files with 112 additions and 16 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions primitives/chain-bridge-hub-cumulus/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ license = "GPL-3.0-or-later WITH Classpath-exception-2.0"

bp-polkadot-core = { path = "../../primitives/polkadot-core", default-features = false }
bp-messages = { path = "../../primitives/messages", default-features = false }
bp-runtime = { path = "../../primitives/runtime", default-features = false }

# Substrate Based Dependencies

Expand All @@ -27,6 +28,7 @@ default = ["std"]
std = [
"bp-polkadot-core/std",
"bp-messages/std",
"bp-runtime/std",
"frame-system/std",
"frame-support/std",
"sp-api/std",
Expand Down
73 changes: 71 additions & 2 deletions primitives/chain-bridge-hub-cumulus/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
use bp_messages::*;
pub use bp_polkadot_core::{
AccountId, AccountInfoStorageMapKeyProvider, AccountPublic, Balance, BlockNumber, Hash, Hasher,
Hashing, Header, Index, Nonce, Perbill, PolkadotSignedExtension, Signature, SignedBlock,
UncheckedExtrinsic, EXTRA_STORAGE_PROOF_SIZE, TX_EXTRA_BYTES,
Hashing, Header, Index, Nonce, Perbill, Signature, SignedBlock, UncheckedExtrinsic,
EXTRA_STORAGE_PROOF_SIZE, TX_EXTRA_BYTES,
};
use frame_support::{
dispatch::DispatchClass,
Expand Down Expand Up @@ -124,3 +124,72 @@ pub const MAX_UNREWARDED_RELAYERS_IN_CONFIRMATION_TX: MessageNonce = 1024;

/// Maximal number of unconfirmed messages at inbound lane for Cumulus-based parachains.
pub const MAX_UNCONFIRMED_MESSAGES_IN_CONFIRMATION_TX: MessageNonce = 4096;

/// Module with rewarding bridge signed extension support
pub mod rewarding_bridge_signed_extension {
use super::*;
use bp_polkadot_core::PolkadotLike;
use bp_runtime::extensions::*;

type RewardingBridgeSignedExtra = (
CheckNonZeroSender,
CheckSpecVersion,
CheckTxVersion,
CheckGenesis<PolkadotLike>,
CheckEra<PolkadotLike>,
CheckNonce<Nonce>,
CheckWeight,
ChargeTransactionPayment<PolkadotLike>,
BridgeRejectObsoleteHeadersAndMessages,
RefundBridgedParachainMessagesSchema,
);

/// The signed extension used by Cumulus and Cumulus-like parachain with bridging and rewarding.
pub type RewardingBridgeSignedExtension = GenericSignedExtension<RewardingBridgeSignedExtra>;

pub fn from_params(
spec_version: u32,
transaction_version: u32,
era: bp_runtime::TransactionEraOf<PolkadotLike>,
genesis_hash: Hash,
nonce: Nonce,
tip: Balance,
) -> RewardingBridgeSignedExtension {
GenericSignedExtension::<RewardingBridgeSignedExtra>::new(
(
(), // non-zero sender
(), // spec version
(), // tx version
(), // genesis
era.frame_era(), // era
nonce.into(), // nonce (compact encoding)
(), // Check weight
tip.into(), // transaction payment / tip (compact encoding)
(), // bridge reject obsolete headers and msgs
(), // bridge register reward to relayer for message passing
),
Some((
(),
spec_version,
transaction_version,
genesis_hash,
era.signed_payload(genesis_hash),
(),
(),
(),
(),
(),
)),
)
}

/// Return signer nonce, used to craft transaction.
pub fn nonce(sign_ext: &RewardingBridgeSignedExtension) -> Nonce {
sign_ext.payload.5.into()
}

/// Return transaction tip.
pub fn tip(sign_ext: &RewardingBridgeSignedExtension) -> Balance {
sign_ext.payload.7.into()
}
}
9 changes: 9 additions & 0 deletions primitives/runtime/src/extensions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,15 @@ pub type ChargeTransactionPayment<C> = GenericSignedExtensionSchema<Compact<Bala
/// The `SignedExtensionSchema` for `BridgeRejectObsoleteHeadersAndMessages`.
pub type BridgeRejectObsoleteHeadersAndMessages = GenericSignedExtensionSchema<(), ()>;

/// The `SignedExtensionSchema` for `RefundBridgedParachainMessages`.
/// This schema is dedicated for `RefundBridgedParachainMessages` signed extension as
/// wildcard/placeholder, which relies on the scale encoding for `()` or `((), ())`, or `((), (),
/// ())` is the same. So runtime can contains any kind of tuple:
/// `(BridgeRefundBridgeHubRococoMessages)`
/// `(BridgeRefundBridgeHubRococoMessages, BridgeRefundBridgeHubWococoMessages)`
/// `(BridgeRefundParachainMessages1, ..., BridgeRefundParachainMessagesN)`
pub type RefundBridgedParachainMessagesSchema = GenericSignedExtensionSchema<(), ()>;

#[impl_for_tuples(1, 12)]
impl SignedExtensionSchema for Tuple {
for_tuples!( type Payload = ( #( Tuple::Payload ),* ); );
Expand Down
13 changes: 9 additions & 4 deletions relays/client-bridge-hub-rococo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
//! Types used to connect to the BridgeHub-Rococo-Substrate parachain.

use bp_bridge_hub_rococo::AVERAGE_BLOCK_INTERVAL;
use bp_bridge_hub_wococo::PolkadotSignedExtension;
use bp_messages::MessageNonce;
use codec::Encode;
use relay_substrate_client::{
Expand Down Expand Up @@ -72,7 +71,7 @@ impl ChainWithTransactions for BridgeHubRococo {
) -> Result<Self::SignedTransaction, SubstrateError> {
let raw_payload = SignedPayload::new(
unsigned.call,
bp_bridge_hub_rococo::SignedExtension::from_params(
runtime::rewarding_bridge_signed_extension::from_params(
param.spec_version,
param.transaction_version,
unsigned.era,
Expand All @@ -86,7 +85,7 @@ impl ChainWithTransactions for BridgeHubRococo {
let signer: sp_runtime::MultiSigner = param.signer.public().into();
let (call, extra, _) = raw_payload.deconstruct();

Ok(bp_bridge_hub_rococo::UncheckedExtrinsic::new_signed(
Ok(runtime::UncheckedExtrinsic::new_signed(
call,
signer.into_account().into(),
signature.into(),
Expand All @@ -109,7 +108,13 @@ impl ChainWithTransactions for BridgeHubRococo {

fn parse_transaction(tx: Self::SignedTransaction) -> Option<UnsignedTransaction<Self>> {
let extra = &tx.signature.as_ref()?.2;
Some(UnsignedTransaction::new(tx.function, extra.nonce()).tip(extra.tip()))
Some(
UnsignedTransaction::new(
tx.function,
runtime::rewarding_bridge_signed_extension::nonce(extra),
)
.tip(runtime::rewarding_bridge_signed_extension::tip(extra)),
)
}
}

Expand Down
9 changes: 5 additions & 4 deletions relays/client-bridge-hub-rococo/src/runtime_wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,22 @@
// 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/>.

// TODO: join with primitives do we need this here or move to the primitives?

//! Types that are specific to the BridgeHubRococo runtime.

use codec::{Decode, Encode};
use scale_info::TypeInfo;

use bp_bridge_hub_rococo::SignedExtension;
pub use bp_bridge_hub_rococo::rewarding_bridge_signed_extension;
pub use bp_header_chain::BridgeGrandpaCallOf;
pub use bp_parachains::BridgeParachainCall;
pub use bridge_runtime_common::messages::BridgeMessagesCallOf;
pub use relay_substrate_client::calls::{SystemCall, UtilityCall};

/// Unchecked BridgeHubRococo extrinsic.
pub type UncheckedExtrinsic = bp_bridge_hub_rococo::UncheckedExtrinsic<Call, SignedExtension>;
pub type UncheckedExtrinsic = bp_bridge_hub_rococo::UncheckedExtrinsic<
Call,
rewarding_bridge_signed_extension::RewardingBridgeSignedExtension,
>;

// The indirect pallet call used to sync `Wococo` GRANDPA finality to `BHRococo`.
pub type BridgeWococoGrandpaCall = BridgeGrandpaCallOf<bp_wococo::Wococo>;
Expand Down
14 changes: 10 additions & 4 deletions relays/client-bridge-hub-wococo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

//! Types used to connect to the BridgeHub-Wococo-Substrate parachain.

use bp_bridge_hub_wococo::{PolkadotSignedExtension, AVERAGE_BLOCK_INTERVAL};
use bp_bridge_hub_wococo::AVERAGE_BLOCK_INTERVAL;
use bp_messages::MessageNonce;
use codec::Encode;
use relay_substrate_client::{
Expand Down Expand Up @@ -71,7 +71,7 @@ impl ChainWithTransactions for BridgeHubWococo {
) -> Result<Self::SignedTransaction, SubstrateError> {
let raw_payload = SignedPayload::new(
unsigned.call,
bp_bridge_hub_wococo::SignedExtension::from_params(
runtime::rewarding_bridge_signed_extension::from_params(
param.spec_version,
param.transaction_version,
unsigned.era,
Expand All @@ -85,7 +85,7 @@ impl ChainWithTransactions for BridgeHubWococo {
let signer: sp_runtime::MultiSigner = param.signer.public().into();
let (call, extra, _) = raw_payload.deconstruct();

Ok(bp_bridge_hub_wococo::UncheckedExtrinsic::new_signed(
Ok(runtime::UncheckedExtrinsic::new_signed(
call,
signer.into_account().into(),
signature.into(),
Expand All @@ -108,7 +108,13 @@ impl ChainWithTransactions for BridgeHubWococo {

fn parse_transaction(tx: Self::SignedTransaction) -> Option<UnsignedTransaction<Self>> {
let extra = &tx.signature.as_ref()?.2;
Some(UnsignedTransaction::new(tx.function, extra.nonce()).tip(extra.tip()))
Some(
UnsignedTransaction::new(
tx.function,
runtime::rewarding_bridge_signed_extension::nonce(extra),
)
.tip(runtime::rewarding_bridge_signed_extension::tip(extra)),
)
}
}

Expand Down
7 changes: 5 additions & 2 deletions relays/client-bridge-hub-wococo/src/runtime_wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,17 @@
use codec::{Decode, Encode};
use scale_info::TypeInfo;

use bp_bridge_hub_wococo::SignedExtension;
pub use bp_bridge_hub_wococo::rewarding_bridge_signed_extension;
pub use bp_header_chain::BridgeGrandpaCallOf;
pub use bp_parachains::BridgeParachainCall;
pub use bridge_runtime_common::messages::BridgeMessagesCallOf;
pub use relay_substrate_client::calls::{SystemCall, UtilityCall};

/// Unchecked BridgeHubWococo extrinsic.
pub type UncheckedExtrinsic = bp_bridge_hub_wococo::UncheckedExtrinsic<Call, SignedExtension>;
pub type UncheckedExtrinsic = bp_bridge_hub_wococo::UncheckedExtrinsic<
Call,
rewarding_bridge_signed_extension::RewardingBridgeSignedExtension,
>;

// The indirect pallet call used to sync `Rococo` GRANDPA finality to `BHWococo`.
pub type BridgeRococoGrandpaCall = BridgeGrandpaCallOf<bp_rococo::Rococo>;
Expand Down

0 comments on commit 1afb13d

Please sign in to comment.