Skip to content

Commit 5e5b177

Browse files
committed
(to squash) sweepbatcher: add mode with presigned transactions
1 parent 959c96a commit 5e5b177

File tree

5 files changed

+77
-18
lines changed

5 files changed

+77
-18
lines changed

sweepbatcher/presigned.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,11 @@ func presign(ctx context.Context, presigner presigner, destAddr btcutil.Address,
340340
)
341341

342342
// Calculate the locktime value to use for high feerate transactions.
343-
highFeeRateLockTime := uint32(timeout - timeoutThreshold)
343+
// If timeout <= timeoutThreshold, don't set LockTime (keep value 0).
344+
var highFeeRateLockTime uint32
345+
if timeout > timeoutThreshold {
346+
highFeeRateLockTime = uint32(timeout - timeoutThreshold)
347+
}
344348

345349
// Calculate which feerate to consider high. At least 100 sat/vbyte and
346350
// at least 10x of current nextBlockFeeRate.
@@ -487,7 +491,8 @@ func (b *batch) publishPresigned(ctx context.Context) (btcutil.Amount, error,
487491
numSweeps := len(tx.TxIn)
488492
b.Infof("attempting to publish custom signed tx=%v, desiredFeerate=%v,"+
489493
" signedFeeRate=%v, weight=%v, fee=%v, sweeps=%d, destAddr=%s",
490-
txHash, feeRate, signedFeeRate, weight, fee, numSweeps, address)
494+
txHash, feeRate, signedFeeRate, realWeight, fee, numSweeps,
495+
address)
491496
b.debugLogTx("serialized batch", tx)
492497

493498
// Publish the transaction.

sweepbatcher/presigned_test.go

Lines changed: 68 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -714,7 +714,37 @@ func TestPresign(t *testing.T) {
714714
},
715715

716716
{
717-
name: "two coop sweeps",
717+
name: "one sweep",
718+
presigner: &mockPresigner{},
719+
primarySweepID: op1,
720+
sweeps: []sweep{
721+
{
722+
outpoint: op1,
723+
value: 1_000_000,
724+
timeout: 1000,
725+
},
726+
},
727+
destAddr: destAddr,
728+
nextBlockFeeRate: chainfee.FeePerKwFloor,
729+
wantOutputs: []btcutil.Amount{
730+
999900, 999880, 999856, 999827, 999793, 999752,
731+
999702, 999643, 999572, 999486, 999384, 999260,
732+
999113, 998935, 998723, 998467, 998161, 997793,
733+
997352, 996823, 996187, 995425, 994510, 993413,
734+
992096, 990515, 988618, 986342, 983610, 980332,
735+
976399, 971679, 966015, 959218, 951062, 941274,
736+
929530, 915435, 898523, 878227, 853873, 824648,
737+
},
738+
wantLockTimes: []uint32{
739+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
740+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 950, 950, 950,
741+
950, 950, 950, 950, 950, 950, 950, 950, 950,
742+
950, 950, 950, 950,
743+
},
744+
},
745+
746+
{
747+
name: "two sweeps",
718748
presigner: &mockPresigner{},
719749
primarySweepID: op1,
720750
sweeps: []sweep{
@@ -751,7 +781,7 @@ func TestPresign(t *testing.T) {
751781
},
752782

753783
{
754-
name: "two coop sweeps, another primary",
784+
name: "two sweeps, another primary",
755785
presigner: &mockPresigner{},
756786
primarySweepID: op2,
757787
sweeps: []sweep{
@@ -787,6 +817,42 @@ func TestPresign(t *testing.T) {
787817
},
788818
},
789819

820+
{
821+
name: "timeout < 50",
822+
presigner: &mockPresigner{},
823+
primarySweepID: op1,
824+
sweeps: []sweep{
825+
{
826+
outpoint: op1,
827+
value: 1_000_000,
828+
timeout: 40,
829+
},
830+
{
831+
outpoint: op2,
832+
value: 2_000_000,
833+
timeout: 40,
834+
},
835+
},
836+
destAddr: destAddr,
837+
nextBlockFeeRate: 50 * chainfee.FeePerKwFloor,
838+
wantOutputs: []btcutil.Amount{
839+
2999841, 2999810, 2999773, 2999728, 2999673,
840+
2999608, 2999530, 2999436, 2999323, 2999188,
841+
2999026, 2998831, 2998598, 2998317, 2997981,
842+
2997577, 2997093, 2996512, 2995814, 2994977,
843+
2993973, 2992768, 2991322, 2989587, 2987505,
844+
2985006, 2982007, 2978409, 2974091, 2968910,
845+
2962691, 2955230, 2946276, 2935532, 2922639,
846+
2907167, 2888600, 2866320, 2839584, 2807501,
847+
2769001, 2722802,
848+
},
849+
wantLockTimes: []uint32{
850+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
851+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
852+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
853+
},
854+
},
855+
790856
{
791857
name: "high current feerate => locktime later",
792858
presigner: &mockPresigner{},

sweepbatcher/sweep_batch.go

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -662,18 +662,6 @@ func (b *batch) addSweeps(ctx context.Context, sweeps []*sweep) (bool, error) {
662662
" this input: %v",
663663
sweeps[0].swapHash[:6], err)
664664

665-
return false, nil
666-
}
667-
}
668-
} else {
669-
// Ensure that all the sweeps in the batch don't use presigned.
670-
for _, s := range b.sweeps {
671-
if s.presigned {
672-
b.Warnf("failed to add a non-presigned sweep "+
673-
"%x to the batch, because the batch "+
674-
"has presigned sweep %x",
675-
sweeps[0].swapHash[:6], s.swapHash[:6])
676-
677665
return false, nil
678666
}
679667
}

sweepbatcher/sweep_batcher.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -718,7 +718,7 @@ func (b *Batcher) PresignSweepsGroup(ctx context.Context, inputs []Input,
718718
// and adds them to the batcher for handling. This will either place the sweep
719719
// in an existing batch or create a new one. The method can be called multiple
720720
// times, but the sweeps (including the order of them) must be the same. If
721-
// notifier is provided, the batcher sends back sweeping results though it.
721+
// notifier is provided, the batcher sends back sweeping results through it.
722722
func (b *Batcher) AddSweep(ctx context.Context, sweepReq *SweepRequest) error {
723723
// If the batcher is shutting down, quit now.
724724
select {

sweepbatcher/sweep_batcher_presigned_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ func (h *mockPresignedHelper) FetchSweep(_ context.Context,
243243
}
244244

245245
// testPresigned_forgotten_presign checks that adding sweeps causes the batcher
246-
// to fail of the sweeps were not presigned with PresignSweepsGroup. In addition
246+
// to fail if the sweeps were not presigned with PresignSweepsGroup. In addition
247247
// to that it checks that PresignSweepsGroup fails if the outpoint is offline.
248248
func testPresigned_forgotten_presign(t *testing.T,
249249
batcherStore testBatcherStore) {

0 commit comments

Comments
 (0)