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§
Sourcefn new_node(
&self,
node_id: &PublicKey,
config: &NodeConfig,
state: &NodeState,
) -> Result<(), Error>
fn new_node( &self, node_id: &PublicKey, config: &NodeConfig, state: &NodeState, ) -> Result<(), Error>
Create a new node
Sourcefn update_node(
&self,
node_id: &PublicKey,
state: &NodeState,
) -> Result<(), Error>
fn update_node( &self, node_id: &PublicKey, state: &NodeState, ) -> Result<(), Error>
Update node enforcement state
Sourcefn delete_node(&self, node_id: &PublicKey) -> Result<(), Error>
fn delete_node(&self, node_id: &PublicKey) -> Result<(), Error>
Delete a node and all of its channels. Used in test mode.
Sourcefn new_channel(
&self,
node_id: &PublicKey,
stub: &ChannelStub,
) -> Result<(), Error>
fn new_channel( &self, node_id: &PublicKey, stub: &ChannelStub, ) -> Result<(), Error>
Will error if exists
Sourcefn delete_channel(
&self,
node_id: &PublicKey,
channel: &ChannelId,
) -> Result<(), Error>
fn delete_channel( &self, node_id: &PublicKey, channel: &ChannelId, ) -> Result<(), Error>
Delete a channel
Sourcefn new_tracker(
&self,
node_id: &PublicKey,
tracker: &ChainTracker<ChainMonitor>,
) -> Result<(), Error>
fn new_tracker( &self, node_id: &PublicKey, tracker: &ChainTracker<ChainMonitor>, ) -> Result<(), Error>
Create a new tracker
Sourcefn update_tracker(
&self,
node_id: &PublicKey,
tracker: &ChainTracker<ChainMonitor>,
) -> Result<(), Error>
fn update_tracker( &self, node_id: &PublicKey, tracker: &ChainTracker<ChainMonitor>, ) -> Result<(), Error>
Update the tracker
Sourcefn get_tracker(
&self,
node_id: PublicKey,
validator_factory: Arc<dyn ValidatorFactory>,
) -> Result<(ChainTracker<ChainMonitor>, Vec<ChainTrackerListenerEntry>), Error>
fn get_tracker( &self, node_id: PublicKey, validator_factory: Arc<dyn ValidatorFactory>, ) -> Result<(ChainTracker<ChainMonitor>, Vec<ChainTrackerListenerEntry>), Error>
Get the tracker
Sourcefn update_channel(
&self,
node_id: &PublicKey,
channel: &Channel,
) -> Result<(), Error>
fn update_channel( &self, node_id: &PublicKey, channel: &Channel, ) -> Result<(), Error>
Will error if doesn’t exist.
id0
original channel ID supplied toPersist::new_channel()
id
an optional additional permanent channel ID
Sourcefn get_channel(
&self,
node_id: &PublicKey,
channel_id: &ChannelId,
) -> Result<ChannelEntry, Error>
fn get_channel( &self, node_id: &PublicKey, channel_id: &ChannelId, ) -> Result<ChannelEntry, Error>
Get a channel from store
Sourcefn get_node_channels(
&self,
node_id: &PublicKey,
) -> Result<Vec<(ChannelId, ChannelEntry)>, Error>
fn get_node_channels( &self, node_id: &PublicKey, ) -> Result<Vec<(ChannelId, ChannelEntry)>, Error>
Get all channels for a node from store
Sourcefn update_node_allowlist(
&self,
node_id: &PublicKey,
allowlist: Vec<String>,
) -> Result<(), Error>
fn update_node_allowlist( &self, node_id: &PublicKey, allowlist: Vec<String>, ) -> Result<(), Error>
Persist the allowlist to the store.
Sourcefn get_node_allowlist(&self, node_id: &PublicKey) -> Result<Vec<String>, Error>
fn get_node_allowlist(&self, node_id: &PublicKey) -> Result<Vec<String>, Error>
Get the allowlist from the store.
Sourcefn clear_database(&self) -> Result<(), Error>
fn clear_database(&self) -> Result<(), Error>
Clears the database. Not for production use.
Provided Methods§
Sourcefn enter(&self) -> Result<(), Error>
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.
Sourcefn prepare(&self) -> Mutations
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.
Sourcefn commit(&self) -> Result<(), Error>
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.
Sourcefn put_batch_unlogged(&self, _m: Mutations) -> Result<(), Error>
fn put_batch_unlogged(&self, _m: Mutations) -> Result<(), Error>
Update the persister with the given mutations.
This doesn’t require a call to enter()
.
Sourcefn on_initial_restore(&self) -> bool
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.
Sourcefn recovery_required(&self) -> bool
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).
Sourcefn begin_replication(&self) -> Result<Mutations, Error>
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.