2
0
mirror of https://github.com/lightninglabs/loop synced 2024-11-16 00:12:52 +00:00

sweepbatcher: fix too long lines

This commit is contained in:
Boris Nagaev 2024-05-28 22:35:08 -03:00
parent 0b2c177445
commit 4258b95dd2
No known key found for this signature in database
5 changed files with 28 additions and 17 deletions

View File

@ -17,7 +17,8 @@ func init() {
UseLogger(build.NewSubLogger("SWEEP", nil)) UseLogger(build.NewSubLogger("SWEEP", nil))
} }
// batchPrefixLogger returns a logger that prefixes all log messages with the ID. // batchPrefixLogger returns a logger that prefixes all log messages with
// the ID.
func batchPrefixLogger(batchID string) btclog.Logger { func batchPrefixLogger(batchID string) btclog.Logger {
return build.NewPrefixLog(fmt.Sprintf("[Batch %s]", batchID), log) return build.NewPrefixLog(fmt.Sprintf("[Batch %s]", batchID), log)
} }

View File

@ -82,8 +82,8 @@ func NewSQLStore(db BaseDB, network *chaincfg.Params) *SQLStore {
// FetchUnconfirmedSweepBatches fetches all the batches from the database that // FetchUnconfirmedSweepBatches fetches all the batches from the database that
// are not in a confirmed state. // are not in a confirmed state.
func (s *SQLStore) FetchUnconfirmedSweepBatches(ctx context.Context) ([]*dbBatch, func (s *SQLStore) FetchUnconfirmedSweepBatches(ctx context.Context) (
error) { []*dbBatch, error) {
var batches []*dbBatch var batches []*dbBatch

View File

@ -594,7 +594,9 @@ func (b *batch) publishBatch(ctx context.Context) (btcutil.Amount, error) {
var ( var (
batchAmt btcutil.Amount batchAmt btcutil.Amount
prevOuts = make([]*wire.TxOut, 0, len(b.sweeps)) prevOuts = make([]*wire.TxOut, 0, len(b.sweeps))
signDescs = make([]*lndclient.SignDescriptor, 0, len(b.sweeps)) signDescs = make(
[]*lndclient.SignDescriptor, 0, len(b.sweeps),
)
sweeps = make([]sweep, 0, len(b.sweeps)) sweeps = make([]sweep, 0, len(b.sweeps))
fee btcutil.Amount fee btcutil.Amount
inputCounter int inputCounter int

View File

@ -328,8 +328,8 @@ func (b *Batcher) handleSweep(ctx context.Context, sweep *sweep,
if !accepted { if !accepted {
return fmt.Errorf("existing sweep %x was not "+ return fmt.Errorf("existing sweep %x was not "+
"accepted by batch %d", sweep.swapHash[:6], "accepted by batch %d",
batch.id) sweep.swapHash[:6], batch.id)
} }
// The sweep was updated in the batch, our job is done. // The sweep was updated in the batch, our job is done.
@ -464,6 +464,8 @@ func (b *Batcher) spinUpBatchFromDB(ctx context.Context, batch *batch) error {
FeeRate: batch.rbfCache.FeeRate, FeeRate: batch.rbfCache.FeeRate,
} }
logger := batchPrefixLogger(fmt.Sprintf("%d", batch.id))
batchKit := batchKit{ batchKit := batchKit{
id: batch.id, id: batch.id,
batchTxid: batch.batchTxid, batchTxid: batch.batchTxid,
@ -480,7 +482,7 @@ func (b *Batcher) spinUpBatchFromDB(ctx context.Context, batch *batch) error {
verifySchnorrSig: b.VerifySchnorrSig, verifySchnorrSig: b.VerifySchnorrSig,
purger: b.AddSweep, purger: b.AddSweep,
store: b.store, store: b.store,
log: batchPrefixLogger(fmt.Sprintf("%d", batch.id)), log: logger,
quit: b.quit, quit: b.quit,
} }
@ -601,15 +603,17 @@ func (b *Batcher) monitorSpendAndNotify(ctx context.Context, sweep *sweep,
totalSwept, totalSwept,
) )
onChainFeePortion := getFeePortionPaidBySweep(
spendTx, feePortionPerSweep,
roundingDifference, sweep,
)
// Notify the requester of the spend // Notify the requester of the spend
// with the spend details, including the fee // with the spend details, including the fee
// portion for this particular sweep. // portion for this particular sweep.
spendDetail := &SpendDetail{ spendDetail := &SpendDetail{
Tx: spendTx, Tx: spendTx,
OnChainFeePortion: getFeePortionPaidBySweep( // nolint:lll OnChainFeePortion: onChainFeePortion,
spendTx, feePortionPerSweep,
roundingDifference, sweep,
),
} }
select { select {

View File

@ -182,7 +182,8 @@ func TestSweepBatcherBatchCreation(t *testing.T) {
<-lnd.RegisterSpendChannel <-lnd.RegisterSpendChannel
require.Eventually(t, func() bool { require.Eventually(t, func() bool {
// Verify that each batch has the correct number of sweeps in it. // Verify that each batch has the correct number of sweeps
// in it.
for _, batch := range batcher.batches { for _, batch := range batcher.batches {
switch batch.primarySweepID { switch batch.primarySweepID {
case sweepReq1.SwapHash: case sweepReq1.SwapHash:
@ -481,7 +482,9 @@ func TestSweepBatcherSweepReentry(t *testing.T) {
}, },
TxOut: []*wire.TxOut{ TxOut: []*wire.TxOut{
{ {
Value: int64(sweepReq1.Value.ToUnit(btcutil.AmountSatoshi)), Value: int64(sweepReq1.Value.ToUnit(
btcutil.AmountSatoshi,
)),
PkScript: []byte{3, 2, 1}, PkScript: []byte{3, 2, 1},
}, },
}, },
@ -683,7 +686,8 @@ func TestSweepBatcherNonWalletAddr(t *testing.T) {
<-lnd.RegisterSpendChannel <-lnd.RegisterSpendChannel
require.Eventually(t, func() bool { require.Eventually(t, func() bool {
// Verify that each batch has the correct number of sweeps in it. // Verify that each batch has the correct number of sweeps
// in it.
for _, batch := range batcher.batches { for _, batch := range batcher.batches {
switch batch.primarySweepID { switch batch.primarySweepID {
case sweepReq1.SwapHash: case sweepReq1.SwapHash: