@@ -30,14 +30,6 @@ import (
3030)
3131
3232var (
33-
34- // DummyGenesisTxOut is the dummy TxOut we'll place in the PSBt funding
35- // request to make sure we leave enough room for change and fees.
36- DummyGenesisTxOut = wire.TxOut {
37- PkScript : tapscript .GenesisDummyScript [:],
38- Value : int64 (GenesisAmtSats ),
39- }
40-
4133 // ErrGroupKeyUnknown is an error returned if an asset has a group key
4234 // attached that has not been previously verified.
4335 ErrGroupKeyUnknown = errors .New ("group key not known" )
@@ -402,7 +394,7 @@ func (b *BatchCaretaker) fundGenesisPsbt(ctx context.Context) (*FundedPsbt, erro
402394 b .batchKey [:])
403395
404396 txTemplate := wire .NewMsgTx (2 )
405- txTemplate .AddTxOut (& DummyGenesisTxOut )
397+ txTemplate .AddTxOut (tapscript . CreateDummyOutput () )
406398 genesisPkt , err := psbt .NewFromUnsignedTx (txTemplate )
407399 if err != nil {
408400 return nil , fmt .Errorf ("unable to make psbt packet: %w" , err )
@@ -411,26 +403,28 @@ func (b *BatchCaretaker) fundGenesisPsbt(ctx context.Context) (*FundedPsbt, erro
411403 log .Infof ("BatchCaretaker(%x): creating skeleton PSBT" , b .batchKey [:])
412404 log .Tracef ("PSBT: %v" , spew .Sdump (genesisPkt ))
413405
414- // If a fee rate was manually assigned for this batch, use that instead
415- // of a fee rate estimate.
416406 var feeRate chainfee.SatPerKWeight
417407 switch {
408+ // If a fee rate was manually assigned for this batch, use that instead
409+ // of a fee rate estimate.
418410 case b .cfg .BatchFeeRate != nil :
419411 feeRate = * b .cfg .BatchFeeRate
420- log .Infof ("BatchCaretaker(%x): using manual fee rate" ,
421- b .batchKey [:])
412+ log .Infof ("BatchCaretaker(%x): using manual fee rate: %s, %d " +
413+ "sat/vB" , b .batchKey [:], feeRate .String (),
414+ feeRate .FeePerKVByte ()/ 1000 )
422415
423416 default :
424417 feeRate , err = b .cfg .ChainBridge .EstimateFee (
425418 ctx , GenesisConfTarget ,
426419 )
427420 if err != nil {
428- return nil , fmt .Errorf ("unable to estimate fee: %w" , err )
421+ return nil , fmt .Errorf ("unable to estimate fee: %w" ,
422+ err )
429423 }
430- }
431424
432- log .Infof ("BatchCaretaker(%x): using fee rate: %v" ,
433- b .batchKey [:], feeRate .FeePerKVByte ().String ())
425+ log .Infof ("BatchCaretaker(%x): estimated fee rate: %s" ,
426+ b .batchKey [:], feeRate .FeePerKVByte ().String ())
427+ }
434428
435429 fundedGenesisPkt , err := b .cfg .Wallet .FundPsbt (
436430 ctx , genesisPkt , 1 , feeRate ,
@@ -755,17 +749,15 @@ func (b *BatchCaretaker) stateStep(currentState BatchState) (BatchState, error)
755749 b .cfg .Batch .GenesisPacket .Pkt = signedPkt
756750
757751 // Populate how much this tx paid in on-chain fees.
758- chainFees , err := GetTxFee (signedPkt )
752+ chainFees , err := signedPkt . GetTxFee ()
759753 if err != nil {
760754 return 0 , fmt .Errorf ("unable to get on-chain fees " +
761755 "for psbt: %w" , err )
762756 }
763- b .cfg .Batch .GenesisPacket .ChainFees = chainFees
757+ b .cfg .Batch .GenesisPacket .ChainFees = int64 ( chainFees )
764758
765- log .Infof ("BatchCaretaker(%x): GenesisPacket absolute fee: " +
766- "%d sats" , b .batchKey [:], chainFees )
767- log .Infof ("BatchCaretaker(%x): GenesisPacket finalized" ,
768- b .batchKey [:])
759+ log .Infof ("BatchCaretaker(%x): GenesisPacket finalized " +
760+ "(absolute_fee_sats: %d)" , b .batchKey [:], chainFees )
769761 log .Tracef ("GenesisPacket: %v" , spew .Sdump (signedPkt ))
770762
771763 // At this point we have a fully signed PSBT packet which'll
@@ -1344,21 +1336,6 @@ func SortAssets(fullAssets []*asset.Asset,
13441336 return anchorAssets , nonAnchorAssets , nil
13451337}
13461338
1347- // GetTxFee returns the value of the on-chain fees paid by a finalized PSBT.
1348- func GetTxFee (pkt * psbt.Packet ) (int64 , error ) {
1349- inputValue , err := psbt .SumUtxoInputValues (pkt )
1350- if err != nil {
1351- return 0 , fmt .Errorf ("unable to sum input values: %v" , err )
1352- }
1353-
1354- outputValue := int64 (0 )
1355- for _ , out := range pkt .UnsignedTx .TxOut {
1356- outputValue += out .Value
1357- }
1358-
1359- return inputValue - outputValue , nil
1360- }
1361-
13621339// GenHeaderVerifier generates a block header on-chain verification callback
13631340// function given a chain bridge.
13641341func GenHeaderVerifier (ctx context.Context ,
0 commit comments