Closed yangby-cryptape closed 1 year ago
Base: 78.42% // Head: 79.56% // Increases project coverage by +1.14%
:tada:
Coverage data is based on head (
b629b2d
) compared to base (c39cce3
). Patch coverage: 97.59% of modified lines in pull request are covered.
:umbrella: View full report at Codecov.
:loudspeaker: Do you have feedback about the report comment? Let us know in this issue.
Issue
Let $N_{last}$ denote the constant
LAST_N_BLOCKS
.Suppose there are follow steps:
Start a light client
C
.C
connected to a CKB nodeN
.C
gets last state of block $h_{1}$ and its proof fromN
.And
C
saves $N_{last}$ last-N headers in its storage.The last state from
N
changes to $h{2}$ with $h{2} = h{1} + t$ and $N{last} \gt t \gt 1$.The bug is:
When
C
updates the last state from $h{1}$ to $h{2}$, the count of saved last-N headers in the storage will changed to $t$.Then, if $t$ is too small, it will be difficult to find the ancestor block for a fork chain.
So long fork will be detected frequently.
Updates
When add proved blocks,
if the count of new last N headers is less than the expected count of the last N blocks, just copy some old last N headers to make sure we have enough stored last N headers.
if the count of new last N headers is greater than the expected count of the last N blocks, just remove some of them to avoid unlimited memory growth.
Refactor unit tests to make it easier to add an
assert
to several unit tests, not just copy the code several times.And also add more unit tests to improve the coverage.
Resolve #117.