Struct evm_adapters::sputnik::SharedBackend [−][src]
pub struct SharedBackend { /* fields omitted */ }
Expand description
A cloneable backend type that shares access to the backend data with all its clones.
This backend type is connected to the BackendHandler
via a mpsc channel. The BackendHandlers
is spawned on a background thread and listens for incoming commands on the receiver half of the
channel. A SharedBackend
holds a sender for that channel, which is Clone
, so their can be
multiple SharedBackend
s communicating with the same BackendHandler
, hence this Backend
type is thread safe.
All Backend
trait functions are delegated as a BackendRequest
via the channel to the
BackendHandler
. All BackendRequest
variants include a sender half of an additional channel
that is used by the BackendHandler
to send the result of an executed BackendRequest
back to
SharedBackend
.
The BackendHandler
holds an ethers Provider
to look up missing accounts or storage slots
from remote (e.g. infura). It detects duplicate requests from multiple SharedBackend
s and
bundles them together, so that always only one provider request is executed. For example, there
are two SharedBackend
s, A
and B
, both request the basic account info of account
0xasd9sa7d...
at the same time. After the BackendHandler
receives the request from A
, it
sends a new provider request to the provider’s endpoint, then it reads the identical request
from B
and simply adds it as an additional listener for the request already in progress,
instead of sending another one. So that after the provider returns the response all listeners
(A
and B
) get notified.
Implementations
pub fn new<M>(
provider: M,
cache: SharedCache<MemCache>,
vicinity: MemoryVicinity,
pin_block: Option<BlockId>
) -> Self where
M: Middleware + Unpin + 'static + Clone,
pub fn new<M>(
provider: M,
cache: SharedCache<MemCache>,
vicinity: MemoryVicinity,
pin_block: Option<BlockId>
) -> Self where
M: Middleware + Unpin + 'static + Clone,
Spawns a new BackendHandler
on a background thread that listens for requests from any
SharedBackend
. Missing values get inserted in the cache
.
NOTE: this should be called with Arc<Provider>
Trait Implementations
Environmental block hash.
Environmental block number.
Environmental coinbase.
Environmental block timestamp.
Environmental block difficulty.
Environmental block gas limit.
Environmental block base fee.
Get storage value of address at index.
Auto Trait Implementations
impl !RefUnwindSafe for SharedBackend
impl Send for SharedBackend
impl Sync for SharedBackend
impl Unpin for SharedBackend
impl !UnwindSafe for SharedBackend
Blanket Implementations
Mutably borrows from an owned value. Read more
Instruments this type with the provided Span
, returning an
Instrumented
wrapper. Read more
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more