ChainSafe / ChainSafe/forest

[bug] Forest doesn't report forks correctly

Open
#4,825 6 comments 0 reactions 0 assignees View on GitHub
Type: Bug Type: Request
Dominant language
Rust
Stars
697
Forks
200
Avg merge
1d 5h
Merged PRs (30d)
65

Description

# Summary

We expose changes to the current HEAD through the `ChainNotify` RPC call. Listeners on this method should be told about new blocks and about forks in the chain.

In Lotus, this is done through three types of messages: `revert,` `apply,` and `current.` When a new tipset is appended to the blockchain, the `apply` message is sent to listeners. If a longer branch is detected (a fork), Lotus reverts tipsets until the common root and then applies the tipsets from the new branch.

https://github.com/filecoin-project/lotus/blob/71927361046f9a11a024d605f71321224b0497b7/chain/store/store.go#L283-L287
```go
const (
HCRevert = "revert"
HCApply = "apply"
HCCurrent = "current"
)
```

In Forest, we do not do this correctly. In fact, we only send out the `apply` message. When a new heaviest tipset is selected, we pretend to immediately apply it:

https://github.com/ChainSafe/forest/blob/00c52a4c75d3387c9d5d1ec5ea1310c434b1e26d/src/chain/store/chain_store.rs#L51-L53

We need to have proper support for navigating the blockchain graph.

# Requirements

- [ ] Basic support for `revert` messages.
- [ ] Re-work state-machine internals to navigate between branches rather than directly jumping to the heaviest tipset.
- [ ] Figure out how to unit test this behavior.
- [ ] Figure out how to test this behavior with a devnet.

Note: The easiest solution may be to keep track of the last reported tipset and then intersperse additional `revert`s or `apply`s if required. This way, we don't have to re-design the internals of our state-machine.

# Motivation

Proper handling of forks is essential for Curio integration. Without it, we cannot mine successfully with Forest.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.