pub struct VelocityControl {
pub start_sec: u64,
pub bucket_interval: u32,
pub buckets: Vec<u64>,
pub limit: u64,
}
Expand description
Limit velocity per unit time.
We track velocity in intervals instead of tracking each send, to keep storage requirements constant.
Fields§
§start_sec: u64
start second for the current velocity epoch
bucket_interval: u32
the number of seconds represented by a bucket
buckets: Vec<u64>
each bucket entry is the total velocity detected in that interval, in satoshi
limit: u64
the limit, or MAX if the control is disabled
Implementations§
Source§impl VelocityControl
impl VelocityControl
Sourcepub fn new_with_intervals(
limit_msat: u64,
bucket_interval: u32,
num_buckets: usize,
) -> Self
pub fn new_with_intervals( limit_msat: u64, bucket_interval: u32, num_buckets: usize, ) -> Self
Create a velocity control with arbitrary specified intervals current_sec: the current second num_buckets: how many buckets to keep track of bucket_interval: each bucket represents this number of seconds limit: the total velocity limit when summing the buckets
Sourcepub fn new_unlimited(bucket_interval: u32, num_buckets: usize) -> Self
pub fn new_unlimited(bucket_interval: u32, num_buckets: usize) -> Self
Create an unlimited velocity control (i.e. no actual control)
Sourcepub fn new(spec: VelocityControlSpec) -> Self
pub fn new(spec: VelocityControlSpec) -> Self
Create a velocity control with the given interval type
Sourcepub fn spec_matches(&self, spec: &VelocityControlSpec) -> bool
pub fn spec_matches(&self, spec: &VelocityControlSpec) -> bool
Whether the spec matches this control
Sourcepub fn update_spec(&mut self, spec: &VelocityControlSpec)
pub fn update_spec(&mut self, spec: &VelocityControlSpec)
Update this control to match the given spec. If the spec does not match the previous spec, the control is reset.
Sourcepub fn load_from_state(
spec: VelocityControlSpec,
state: (u64, Vec<u64>),
) -> Self
pub fn load_from_state( spec: VelocityControlSpec, state: (u64, Vec<u64>), ) -> Self
Load from persistence
Sourcepub fn is_unlimited(&self) -> bool
pub fn is_unlimited(&self) -> bool
Whether this instance is unlimited (no control)
Trait Implementations§
Source§impl Clone for VelocityControl
impl Clone for VelocityControl
Source§fn clone(&self) -> VelocityControl
fn clone(&self) -> VelocityControl
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreAuto Trait Implementations§
impl Freeze for VelocityControl
impl RefUnwindSafe for VelocityControl
impl Send for VelocityControl
impl Sync for VelocityControl
impl Unpin for VelocityControl
impl UnwindSafe for VelocityControl
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more