Conversation
- included latest fork reciever in NonFinalisedState
| pub async fn spawn( | ||
| fetcher: &JsonRpSeeConnector, | ||
| block_sender: tokio::sync::mpsc::Sender<(Height, Hash, CompactBlock)>, | ||
| latest_fork_sender: tokio::sync::watch::Sender<BlockId>, |
There was a problem hiding this comment.
I think we could create the channel inside the spawn method to simplify the inputs.
eg. move:
let (channel_fork_tx, channel_fork_rx) = tokio::sync::watch::channel(BlockId {
height: 0,
hash: vec![0, 0],
});
inside NonFinalisedState::spawn().
There was a problem hiding this comment.
btw, what do you think the correct default values should be? i went with 0 for no reason in particular. Maybe we want to make it Option<BlockId> and only set it if we already have actual values?
There was a problem hiding this comment.
I'm adding this comment before I've finished reading the code in question so this may be obviously impossible, but can we do some sort of lazy initialization so that we don't start the channel until we have the first value?
There was a problem hiding this comment.
Oh...except in theory we might never have one. I think an optional value makes the most sense, returning None if there are no known chain forks in the last 100 blocks (nonfinalized state)
There was a problem hiding this comment.
Ye using an option should work well for lazy initialisation.
I think that technically when a new block is mined there is a chain fork at [chain tip - 1] so once we are running this should always return a chain-fork BlockId which was why I originally thought we didn't need the option. (maybe this is wrong though?)
|
In the case where the latest chain fork is >100 blocks old (and therefore no longer part of the nonfinalized state), should it still be reported, or should we report |
|
I think we still want to report it, it may actually be more important that we do for deep reorgs. The reorg logic here can actually fix reorgs in the finalised state as well as the non- finalised state. If the reorg height goes below [chain tip - 100 blocks] the non-finalised state will repopulate from that height, and as any blocks leave the non-finalised state they are pushed to the finalised state. Then the finalised state deals with any duplicate block heights. EDIT: I've been thinking about this more and I'm not 100% what happens if the chain fork is deeper than 100 blocks. There is a chance that the non-finalised state will grow to [chain fork depth] in size. If this is the case we will need to add a |
- it now waits for reorg_height and reorg_hash to be updated
My understanding is that finalized state is intended to be 'trusted' as old enough that it won't be reorged away. I haven't fully thought through how that interacts with latest fork reporting |
|
@nachog00 what's the state of this PR? |
|
This became stale after API redesign. Closing. |
Implements #263