interledgerjs / settlement-lightning

⚡️ Settle Interledger payments using the Lightning Network
Apache License 2.0
15 stars 4 forks source link

Retroactively credit incoming payments if notification failed #35

Open kincaidoneil opened 5 years ago

kincaidoneil commented 5 years ago

In the current implementation, the plugin must be online in order to credit an incoming Lightning payment. If the plugin is offline but the LND node is online, the sender may have sent a settlement, but it wouldn't be credited.

There should be a protocol or mechanism to retroactively credit settlements to get peers' balances back in sync if the receiver goes offline, then comes back online, or for some reason they fail to get the notification.

kincaidoneil commented 5 years ago

while ensuring no invoice is credited more than once

Persist the monotonically increasing settle_index and replay notifications beginning with the last one credited to ensure no invoice is credited more than once.

The plugin could iterate through previously paid invoices to ensure each was credited, and the counter ensures no invoice is credited more than once.

And, instead of persisting the invoices sent to each peer to determine which account each settled invoice should be credited to, require the counterparty to include their accountId in the memo field of the payment. (There might need to be a subprotocol to advertise, "hey, use this accountId if you send me any payments!")