Struct ChainTracker

Source
pub struct ChainTracker<L: ChainListener> {
    pub headers: VecDeque<Headers>,
    pub tip: Headers,
    pub height: u32,
    pub network: Network,
    pub listeners: OrderedMap<L::Key, (L, ListenSlot)>,
    pub trusted_oracle_pubkeys: Vec<PublicKey>,
    /* private fields */
}
Expand description

Track chain, with basic validation

Fields§

§headers: VecDeque<Headers>

headers past the tip

§tip: Headers

tip header

§height: u32

height

§network: Network

The network

§listeners: OrderedMap<L::Key, (L, ListenSlot)>

listeners

§trusted_oracle_pubkeys: Vec<PublicKey>

public keys of trusted TXO oracle

Implementations§

Source§

impl<L: ChainListener> ChainTracker<L>

Source

pub const MAX_REORG_SIZE: usize = 100usize

Maximum reorg size that we will accept

Source

pub fn new( network: Network, height: u32, tip: Headers, node_id: PublicKey, validator_factory: Arc<dyn ValidatorFactory>, trusted_oracle_pubkeys: Vec<PublicKey>, ) -> Result<Self, Error>

Create a new tracker

Source

pub fn set_allow_deep_reorgs(&mut self, allow: bool)

Set whether deep reorgs are allowed

Source

pub fn restore( headers: VecDeque<Headers>, tip: Headers, height: u32, network: Network, listeners: OrderedMap<L::Key, (L, ListenSlot)>, node_id: PublicKey, validator_factory: Arc<dyn ValidatorFactory>, trusted_oracle_pubkeys: Vec<PublicKey>, ) -> Self

Restore a tracker

Source

pub fn from_genesis( network: Network, node_id: PublicKey, validator_factory: Arc<dyn ValidatorFactory>, trusted_oracle_pubkeys: Vec<PublicKey>, ) -> Self

Create a tracker at genesis

Source

pub fn for_network( network: Network, node_id: PublicKey, validator_factory: Arc<dyn ValidatorFactory>, trusted_oracle_pubkeys: Vec<PublicKey>, ) -> Self

Create a tracker for a network, from a checkpoint if exists or from genesis otherwise

Source

pub fn tip(&self) -> &Headers

Current chain tip header

Source

pub fn headers(&self) -> &VecDeque<Headers>

Headers past the tip

Source

pub fn height(&self) -> u32

Height of current chain tip

Source

pub fn remove_block( &mut self, proof: TxoProof, supplied_prev_headers: Headers, ) -> Result<BlockHeader, Error>

Remove block at tip due to reorg

The previous block and filter headers are provided in case the reorg is too deep for our local memory of headers. However, this should only be used on testnet, since a deep reorg may be incompatible with the Lightning security model.

Source

pub fn restore_listener( &mut self, outpoint: L::Key, listener: L, slot: ListenSlot, )

Restore a listener

Source

pub fn block_chunk( &mut self, hash: BlockHash, offset: u32, chunk: &[u8], ) -> Result<(), Error>

Handle a streamed block

Source

pub fn add_block( &mut self, header: BlockHeader, proof: TxoProof, ) -> Result<(), Error>

Add a block, which becomes the new tip

Source

pub fn add_listener( &mut self, listener: L, initial_txid_watches: OrderedSet<Txid>, )

Add a listener and initialize the watched outpoint set

Source

pub fn remove_listener(&mut self, key: &L::Key)

Remove a listener

Source

pub fn add_listener_watches( &mut self, key: &L::Key, watches: OrderedSet<OutPoint>, )

Add more watches to a listener

Source

pub fn get_all_forward_watches(&self) -> (Vec<Txid>, Vec<OutPoint>)

Return all Txid and OutPoint watches for future blocks.

Source

pub fn get_all_reverse_watches(&self) -> (Vec<Txid>, Vec<OutPoint>)

Return all Txid and OutPoint watches for removing blocks. This is a superset of the forward watches, and also includes watches for outpoints which were seen as spent in previous blocks.

Auto Trait Implementations§

§

impl<L> !Freeze for ChainTracker<L>

§

impl<L> !RefUnwindSafe for ChainTracker<L>

§

impl<L> Send for ChainTracker<L>
where <L as ChainListener>::Key: Send,

§

impl<L> !Sync for ChainTracker<L>

§

impl<L> Unpin for ChainTracker<L>

§

impl<L> !UnwindSafe for ChainTracker<L>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more