Skip to content

Commit

Permalink
Simplify the chain_head.rs module (#409)
Browse files Browse the repository at this point in the history
* Move the chainhead_follow task to another function

* Merge FollowSubscription into ChainHeadFollowTask

* Extract processing foreground message to separate function

* Move the subscription start functions as methods of ChainHeadFollowTask

* Fix generating a `chainHead_unstable_followEvent` event on unfollow

* Fix cyclic references in the chainHead sub-tasks

* Finish fixing cyclic references issues

* Move some fields to the struct

* Move subscription as a struct field

* PR link

* CHANGELOG entry for cyclic reference

* Remove CHANGELOG entry as still not fixed

* Properly fix cyclic reference

* Add back CHANGELOG entry

* Oops, fix bug
  • Loading branch information
tomaka authored Apr 12, 2023
1 parent eca3039 commit d68340e
Show file tree
Hide file tree
Showing 3 changed files with 1,437 additions and 1,339 deletions.
12 changes: 0 additions & 12 deletions light-base/src/json_rpc_service/background.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ use core::{
time::Duration,
};
use futures::{lock::Mutex, prelude::*};
use hashbrown::HashMap;
use smoldot::{
chain::fork_tree,
executor::{host, runtime_host},
header,
json_rpc::{self, methods, requests_subscriptions},
Expand Down Expand Up @@ -101,16 +99,6 @@ struct Background<TPlat: Platform> {
printed_legacy_json_rpc_warning: atomic::AtomicBool,
}

struct FollowSubscription {
/// Tree of hashes of all the current non-finalized blocks. This includes unpinned blocks.
non_finalized_blocks: fork_tree::ForkTree<[u8; 32]>,

/// For each pinned block hash, the SCALE-encoded header of the block.
pinned_blocks_headers: HashMap<[u8; 32], Vec<u8>, fnv::FnvBuildHasher>,

runtime_subscribe_all: Option<runtime_service::SubscriptionId>,
}

pub(super) enum SubscriptionMessage {
StopIfAllHeads {
stop_request_id: (String, requests_subscriptions::RequestId),
Expand Down
Loading

0 comments on commit d68340e

Please sign in to comment.