mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-24 01:24:26 +01:00
daemon: handle HTLC as per BOLT #2 algorithm.
From BOLT#2 (rev 8ee09e749990a11fa53bea03d5961cfde4be4616): Thus each node (conceptually) tracks: ... 3. Two *unacked changesets*: one for the local commitment (their proposals) and one for the remote (our proposals) 4. Two *acked changesets*: one for the local commitment (our proposals, acknowledged) and one for the remote (their proposals, acknowledged). (Note that an implementation MAY optimize this internally, for example, pre-applying the changesets in some cases). In our case, we apply the unacked changes immediately into staging_cstate, and save them in an unacked_changes array. That array gets applied to staging_cstate as soon as it's acked (we only allow one outstanding update_commit, so we only need one array). Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
@@ -84,8 +84,11 @@ struct peer_visible_state {
|
||||
struct sha256 next_revocation_hash;
|
||||
/* Commit txs: last one is current. */
|
||||
struct commit_info *commit;
|
||||
|
||||
/* cstate to generate next commitment tx. */
|
||||
struct channel_state *staging_cstate;
|
||||
/* unacked changes (already applied to staging_cstate) */
|
||||
union htlc_staging *unacked_changes;
|
||||
};
|
||||
|
||||
struct htlc_progress {
|
||||
@@ -236,6 +239,13 @@ void set_peer_state(struct peer *peer, enum state newstate, const char *why);
|
||||
/* Call this after commit changes, or revocation accepted/sent. */
|
||||
void peer_check_if_cleared(struct peer *peer);
|
||||
|
||||
/* Set up timer: we have something we can commit. */
|
||||
void remote_changes_pending(struct peer *peer);
|
||||
|
||||
/* Add this unacked change */
|
||||
void add_unacked(struct peer_visible_state *which,
|
||||
const union htlc_staging *stage);
|
||||
|
||||
void peer_add_htlc_expiry(struct peer *peer,
|
||||
const struct abs_locktime *expiry);
|
||||
|
||||
@@ -244,8 +254,5 @@ struct bitcoin_tx *peer_create_close_tx(struct peer *peer, u64 fee);
|
||||
uint64_t commit_tx_fee(const struct bitcoin_tx *commit,
|
||||
uint64_t anchor_satoshis);
|
||||
|
||||
/* We have something pending for them. */
|
||||
void their_commit_changed(struct peer *peer);
|
||||
|
||||
bool resolve_one_htlc(struct peer *peer, u64 id, const struct sha256 *preimage);
|
||||
#endif /* LIGHTNING_DAEMON_PEER_H */
|
||||
|
||||
Reference in New Issue
Block a user