pub trait RecoveryFromHistory:
Debug
+ MaybeSend
+ MaybeSync
+ Clone {
type Init: ClientModuleInit;
// Required methods
fn new<'life0, 'life1, 'life2, 'async_trait>(
init: &'life0 Self::Init,
args: &'life1 ClientModuleRecoverArgs<Self::Init>,
snapshot: Option<&'life2 <<Self::Init as ClientModuleInit>::Module as ClientModule>::Backup>,
) -> Pin<Box<dyn Future<Output = Result<(Self, u64)>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait;
fn load_dbtx<'life0, 'life1, 'life2, 'life3, 'async_trait>(
init: &'life0 Self::Init,
dbtx: &'life1 mut DatabaseTransaction<'life2>,
args: &'life3 ClientModuleRecoverArgs<Self::Init>,
) -> Pin<Box<dyn Future<Output = Result<Option<(Self, RecoveryFromHistoryCommon)>>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait;
fn store_dbtx<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
dbtx: &'life1 mut DatabaseTransaction<'life2>,
common: &'life3 RecoveryFromHistoryCommon,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait;
fn delete_dbtx<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
dbtx: &'life1 mut DatabaseTransaction<'life2>,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait;
fn load_finalized<'life0, 'life1, 'async_trait>(
dbtx: &'life0 mut DatabaseTransaction<'life1>,
) -> Pin<Box<dyn Future<Output = Option<bool>> + Send + 'async_trait>>
where 'life0: 'async_trait,
'life1: 'async_trait;
fn store_finalized<'life0, 'life1, 'async_trait>(
dbtx: &'life0 mut DatabaseTransaction<'life1>,
state: bool,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where 'life0: 'async_trait,
'life1: 'async_trait;
fn finalize_dbtx<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
dbtx: &'life1 mut DatabaseTransaction<'life2>,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait;
// Provided methods
fn handle_session<'life0, 'life1, 'life2, 'async_trait>(
&'life0 mut self,
client_ctx: &'life1 ClientContext<<Self::Init as ClientModuleInit>::Module>,
session_idx: u64,
session_items: &'life2 Vec<AcceptedItem>,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: Send + 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait { ... }
fn handle_transaction<'life0, 'life1, 'life2, 'async_trait>(
&'life0 mut self,
client_ctx: &'life1 ClientContext<<Self::Init as ClientModuleInit>::Module>,
transaction: &'life2 Transaction,
session_idx: u64,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: Send + 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait { ... }
fn handle_input<'life0, 'life1, 'life2, 'async_trait>(
&'life0 mut self,
_client_ctx: &'life1 ClientContext<<Self::Init as ClientModuleInit>::Module>,
_idx: usize,
_input: &'life2 <<<Self::Init as ClientModuleInit>::Module as ClientModule>::Common as ModuleCommon>::Input,
_session_idx: u64,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: Send + 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait { ... }
fn handle_output<'life0, 'life1, 'life2, 'async_trait>(
&'life0 mut self,
_client_ctx: &'life1 ClientContext<<Self::Init as ClientModuleInit>::Module>,
_out_point: OutPoint,
_output: &'life2 <<<Self::Init as ClientModuleInit>::Module as ClientModule>::Common as ModuleCommon>::Output,
_session_idx: u64,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: Send + 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait { ... }
fn pre_finalize<'life0, 'async_trait>(
&'life0 mut self,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: Send + 'async_trait,
'life0: 'async_trait { ... }
}
Expand description
Module specific logic for ClientModuleRecoverArgs::recover_from_history
See ClientModuleRecoverArgs::recover_from_history
for more information.
Required Associated Types§
sourcetype Init: ClientModuleInit
type Init: ClientModuleInit
ClientModuleInit
of this recovery logic.
Required Methods§
sourcefn new<'life0, 'life1, 'life2, 'async_trait>(
init: &'life0 Self::Init,
args: &'life1 ClientModuleRecoverArgs<Self::Init>,
snapshot: Option<&'life2 <<Self::Init as ClientModuleInit>::Module as ClientModule>::Backup>,
) -> Pin<Box<dyn Future<Output = Result<(Self, u64)>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn new<'life0, 'life1, 'life2, 'async_trait>(
init: &'life0 Self::Init,
args: &'life1 ClientModuleRecoverArgs<Self::Init>,
snapshot: Option<&'life2 <<Self::Init as ClientModuleInit>::Module as ClientModule>::Backup>,
) -> Pin<Box<dyn Future<Output = Result<(Self, u64)>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
New empty state to start recovery from, and session number to start from
sourcefn load_dbtx<'life0, 'life1, 'life2, 'life3, 'async_trait>(
init: &'life0 Self::Init,
dbtx: &'life1 mut DatabaseTransaction<'life2>,
args: &'life3 ClientModuleRecoverArgs<Self::Init>,
) -> Pin<Box<dyn Future<Output = Result<Option<(Self, RecoveryFromHistoryCommon)>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
fn load_dbtx<'life0, 'life1, 'life2, 'life3, 'async_trait>(
init: &'life0 Self::Init,
dbtx: &'life1 mut DatabaseTransaction<'life2>,
args: &'life3 ClientModuleRecoverArgs<Self::Init>,
) -> Pin<Box<dyn Future<Output = Result<Option<(Self, RecoveryFromHistoryCommon)>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
Try to load the existing state previously stored with
RecoveryFromHistory::store_dbtx
.
Storing and restoring progress is used to save progress and continue recovery if it was previously terminated before completion.
sourcefn store_dbtx<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
dbtx: &'life1 mut DatabaseTransaction<'life2>,
common: &'life3 RecoveryFromHistoryCommon,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
fn store_dbtx<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
dbtx: &'life1 mut DatabaseTransaction<'life2>,
common: &'life3 RecoveryFromHistoryCommon,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
Store the current recovery state in the database
See Self::load_dbtx
.
sourcefn delete_dbtx<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
dbtx: &'life1 mut DatabaseTransaction<'life2>,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn delete_dbtx<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
dbtx: &'life1 mut DatabaseTransaction<'life2>,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Delete the recovery state from the database
See Self::load_dbtx
.
sourcefn load_finalized<'life0, 'life1, 'async_trait>(
dbtx: &'life0 mut DatabaseTransaction<'life1>,
) -> Pin<Box<dyn Future<Output = Option<bool>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
fn load_finalized<'life0, 'life1, 'async_trait>(
dbtx: &'life0 mut DatabaseTransaction<'life1>,
) -> Pin<Box<dyn Future<Output = Option<bool>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Read the finalization status
See Self::load_dbtx
.
sourcefn store_finalized<'life0, 'life1, 'async_trait>(
dbtx: &'life0 mut DatabaseTransaction<'life1>,
state: bool,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
fn store_finalized<'life0, 'life1, 'async_trait>(
dbtx: &'life0 mut DatabaseTransaction<'life1>,
state: bool,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Store finalization status
See Self::load_finalized
.
sourcefn finalize_dbtx<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
dbtx: &'life1 mut DatabaseTransaction<'life2>,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn finalize_dbtx<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
dbtx: &'life1 mut DatabaseTransaction<'life2>,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Finalize the recovery converting the tracked state to final changes in the database.
This is the only place during recovery where module gets a chance to create state machines, etc.
Notably this function is running in a database-autocommit wrapper, so might be called again on database commit failure.
Provided Methods§
sourcefn handle_session<'life0, 'life1, 'life2, 'async_trait>(
&'life0 mut self,
client_ctx: &'life1 ClientContext<<Self::Init as ClientModuleInit>::Module>,
session_idx: u64,
session_items: &'life2 Vec<AcceptedItem>,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: Send + 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn handle_session<'life0, 'life1, 'life2, 'async_trait>(
&'life0 mut self,
client_ctx: &'life1 ClientContext<<Self::Init as ClientModuleInit>::Module>,
session_idx: u64,
session_items: &'life2 Vec<AcceptedItem>,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: Send + 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Handle session outcome, adjusting the current state
It is expected that most implementations don’t need to override this
function, and override more granular ones instead (e.g.
Self::handle_input
and/or Self::handle_output
).
The default implementation will loop through items in the
session.items
and forward them one by one to respective functions
(see Self::handle_transaction
).
sourcefn handle_transaction<'life0, 'life1, 'life2, 'async_trait>(
&'life0 mut self,
client_ctx: &'life1 ClientContext<<Self::Init as ClientModuleInit>::Module>,
transaction: &'life2 Transaction,
session_idx: u64,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: Send + 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn handle_transaction<'life0, 'life1, 'life2, 'async_trait>(
&'life0 mut self,
client_ctx: &'life1 ClientContext<<Self::Init as ClientModuleInit>::Module>,
transaction: &'life2 Transaction,
session_idx: u64,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: Send + 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Handle session outcome, adjusting the current state
It is expected that most implementations don’t need to override this
function, and override more granular ones instead (e.g.
Self::handle_input
and/or Self::handle_output
).
The default implementation will loop through inputs and outputs
of the transaction, filter and downcast ones matching current module
and forward them one by one to respective functions
(e.g. Self::handle_input
, Self::handle_output
).
sourcefn handle_input<'life0, 'life1, 'life2, 'async_trait>(
&'life0 mut self,
_client_ctx: &'life1 ClientContext<<Self::Init as ClientModuleInit>::Module>,
_idx: usize,
_input: &'life2 <<<Self::Init as ClientModuleInit>::Module as ClientModule>::Common as ModuleCommon>::Input,
_session_idx: u64,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: Send + 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn handle_input<'life0, 'life1, 'life2, 'async_trait>(
&'life0 mut self,
_client_ctx: &'life1 ClientContext<<Self::Init as ClientModuleInit>::Module>,
_idx: usize,
_input: &'life2 <<<Self::Init as ClientModuleInit>::Module as ClientModule>::Common as ModuleCommon>::Input,
_session_idx: u64,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: Send + 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Handle transaction input, adjusting the current state
Default implementation does nothing.
sourcefn handle_output<'life0, 'life1, 'life2, 'async_trait>(
&'life0 mut self,
_client_ctx: &'life1 ClientContext<<Self::Init as ClientModuleInit>::Module>,
_out_point: OutPoint,
_output: &'life2 <<<Self::Init as ClientModuleInit>::Module as ClientModule>::Common as ModuleCommon>::Output,
_session_idx: u64,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: Send + 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn handle_output<'life0, 'life1, 'life2, 'async_trait>(
&'life0 mut self,
_client_ctx: &'life1 ClientContext<<Self::Init as ClientModuleInit>::Module>,
_out_point: OutPoint,
_output: &'life2 <<<Self::Init as ClientModuleInit>::Module as ClientModule>::Common as ModuleCommon>::Output,
_session_idx: u64,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: Send + 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Handle transaction output, adjusting the current state
Default implementation does nothing.