Skip to content

Commit

Permalink
mixpool: Remove unused exported methods
Browse files Browse the repository at this point in the history
The MixPRs method has been modified to remove the query parameter, as it was
only ever called with nil.

The RPC server no longer needs access to directly call RemoveConfirmedMixes.
This same operation is already (and incorrectly) done by MixPRs, and it will
need the eventual fix.

One exception: we are keeping RemoveConfirmedMixes which is still not used
anywhere.  This method behaves similarly to RemoveSpentPRs but removes mixes
that completed with a confirmed coinjoin transaction matching any of the
provided hashes.  This may be used later by wallet to remove mixes that
include transaction hashes in the merkle tree, while dcrd can just provide the
mined transactions themselves and remove anything that double spends a PR
UTXO.
  • Loading branch information
jrick authored and davecgh committed Jun 3, 2024
1 parent 2796b22 commit fca1a59
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 70 deletions.
11 changes: 2 additions & 9 deletions internal/rpcserver/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -659,18 +659,11 @@ type TxMempooler interface {
// The interface contract requires that all of these methods are safe for
// concurrent access.
type MixPooler interface {
// MixPRs returns all MixPR messages with hashes matching the query.
// Unknown messages are ignored.
//
// If query is nil, all PRs are returned.
MixPRs(query []chainhash.Hash) []*wire.MsgMixPairReq
// MixPRs returns all MixPR messages.
MixPRs() []*wire.MsgMixPairReq

// Message searches the mixing pool for a message by its hash.
Message(query *chainhash.Hash) (mixing.Message, error)

// RemoveConfirmedRuns removes all messages including pair requests
// from runs which ended in each peer sending a confirm mix message.
RemoveConfirmedRuns()
}

// TxIndexer provides an interface for retrieving details for a given
Expand Down
3 changes: 1 addition & 2 deletions internal/rpcserver/rpcserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -2608,8 +2608,7 @@ func handleGetMixMessage(_ context.Context, s *Server, cmd interface{}) (interfa
func handleGetMixPairRequests(_ context.Context, s *Server, _ interface{}) (interface{}, error) {
mp := s.cfg.MixPooler

mp.RemoveConfirmedRuns() // XXX: a bit hacky to do this here
prs := mp.MixPRs(nil)
prs := mp.MixPRs()

buf := new(strings.Builder)
res := make([]string, 0, len(prs))
Expand Down
2 changes: 1 addition & 1 deletion mixing/mixclient/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ func (c *Client) removeUnresponsiveDuringEpoch(prs []*wire.MsgMixPairReq, prevEp
}

func (c *Client) epochTicker(ctx context.Context) error {
prevPRs := c.mixpool.MixPRs(nil)
prevPRs := c.mixpool.MixPRs()

// Wait for the next epoch + the KE timeout + extra duration for local
// clock differences, then remove any previous pair requests that are
Expand Down
68 changes: 10 additions & 58 deletions mixing/mixpool/mixpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,19 +214,6 @@ func (p *Pool) Epoch() time.Duration {
return p.epoch
}

// MixPRHashes returns the hashes of all MixPR messages recorded by the pool.
// This data is provided to peers requesting initial state of the mixpool.
func (p *Pool) MixPRHashes() []chainhash.Hash {
p.mtx.RLock()
hashes := make([]chainhash.Hash, 0, len(p.prs))
for hash := range p.prs {
hashes = append(hashes, hash)
}
p.mtx.RUnlock()

return hashes
}

// Message searches the mixing pool for a message by its hash.
func (p *Pool) Message(query *chainhash.Hash) (mixing.Message, error) {
p.mtx.RLock()
Expand All @@ -253,60 +240,25 @@ func (p *Pool) HaveMessage(query *chainhash.Hash) bool {
return ok
}

// MixPR searches the mixing pool for a PR message by its hash.
func (p *Pool) MixPR(query *chainhash.Hash) (*wire.MsgMixPairReq, error) {
var pr *wire.MsgMixPairReq

p.mtx.RLock()
pr = p.prs[*query]
p.mtx.RUnlock()

if pr == nil {
return nil, fmt.Errorf("PR message not found")
}

return pr, nil
}

// MixPRs returns all MixPR messages with hashes matching the query. Unknown
// messages are ignored.
//
// If query is nil, all PRs are returned.
// MixPRs returns all MixPR messages.
//
// In both cases, any expired PRs that are still internally tracked by the
// mixpool for ongoing sessions are excluded from the result set.
func (p *Pool) MixPRs(query []chainhash.Hash) []*wire.MsgMixPairReq {
// Any expired PRs that are still internally tracked by the mixpool for
// ongoing sessions are excluded from the result set.
func (p *Pool) MixPRs() []*wire.MsgMixPairReq {
p.mtx.Lock()
defer p.mtx.Unlock()

p.removeConfirmedRuns()

if query == nil {
res := make([]*wire.MsgMixPairReq, 0, len(p.prs))
for _, pr := range p.prs {
// Exclude expired but not yet removed PRs.
if pr.Expiry <= p.expireHeight {
continue
}

res = append(res, pr)
res := make([]*wire.MsgMixPairReq, 0, len(p.prs))
for _, pr := range p.prs {
// Exclude expired but not yet removed PRs.
if pr.Expiry <= p.expireHeight {
continue
}
return res
}

res := make([]*wire.MsgMixPairReq, 0, len(query))
for i := range query {
pr, ok := p.prs[query[i]]
if ok {
// Exclude expired but not yet removed PRs.
if pr.Expiry <= p.expireHeight {
continue
}

res = append(res, pr)
}
res = append(res, pr)
}

return res
}

Expand Down

0 comments on commit fca1a59

Please sign in to comment.