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

Support dedicated lanes for pallets #962

Merged
merged 15 commits into from
Mar 14, 2022

Conversation

svyatonik
Copy link
Contributor

Initial concept of the lane was that single application will use single lane (now we have two generic lanes in test deployments, though). While working on #944 I've found that the current set of messages integration APIs doesn't allow us to have lanes dedicated to runtime pallets. So if we have pallet (in this context: application) that is going to use messages pallet to send messages, then we can't verify (in the LaneMessageVerifier) that the message is actually sent by the pallet (not by the regular user).

Why this is important? In #935 I've introduced at-source-chain-callback for processing messages dispatch result. This callback is something like fn on_messages_dispatched(lane: LaneId, dispatch_results: MessageDispatchResults) {}. If the token-swap pallet (from #944 that uses this callback) would use existing generic lanes (0x00000000 or 0x00000001), then implementation of this callback won't be trivial - it'll need to check if every dispatched message is actually token-swap pallet message (=> extra storage read for every message) before doing something useful. If we'll have lane, dedicated to this pallet, then the implementation won't need to do this check (because it'll has if lane != T::OutboundLaneId::get() { return }) && will only deal with its own messages.

I've started this back in the April && just opening this PR for visibility now. If you guys think it makes sense to support such 'dedicated' lanes, then I'll continue to work on this after #935 is accepted. If this is not required - I'll just close the PR. Probably after review of #935 , something will change - I just didn't want to lose this code.

The alternative solutions I've considered:

  1. use something like enum SendOrigin { External(AccountId), Root, Internal } in messages integration APIs. But then I've found that pallets may define their own origins && I've decided to use it - it seems to be the proper way;
  2. give special meaning to frame_system::RawOrigin::None - so it'll mean that the message is sent by the runtime itself. But this is super-confusing.

Copy link
Contributor

@tomusdrw tomusdrw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the idea of passing origin to is_message_accepted, but I'd drop the custom trait for that - is it necessary? Or why is it useful? It adds extra generic parameters, hence I'd prefer to avoid it.

@svyatonik svyatonik force-pushed the pass-message-send-origin-to-verify-message branch from 7ee6e51 to e641a1f Compare July 7, 2021 08:50
@svyatonik
Copy link
Contributor Author

svyatonik commented Jul 7, 2021

I like the idea of passing origin to is_message_accepted, but I'd drop the custom trait for that - is it necessary? Or why is it useful? It adds extra generic parameters, hence I'd prefer to avoid it.

My understanding is that any pallet may declare its own origin (using #[pallet::origin]). All origins (including the one from frame_system) are then merged into final runtime-specific Origin. So when origin comes to message lane verifier/message payment components, they'll need to know at least two things:

  1. who has crafted the message - e.g. we may use something like *lane_id == *b"swap" && matches!(origin, crate::Origin::TokenSwap(_)) to only accept messages from token swap pallet to swap lane;
  2. whether the message is paid (and by whom) or not. This way we may have system-level pallets that may send messages for free (and altruistic relayers who are serving such lanes) and general/pallet-specific lanes, which require messages to be paid.

The trait is a way to keep using existing generic code (instant payments), which was previously using frame_system::Origin with this new concept. So in the end, it needs to convert generic runtime origin into account id to know who's paying for the message. Without trait, you'll need to do that on runtime level - i.e. every runtime will need its own implementation of the MessageDeliveryAndDispatchPayment, which will extract account id and then call InstantCurrencyPayments using extracted account.

The simpler option would be to use struct MessageSenderOrigin { sender_id: [u8; 4], paid_by: Option<AccountId> } (where e.g. sender_id=00000000 would mean that the message is sent by the regular user, sender_id=*b"swap" will meanthe token swap pallet, etc) everywhere instead of runtime-level origin, but I was assuming that it'll be better to use existing origin concept.

Copy link
Contributor

@tomusdrw tomusdrw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My understanding is that any pallet may declare its own origin (using #[pallet::origin]). All origins (including the one from frame_system) are then merged into final runtime-specific Origin. So when origin comes to message lane verifier/message payment components, they'll need to know at least two things:

I see it totally makes sense, I didn't connect the dots. Looks good to me!

/// The call is originated by the token swap account.
TokenSwap {
/// Id of the account that has started the swap.
source_account_at_this_chain: AccountId,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This field isn't used now anywhere deployments, but if this pallet will ever end up in some real-chain && we'll want to filter it by the token-swap originator, then we may use this field in the filter. Could remove on demand

@svyatonik svyatonik marked this pull request as ready for review September 30, 2021 10:30
@svyatonik svyatonik marked this pull request as draft September 30, 2021 11:11
@svyatonik svyatonik marked this pull request as ready for review September 30, 2021 12:15
@svyatonik svyatonik added the PR-audit-needed A PR has to be audited before going live. label Sep 30, 2021
@tomusdrw
Copy link
Contributor

@svyatonik shall we merge?

@svyatonik
Copy link
Contributor Author

@svyatonik shall we merge?

I've been asking this on Riot couple of weeks ago :) It won't be audited, and imo it deserves audit. So probably not now? Or we'll have some dedicated release branch without this PR merged in?

@tomusdrw tomusdrw added the PR-onice The PR is not meant to be merged when this label is applied. label Oct 22, 2021
@tomusdrw
Copy link
Contributor

I've been asking this on Riot couple of weeks ago :) It won't be audited, and imo it deserves audit. So probably not now? Or we'll have some dedicated release branch without this PR merged in?

Sorry, must have missed it or forgot. Sounds good, let's wait and branch out when we are ready to go live and after that merge to master.

@tomusdrw
Copy link
Contributor

We've branched out polkadot-staging, so I guess this is good to go now?

@svyatonik
Copy link
Contributor Author

We've branched out polkadot-staging, so I guess this is good to go now?

Let's not merge any needsaudit PRs related to existing pallets until we'll have a strict audit solution+policy. Like before opening polkadot-staging -> polkadot repo PR we'll need to update Substrate+Polkadot+Cumulus refs. Where shall we do that? If in master + then simply make a master -> polkadot-staging PR, then either difference(master, polkadot-staging) shall not have any needsaudit PRs, or we shall make reaudit. If we'll only update refs in polkadot-staging branch, then master and polkadot-staging will diverge and we'll have to do the same work twice. So I suggest to not to merge this PR now.

@svyatonik svyatonik added PR-audited A PR that had `X-needsaudit` label is already audited. and removed PR-audit-needed A PR has to be audited before going live. labels Mar 14, 2022
@svyatonik svyatonik merged commit 1581f60 into master Mar 14, 2022
@svyatonik svyatonik deleted the pass-message-send-origin-to-verify-message branch March 14, 2022 13:36
svyatonik added a commit that referenced this pull request Mar 21, 2022
* Fix mandatory headers scanning in on-demand relay (#1306)

* more logging in on-demand headerss

* remove `maximal_headers_difference` concept from on-demand-relay

* another leftover from previous on-demand version

* removed extra log

* fmt

* increase relay balance guard limits for Polkadot<>Kusama bridge (#1308)

* fix benchmarks before using it in Polkadot/Kusama/Rococo runtimes (#1309)

* Endow relayer account at target chain in message benchmarks (#1310)

* endow relayer account at target chain in message benchmarks

* pick another line

* expose fee multiplier metrics in messages relay (#1312)

* Fix issues from cargo deny (#1311)

* update libp2p-core (RUSTSEC-2022-0009)

* update thread_local (RUSTSEC-2022-0006)

* time 0.2 -> time 0.3

* ignore RUSTSEC-2021-0130

* proper migration to time 0.3

* fix clippy?

* Revert "fix clippy?"

This reverts commit 53bc289.

* Add some tests to check integrity of chain constants + bridge configuration (#1316)

* add some tests to check integrity of chain constants + bridge configuration

* try to use named parameters where possible

* Encode and estimate Rococo/Wococo/Kusama/Polkadot messages (#1322)

* encode and estimate Rococo/Wococo/Kusama/Polkadot messages

* allow send-message for non-bundled chains

* weight -> dispatch-weight

* fmt

* fix spelling

* impl Decode for SignedExtensions (otherwise transaction resubmitter panicks) (#1325)

* use mortal transactions in transaction resubmitter (#1326)

* Using-same-fork metric for finality and complex relay (#1327)

* using_same_fork metric in finality relay

* support `using_different_forks` in messages relay

* added dashboards and alerts

* lockfile

* fix typo in alert expression (#1329)

* removed extra *_RUNTIME_VERSION consts from relay code (#1330)

* Reinitialize bridge relay subcommand (#1331)

* reinitialize bridge subcommand

* PolkadotToKusama in reinit-bridge

* fix clippy issues (#1332)

* Revert "Revert "override conversion rate in estimate-message-fee RPC (#1189)" (#1275)" (#1333)

This reverts commit ed7def6.

* Override conversion rate when computing message fee (#1261)

* override conversion rate when message is sent

* spelling + fmt

* add --conversion-rate-override cli option

* try to read conversion rate from cmd output

* fix output

* fmt

* fi typo in generator script (#1334)

* override conversion rate in tokens swap generator (#1335)

* fix conversion rate override in token swap (#1336)

* synchronize relay cli changes and token swap generator script (#1337)

* fixed mess with conversion rates (#1338)

* fix generator scripts to be consistent with updatedrelay output (#1339)

* Increase rate from metric when estimating fee (#1340)

* ignore errors when dumping logs and container is missing

* fixed typo

* print correct payload length

* increase conversion rate a bit when estimating fee (to avoid message rejects when rate update tx is active)

* fmt

* fix conversion rate metric in dashboards (#1341)

* get rid of '[No Data] Messages from Millau to Rialto are not being delivered' warnings (#1342)

* use DecodeLimit when decoding incoming calls (#1344)

* update regex to 1.5.5 (#1345)

* edition = "2021" (#1346)

* Mortal conversion rate updater transactions (#1257)

* merge all similar update_conversion_rate functions

* stall timeout in conversion rate update loop

* fmt

* fix

* added alerts for relay balances (#1347)

* replace From<>InboundLaneApi with direct storage reads (#1348)

* added no_stack_overflow_when_decoding_nested_call_during_dispatch test (#1349)

* ignore more "increase" alerts that are sometimes signalling NoData at startup (#1351)

* Support dedicated lanes for pallets (#962)

* pass call origin to the message verifier

* is_outbound_lane_enabled -> is_message_accepted

* trait SenderOrigin

* only accept messages from token swap pallet to token swap lane

* tests for edge cases of pay_delivery_and_dispatch_fee

* fixed origin verification

* fmt

* fix benchmarks compilation

* fix TODO with None account and non-zero message fee (already covered by tests)

* revert cargo fmt changes temporarily

* Update Substrate/Polkadot/Cumulus references (#1353)

* cumulus: 4e95228
polkadot: 975e780ae0d988dc033f400ba822d14b326ee5b9
substrate: 89fcb3e4f62d221d4e161a437768e77d6265889e

* fix refs

* sync changes from paritytech/polkadot#3828

* sync changes from paritytech/polkadot#4387

* sync changes from paritytech/polkadot#3940

* sync with changes from paritytech/polkadot#4493

* sync with changes from paritytech/polkadot#4958

* sync with changes from paritytech/polkadot#3889

* sync with changes from paritytech/polkadot#5033

* sync with changes from paritytech/polkadot#5065

* compilation fixes

* fixed prometheus endpoint startup (it now requires to be spawned within tokio context)

* update chain versions (#1358)

* update parity-scale-codec to 3.1.2 (#1359)

* fix parse_transaction on Rialto+Millau (#1360)
AurevoirXavier added a commit to darwinia-network/darwinia-common that referenced this pull request Sep 15, 2022
serban300 pushed a commit to serban300/parity-bridges-common that referenced this pull request Mar 27, 2024
* pass call origin to the message verifier

* is_outbound_lane_enabled -> is_message_accepted

* trait SenderOrigin

* only accept messages from token swap pallet to token swap lane

* tests for edge cases of pay_delivery_and_dispatch_fee

* fixed origin verification

* fmt

* fix benchmarks compilation

* fix TODO with None account and non-zero message fee (already covered by tests)

* revert cargo fmt changes temporarily
serban300 pushed a commit to serban300/parity-bridges-common that referenced this pull request Apr 8, 2024
* pass call origin to the message verifier

* is_outbound_lane_enabled -> is_message_accepted

* trait SenderOrigin

* only accept messages from token swap pallet to token swap lane

* tests for edge cases of pay_delivery_and_dispatch_fee

* fixed origin verification

* fmt

* fix benchmarks compilation

* fix TODO with None account and non-zero message fee (already covered by tests)

* revert cargo fmt changes temporarily
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P-Message Delivery PR-audited A PR that had `X-needsaudit` label is already audited. PR-onice The PR is not meant to be merged when this label is applied.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants