mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-09-06 17:47:01 +02:00
contractcourt: persist remote outgoing htlc claim outcome on disk
When a remote peer claims one of our outgoing htlcs on chain, we do not care whether they claimed with multiple stages. We simply store the claim outgome then forget the resolver.
This commit is contained in:
@@ -11,6 +11,7 @@ import (
|
||||
"github.com/lightningnetwork/lnd/input"
|
||||
"github.com/lightningnetwork/lnd/lntypes"
|
||||
"github.com/lightningnetwork/lnd/lnwallet"
|
||||
"github.com/lightningnetwork/lnd/lnwire"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -47,22 +48,43 @@ func TestHtlcOutgoingResolverRemoteClaim(t *testing.T) {
|
||||
// Setup the resolver with our test resolution and start the resolution
|
||||
// process.
|
||||
ctx := newOutgoingResolverTestContext(t)
|
||||
|
||||
// Replace our mocked checkpoint function with one which will push
|
||||
// reports into a channel for us to consume. We do so on the resolver
|
||||
// level because our test context has already created the resolver.
|
||||
reportChan := make(chan *channeldb.ResolverReport)
|
||||
ctx.resolver.Checkpoint = func(_ ContractResolver,
|
||||
reports ...*channeldb.ResolverReport) error {
|
||||
|
||||
// Send all of our reports into the channel.
|
||||
for _, report := range reports {
|
||||
reportChan <- report
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
ctx.resolve()
|
||||
|
||||
// The remote party sweeps the htlc. Notify our resolver of this event.
|
||||
preimage := lntypes.Preimage{}
|
||||
ctx.notifier.spendChan <- &chainntnfs.SpendDetail{
|
||||
SpendingTx: &wire.MsgTx{
|
||||
TxIn: []*wire.TxIn{
|
||||
{
|
||||
Witness: [][]byte{
|
||||
{0}, {1}, {2}, preimage[:],
|
||||
},
|
||||
spendTx := &wire.MsgTx{
|
||||
TxIn: []*wire.TxIn{
|
||||
{
|
||||
Witness: [][]byte{
|
||||
{0}, {1}, {2}, preimage[:],
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
spendHash := spendTx.TxHash()
|
||||
|
||||
ctx.notifier.spendChan <- &chainntnfs.SpendDetail{
|
||||
SpendingTx: spendTx,
|
||||
SpenderTxHash: &spendHash,
|
||||
}
|
||||
|
||||
// We expect the extracted preimage to be added to the witness beacon.
|
||||
<-ctx.preimageDB.newPreimages
|
||||
|
||||
@@ -70,6 +92,17 @@ func TestHtlcOutgoingResolverRemoteClaim(t *testing.T) {
|
||||
// circuit.
|
||||
<-ctx.resolutionChan
|
||||
|
||||
// Finally, check that we have a report as expected.
|
||||
expectedReport := &channeldb.ResolverReport{
|
||||
OutPoint: wire.OutPoint{},
|
||||
Amount: 0,
|
||||
ResolverType: channeldb.ResolverTypeOutgoingHtlc,
|
||||
ResolverOutcome: channeldb.ResolverOutcomeClaimed,
|
||||
SpendTxID: &spendHash,
|
||||
}
|
||||
|
||||
assertResolverReport(t, reportChan, expectedReport)
|
||||
|
||||
// Assert that the resolver finishes without error.
|
||||
ctx.waitForResult(false)
|
||||
}
|
||||
@@ -147,6 +180,7 @@ func newOutgoingResolverTestContext(t *testing.T) *outgoingResolverTestContext {
|
||||
contractResolverKit: *newContractResolverKit(cfg),
|
||||
htlcResolution: outgoingRes,
|
||||
htlc: channeldb.HTLC{
|
||||
Amt: lnwire.MilliSatoshi(testHtlcAmount),
|
||||
RHash: testResHash,
|
||||
OnionBlob: testOnionBlob,
|
||||
},
|
||||
|
Reference in New Issue
Block a user