Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions wallet/chainntfns.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,9 +307,7 @@ func (w *Wallet) ChainSwitch(ctx context.Context, forest *SidechainForest, chain
forest.PruneChain(chain)
forest.Prune(int32(chain[len(chain)-1].Header.Height), w.chainParams)

if w.mixingEnabled {
w.mixClient.ExpireMessages(chain[len(chain)-1].Header.Height)
}
w.expireMixMessages(chain[len(chain)-1].Header.Height)

w.NtfnServer.notifyMainChainTipChanged(chainTipChanges)
w.NtfnServer.sendAttachedBlockNotification(ctx)
Expand Down
2 changes: 1 addition & 1 deletion wallet/createtx.go
Original file line number Diff line number Diff line change
Expand Up @@ -1072,7 +1072,7 @@ func (w *Wallet) mixedSplit(ctx context.Context, req *PurchaseTicketsRequest, ne
}
}

err = w.mixClient.Dicemix(ctx, cj)
err = w.dicemix(ctx, cj)
if err != nil {
return
}
Expand Down
18 changes: 17 additions & 1 deletion wallet/mixing.go
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ SplitPoints:

log.Infof("Mixing output %v (%v)", output, amount)

err = w.mixClient.Dicemix(ctx, cj)
err = w.dicemix(ctx, cj)
if err != nil {
return errors.E(op, err)
}
Expand Down Expand Up @@ -561,3 +561,19 @@ func (w *Wallet) AcceptMixMessage(msg mixing.Message) error {

return nil
}

func (w *Wallet) expireMixMessages(height uint32) {
mixc := w.mixClient.Load()
if mixc == nil {
return
}
mixc.ExpireMessages(height)
}

func (w *Wallet) dicemix(ctx context.Context, cj *mixclient.CoinJoin) error {
mixc := w.mixClient.Load()
if mixc == nil {
return errors.E(errors.Invalid, "mixing client is not running")
}
return mixc.Dicemix(ctx, cj)
}
14 changes: 10 additions & 4 deletions wallet/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ type Wallet struct {
mixingEnabled bool
mixpool *mixpool.Pool
mixSems mixSemaphores
mixClient *mixclient.Client
mixClient atomic.Pointer[mixclient.Client]

// Cached Blake3 anchor candidate
cachedBlake3WorkDiffCandidateAnchor *wire.BlockHeader
Expand Down Expand Up @@ -5523,8 +5523,6 @@ func Open(ctx context.Context, cfg *Config) (*Wallet, error) {

if w.mixingEnabled {
w.mixpool = mixpool.NewPool((*mixpoolBlockchain)(w))
w.mixClient = mixclient.NewClient((*mixingWallet)(w))
w.mixClient.SetLogger(loggers.MixcLog)
}

return w, nil
Expand All @@ -5536,10 +5534,18 @@ func (w *Wallet) MixingEnabled() bool {
return w.mixingEnabled
}

func newMixClient(w *Wallet) *mixclient.Client {
c := mixclient.NewClient((*mixingWallet)(w))
c.SetLogger(loggers.MixcLog)
return c
}

// Run executes any necessary background goroutines for the wallet.
func (w *Wallet) Run(ctx context.Context) error {
if w.mixingEnabled {
return w.mixClient.Run(ctx)
c := newMixClient(w)
w.mixClient.Store(c)
return c.Run(ctx)
}
return nil
}
Expand Down
Loading