Skip to content
This repository has been archived by the owner on Oct 22, 2024. It is now read-only.

Free finalized Ethereum updates #159

Merged
merged 14 commits into from
Jul 31, 2024
Merged

Conversation

claravanstaden
Copy link
Collaborator

@claravanstaden claravanstaden commented Jul 18, 2024

Allows free Ethereum finalized header updates if they larger or equal to the last interval within a certain interval.

  • Adds pallet config FreeHeadersInterval, to be set to 32.
  • All beacon headers equal to or more than 32 slots newer than the latest imported header will be free.
  • All valid sync committee updates are free.
  • Any extrinsic resulting in an error condition will be a paid transaction.

Resolves: https://linear.app/snowfork/issue/SNO-1053

@claravanstaden claravanstaden marked this pull request as ready for review July 18, 2024 18:38
@@ -281,10 +285,9 @@ pub mod pallet {
Ok(())
}

pub(crate) fn process_update(update: &Update) -> DispatchResult {
pub(crate) fn process_update(update: &Update) -> DispatchResultWithPostInfo {

Choose a reason for hiding this comment

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

Non-blocking: Do you think this function is even necessary?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Lol maybe not! I think its just to much the Ethereum consensus spec, which has a pattern of a "process" method, that does a "verify" and an "apply".

// If free headers are allowed and the latest finalized header is larger than the
// minimum slot interval, the header import transaction is free.
if let Some(free_headers_interval) = T::FreeHeadersInterval::get() {
if improved_by_slot >= latest_slot + free_headers_interval as u64 {

Choose a reason for hiding this comment

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

So this is basically saying you get a free update if the update is far enough in the future?

Copy link

Choose a reason for hiding this comment

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

Yeah, seems follow the same pattern for the P->K bridge here with free update at a minimal interval.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Exactly. It will be set to every 32 slots (so basically all the finalized updates), but if we ever need to make it less frequent we can.

@yrong
Copy link

yrong commented Jul 29, 2024

Maybe we can add a runtime test checking the balance of the relayer before and after the extrinsic, make sure that there is no fee charged actually.

IIUC set pays_fee flag to false does not mean it won't charge for the extrinsic, just the fee will be refunded to the caller. But I may not wrong here.

Copy link

@yrong yrong left a comment

Choose a reason for hiding this comment

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

+1

@claravanstaden
Copy link
Collaborator Author

Maybe we can add a runtime test checking the balance of the relayer before and after the extrinsic, make sure that there is no fee charged actually.

IIUC set pays_fee flag to false does not mean it won't charge for the extrinsic, just the fee will be refunded to the caller. But I may not wrong here.

@yrong that's a great suggestion, thanks. Added in c82647f.

@@ -83,6 +86,8 @@ pub mod pallet {
type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;
#[pallet::constant]
type ForkVersions: Get<ForkVersions>;
#[pallet::constant]
type FreeHeadersInterval: Get<Option<u32>>;
Copy link

Choose a reason for hiding this comment

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

Why does this need to be optional? Can't we just make free headers the default?

Comment on lines 670 to 672
if sync_committee_updated {
return Pays::No;
}
Copy link

Choose a reason for hiding this comment

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

This effectively is just returning the parameter of sync_committee_updated of mapped to Pays, which seems redundant.

And given my other comment above, I would advise restructuring as follows:

fn check_refundable(update: &Update, latest_slot: u64) -> Pays

@@ -464,13 +469,24 @@ pub mod pallet {
Self::deposit_event(Event::SyncCommitteeUpdated {
period: update_finalized_period,
});
sync_committee_updated = true;
Copy link

Choose a reason for hiding this comment

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

This sync_committee_updated flag seems redundant. Following the code, when sync_committee_updated=True, it follows that update.next_sync_committee_update == Some(...)

@claravanstaden
Copy link
Collaborator Author

@vgeddes thanks for the suggestions, fixed in e3281f8.

@claravanstaden claravanstaden requested a review from vgeddes July 30, 2024 18:13
@claravanstaden claravanstaden merged commit c7cbd99 into snowbridge Jul 31, 2024
8 checks passed
@claravanstaden claravanstaden deleted the free-finalized-updates branch July 31, 2024 12:30
claravanstaden added a commit that referenced this pull request Jul 31, 2024
* free finalized updates

* update comment

* fix check

* fixes

* tests

* fixes

* fmt

* finishing touches

* comments

* adds missing impl

* adds test

* fixes

* fix
github-merge-queue bot pushed a commit to paritytech/polkadot-sdk that referenced this pull request Sep 2, 2024
Allow free Snowbridge consensus updates, if the header interval is
larger than the configured value (set to 32, so once a epoch).

This PR also moves the Rococo Snowbridge pallet config into its own
module.

Original PR: Snowfork#159

---------

Co-authored-by: Francisco Aguirre <[email protected]>
acatangiu pushed a commit to acatangiu/polkadot-sdk that referenced this pull request Sep 3, 2024
Allow free Snowbridge consensus updates, if the header interval is
larger than the configured value (set to 32, so once a epoch).

This PR also moves the Rococo Snowbridge pallet config into its own
module.

Original PR: Snowfork#159

---------

Co-authored-by: Francisco Aguirre <[email protected]>
acatangiu added a commit to paritytech/polkadot-sdk that referenced this pull request Sep 3, 2024
Allow free Snowbridge consensus updates, if the header interval is
larger than the configured value (set to 32, so once a epoch).

This PR also moves the Rococo Snowbridge pallet config into its own
module.

Original PR: Snowfork#159

----------

Original `pr_5201.prdoc` is present but moved to release dir, ergo
`R0-Silent` for this backport PR.

---------

Co-authored-by: Clara van Staden <[email protected]>
Co-authored-by: Francisco Aguirre <[email protected]>
x3c41a pushed a commit to paritytech/polkadot-sdk that referenced this pull request Sep 4, 2024
Allow free Snowbridge consensus updates, if the header interval is
larger than the configured value (set to 32, so once a epoch).

This PR also moves the Rococo Snowbridge pallet config into its own
module.

Original PR: Snowfork#159

---------

Co-authored-by: Francisco Aguirre <[email protected]>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants