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

FIlters and Blocks go out of sync in unstable network connections #155

Open
Eunovo opened this issue Apr 24, 2024 · 0 comments
Open

FIlters and Blocks go out of sync in unstable network connections #155

Eunovo opened this issue Apr 24, 2024 · 0 comments
Assignees

Comments

@Eunovo
Copy link

Eunovo commented Apr 24, 2024

Filter height and store height sometimes go out of sync in unstable network connections as seen below:

flutter: INFO (sp_backend::api): Nakamoto started
flutter: INFO (client): Initializing client (Signet)..
flutter: INFO (client): Genesis block hash is 00000008819873e925422c1ff0f99f7cc9bbb232af63a077a480a3633bee1ef6
flutter: INFO (client): Found existing store "...../db/.nakamoto/signet/headers.db"
flutter: INFO (client): Store height = 80000
flutter: INFO (client): Loading block headers from store..
flutter: INFO (client): Initializing block filters..
flutter: INFO (client): Found existing store "..../db/.nakamoto/signet/filters.db"
flutter: INFO (client): Filters height = 28000
flutter: INFO (client): Loading filter headers from store..
flutter: INFO (client): Skipping filter header verification (verify = false)
flutter: INFO (client): Loading peer addresses..
flutter: INFO (client): Found existing peer cache "..../db/.nakamoto/signet/peers.json"
flutter: INFO (client): 4575 peer(s) found.. 80 with compact filters support

This presents a problem when you try to request filters using the height returned from handle.get_tip(). The height returned from get_tip() is the block store height. If this height is greater than the filter height, request_filters will fail with an assertion error.

thread '<unnamed>' panicked at ..../.cargo/git/checkouts/nakamoto-75926082020ea03a/08203fd/p2p/src/fsm/cbfmgr.rs:449:9:
assertion failed: *range.end() <= self.filters.height()

Environment
Flutter Linux with flutter_rust_bridge v1

How are you running Nakomoto?
Due to constraints on mobile devices, we do not keep Nakomoto running indefinitely in the background. We start it when we want to sync Nakomoto with peers and request filters. See sync code excerpt below:

pub fn sync_blockchain(mut handle: Handle<Waker>) -> Result<()> {
    handle.set_timeout(Duration::from_secs(10));

    if let Err(_) = handle.wait_for_peers(1, ServiceFlags::NETWORK) {
        return Err(Error::msg("Can't connect to peers"));
    }

    let mut last_height = 0;

    loop {
        let peer_count = handle.get_peers(ServiceFlags::NETWORK)?;
        if peer_count.is_empty() {
            continue;
        };
        let (height, header, _) = handle.get_tip()?;
        send_sync_progress(SyncStatus {
            peer_count: peer_count.len() as u32,
            blockheight: height,
            bestblockhash: header.block_hash().to_string(),
        });
        if last_height == 0 || last_height < height {
            last_height = height;
            sleep(Duration::from_secs(2));
            continue;
        }
        break;
    }

    Ok(())
}

How to Reproduce
Run the above code and turn off your internet connection to interrupt the sync process.

I think this problem could be solved by exposing the filter height in get_tip() so we can use that to request filters instead.

@vincenzopalazzo vincenzopalazzo self-assigned this Apr 24, 2024
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

No branches or pull requests

2 participants