-
Notifications
You must be signed in to change notification settings - Fork 159
Bound finalized header, execution header and sync committee by RingBuffer and BoundedVec #815
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
f3bd6c3
add ringbuffer to limit the storage
ParthDesai e560e99
Refactoring & Fix relayer
yrong 726b78c
Merge branch 'main' into add-ringbuffer
yrong 5cd005b
Merge branch 'main' into add-ringbuffer
yrong 7f1ee23
More refactoring
yrong 9716177
Some polish
yrong 155dc74
Some polish
yrong 9ad78ac
Merge branch 'main' into add-ringbuffer
yrong File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
parachain/pallets/ethereum-beacon-client/src/ringbuffer.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| use codec::FullCodec; | ||
| use core::{cmp::Ord, marker::PhantomData, ops::Add}; | ||
| use frame_support::storage::{types::QueryKindTrait, StorageMap, StorageValue}; | ||
| use sp_core::{Get, GetDefault}; | ||
| use sp_runtime::traits::{One, Zero}; | ||
|
|
||
| /// Trait object presenting the ringbuffer interface. | ||
| pub trait RingBufferMap<Key, Value, QueryKind> | ||
| where | ||
| Key: FullCodec, | ||
| Value: FullCodec, | ||
| QueryKind: QueryKindTrait<Value, GetDefault>, | ||
| { | ||
| /// Insert a map entry. | ||
| fn insert(k: Key, v: Value); | ||
|
|
||
| /// Check if map contains a key | ||
| fn contains_key(k: Key) -> bool; | ||
|
|
||
| /// Get the value of the key | ||
| fn get(k: Key) -> QueryKind::Query; | ||
| } | ||
|
|
||
| pub struct RingBufferMapImpl<Index, B, CurrentIndex, Intermediate, M, QueryKind>( | ||
| PhantomData<(Index, B, CurrentIndex, Intermediate, M, QueryKind)>, | ||
| ); | ||
|
|
||
| /// Ringbuffer implementation based on `RingBufferTransient` | ||
| impl<Key, Value, Index, B, CurrentIndex, Intermediate, M, QueryKind> | ||
| RingBufferMap<Key, Value, QueryKind> | ||
| for RingBufferMapImpl<Index, B, CurrentIndex, Intermediate, M, QueryKind> | ||
| where | ||
| Key: FullCodec + Clone, | ||
| Value: FullCodec, | ||
| Index: Ord + One + Zero + Add<Output = Index> + Copy + FullCodec + Eq, | ||
| B: Get<Index>, | ||
| CurrentIndex: StorageValue<Index, Query = Index>, | ||
| Intermediate: StorageMap<Index, Key, Query = Key>, | ||
| M: StorageMap<Key, Value, Query = QueryKind::Query>, | ||
| QueryKind: QueryKindTrait<Value, GetDefault>, | ||
| { | ||
| /// Insert a map entry. | ||
| fn insert(k: Key, v: Value) { | ||
| let bound = B::get(); | ||
| let mut current_index = CurrentIndex::get(); | ||
|
|
||
| // Adding one here as bound denotes number of items but our index starts with zero. | ||
| if (current_index + Index::one()) >= bound { | ||
| current_index = Index::zero(); | ||
| } else { | ||
| current_index = current_index + Index::one(); | ||
| } | ||
|
|
||
| // Deleting earlier entry if it exists | ||
| if Intermediate::contains_key(current_index) { | ||
| let older_key = Intermediate::get(current_index); | ||
| M::remove(older_key); | ||
| } | ||
|
|
||
| Intermediate::insert(current_index, k.clone()); | ||
| CurrentIndex::set(current_index); | ||
| M::insert(k, v); | ||
| } | ||
|
|
||
| /// Check if map contains a key | ||
| fn contains_key(k: Key) -> bool { | ||
| M::contains_key(k) | ||
| } | ||
|
|
||
| /// Get the value associated with key | ||
| fn get(k: Key) -> M::Query { | ||
| M::get(k) | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.