From fca1a59fda7dfdd405c5d56d81428d86c31b8e53 Mon Sep 17 00:00:00 2001 From: Josh Rickmar Date: Mon, 3 Jun 2024 18:21:56 +0000 Subject: [PATCH] mixpool: Remove unused exported methods 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. --- internal/rpcserver/interface.go | 11 +----- internal/rpcserver/rpcserver.go | 3 +- mixing/mixclient/client.go | 2 +- mixing/mixpool/mixpool.go | 68 +++++---------------------------- 4 files changed, 14 insertions(+), 70 deletions(-) diff --git a/internal/rpcserver/interface.go b/internal/rpcserver/interface.go index 05bee68c2..ecbb5daa1 100644 --- a/internal/rpcserver/interface.go +++ b/internal/rpcserver/interface.go @@ -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 diff --git a/internal/rpcserver/rpcserver.go b/internal/rpcserver/rpcserver.go index c7606187c..330174a7b 100644 --- a/internal/rpcserver/rpcserver.go +++ b/internal/rpcserver/rpcserver.go @@ -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)) diff --git a/mixing/mixclient/client.go b/mixing/mixclient/client.go index 6debbc3b5..f8a682a5c 100644 --- a/mixing/mixclient/client.go +++ b/mixing/mixclient/client.go @@ -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 diff --git a/mixing/mixpool/mixpool.go b/mixing/mixpool/mixpool.go index ecae2110f..8a1e1187d 100644 --- a/mixing/mixpool/mixpool.go +++ b/mixing/mixpool/mixpool.go @@ -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() @@ -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 }