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: panic when no enough block filter hashes #155

Conversation

yangby-cryptape
Copy link
Collaborator

Descriptions

Commits

  • Add a test to reproduce the bug.

  • Fix the bug.

    Review this commit could find the difference on the unit test easier.

    And could understand how does this bug happened and how to fix it easier.

  • Add more logs.

Error Logs

Full of the Error Logs
[2023-10-08T22:29:01Z TRACE ckb_light_client::protocols::status] LightClientProtocol.received SendLastStateProof from SessionId(7094), result OK(200)
[2023-10-08T22:29:01Z TRACE ckb_light_client::protocols::synchronizer] SyncProtocol.received peer=SessionId(6201), message=GetHeaders
[2023-10-08T22:29:02Z TRACE ckb_light_client::protocols::light_client] no fetching headers/transactions needed
[2023-10-08T22:29:02Z TRACE ckb_light_client::protocols::synchronizer] SyncProtocol.received peer=SessionId(23), message=GetHeaders
[2023-10-08T22:29:03Z TRACE ckb_light_client::protocols::filter::block_filter] could request block filters from 10888757 or not: true, finalized: index 5443, number 10886000; cached: index 5444, number 10888000, length 0; next cached: number 10890000
[2023-10-08T22:29:03Z DEBUG ckb_light_client::protocols::filter::block_filter] found best proved peer SessionId(9261)
[2023-10-08T22:29:03Z TRACE ckb_light_client::protocols::filter::block_filter] no block filters is required to download
[2023-10-08T22:29:04Z TRACE ckb_light_client::protocols::filter::block_filter] request block filter hashes from peer SessionId(7094), starts at 10886001
[2023-10-08T22:29:04Z TRACE ckb_light_client::protocols::filter::block_filter] request block filter hashes from peer SessionId(23), starts at 10888759
[2023-10-08T22:29:04Z TRACE ckb_light_client::protocols::filter::block_filter] request block filter hashes from peer SessionId(9262), starts at 10888759
[2023-10-08T22:29:04Z TRACE ckb_light_client::protocols::filter::block_filter] request block filter hashes from peer SessionId(9261), starts at 10888759
[2023-10-08T22:29:04Z TRACE ckb_light_client::protocols::filter::components::block_filter_hashes_process] peer SessionId(9261): last-state: PeerState::Ready { last_state: 10888759 }, add block filter hashes (start: 10888759, len: 1) and parent block filter hash is 0xc5ca1bf9b62cc39580d3619bf33081c7ee38bbe3a3dbfcdd9fe740da14b35d51
[2023-10-08T22:29:04Z TRACE ckb_light_client::protocols::filter::components::block_filter_hashes_process] finalized: index 5443, number 10886000; cached: index 5444, number 10888000, length 0; next cached: number 10890000
[2023-10-08T22:29:04Z TRACE ckb_light_client::protocols::status] BlockFilterProtocol.received BlockFilterHashes from SessionId(9261), result OK(200)
[2023-10-08T22:29:04Z TRACE ckb_light_client::protocols::filter::components::block_filter_hashes_process] peer SessionId(9262): last-state: PeerState::Ready { last_state: 10888759 }, add block filter hashes (start: 10888759, len: 1) and parent block filter hash is 0xc5ca1bf9b62cc39580d3619bf33081c7ee38bbe3a3dbfcdd9fe740da14b35d51
[2023-10-08T22:29:04Z TRACE ckb_light_client::protocols::filter::components::block_filter_hashes_process] finalized: index 5443, number 10886000; cached: index 5444, number 10888000, length 0; next cached: number 10890000
[2023-10-08T22:29:04Z TRACE ckb_light_client::protocols::status] BlockFilterProtocol.received BlockFilterHashes from SessionId(9262), result OK(200)
[2023-10-08T22:29:04Z TRACE ckb_light_client::protocols::filter::components::block_filter_hashes_process] peer SessionId(23): last-state: PeerState::Ready { last_state: 10888759 }, add block filter hashes (start: 10888759, len: 1) and parent block filter hash is 0xc5ca1bf9b62cc39580d3619bf33081c7ee38bbe3a3dbfcdd9fe740da14b35d51
[2023-10-08T22:29:04Z TRACE ckb_light_client::protocols::filter::components::block_filter_hashes_process] finalized: index 5443, number 10886000; cached: index 5444, number 10888000, length 0; next cached: number 10890000
[2023-10-08T22:29:04Z TRACE ckb_light_client::protocols::status] BlockFilterProtocol.received BlockFilterHashes from SessionId(23), result OK(200)
[2023-10-08T22:29:05Z TRACE ckb_light_client::protocols::light_client] no fetching headers/transactions needed
[2023-10-08T22:29:05Z TRACE ckb_light_client::protocols::filter::components::block_filter_hashes_process] peer SessionId(7094): last-state: PeerState::Ready { last_state: 10888759 }, add block filter hashes (start: 10886001, len: 2000) and parent block filter hash is 0x5f388b30206fe7324bfaeec95ef15b7c791fe02d408a251aeba38d270eb3de5d
[2023-10-08T22:29:05Z TRACE ckb_light_client::protocols::filter::components::block_filter_hashes_process] finalized: index 5443, number 10886000; cached: index 5444, number 10888000, length 0; next cached: number 10890000
[2023-10-08T22:29:05Z TRACE ckb_light_client::protocols::filter::block_filter] request block filter hashes from peer SessionId(7094), starts at 10888001
[2023-10-08T22:29:05Z TRACE ckb_light_client::protocols::status] BlockFilterProtocol.received BlockFilterHashes from SessionId(7094), result OK(200)
[2023-10-08T22:29:05Z TRACE ckb_light_client::protocols::filter::components::block_filter_hashes_process] peer SessionId(7094): last-state: PeerState::Ready { last_state: 10888759 }, add block filter hashes (start: 10888001, len: 759) and parent block filter hash is 0x5ecfac4d3328b6cc7f53d0d8c18bfc9d701d4fca4efc9e3cda80987ebe928c89
[2023-10-08T22:29:05Z TRACE ckb_light_client::protocols::filter::components::block_filter_hashes_process] finalized: index 5443, number 10886000; cached: index 5444, number 10888000, length 0; next cached: number 10890000
[2023-10-08T22:29:05Z TRACE ckb_light_client::protocols::status] BlockFilterProtocol.received BlockFilterHashes from SessionId(7094), result OK(200)
[2023-10-08T22:29:06Z TRACE ckb_light_client::protocols::filter::block_filter] could request block filters from 10888757 or not: true, finalized: index 5443, number 10886000; cached: index 5444, number 10888000, length 0; next cached: number 10890000
[2023-10-08T22:29:06Z DEBUG ckb_light_client::protocols::filter::block_filter] found best proved peer SessionId(9261)
[2023-10-08T22:29:06Z TRACE ckb_light_client::protocols::filter::block_filter] no block filters is required to download
[2023-10-08T22:29:08Z TRACE ckb_light_client::protocols::light_client] no fetching headers/transactions needed
[2023-10-08T22:29:09Z TRACE ckb_light_client::protocols::filter::block_filter] could request block filters from 10888757 or not: true, finalized: index 5443, number 10886000; cached: index 5444, number 10888000, length 0; next cached: number 10890000
[2023-10-08T22:29:09Z DEBUG ckb_light_client::protocols::filter::block_filter] found best proved peer SessionId(9261)
[2023-10-08T22:29:09Z DEBUG ckb_light_client::protocols::filter::block_filter] send get block filters to SessionId(9261), start_number=10888757
[2023-10-08T22:29:09Z TRACE ckb_light_client::protocols::filter::block_filter] request block filter from peer SessionId(9261), starts at 10888757
[2023-10-08T22:29:09Z TRACE ckb_light_client::protocols::light_client] peer SessionId(6201): copy prove state from peer SessionId(7094)
[2023-10-08T22:29:09Z TRACE ckb_light_client::protocols::light_client] peer SessionId(2): copy prove state from peer SessionId(6201)
[2023-10-08T22:29:09Z TRACE ckb_light_client::protocols::light_client] peer SessionId(9265): copy prove state from peer SessionId(6201)
[2023-10-08T22:29:09Z TRACE ckb_light_client::protocols::light_client] peer SessionId(7097): copy prove state from peer SessionId(6201)
[2023-10-08T22:29:09Z TRACE ckb_light_client::protocols::light_client] check points for peer SessionId(2) in [5443,5443]
[2023-10-08T22:29:09Z TRACE ckb_light_client::protocols::light_client] check points for peer SessionId(23) in [5443,5443]
[2023-10-08T22:29:09Z TRACE ckb_light_client::protocols::light_client] check points for peer SessionId(7097) in [5443,5443]
[2023-10-08T22:29:09Z TRACE ckb_light_client::protocols::light_client] check points for peer SessionId(7094) in [5443,5443]
[2023-10-08T22:29:09Z TRACE ckb_light_client::protocols::light_client] check points for peer SessionId(6201) in [5443,5443]
[2023-10-08T22:29:09Z TRACE ckb_light_client::protocols::light_client] check points for peer SessionId(9265) in [5443,5443]
[2023-10-08T22:29:09Z TRACE ckb_light_client::protocols::light_client] check points for peer SessionId(9262) in [5443,5443]
[2023-10-08T22:29:09Z TRACE ckb_light_client::protocols::light_client] check points for peer SessionId(9261) in [5443,5443]
[2023-10-08T22:29:09Z TRACE ckb_light_client::protocols::light_client] requires 4 peers for finalizing check points and got 8
[2023-10-08T22:29:09Z TRACE ckb_light_client::protocols::light_client] finalized check point is 5443, 0x5f388b30206fe7324bfaeec95ef15b7c791fe02d408a251aeba38d270eb3de5d
[2023-10-08T22:29:09Z TRACE ckb_light_client::protocols::light_client] new last check point will be less than or equal to 5443
[2023-10-08T22:29:09Z TRACE ckb_light_client::protocols::light_client] no check point is found which could be finalized
thread 'GlobalRt-0' panicked at 'index out of bounds: the len is 0 but the index is 2755', src/protocols/filter/components/block_filters_process.rs:159:39
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
[2023-10-08T22:29:09Z INFO  ckb_network::network] Ban peer "/ip4/*.*.*.*/tcp/8111/p2p/***********************************************" for 300 seconds, reason: protocol ProtocolId(121) panic when process peer message

@yangby-cryptape yangby-cryptape changed the title test: reproduce panic when no enough block filter hashes fix: panic when no enough block filter hashes Oct 13, 2023
@codecov-commenter
Copy link

codecov-commenter commented Oct 13, 2023

Codecov Report

All modified lines are covered by tests ✅

Comparison is base (dfcd2cc) 69.83% compared to head (96a9209) 69.88%.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop     #155      +/-   ##
===========================================
+ Coverage    69.83%   69.88%   +0.04%     
===========================================
  Files           25       25              
  Lines         6409     6418       +9     
===========================================
+ Hits          4476     4485       +9     
  Misses        1933     1933              
Flag Coverage Δ
unittests 69.88% <100.00%> (+0.04%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
...otocols/filter/components/block_filters_process.rs 75.24% <100.00%> (+0.37%) ⬆️
src/protocols/light_client/peers.rs 61.73% <100.00%> (+0.16%) ⬆️

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@yangby-cryptape yangby-cryptape marked this pull request as ready for review October 13, 2023 08:54
@yangby-cryptape yangby-cryptape requested a review from quake October 13, 2023 08:54
@quake quake merged commit bdd5f32 into nervosnetwork:develop Nov 1, 2023
6 checks passed
@yangby-cryptape yangby-cryptape deleted the bugfix/panic-when-no-enough-block-filter-hashes branch November 20, 2023 11:18
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.

3 participants