pub struct BatchSigner { /* private fields */ }Expand description
Coalesces concurrent single-message signing into batched proxy calls under a
configurable rate budget. Implements ArchSignerT, so call sites are
unchanged.
A local backend is passed straight through — see
is_batching.
§Examples
use std::time::Duration;
use cosigner_client::{ArchSigner, ArchSignerT, BatchSigner};
let signer = BatchSigner::spawn(ArchSigner::from_env()?)
.with_max_rps(8.0)
.with_max_batch(32)
.with_deadline(Duration::from_millis(2000));
// Unchanged call site; concurrent calls share one proxy round trip.
let response = signer.sign_message(&message).await?;Implementations§
Source§impl BatchSigner
impl BatchSigner
Sourcepub fn spawn(inner: ArchSigner) -> Self
pub fn spawn(inner: ArchSigner) -> Self
Creates the signer and the dispatcher that serves it.
A local inner is passed through directly, with no task, channel, or
limiter. For a remote inner the dispatcher task starts with the first
queued request; apply the builder setters before then, since they
configure a queue that is already in use afterwards.
inner’s own retry budget is cleared: the dispatcher owns retry so that
every attempt spends a rate-limiter permit.
Sourcepub fn is_batching(&self) -> bool
pub fn is_batching(&self) -> bool
Returns whether requests are coalesced, i.e. whether the backend is remote.
Worth logging beside the resolved backend: under a local signer the batch metrics stay flat, which otherwise reads as a bug.
Sourcepub fn with_max_rps(self, rps: f64) -> Self
pub fn with_max_rps(self, rps: f64) -> Self
Returns this signer with the ceiling on activities per second.
A non-positive or non-finite rate means unlimited.
Sourcepub fn with_max_batch(self, n: usize) -> Self
pub fn with_max_batch(self, n: usize) -> Self
Returns this signer with the largest number of messages per activity.
Sourcepub fn with_max_in_flight(self, n: usize) -> Self
pub fn with_max_in_flight(self, n: usize) -> Self
Returns this signer with the cap on concurrent in-flight activities.
Sourcepub fn with_queue_depth(self, n: usize) -> Self
pub fn with_queue_depth(self, n: usize) -> Self
Returns this signer with the bound on queued requests. Beyond it, signing fails immediately rather than waiting.
Sourcepub fn with_deadline(self, deadline: Duration) -> Self
pub fn with_deadline(self, deadline: Duration) -> Self
Returns this signer with the per-request deadline. A request still queued when it expires is dropped rather than signed.
Sourcepub fn with_retries(self, retries: u32) -> Self
pub fn with_retries(self, retries: u32) -> Self
Returns this signer with the dispatcher’s retry budget for a whole batch. Each attempt spends a rate-limiter permit.
Trait Implementations§
Source§impl ArchSignerT for BatchSigner
impl ArchSignerT for BatchSigner
Source§fn sign_message<'life0, 'life1, 'async_trait>(
&'life0 self,
message: &'life1 ArchMessage,
) -> Pin<Box<dyn Future<Output = Result<SignResponse, SignError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn sign_message<'life0, 'life1, 'async_trait>(
&'life0 self,
message: &'life1 ArchMessage,
) -> Pin<Box<dyn Future<Output = Result<SignResponse, SignError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Source§fn sign_messages<'life0, 'life1, 'async_trait>(
&'life0 self,
messages: &'life1 [ArchMessage],
) -> Pin<Box<dyn Future<Output = Result<Vec<Result<SignResponse, SignError>>, SignError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn sign_messages<'life0, 'life1, 'async_trait>(
&'life0 self,
messages: &'life1 [ArchMessage],
) -> Pin<Box<dyn Future<Output = Result<Vec<Result<SignResponse, SignError>>, SignError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
messages, returning one result per input in
input order. Read more