Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: let peers cached their own last headers to avoid be overridden #177

Conversation

yangby-cryptape
Copy link
Collaborator

Description

At present, only one set of verified last N block headers are cached.

// verified last N block headers
last_headers: RwLock<Vec<HeaderView>>,

But, in fact, all peers could have different sets of last N block headers.

Consider that:

  • A and B are same chain.
  • A's tip is N.
  • B's tip is N+k.
  • Light client connects to A and B at same time.
  • The last state proof from B is arrived earlier than A's.

What will be happened?

  • B's last N headers are cached.
  • Then, A's last N headers overrides B's.

How to fix that?

Traverse last headers of all peers every time.

Commits

  • test: reproduce the bug that last headers could be overridden by worse data
  • fix: let peers cached their own last headers to avoid be overridden

@yangby-cryptape yangby-cryptape marked this pull request as ready for review January 9, 2024 05:40
quake
quake previously approved these changes Jan 9, 2024
src/protocols/light_client/peers.rs Outdated Show resolved Hide resolved
@quake quake merged commit 4147b4a into nervosnetwork:develop Jan 9, 2024
6 checks passed
@yangby-cryptape yangby-cryptape deleted the bugfix/last-headers-are-overridden branch January 9, 2024 07:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants