Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewards refund for relaying BridgeHubRococo/BridgeHubWococo #1894

Merged
merged 10 commits into from
Feb 21, 2023
2 changes: 2 additions & 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 relays/client-bridge-hub-rococo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ bp-bridge-hub-wococo = { path = "../../primitives/chain-bridge-hub-wococo" }
bp-header-chain = { path = "../../primitives/header-chain" }
bp-messages = { path = "../../primitives/messages" }
bp-parachains = { path = "../../primitives/parachains" }
bp-polkadot-core = { path = "../../primitives/polkadot-core" }
bp-runtime = { path = "../../primitives/runtime" }
bp-wococo = { path = "../../primitives/chain-wococo" }

bridge-runtime-common = { path = "../../bin/runtime-common" }
Expand Down
6 changes: 3 additions & 3 deletions relays/client-bridge-hub-rococo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ impl ChainWithTransactions for BridgeHubRococo {
) -> Result<Self::SignedTransaction, SubstrateError> {
let raw_payload = SignedPayload::new(
unsigned.call,
bp_bridge_hub_rococo::rewarding_bridge_signed_extension::from_params(
runtime::rewarding_bridge_signed_extension::from_params(
param.spec_version,
param.transaction_version,
unsigned.era,
Expand Down Expand Up @@ -111,9 +111,9 @@ impl ChainWithTransactions for BridgeHubRococo {
Some(
UnsignedTransaction::new(
tx.function,
bp_bridge_hub_rococo::rewarding_bridge_signed_extension::nonce(extra),
runtime::rewarding_bridge_signed_extension::nonce(extra),
)
.tip(bp_bridge_hub_rococo::rewarding_bridge_signed_extension::tip(extra)),
.tip(runtime::rewarding_bridge_signed_extension::tip(extra)),
)
}
}
Expand Down
74 changes: 73 additions & 1 deletion relays/client-bridge-hub-rococo/src/runtime_wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub use relay_substrate_client::calls::{SystemCall, UtilityCall};
/// Unchecked BridgeHubRococo extrinsic.
pub type UncheckedExtrinsic = bp_bridge_hub_rococo::UncheckedExtrinsic<
Call,
bp_bridge_hub_rococo::rewarding_bridge_signed_extension::RewardingBridgeSignedExtension,
rewarding_bridge_signed_extension::RewardingBridgeSignedExtension,
>;

// The indirect pallet call used to sync `Wococo` GRANDPA finality to `BHRococo`.
Expand Down Expand Up @@ -69,3 +69,75 @@ impl From<UtilityCall<Call>> for Call {
Call::Utility(call)
}
}

// TODO: remove this and use common from cumulus-like once fixed (/~https://github.com/paritytech/parity-bridges-common/issues/1598)
/// Module with rewarding bridge signed extension support
pub mod rewarding_bridge_signed_extension {
use bp_polkadot_core::{Balance, Hash, Nonce, PolkadotLike};
use bp_runtime::extensions::*;

type RewardingBridgeSignedExtra = (
CheckNonZeroSender,
CheckSpecVersion,
CheckTxVersion,
CheckGenesis<PolkadotLike>,
CheckEra<PolkadotLike>,
CheckNonce<Nonce>,
CheckWeight,
ChargeTransactionPayment<PolkadotLike>,
BridgeRejectObsoleteHeadersAndMessages,
RefundBridgedParachainMessages,
RefundBridgedParachainMessages,
serban300 marked this conversation as resolved.
Show resolved Hide resolved
);

/// 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-hub-rococo instance1 register reward for message passing
(), // bridge-hub-rococo instance2 register reward 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()
}
}
1 change: 1 addition & 0 deletions relays/client-bridge-hub-wococo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ bp-bridge-hub-wococo = { path = "../../primitives/chain-bridge-hub-wococo" }
bp-header-chain = { path = "../../primitives/header-chain" }
bp-messages = { path = "../../primitives/messages" }
bp-parachains = { path = "../../primitives/parachains" }
bp-polkadot-core = { path = "../../primitives/polkadot-core" }
bp-rococo = { path = "../../primitives/chain-rococo" }
bp-runtime = { path = "../../primitives/runtime" }

Expand Down
6 changes: 3 additions & 3 deletions relays/client-bridge-hub-wococo/src/lib.rs
Original file line number Diff line number Diff line change
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::rewarding_bridge_signed_extension::from_params(
runtime::rewarding_bridge_signed_extension::from_params(
param.spec_version,
param.transaction_version,
unsigned.era,
Expand Down Expand Up @@ -111,9 +111,9 @@ impl ChainWithTransactions for BridgeHubWococo {
Some(
UnsignedTransaction::new(
tx.function,
bp_bridge_hub_wococo::rewarding_bridge_signed_extension::nonce(extra),
runtime::rewarding_bridge_signed_extension::nonce(extra),
)
.tip(bp_bridge_hub_wococo::rewarding_bridge_signed_extension::tip(extra)),
.tip(runtime::rewarding_bridge_signed_extension::tip(extra)),
)
}
}
Expand Down
74 changes: 73 additions & 1 deletion relays/client-bridge-hub-wococo/src/runtime_wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub use relay_substrate_client::calls::{SystemCall, UtilityCall};
/// Unchecked BridgeHubWococo extrinsic.
pub type UncheckedExtrinsic = bp_bridge_hub_wococo::UncheckedExtrinsic<
Call,
bp_bridge_hub_wococo::rewarding_bridge_signed_extension::RewardingBridgeSignedExtension,
rewarding_bridge_signed_extension::RewardingBridgeSignedExtension,
>;

// The indirect pallet call used to sync `Rococo` GRANDPA finality to `BHWococo`.
Expand Down Expand Up @@ -70,6 +70,78 @@ impl From<UtilityCall<Call>> for Call {
}
}

// TODO: remove this and use common from cumulus-like once fixed (/~https://github.com/paritytech/parity-bridges-common/issues/1598)
/// Module with rewarding bridge signed extension support
pub mod rewarding_bridge_signed_extension {
use bp_polkadot_core::{Balance, Hash, Nonce, PolkadotLike};
use bp_runtime::extensions::*;

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

/// 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-hub-rococo instance1 register reward for message passing
(), // bridge-hub-rococo instance2 register reward 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()
}
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down