Skip to content

Commit

Permalink
Merge branch 'quake/fix-disconnect-timeout' into bugfix/dirty-state-a…
Browse files Browse the repository at this point in the history
…fter-unexpected-disconnection
  • Loading branch information
yangby-cryptape committed Nov 20, 2023
2 parents 5fe518e + 0874146 commit fef2381
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
15 changes: 9 additions & 6 deletions src/protocols/light_client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ use std::collections::HashMap;
use std::sync::Arc;

use ckb_chain_spec::consensus::Consensus;
use ckb_constant::sync::INIT_BLOCKS_IN_TRANSIT_PER_PEER;
use ckb_constant::{
hardfork::{mainnet, testnet},
sync::INIT_BLOCKS_IN_TRANSIT_PER_PEER,
};
use ckb_network::{
async_trait, bytes::Bytes, CKBProtocolContext, CKBProtocolHandler, PeerIndex, SupportProtocols,
};
Expand Down Expand Up @@ -409,11 +412,11 @@ impl LightClientProtocol {

impl LightClientProtocol {
pub(crate) fn new(storage: Storage, peers: Arc<Peers>, consensus: Consensus) -> Self {
// TODO remove this hard code when mmr is activated on testnet
let mmr_activated_epoch = if consensus.is_public_chain() {
EpochNumber::MAX
} else {
0
// Ref: https://github.com/nervosnetwork/rfcs/blob/01f3bc64ef8f54c94c7b0dcf9d30c84b6c8418b0/rfcs/0044-ckb-light-client/0044-ckb-light-client.md#deployment
let mmr_activated_epoch = match consensus.id.as_str() {
mainnet::CHAIN_SPEC_NAME => 8648,
testnet::CHAIN_SPEC_NAME => 5676,
_ => 0,
};
Self {
storage,
Expand Down
2 changes: 2 additions & 0 deletions src/protocols/light_client/peers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1260,6 +1260,8 @@ impl Peers {
}

pub(crate) fn remove_peer(&self, index: PeerIndex) {
self.mark_fetching_headers_timeout(index);
self.mark_fetching_txs_timeout(index);
self.inner.remove(&index);
}

Expand Down
4 changes: 2 additions & 2 deletions src/tests/protocols/light_client/send_transactions_proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,6 @@ async fn test_send_headers_txs_request() {
protocol.disconnected(nc.context(), peer_index).await;
protocol.notify(nc.context(), REFRESH_PEERS_TOKEN).await;

assert_eq!(peers.get_txs_to_fetch().len(), 0);
assert_eq!(peers.get_headers_to_fetch().len(), 0);
assert_eq!(peers.get_txs_to_fetch().len(), 1);
assert_eq!(peers.get_headers_to_fetch().len(), 1);
}

0 comments on commit fef2381

Please sign in to comment.