multi: add preimage push to loop out after sweep attempt

Once we have revealed our preimage to the world with a sweep attempt,
we can safely push our preimage to the server to speed up on chain
claim.

Rather than rely on the server, we use the state of our invoice in lnd
to determine whether we should continue trying to push the preimage to
the server.
This commit is contained in:
carla 2020-06-02 09:31:39 +02:00
parent 488df785e0
commit 65c847674d
No known key found for this signature in database
GPG key ID: 4CA7FE54A6213C91
11 changed files with 600 additions and 72 deletions

View file

@ -36,6 +36,9 @@ type serverMock struct {
swapInvoice string
swapHash lntypes.Hash
// preimagePush is a channel that preimage pushes are sent into.
preimagePush chan lntypes.Preimage
}
var _ swapServerClient = (*serverMock)(nil)
@ -49,6 +52,8 @@ func newServerMock() *serverMock {
prepayInvoiceAmt: 100,
height: 600,
preimagePush: make(chan lntypes.Preimage),
}
}
@ -151,6 +156,15 @@ func (s *serverMock) NewLoopInSwap(ctx context.Context,
return resp, nil
}
func (s *serverMock) PushLoopOutPreimage(_ context.Context,
preimage lntypes.Preimage) error {
// Push the preimage into the mock's preimage channel.
s.preimagePush <- preimage
return nil
}
func (s *serverMock) GetLoopInTerms(ctx context.Context) (
*LoopInTerms, error) {