Skip to content

Commit 1d4fd56

Browse files
committed
. review fixes
1 parent 418bd2d commit 1d4fd56

File tree

3 files changed

+35
-19
lines changed

3 files changed

+35
-19
lines changed

sweepbatcher/presigned.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ func (b *batch) presign(ctx context.Context, newSweep *sweep) error {
8989
return fmt.Errorf("failed to get nextBlockFeerate: %w", err)
9090
}
9191

92-
b.log().Infof("nextBlockFeerate is %v", nextBlockFeerate)
92+
b.Infof("nextBlockFeerate is %v", nextBlockFeerate)
9393

9494
// Create the list of sweeps of the future batch.
9595
sweeps := make([]sweep, 0, len(b.sweeps)+1)
@@ -294,7 +294,7 @@ func (b *batch) publishPresigned(ctx context.Context) (btcutil.Amount, error,
294294
blockchain.GetTransactionWeight(btcutil.NewTx(tx)),
295295
)
296296
if realWeight != weight {
297-
b.log().Warnf("actual weight of tx %v is %v, estimated as %d",
297+
b.Warnf("actual weight of tx %v is %v, estimated as %d",
298298
txHash, realWeight, weight)
299299
}
300300

@@ -304,10 +304,10 @@ func (b *batch) publishPresigned(ctx context.Context) (btcutil.Amount, error,
304304
fee = batchAmt - output
305305
signedFeeRate := chainfee.NewSatPerKWeight(fee, realWeight)
306306

307-
b.log().Infof("attempting to publish custom signed tx=%v, "+
308-
"desiredFeerate=%v, signedFeeRate=%v, weight=%v, fee=%v, "+
309-
"sweeps=%d, destAddr=%s", txHash, feeRate, signedFeeRate,
310-
weight, fee, len(tx.TxIn), address)
307+
numSweeps := len(tx.TxIn)
308+
b.Infof("attempting to publish custom signed tx=%v, desiredFeerate=%v,"+
309+
" signedFeeRate=%v, weight=%v, fee=%v, sweeps=%d, destAddr=%s",
310+
txHash, feeRate, signedFeeRate, weight, fee, numSweeps, address)
311311
b.debugLogTx("serialized batch", tx)
312312

313313
// Publish the transaction.

sweepbatcher/sweep_batch.go

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -587,8 +587,8 @@ func (b *batch) addSweep(ctx context.Context, sweep *sweep) (bool, error) {
587587
// Ensure that all the sweeps in the batch use presigned mode.
588588
for _, s := range b.sweeps {
589589
if !s.presigned {
590-
b.log().Infof("failed to add sweep %x to the "+
591-
"batch, because the batch has "+
590+
b.Infof("failed to add presigned sweep %x to "+
591+
"the batch, because the batch has "+
592592
"non-presigned sweep %x",
593593
sweep.swapHash[:6], s.swapHash[:6])
594594

@@ -598,7 +598,7 @@ func (b *batch) addSweep(ctx context.Context, sweep *sweep) (bool, error) {
598598

599599
if len(b.sweeps) != 0 {
600600
if err := b.presign(ctx, sweep); err != nil {
601-
b.log().Infof("failed to add sweep %x to the "+
601+
b.Infof("failed to add sweep %x to the "+
602602
"batch, because failed to presign new "+
603603
"version of batch tx: %v",
604604
sweep.swapHash[:6], err)
@@ -618,9 +618,9 @@ func (b *batch) addSweep(ctx context.Context, sweep *sweep) (bool, error) {
618618
// Ensure that all the sweeps in the batch don't use presigned.
619619
for _, s := range b.sweeps {
620620
if s.presigned {
621-
b.log().Infof("failed to add sweep %x to the "+
622-
"batch, because the batch has "+
623-
"presigned sweep %x",
621+
b.Infof("failed to add a non-presigned sweep "+
622+
"%x to the batch, because the batch "+
623+
"has presigned sweep %x",
624624
sweep.swapHash[:6], s.swapHash[:6])
625625

626626
return false, nil
@@ -927,19 +927,35 @@ func (b *batch) isUrgent(skipBefore time.Time) bool {
927927

928928
// isPresigned returns if the batch uses presigned mode. Currently presigned and
929929
// non-presigned sweeps never appear in the same batch. Fails if the batch is
930-
// empty.
930+
// empty or contains both presigned and regular sweeps.
931931
func (b *batch) isPresigned() (bool, error) {
932-
if len(b.sweeps) == 0 {
933-
return false, fmt.Errorf("the batch is empty")
934-
}
932+
var (
933+
hasPresigned bool
934+
hasRegular bool
935+
)
935936

936937
for _, sweep := range b.sweeps {
937938
if sweep.presigned {
938-
return true, nil
939+
hasPresigned = true
940+
} else {
941+
hasRegular = true
939942
}
940943
}
941944

942-
return false, nil
945+
switch {
946+
case hasPresigned && !hasRegular:
947+
return true, nil
948+
949+
case !hasPresigned && hasRegular:
950+
return false, nil
951+
952+
case hasPresigned && hasRegular:
953+
return false, fmt.Errorf("the batch has both presigned and " +
954+
"non-presigned sweeps")
955+
956+
default:
957+
return false, fmt.Errorf("the batch is empty")
958+
}
943959
}
944960

945961
// publish creates and publishes the latest batch transaction to the network.

sweepbatcher/sweep_batcher.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -643,7 +643,7 @@ func (b *Batcher) PresignSweep(ctx context.Context, sweepOutpoint wire.OutPoint,
643643
if err != nil {
644644
return fmt.Errorf("failed to get nextBlockFeerate: %w", err)
645645
}
646-
log().Infof("nextBlockFeerate is %v", nextBlockFeerate)
646+
infof("nextBlockFeerate is %v", nextBlockFeerate)
647647

648648
sweeps := []sweep{
649649
{

0 commit comments

Comments
 (0)