@@ -759,6 +759,10 @@ func (s *covenantlessService) UpdateTxRequestStatus(_ context.Context, id string
759
759
}
760
760
761
761
func (s * covenantlessService ) SignVtxos (ctx context.Context , forfeitTxs []string ) error {
762
+ if len (forfeitTxs ) <= 0 {
763
+ return nil
764
+ }
765
+
762
766
if err := s .forfeitTxs .sign (forfeitTxs ); err != nil {
763
767
return err
764
768
}
@@ -774,6 +778,14 @@ func (s *covenantlessService) SignVtxos(ctx context.Context, forfeitTxs []string
774
778
}
775
779
776
780
func (s * covenantlessService ) SignRoundTx (ctx context.Context , signedRoundTx string ) error {
781
+ numSignedInputs , err := s .builder .CountSignedTaprootInputs (signedRoundTx )
782
+ if err != nil {
783
+ return fmt .Errorf ("failed to count number of signed boarding inputs: %s" , err )
784
+ }
785
+ if numSignedInputs == 0 {
786
+ return nil
787
+ }
788
+
777
789
s .currentRoundLock .Lock ()
778
790
defer s .currentRoundLock .Unlock ()
779
791
currentRound := s .currentRound
@@ -1469,68 +1481,95 @@ func (s *covenantlessService) finalizeRound(notes []note.Note, roundEndTime time
1469
1481
}
1470
1482
}()
1471
1483
1472
- remainingTime := time .Until (roundEndTime )
1473
- select {
1474
- case <- s .forfeitsBoardingSigsChan :
1475
- log .Debug ("all forfeit txs and boarding inputs signatures have been sent" )
1476
- case <- time .After (remainingTime ):
1477
- log .Debug ("timeout waiting for forfeit txs and boarding inputs signatures" )
1478
- }
1479
-
1480
- forfeitTxs , err := s .forfeitTxs .pop ()
1481
- if err != nil {
1482
- changes = round .Fail (fmt .Errorf ("failed to finalize round: %s" , err ))
1483
- log .WithError (err ).Warn ("failed to finalize round" )
1484
- return
1485
- }
1486
-
1487
- if err := s .verifyForfeitTxsSigs (forfeitTxs ); err != nil {
1488
- changes = round .Fail (err )
1489
- log .WithError (err ).Warn ("failed to validate forfeit txs" )
1490
- return
1491
- }
1492
-
1493
- log .Debugf ("signing round transaction %s\n " , round .Id )
1494
-
1495
- boardingInputsIndexes := make ([]int , 0 )
1496
- boardingInputs := make ([]domain.VtxoKey , 0 )
1497
1484
roundTx , err := psbt .NewFromRawBytes (strings .NewReader (round .UnsignedTx ), true )
1498
1485
if err != nil {
1499
1486
log .Debugf ("failed to parse round tx: %s" , round .UnsignedTx )
1500
1487
changes = round .Fail (fmt .Errorf ("failed to parse round tx: %s" , err ))
1501
1488
log .WithError (err ).Warn ("failed to parse round tx" )
1502
1489
return
1503
1490
}
1491
+ includesBoardingInputs := false
1492
+ for _ , in := range roundTx .Inputs {
1493
+ // TODO: this is ok as long as the server doesn't use taproot address too!
1494
+ // We need to find a better way to understand if an in input is ours or if
1495
+ // it's a boarding one.
1496
+ scriptType := txscript .GetScriptClass (in .WitnessUtxo .PkScript )
1497
+ if scriptType == txscript .WitnessV1TaprootTy {
1498
+ includesBoardingInputs = true
1499
+ break
1500
+ }
1501
+ }
1504
1502
1505
- for i , in := range roundTx .Inputs {
1506
- if len (in .TaprootLeafScript ) > 0 {
1507
- if len (in .TaprootScriptSpendSig ) == 0 {
1508
- err = fmt .Errorf ("missing tapscript spend sig for input %d" , i )
1509
- changes = round .Fail (err )
1510
- log .WithError (err ).Warn ("missing boarding sig" )
1511
- return
1512
- }
1503
+ txToSign := round .UnsignedTx
1504
+ boardingInputs := make ([]domain.VtxoKey , 0 )
1505
+ forfeitTxs := make ([]string , 0 )
1513
1506
1514
- boardingInputsIndexes = append (boardingInputsIndexes , i )
1515
- boardingInputs = append (boardingInputs , domain.VtxoKey {
1516
- Txid : roundTx .UnsignedTx .TxIn [i ].PreviousOutPoint .Hash .String (),
1517
- VOut : roundTx .UnsignedTx .TxIn [i ].PreviousOutPoint .Index ,
1518
- })
1507
+ if len (s .forfeitTxs .forfeitTxs ) > 0 || includesBoardingInputs {
1508
+ remainingTime := time .Until (roundEndTime )
1509
+ select {
1510
+ case <- s .forfeitsBoardingSigsChan :
1511
+ log .Debug ("all forfeit txs and boarding inputs signatures have been sent" )
1512
+ case <- time .After (remainingTime ):
1513
+ log .Debug ("timeout waiting for forfeit txs and boarding inputs signatures" )
1519
1514
}
1520
- }
1521
1515
1522
- signedRoundTx := round .UnsignedTx
1516
+ s .currentRoundLock .Lock ()
1517
+ round := s .currentRound
1518
+ s .currentRoundLock .Unlock ()
1519
+
1520
+ roundTx , err := psbt .NewFromRawBytes (strings .NewReader (round .UnsignedTx ), true )
1521
+ if err != nil {
1522
+ log .Debugf ("failed to parse round tx: %s" , round .UnsignedTx )
1523
+ changes = round .Fail (fmt .Errorf ("failed to parse round tx: %s" , err ))
1524
+ log .WithError (err ).Warn ("failed to parse round tx" )
1525
+ return
1526
+ }
1527
+ txToSign = round .UnsignedTx
1523
1528
1524
- if len (boardingInputsIndexes ) > 0 {
1525
- signedRoundTx , err = s .wallet .SignTransactionTapscript (ctx , signedRoundTx , boardingInputsIndexes )
1529
+ forfeitTxs , err = s .forfeitTxs .pop ()
1526
1530
if err != nil {
1527
- changes = round .Fail (fmt .Errorf ("failed to sign round tx: %s" , err ))
1528
- log .WithError (err ).Warn ("failed to sign round tx" )
1531
+ changes = round .Fail (fmt .Errorf ("failed to finalize round: %s" , err ))
1532
+ log .WithError (err ).Warn ("failed to finalize round" )
1533
+ return
1534
+ }
1535
+
1536
+ if err := s .verifyForfeitTxsSigs (forfeitTxs ); err != nil {
1537
+ changes = round .Fail (err )
1538
+ log .WithError (err ).Warn ("failed to validate forfeit txs" )
1529
1539
return
1530
1540
}
1541
+
1542
+ boardingInputsIndexes := make ([]int , 0 )
1543
+ for i , in := range roundTx .Inputs {
1544
+ if len (in .TaprootLeafScript ) > 0 {
1545
+ if len (in .TaprootScriptSpendSig ) == 0 {
1546
+ err = fmt .Errorf ("missing tapscript spend sig for input %d" , i )
1547
+ changes = round .Fail (err )
1548
+ log .WithError (err ).Warn ("missing boarding sig" )
1549
+ return
1550
+ }
1551
+
1552
+ boardingInputsIndexes = append (boardingInputsIndexes , i )
1553
+ boardingInputs = append (boardingInputs , domain.VtxoKey {
1554
+ Txid : roundTx .UnsignedTx .TxIn [i ].PreviousOutPoint .Hash .String (),
1555
+ VOut : roundTx .UnsignedTx .TxIn [i ].PreviousOutPoint .Index ,
1556
+ })
1557
+ }
1558
+ }
1559
+
1560
+ if len (boardingInputsIndexes ) > 0 {
1561
+ txToSign , err = s .wallet .SignTransactionTapscript (ctx , txToSign , boardingInputsIndexes )
1562
+ if err != nil {
1563
+ changes = round .Fail (fmt .Errorf ("failed to sign round tx: %s" , err ))
1564
+ log .WithError (err ).Warn ("failed to sign round tx" )
1565
+ return
1566
+ }
1567
+ }
1531
1568
}
1532
1569
1533
- signedRoundTx , err = s .wallet .SignTransaction (ctx , signedRoundTx , true )
1570
+ log .Debugf ("signing transaction %s\n " , round .Id )
1571
+
1572
+ signedRoundTx , err := s .wallet .SignTransaction (ctx , txToSign , true )
1534
1573
if err != nil {
1535
1574
changes = round .Fail (fmt .Errorf ("failed to sign round tx: %s" , err ))
1536
1575
log .WithError (err ).Warn ("failed to sign round tx" )
0 commit comments