Bound finalized header, execution header and sync committee by RingBuffer and BoundedVec#815
Bound finalized header, execution header and sync committee by RingBuffer and BoundedVec#815
Conversation
|
Looks good! The implementation seems sound. Will give a more thorough review next week. |
There was a problem hiding this comment.
This is a good design ring buffer design, but I think we can do even better to optimize the overhead of the implementation.
It seems the mappings ExecutionHeaderMapping and SyncCommitteesMapping simply contain pointers to next inserted node.
So lets consider storing the next pointers with the actual nodes.
See this rough example which explains it better:
struct RingBufferNode<K, V> {
value: V,
next: Option<K>,
}
struct RingBufferCursor<K> {
// last inserted node
node: K,
// number of nodes in ring buffer
count: u32
}
struct RingBufferTransient<K, V, Nodes, Cursor>
where
Nodes: StorageMap<K, RingBufferNode<K, V>>,
Cursor: StorageValue<RingBufferCursor<K>>;
impl<K, V, Nodes, Cursor> RingBufferTransient<K, V, Nodes, Cursor>
where
Nodes: StorageMap<K, RingBufferNode<K, V>>,
Cursor: StorageValue<RingBufferCursor<K>>;
{
fn insert(key: K, value: V) {
// handle all cases here, much like a circular singly linked list
}
}
// Ring buffer nodes
#[pallet::storage]
pub(super) type SyncCommittees<T: Config> = StorageMap<_, Identity, H256, RingBufferNode<H256, SyncCommitteeOf<T>>, ValueQuery>;
// Ring buffer cursor
#[pallet::storage]
pub(crate) type SyncCommitteesCursor<T: Config> = StorageValue<_, RingBufferCursor<H256>, ValueQuery>;With this design, we reduce the number of storage writes from 3 to 2, so uses less weight.
Let me know what you think.
Actually, just realised this idea will have worse performance, since every time we need to update the |
Hmm. Make sense. One other concern is implemeting |
ParthDesai
left a comment
There was a problem hiding this comment.
Overall make sense to me. Though, some unrelated changes are from the main, which I haven't reviewed as I do not have enough context for those.
|
@yrong Is it possible to merge this PR now? |
|
@ParthDesai Note, you need at least rust 1.70 (nightly) to successfully compile the light client in all modes that are required (debug, release, etc). Older versions of Rust struggle: paritytech/substrate#14075 |
Based on #814 from @ParthDesai
Companion for cumulus: Snowfork/cumulus#20
Fixes: SNO-328