Skip to content

Commit

Permalink
Introduce client-legacy for handling version discrepancies between …
Browse files Browse the repository at this point in the history
…clients and runtime-codegen
  • Loading branch information
bkontur committed Jun 26, 2024
1 parent 8fc95e8 commit 5b3637e
Show file tree
Hide file tree
Showing 5 changed files with 116 additions and 0 deletions.
10 changes: 10 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ members = [
"relay-clients/client-bridge-hub-rococo",
"relay-clients/client-bridge-hub-westend",
"relay-clients/client-kusama",
"relay-clients/client-legacy",
"relay-clients/client-polkadot",
"relay-clients/client-polkadot-bulletin",
"relay-clients/client-rococo",
Expand Down
20 changes: 20 additions & 0 deletions relay-clients/client-legacy/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[package]
name = "relay-legacy-client"
version = "0.1.0"
authors.workspace = true
edition.workspace = true
license = "GPL-3.0-or-later WITH Classpath-exception-2.0"
repository.workspace = true

[lints]
workspace = true

[dependencies]
codec = { package = "parity-scale-codec", version = "3.6.1", features = ["derive"] }
scale-info = { version = "2.11.3", default-features = false, features = ["derive"] }

# Bridge dependencies
bp-messages = { git = "https://github.com/paritytech/polkadot-sdk", branch = "bko-bridges-v2-compact-proofs" }

# Substrate Dependencies
sp-runtime = { git = "https://github.com/paritytech/polkadot-sdk", branch = "bko-bridges-v2-compact-proofs" }
77 changes: 77 additions & 0 deletions relay-clients/client-legacy/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// Copyright 2019-2021 Parity Technologies (UK) Ltd.
// This file is part of Parity Bridges Common.

// Parity Bridges Common is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// Parity Bridges Common is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// 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/>.

//! Types used to ensure compatibility with older versions of various types from `polkadot-sdk`.
//!
//! E.g. When a runtime is changed and uses different or newer types for the same struct, we can add
//! the older versions here and use them with `tools/runtime-codegen` for `TypeSubstitute`.
/// Types compatible with versions before the "compact proofs" feature.
pub mod non_compact_proofs {
pub mod bridge_runtime_common {
pub mod messages {
use bp_messages::{LaneId, MessageNonce};
use codec::{Decode, Encode};
use scale_info::TypeInfo;
use sp_runtime::RuntimeDebug;

/// Raw storage proof type (just raw trie nodes).
pub type RawStorageProof = Vec<Vec<u8>>;

pub mod source {
use super::*;

/// Messages delivery proof from bridged chain:
///
/// - hash of finalized header;
/// - storage proof of inbound lane state;
/// - lane id.
#[derive(Clone, Decode, Encode, Eq, PartialEq, RuntimeDebug, TypeInfo)]
pub struct FromBridgedChainMessagesDeliveryProof<BridgedHeaderHash> {
/// Hash of the bridge header the proof is for.
pub bridged_header_hash: BridgedHeaderHash,
/// Storage trie proof generated for [`Self::bridged_header_hash`].
pub storage_proof: RawStorageProof,
/// Lane id of which messages were delivered and the proof is for.
pub lane: LaneId,
}
}
pub mod target {
use super::*;

/// Messages proof from bridged chain:
///
/// - hash of finalized header;
/// - storage proof of messages and (optionally) outbound lane state;
/// - lane id;
/// - nonces (inclusive range) of messages which are included in this proof.
#[derive(Clone, Decode, Encode, Eq, PartialEq, RuntimeDebug, TypeInfo)]
pub struct FromBridgedChainMessagesProof<BridgedHeaderHash> {
/// Hash of the finalized bridged header the proof is for.
pub bridged_header_hash: BridgedHeaderHash,
/// A storage trie proof of messages being delivered.
pub storage_proof: RawStorageProof,
/// Messages in this proof are sent over this lane.
pub lane: LaneId,
/// Nonce of the first message being delivered.
pub nonces_start: MessageNonce,
/// Nonce of the last message being delivered.
pub nonces_end: MessageNonce,
}
}
}
}
}
8 changes: 8 additions & 0 deletions tools/runtime-codegen/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,14 @@ fn main() -> color_eyre::Result<()> {
TypeSubstitute::simple("bp_header_chain::InitializationData"),
TypeSubstitute::simple("bp_polkadot_core::parachains::ParaId"),
TypeSubstitute::simple("bp_polkadot_core::parachains::ParaHeadsProof"),
TypeSubstitute::custom(
"bridge_runtime_common::messages::target::FromBridgedChainMessagesProof",
"::relay_legacy_client::non_compact_proofs::bridge_runtime_common::messages::target::FromBridgedChainMessagesProof",
),
TypeSubstitute::custom(
"bridge_runtime_common::messages::source::FromBridgedChainMessagesDeliveryProof",
"::relay_legacy_client::non_compact_proofs::bridge_runtime_common::messages::source::FromBridgedChainMessagesDeliveryProof",
),
TypeSubstitute::simple(
"bp_messages::target_chain::FromBridgedChainMessagesProof",
),
Expand Down

0 comments on commit 5b3637e

Please sign in to comment.