Skip to content

Commit

Permalink
wallet: redistribute into 100 outputs
Browse files Browse the repository at this point in the history
  • Loading branch information
peterjan committed Feb 10, 2025
1 parent 3b2e36d commit 7135f70
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
default: patch
---

# Redistribute wallet into 100 outputs instead of 10.
16 changes: 11 additions & 5 deletions autopilot/walletmaintainer/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,18 +79,24 @@ func (w *walletMaintainer) PerformWalletMaintenance(ctx context.Context, cfg api
}
}

// check whether the wallet needs to be redistributed
wantedNumOutputs := 10
// calculate num outputs
const maxOutputs = 100
amount := contractor.InitialContractFunding.Mul64(10)
if balance.Cmp(amount.Mul64(uint64(wantedNumOutputs))) < 0 {
numOutputs := balance.Div(amount).Big().Uint64()
if numOutputs > maxOutputs {
numOutputs = maxOutputs
}

// skip maintenance if wallet balance is too low
if numOutputs < 10 {
w.logger.Warnf("wallet maintenance skipped, wallet balance %v is too low to redistribute into meaningful outputs", balance)
return nil
}

// redistribute outputs
ids, err := w.bus.WalletRedistribute(ctx, wantedNumOutputs, amount)
ids, err := w.bus.WalletRedistribute(ctx, int(numOutputs), amount)
if err != nil {
return fmt.Errorf("failed to redistribute wallet into %d outputs of amount %v, balance %v, err %v", wantedNumOutputs, amount, balance, err)
return fmt.Errorf("failed to redistribute wallet into %d outputs of amount %v, balance %v, err %v", int(numOutputs), amount, balance, err)
}

w.logger.Infof("wallet maintenance succeeded, txns %v", ids)
Expand Down

0 comments on commit 7135f70

Please sign in to comment.