Skip to content

Commit

Permalink
sweepbatcher: log the reason of acceptance failure
Browse files Browse the repository at this point in the history
Add Info log message in cases when addSweep returns accept=false and err=nil.
  • Loading branch information
starius committed Aug 26, 2024
1 parent f21a21e commit 7780aca
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion sweepbatcher/sweep_batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,8 @@ func (b *batch) addSweep(ctx context.Context, sweep *sweep) (bool, error) {
// If the provided sweep is nil, we can't proceed with any checks, so
// we just return early.
if sweep == nil {
b.log.Infof("the sweep is nil")

return false, nil
}

Expand Down Expand Up @@ -471,21 +473,36 @@ func (b *batch) addSweep(ctx context.Context, sweep *sweep) (bool, error) {
// the batch, do not add another sweep to prevent the tx from becoming
// non-standard.
if len(b.sweeps) >= MaxSweepsPerBatch {
b.log.Infof("the batch has already too many sweeps (%d >= %d)",
len(b.sweeps), MaxSweepsPerBatch)

return false, nil
}

// Since all the actions of the batch happen sequentially, we could
// arrive here after the batch got closed because of a spend. In this
// case we cannot add the sweep to this batch.
if b.state != Open {
b.log.Infof("the batch state (%v) is not open", b.state)

return false, nil
}

// If this batch contains a single sweep that spends to a non-wallet
// address, or the incoming sweep is spending to non-wallet address,
// we cannot add this sweep to the batch.
for _, s := range b.sweeps {
if s.isExternalAddr || sweep.isExternalAddr {
if s.isExternalAddr {
b.log.Infof("the batch already has a sweep (%x) with "+
"an external address", s.swapHash[:6])

return false, nil
}

if sweep.isExternalAddr {
b.log.Infof("the batch is not empty and new sweep (%x)"+
" has an external address", sweep.swapHash[:6])

return false, nil
}
}
Expand All @@ -498,6 +515,11 @@ func (b *batch) addSweep(ctx context.Context, sweep *sweep) (bool, error) {
int32(math.Abs(float64(sweep.timeout - s.timeout)))

if timeoutDistance > b.cfg.maxTimeoutDistance {
b.log.Infof("too long timeout distance between the "+
"batch and sweep %x: %d > %d",
sweep.swapHash[:6], timeoutDistance,
b.cfg.maxTimeoutDistance)

return false, nil
}
}
Expand Down

0 comments on commit 7780aca

Please sign in to comment.