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

Select header that will be fully refunded in on-demand batch finality relay #2729

Merged
merged 5 commits into from
Dec 6, 2023

Conversation

svyatonik
Copy link
Contributor

@svyatonik svyatonik commented Dec 6, 2023

This is a better alternative of #2728. The idea is to change relayer a bit and let it wait for the header that will be fully refunded (when speaking of its size) before submitting batch delivery/confirmation transaction. That allows us to have better bridge fee estimations:

  • we believe that our relayer will be trying to select such header and justification, so that it'll be fully covered by our refund mechanism. Relayer is economically incentivized to do that;
  • so we can use the regular/average header size in our fee estimations and be sure that we won't refund more than this fee.

As a backup plan for the breaking changes (when header size suddenly grows), the relayer will be "selecting" smaller header only a few times (4 atm). If after 4 attempts, the call size is still above maximal, it'll submit what it has.

The runtime code logic changes are minimal:

  • before we have been always using MAX_HEADER_SIZE + max_justification_size(AVERAGE_HEADER_SIZE), where MAX_HEADER_SIZE was 90_000 and max justification size was 2 * 20_000 + some overhead for other fields. So max refundable call size was about 90_000 + 40_000 = 130_000;
  • now we have two max call sizes. One for mandatory header submission: 120kb + 2 *1024 + overhead for other fields = 122kb + overhead for other fields. The other is for regular headers - it is somewhere near 3Kb + overhead for other fields. Since we assume that mandatory header submission is mandatory for our bridge (and also rare), we could use the latter estimation for our batch transactions.

The "core" of relayer logic changes is in the relays/lib-substrate-relay/src/on_demand/headers.rs file.

What is left in this PR:

  • test it: tested locally by using slightly modified polkadot binary (session time for Rococo and Westend increased from 1m to 5m) + modified substrate-relay (average Rococo header size is set to 100 bytes):
[BridgeHubRococo_to_BridgeHubWestend_MessageLane_00000002] 2023-12-06 10:26:23 +00 DEBUG bridge [Rococo-to-BridgeHubWestend-on-demand-headers] Requested to prove Rococo head 120. Selected to prove Rococo head HeaderId(121, 0x2ddbcfea419006daf5361c32dfd59b581c738b2b771898a77bdf3d4ad3b624d1). But it is too large: 767 vs 740. Going to select next header
...
[BridgeHubRococo_to_BridgeHubWestend_MessageLane_00000002] 2023-12-06 10:26:27 +00 DEBUG bridge [Rococo-to-BridgeHubWestend-on-demand-headers] Requested to prove Rococo head 120. Selected to prove Rococo head HeaderId(122, 0x841844afd16fe63d05c692ac60d7c796ead7817a9e39d0372282e23e3e0e2e21). But it is too large: 767 vs 740. Going to select next header
...
[BridgeHubRococo_to_BridgeHubWestend_MessageLane_00000002] 2023-12-06 10:26:35 +00 DEBUG bridge [Rococo-to-BridgeHubWestend-on-demand-headers] Requested to prove Rococo head 120. Selected to prove Rococo head HeaderId(123, 0xeae7a1a926584410ee36e36094c1fe3fb7c859f93d09b447a15b0a22410f9dec). But it is too large: 767 vs 740. Going to select next header
...
[BridgeHubRococo_to_BridgeHubWestend_MessageLane_00000002] 2023-12-06 10:26:39 +00 DEBUG bridge [Rococo-to-BridgeHubWestend-on-demand-headers] Requested to prove Rococo head 120. Selected to prove Rococo head HeaderId(124, 0x4bfd833825ff96dc5d39524e2da8587d46029bbf3c32c700ead9a6f5f20aece3) (after 4 iterations)
  • add unit tests where possible: unfortunately, we still miss ability to write tests for on-demand relays (Tests for on-demand relays #2413), so this PR has been tested locally on Rococo <> Westend and it has just one unit test :(;
  • file an issue for adding similar functionality to non-batch on-demand relays. We do not need it now, but better have some issue to not forget this fact in the future: Improvements for transaction refundability checks #2730

@svyatonik svyatonik marked this pull request as ready for review December 6, 2023 10:59
Copy link
Collaborator

@serban300 serban300 left a comment

Choose a reason for hiding this comment

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

Looks good !

relays/lib-substrate-relay/src/finality_base/engine.rs Outdated Show resolved Hide resolved
@bkontur
Copy link
Contributor

bkontur commented Dec 6, 2023

Do you want to update subtree? I could do it also maybe with #2727

@svyatonik
Copy link
Contributor Author

Do you want to update subtree? I could do it also maybe with #2727

Main thing I want to do here is to deploy relay once this PR is merged. Constants are not that important - tests in fellowship repo are "manual" atm until we'll do another round of upgrade dependencies. But yes - if you'll be doing update in #2727, let's bring those changes too

@svyatonik svyatonik merged commit 390e836 into polkadot-staging Dec 6, 2023
13 checks passed
@svyatonik svyatonik deleted the select-smaller-header-for-submission branch December 6, 2023 12:16
bkontur added a commit to paritytech/polkadot-sdk that referenced this pull request Dec 6, 2023
svyatonik added a commit that referenced this pull request Dec 8, 2023
… relay (#2729)

* select header that will be fully refunded for submission in on-demand **batch** finality relay

* added the only possible test

* spelling

* nl

* updated comment
svyatonik added a commit that referenced this pull request Dec 8, 2023
* separate constants for average and worst case relay headers (#2728)

* separate constants for average and worst case relay headers

* fix compilation

* Select header that will be fully refunded in on-demand batch finality relay (#2729)

* select header that will be fully refunded for submission in on-demand **batch** finality relay

* added the only possible test

* spelling

* nl

* updated comment

* backport some nits from #2727

* NotApplicable instead of Unroutable

* Grafana update stuff (#2733)

---------

Co-authored-by: Branislav Kontur <bkontur@gmail.com>
serban300 pushed a commit to serban300/parity-bridges-common that referenced this pull request Mar 27, 2024
… relay (paritytech#2729)

* select header that will be fully refunded for submission in on-demand **batch** finality relay

* added the only possible test

* spelling

* nl

* updated comment
serban300 pushed a commit to serban300/parity-bridges-common that referenced this pull request Apr 8, 2024
… relay (paritytech#2729)

* select header that will be fully refunded for submission in on-demand **batch** finality relay

* added the only possible test

* spelling

* nl

* updated comment
bkontur added a commit that referenced this pull request May 7, 2024
* separate constants for average and worst case relay headers (#2728)

* separate constants for average and worst case relay headers

* fix compilation

* Select header that will be fully refunded in on-demand batch finality relay (#2729)

* select header that will be fully refunded for submission in on-demand **batch** finality relay

* added the only possible test

* spelling

* nl

* updated comment

* backport some nits from #2727

* NotApplicable instead of Unroutable

* Grafana update stuff (#2733)

---------

Co-authored-by: Branislav Kontur <bkontur@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants