mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-02-22 14:42:40 +01:00
wallet: Added helper to rewire HTLCs after loading from DB
This is a necessary evil since at the time we load `struct htlc_out` associated with a channel we might not have loaded the `struct htlc_in` that it depends on, so we defer the rewiring until we have loaded all HTLCs for all channels. At that point rewiring MUST work, otherwise we report a failure. Signed-off-by: Christian Decker <decker.christian@gmail.com>
This commit is contained in:
parent
c6f210a46c
commit
df9b8e22b4
2 changed files with 52 additions and 0 deletions
|
@ -1064,3 +1064,44 @@ bool wallet_htlcs_load_for_channel(struct wallet *wallet,
|
|||
|
||||
return ok;
|
||||
}
|
||||
|
||||
bool wallet_htlcs_reconnect(struct wallet *wallet,
|
||||
struct htlc_in_map *htlcs_in,
|
||||
struct htlc_out_map *htlcs_out)
|
||||
{
|
||||
struct htlc_in_map_iter ini;
|
||||
struct htlc_out_map_iter outi;
|
||||
struct htlc_in *hin;
|
||||
struct htlc_out *hout;
|
||||
|
||||
for (hout = htlc_out_map_first(htlcs_out, &outi); hout;
|
||||
hout = htlc_out_map_next(htlcs_out, &outi)) {
|
||||
|
||||
if (hout->origin_htlc_id == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
for (hin = htlc_in_map_first(htlcs_in, &ini); hin;
|
||||
hin = htlc_in_map_next(htlcs_in, &ini)) {
|
||||
if (hout->origin_htlc_id == hin->dbid) {
|
||||
log_debug(wallet->log,
|
||||
"Found corresponding htlc_in %" PRIu64
|
||||
" for htlc_out %" PRIu64,
|
||||
hin->dbid, hout->dbid);
|
||||
hout->in = hin;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!hout->in) {
|
||||
log_broken(
|
||||
wallet->log,
|
||||
"Unable to find corresponding htlc_in %" PRIu64
|
||||
" for htlc_out %" PRIu64,
|
||||
hout->origin_htlc_id, hout->dbid);
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -289,4 +289,15 @@ bool wallet_htlcs_load_for_channel(struct wallet *wallet,
|
|||
struct htlc_in_map *htlcs_in,
|
||||
struct htlc_out_map *htlcs_out);
|
||||
|
||||
/**
|
||||
* wallet_htlcs_reconnect -- Link outgoing HTLCs to their origins
|
||||
*
|
||||
* For each outgoing HTLC find the incoming HTLC that triggered it. If
|
||||
* we are the origin of the transfer then we cannot resolve the
|
||||
* incoming HTLC in which case we just leave it `NULL`.
|
||||
*/
|
||||
bool wallet_htlcs_reconnect(struct wallet *wallet,
|
||||
struct htlc_in_map *htlcs_in,
|
||||
struct htlc_out_map *htlcs_out);
|
||||
|
||||
#endif /* WALLET_WALLET_H */
|
||||
|
|
Loading…
Add table
Reference in a new issue