-
Notifications
You must be signed in to change notification settings - Fork 118
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Loop Out Sweep Batcher #634
Conversation
9b82ff8
to
6429806
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did a first pass. As far as I can understand it it seems like an elegant approach.
However I'm not sure if the batcher is restart safe. E.g. what would happen if we have an inflight batch and restart loop. If no RBF of 'new' (but already broadcasted) sweeps would be braodcasted, would the confirmation logic be able to handle that?
6429806
to
be05283
Compare
ac3d79e
to
2f3bce1
Compare
95938d0
to
fc13d50
Compare
f5fc60f
to
3adf5aa
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really great work @GeorgeTsagk, your code comments help reviewing this PR. I will go over the functionality of this PR again more throughly - so far I got nits and questions for you :D
3adf5aa
to
844f27e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added some more comments but will hold back with further review until design Qs are ironed out.
844f27e
to
d82674a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Partial review, more is coming.
loopdb/batch.go
Outdated
ID int32 | ||
|
||
// BatchID is the ID of the batch that the sweep belongs to. | ||
BatchID lntypes.Hash |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not store a slice of sweeps in the Batch
object instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still applies.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we're storing sweeps in their own table it seems simpler to me to separate them in the loopdb models.
In the application level (sweepbatcher
pkg) sweeps are indeed stored within a batch
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reflecting the database scheme on the application level will add complexity to the application code. I advise not doing so.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the application level (sweepbatcher pkg) sweeps are indeed stored within a batch
I think this aligns with what you just said.
I am only keeping batches/sweeps separate in the loopdb
level (I consider loopdb
to not be application code..?)
batcher/sweep_batch.go
Outdated
Value: int64(batchAmt - fee), | ||
}) | ||
|
||
packet, err := psbt.NewFromUnsignedTx(batchTx) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we'd also need to sort the inputs and outputs to conform to BIP-69. AFAICT psbt lib doesn't do that.
txsort.InPlaceSort(batchTx)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is still an issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was this discussed offline? Marked as resolved but can't find the sorting
d82674a
to
e50afef
Compare
Ty for the review @bhandras Just pushed some changes, mostly affecting test files |
1a71384
to
b910c03
Compare
85580fb
to
53129d2
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Getting close, great work on this last push!
executor.go
Outdated
@@ -121,6 +125,20 @@ func (s *executor) run(mainCtx context.Context, | |||
return mainCtx.Err() | |||
} | |||
|
|||
batcherErrChan = make(chan error, 1) | |||
batcherCtx, cancel := context.WithCancel(mainCtx) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So what I meant is that it's fine to just call s.batcher.Run(mainCtx)
.
0fc4e68
to
fec3c5c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks ripe! Nice work @GeorgeTsagk 🥇
A few last nits from my side.
fec3c5c
to
aa4427b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, great work @GeorgeTsagk ⚡ ⚡
case <-ctx.Done(): | ||
} | ||
|
||
_ = b.writeToErrChan(ctx, err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
q: Do we need to add this error to the batcher's error channel? It'll stop the batcher altogether.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, not sure. If we don't it will only fail on the batch/swap level. One reason to error out the whole daemon is that a restart may fix the monitor spend issue. But that could also "deadlock" the whole daemon just for the sake of 1 swap
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Congrats on the big PR.
I have a small set of nits that would be nice to haves.
|
||
// If the provided sweep is nil, we can't proceed with any checks, so | ||
// we just return early. | ||
if sweep == nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why could a sweep be nil?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
idk, always nice to check?
// To be sure that we're good, parse and validate that the | ||
// combined signature is indeed valid for the sig hash and the | ||
// internal pubkey. | ||
err = b.verifySchnorrSig( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: combine sigs already checks if the sig is valid. removing the b.verifySchnorrSig
part removes some code in this PR so i deem it worthy to remove.
See https://github.com/btcsuite/btcd/blob/master/btcec/schnorr/musig2/context.go#L650, which is called from https://github.com/lightningnetwork/lnd/blob/7d03b43ddfa11674a5002b4ecb5516ccc99f5303/input/musig2.go#L510
@@ -162,27 +164,36 @@ func NewClient(dbDir string, loopDB loopdb.SwapStore, | |||
Lnd: cfg.Lnd, | |||
} | |||
|
|||
verifySchnorrSig := func(pubKey *btcec.PublicKey, hash, sig []byte) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this could be removed, as we verify the sig when combining.
does this need a release notes comment? |
any readme notes needed on config settings? |
aa4427b
to
33fdde9
Compare
Description
This PR adds a batcher for loop out htlc sweeps.
ToDo
Also closes #675, this change was required due to the increased demands from our mocking interfaces with the introduction of the sweepbatcher