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 cd19e70
Show file tree
Hide file tree
Showing 2 changed files with 15 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.
15 changes: 10 additions & 5 deletions autopilot/walletmaintainer/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,18 +79,23 @@ func (w *walletMaintainer) PerformWalletMaintenance(ctx context.Context, cfg api
}
}

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

// check whether the wallet needs to be redistributed
if maxOutputs < 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(maxOutputs), 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(maxOutputs), amount, balance, err)
}

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

0 comments on commit cd19e70

Please sign in to comment.