From 1e489dddce1f36824bfe00157f9972f7e7ad22ee Mon Sep 17 00:00:00 2001 From: Branislav Kontur Date: Mon, 17 Apr 2023 14:18:00 +0200 Subject: [PATCH 1/2] Updated REAMDE.md and BRIDGES.md (inspired by original https://github.com/paritytech/polkadot/blob/d22eb62fe40e55e15eb91d375f48cc540d83a47e/BRIDGES.md) --- BRIDGES.md | 88 +++++++++++++++++++++++ parachains/runtimes/bridge-hubs/README.md | 38 ---------- 2 files changed, 88 insertions(+), 38 deletions(-) create mode 100644 BRIDGES.md diff --git a/BRIDGES.md b/BRIDGES.md new file mode 100644 index 00000000000..a9fff624cdc --- /dev/null +++ b/BRIDGES.md @@ -0,0 +1,88 @@ +# Using Parity Bridges Common dependency (`git subtree`). + +In `./bridges` sub-directory you can find a `git subtree` imported version of: +[parity-bridges-common](https://github.com/paritytech/parity-bridges-common/) repository. + +(For regular Cumulus contributor 1. is relevant) \ +(For Cumulus maintainer 1. and 2. are relevant) \ +(For Bridges team 1. and 2. and 3. are relevant) + +# 1. How to fix broken Bridges code? + +To fix Bridges code simply create a commit in current (`Cumulus`) repo. Best if +the commit is isolated to changes in `./bridges` sub-directory, because it makes +it easier to import that change back to upstream repo. + +(Any changes to `bridges` subtree require Bridges team approve and they should manage backport to Bridges repo) + + +# 2. How to pull latest Bridges code to the `bridges` subtree +(in practice) +``` +cd + +# this will update new git branches from bridges repo +# there could be unresolved conflicts, but dont worry, +# lots of them are caused because of removed unneeded files with patch step, +./scripts/bridges_update_subtree.sh fetch + +# so, after fetch and before solving conflicts just run patch, +# this will remove unneeded files and checks if subtree modules compiles +./scripts/bridges_update_subtree.sh patch + +# if there are conflicts, this could help, +# this removes locally deleted files at least (move changes to git stash for commit) +./scripts/bridges_update_subtree.sh merge + +# (optional) when conflicts resolved, you can check build again - should pass +# also important: this updates global Cargo.lock +./scripts/bridges_update_subtree.sh patch + +# add changes to the commit, first command `fetch` starts merge, +# so after all conflicts are solved and patch passes and compiles, +# then we need to finish merge with: +git merge --continue +```` + +# 3. How to pull latest Bridges code or contribute back? +(in theory) + +Note that it's totally fine to ping the **Bridges Team** to do that for you. The point +of adding the code as `git subtree` is to **reduce maintenance cost** for Cumulus/Polkadot +developers. + +If you still would like to either update the code to match latest code from the repo +or create an upstream PR read below. The following commands should be run in the +current (`polkadot`) repo. + +1. Add Bridges repo as a local remote: +``` +$ git remote add -f bridges git@github.com:paritytech/parity-bridges-common.git +``` + +If you plan to contribute back, consider forking the repository on Github and adding +your personal fork as a remote as well. +``` +$ git remote add -f my-bridges git@github.com:tomusdrw/parity-bridges-common.git +``` + +2. To update Bridges: +``` +$ git fetch bridges master +$ git subtree pull --prefix=bridges bridges master --squash +```` + +We use `--squash` to avoid adding individual commits and rather squashing them +all into one. + +3. Clean unneeded files here: +``` +./bridges/scripts/verify-pallets-build.sh --ignore-git-state --no-revert +``` + +4. Contributing back to Bridges (creating upstream PR) +``` +$ git subtree push --prefix=bridges my-bridges master +``` +This command will push changes to your personal fork of Bridges repo, from where +you can simply create a PR to the main repo. diff --git a/parachains/runtimes/bridge-hubs/README.md b/parachains/runtimes/bridge-hubs/README.md index 7a6cb35aaf7..79e82f3497a 100644 --- a/parachains/runtimes/bridge-hubs/README.md +++ b/parachains/runtimes/bridge-hubs/README.md @@ -35,41 +35,3 @@ or # BridgeHubPolkadot zombienet-linux --provider native spawn ./zombienet/examples/bridge_hub_polkadot_local_network.toml ``` - ----- -## Git subtree `./bridges` - -Add Bridges repo as a local remote and synchronize it with latest `master` from bridges repo: - -### How to update `bridges` subtree -``` -cd -# this will update new git branches from bridges repo -# there could be unresolved conflicts, but dont worry, -# lots of them are caused because of removed unneeded files with patch step :) -# so before solving conflicts just run patch -./scripts/bridges_update_subtree.sh fetch -# this will remove unneeded files and checks if subtree modules compiles -./scripts/bridges_update_subtree.sh patch -# if there are conflicts, this could help, removes locally deleted files at least -# (but you can also do this manually) -./scripts/bridges_update_subtree.sh merge -# when conflicts resolved, you can check build again - should pass -# also important: this updates global Cargo.lock -./scripts/bridges_update_subtree.sh patch -```` -We use `--squash` to avoid adding individual commits and rather squashing them -all into one. -Now we use `master` branch, but in future, it could change to some release branch/tag. - -### How was first time initialized (does not need anymore) -``` -cd -git remote add -f bridges git@github.com:paritytech/parity-bridges-common.git -# (ran just only first time, when subtree was initialized) -git subtree add --prefix=bridges bridges master --squash -# remove unnecessery files -./scripts/bridges_update_subtree.sh patch -./scripts/bridges_update_subtree.sh merge -git commit --amend -``` From 0670d9fa5ae67f6f01028440318a723d1b330720 Mon Sep 17 00:00:00 2001 From: Branislav Kontur Date: Mon, 17 Apr 2023 14:19:03 +0200 Subject: [PATCH 2/2] Squashed 'bridges/' changes from d30927c08..d3970944b d3970944b Small simplifications (#2050) git-subtree-dir: bridges git-subtree-split: d3970944b0cfc4ea5226225e1ca07dab234c3556 --- modules/messages/src/inbound_lane.rs | 16 +++++++--------- primitives/messages/src/lib.rs | 12 +++++------- 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/modules/messages/src/inbound_lane.rs b/modules/messages/src/inbound_lane.rs index 3f64ab765b5..59ff5667195 100644 --- a/modules/messages/src/inbound_lane.rs +++ b/modules/messages/src/inbound_lane.rs @@ -198,19 +198,17 @@ impl InboundLane { ); // now let's update inbound lane storage - let push_new = match data.relayers.back_mut() { + match data.relayers.back_mut() { Some(entry) if entry.relayer == *relayer_at_bridged_chain => { entry.messages.note_dispatched_message(); - false }, - _ => true, + _ => { + data.relayers.push_back(UnrewardedRelayer { + relayer: relayer_at_bridged_chain.clone(), + messages: DeliveredMessages::new(nonce), + }); + }, }; - if push_new { - data.relayers.push_back(UnrewardedRelayer { - relayer: (*relayer_at_bridged_chain).clone(), - messages: DeliveredMessages::new(nonce), - }); - } self.storage.set_data(data); ReceivalResult::Dispatched(dispatch_result) diff --git a/primitives/messages/src/lib.rs b/primitives/messages/src/lib.rs index 3910837a442..2828d5af006 100644 --- a/primitives/messages/src/lib.rs +++ b/primitives/messages/src/lib.rs @@ -164,11 +164,9 @@ impl InboundLaneData { where RelayerId: MaxEncodedLen, { - let message_nonce_size = MessageNonce::max_encoded_len(); - let relayer_id_encoded_size = RelayerId::max_encoded_len(); - let relayers_entry_size = relayer_id_encoded_size.checked_add(2 * message_nonce_size)?; - let relayers_size = relayers_entries.checked_mul(relayers_entry_size)?; - relayers_size.checked_add(message_nonce_size) + relayers_entries + .checked_mul(UnrewardedRelayer::::max_encoded_len())? + .checked_add(MessageNonce::max_encoded_len()) } /// Returns the approximate size of the struct as u32, given a number of entries in the @@ -223,7 +221,7 @@ pub struct InboundMessageDetails { /// /// This struct represents a continuous range of messages that have been delivered by the same /// relayer and whose confirmations are still pending. -#[derive(Encode, Decode, Clone, RuntimeDebug, PartialEq, Eq, TypeInfo)] +#[derive(Encode, Decode, Clone, RuntimeDebug, PartialEq, Eq, TypeInfo, MaxEncodedLen)] pub struct UnrewardedRelayer { /// Identifier of the relayer. pub relayer: RelayerId, @@ -270,7 +268,7 @@ pub enum ReceivalResult { } /// Delivered messages with their dispatch result. -#[derive(Clone, Default, Encode, Decode, RuntimeDebug, PartialEq, Eq, TypeInfo)] +#[derive(Clone, Default, Encode, Decode, RuntimeDebug, PartialEq, Eq, TypeInfo, MaxEncodedLen)] pub struct DeliveredMessages { /// Nonce of the first message that has been delivered (inclusive). pub begin: MessageNonce,