ethereum / trin

An Ethereum portal client: a json-rpc server with nearly instant sync, and low CPU & storage usage
379 stars 112 forks source link

Preferring variable ownership over locks in beacon bridge #873

Open carver opened 1 year ago

carver commented 1 year ago

I have some intuition that some refactors in the beacon bridge, portal-bridge/src/beacon_bridge.rs, can help us strip away some Mutexes, like this one:

let finalized_block_root = Arc::new(Mutex::new(String::new()));

Roughly, the approach would be to move the block root into the spawned async service task, and then return it from that task to re-assign the variable in the outer scope from the returned task value.

I can't do it in my head quite well enough to explain on a PR review, so I'll just code it myself locally to try it out, and show an example.

carver commented 1 year ago

I linked an example. There might be more places, so we can leave the issue open until all similar cases are handled.