Plan to Increase Logging in Payments
@kevkevinpal tracking here.
Can we introduce Logging to activities on attempts to make invoice payments through the Sphinx Payment Architecture.
This will be to address issues where we have observed rare occurrences of a payment being made, failing and then the balance being deducted from the Sphinx App.
The plan would be to introduce three additional logging records for each of the attempts to pay an invoice so we can begin to track any specific balance issues.
ON SEND: Track the state of the balance on every attempt to make a payment. As I understand it he sphinx wallet will try this once and the LSP will attempt multiple retries if the first fails.
The idea is to track the state of the wallet prior to a send happening, this is like having a user write down their balance before they try and send. { SendID: // I'm assuming we might track a unique ID for each attempt to pay perhaps we track that here if we do. timestamps: timestamp // log time of send balance state: int. // Should be the balance of Pubkey account prior to sending invoice: string amount: int sphinxPubKey: // pubkey of account holder
}
ON SEND SUCCESS: Track the balance state immediately after we see the receipt of payment and preImage is received by our node. { SendID: // If we can track the specific Send that led to success we can track that to make reconcilliation easier. timestamps: timestamp // log time of success balance state: int // Check curent balance after successful payment - should be less than ON SEND invoice: string amount: int preImage: string // acts as a receipt so we know the funds were definitely received sphinxPubKey: // pubkey of account holder }
ON SEND FAIL: If a send fails. Then we will track the balance { SendID: // If we can track the specific Send that led to success we can track that to make reconcilliation easier. timestamps: timestamp // log time of fail balance state: int. // IF we refund the balance on the failed payment, we need to log the current balance state after payment refund - this hsould be the same as ON SEND - if not we could trigger an alert. invoice: string amount: int error: string // any error messages we are throwing. sphinxPubKey: // pubkey of account holder }
- From a single invoice we should then be able to see an entire timeline of sends, success and failures.
- If a hunter has a failed payment we should be able to track to the set of invoices, use the preimages to ensure receipt or not and see where the balance state os getting updated correctly or not.
Current implementation Logic:
- Balance is deducted on send
- Balance is then refunded when we know it is failed
- Balance could get out of sync if we don't get the failure reversal executed correctly
We could potentially reverse this logic.
or we could log and monitor figure out the frequency, triggers (e.g. channels down, restarts)
Current plan we should log first prior to updates.