Trait Persist

Source
pub trait Persist: SendSync {
Show 23 methods // Required methods fn new_node( &self, node_id: &PublicKey, config: &NodeConfig, state: &NodeState, ) -> Result<(), Error>; fn update_node( &self, node_id: &PublicKey, state: &NodeState, ) -> Result<(), Error>; fn delete_node(&self, node_id: &PublicKey) -> Result<(), Error>; fn new_channel( &self, node_id: &PublicKey, stub: &ChannelStub, ) -> Result<(), Error>; fn delete_channel( &self, node_id: &PublicKey, channel: &ChannelId, ) -> Result<(), Error>; fn new_tracker( &self, node_id: &PublicKey, tracker: &ChainTracker<ChainMonitor>, ) -> Result<(), Error>; fn update_tracker( &self, node_id: &PublicKey, tracker: &ChainTracker<ChainMonitor>, ) -> Result<(), Error>; fn get_tracker( &self, node_id: PublicKey, validator_factory: Arc<dyn ValidatorFactory>, ) -> Result<(ChainTracker<ChainMonitor>, Vec<ChainTrackerListenerEntry>), Error>; fn update_channel( &self, node_id: &PublicKey, channel: &Channel, ) -> Result<(), Error>; fn get_channel( &self, node_id: &PublicKey, channel_id: &ChannelId, ) -> Result<ChannelEntry, Error>; fn get_node_channels( &self, node_id: &PublicKey, ) -> Result<Vec<(ChannelId, ChannelEntry)>, Error>; fn update_node_allowlist( &self, node_id: &PublicKey, allowlist: Vec<String>, ) -> Result<(), Error>; fn get_node_allowlist( &self, node_id: &PublicKey, ) -> Result<Vec<String>, Error>; fn get_nodes(&self) -> Result<Vec<(PublicKey, NodeEntry)>, Error>; fn clear_database(&self) -> Result<(), Error>; fn signer_id(&self) -> SignerId; // Provided methods fn enter(&self) -> Result<(), Error> { ... } fn prepare(&self) -> Mutations { ... } fn commit(&self) -> Result<(), Error> { ... } fn put_batch_unlogged(&self, _m: Mutations) -> Result<(), Error> { ... } fn on_initial_restore(&self) -> bool { ... } fn recovery_required(&self) -> bool { ... } fn begin_replication(&self) -> Result<Mutations, Error> { ... }
}
Expand description

Persister of nodes and channels

A Node will call the relevant methods here as needed.

There are two types of persisters:

  • Memorizing persisters, which only store the mutations in memory, for later retrieval and storage by the caller. This is used in embedded environments to return the mutations to the host system.

  • Real persisters, which store the mutations directly, for example to disk. This is used in non-embedded environments. This kind of persister should persist durably before returning, for safety.

Required Methods§

Source

fn new_node( &self, node_id: &PublicKey, config: &NodeConfig, state: &NodeState, ) -> Result<(), Error>

Create a new node

Source

fn update_node( &self, node_id: &PublicKey, state: &NodeState, ) -> Result<(), Error>

Update node enforcement state

Source

fn delete_node(&self, node_id: &PublicKey) -> Result<(), Error>

Delete a node and all of its channels. Used in test mode.

Source

fn new_channel( &self, node_id: &PublicKey, stub: &ChannelStub, ) -> Result<(), Error>

Will error if exists

Source

fn delete_channel( &self, node_id: &PublicKey, channel: &ChannelId, ) -> Result<(), Error>

Delete a channel

Source

fn new_tracker( &self, node_id: &PublicKey, tracker: &ChainTracker<ChainMonitor>, ) -> Result<(), Error>

Create a new tracker

Source

fn update_tracker( &self, node_id: &PublicKey, tracker: &ChainTracker<ChainMonitor>, ) -> Result<(), Error>

Update the tracker

Source

fn get_tracker( &self, node_id: PublicKey, validator_factory: Arc<dyn ValidatorFactory>, ) -> Result<(ChainTracker<ChainMonitor>, Vec<ChainTrackerListenerEntry>), Error>

Get the tracker

Source

fn update_channel( &self, node_id: &PublicKey, channel: &Channel, ) -> Result<(), Error>

Will error if doesn’t exist.

Source

fn get_channel( &self, node_id: &PublicKey, channel_id: &ChannelId, ) -> Result<ChannelEntry, Error>

Get a channel from store

Source

fn get_node_channels( &self, node_id: &PublicKey, ) -> Result<Vec<(ChannelId, ChannelEntry)>, Error>

Get all channels for a node from store

Source

fn update_node_allowlist( &self, node_id: &PublicKey, allowlist: Vec<String>, ) -> Result<(), Error>

Persist the allowlist to the store.

Source

fn get_node_allowlist(&self, node_id: &PublicKey) -> Result<Vec<String>, Error>

Get the allowlist from the store.

Source

fn get_nodes(&self) -> Result<Vec<(PublicKey, NodeEntry)>, Error>

Get all nodes from store

Source

fn clear_database(&self) -> Result<(), Error>

Clears the database. Not for production use.

Source

fn signer_id(&self) -> SignerId

Get our unique 128-bit signer ID

Provided Methods§

Source

fn enter(&self) -> Result<(), Error>

Enter a persistence context

Must call prepare(), commit the mutations in the cloud and then call commit() to persist the mutations locally.

If this is not a transactional persister, this is a no-op and prepare() will return an empty list of mutations.

Source

fn prepare(&self) -> Mutations

Get the logged mutations since the last call to enter().

If this is not a transactional persister, this returns an empty list.

Source

fn commit(&self) -> Result<(), Error>

Commit the logged mutations.

If this is not a transactional persister, this is a no-op and the mutations were already persisted.

Source

fn put_batch_unlogged(&self, _m: Mutations) -> Result<(), Error>

Update the persister with the given mutations.

This doesn’t require a call to enter().

Source

fn on_initial_restore(&self) -> bool

Notifies the persister that the initial restore from persistence is done and queries whether a sync is required.

A sync is required when using a composite persister, since one of the persisters may have fallen behind due to a crash.

Source

fn recovery_required(&self) -> bool

Whether recovery from backup is required on signer startup. Should return true if the persister is in a state where it needs to recover from a backup (e.g. empty).

Source

fn begin_replication(&self) -> Result<Mutations, Error>

Start replication by putting the local store into a compatible starting state for a cloud persister.

All versions are reset to zero. Gets the entire stored content as Mutations that the caller must store into the empty cloud store.

Implementors§