Skip to content

[PR #31] connect() returns bare ChainProvider — no Arc, no Clone; multi-task sharing unsound #91

@obchain

Description

@obchain

PR: #31 (feat/06-chainprovider-ws)
File: crates/charon-scanner/src/provider.rs
Lines: 31, 43

Problem: connect returns owned ChainProvider. RootProvider<PubSubFrontend> does not implement Clone. Scanner needs to share provider across at least two concurrent tokio tasks (block subscriber + liquidation executor). Without Arc, callers must unsafely alias reference or restructure entire task topology.

No compile-time assertion that ChainProvider: Send + Sync, so future field addition could silently break task-spawn without clear error.

Impact: Any scanner PR spawning two tasks over same provider fails to compile or requires undocumented Arc wrap not enforced by API.

Fix:

pub async fn connect(...) -> Result<Arc<Self>> {
    // ... existing logic ...
    Ok(Arc::new(Self { name, ws: provider }))
}

const _: () = {
    fn assert_send_sync<T: Send + Sync>() {}
    fn check() { assert_send_sync::<ChainProvider>(); }
};

Document in rustdoc that callers Arc::clone per spawned task.

Metadata

Metadata

Assignees

No one assigned

    Labels

    layer:rustRust crates (core / scanner / protocols / executor / cli)pr-reviewFindings from PR review processpriority:p2-polishNice-to-have / polish

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions