From 7312742fa63a2375774eebe1390c5d5ed9f9e40a Mon Sep 17 00:00:00 2001 From: yyforyongyu Date: Fri, 5 Jan 2024 04:17:31 +0800 Subject: [PATCH] chain+wallet: add `TestMempoolAccept` to chain interface --- chain/bitcoind_client.go | 10 ++++++++++ chain/btcd.go | 4 ++++ chain/interface.go | 2 ++ chain/neutrino.go | 19 +++++++++++++++++++ wallet/mock.go | 11 +++++++++++ 5 files changed, 46 insertions(+) diff --git a/chain/bitcoind_client.go b/chain/bitcoind_client.go index dad4722f86..4082b729df 100644 --- a/chain/bitcoind_client.go +++ b/chain/bitcoind_client.go @@ -217,6 +217,16 @@ func (c *BitcoindClient) SendRawTransaction(tx *wire.MsgTx, return c.chainConn.client.SendRawTransaction(tx, allowHighFees) } +// TestMempoolAcceptCmd returns result of mempool acceptance tests indicating +// if raw transaction(s) would be accepted by mempool. +// +// NOTE: This is part of the chain.Interface interface. +func (c *BitcoindClient) TestMempoolAccept(txns []*wire.MsgTx, + maxFeeRate float64) ([]*btcjson.TestMempoolAcceptResult, error) { + + return c.chainConn.client.TestMempoolAccept(txns, maxFeeRate) +} + // Notifications returns a channel to retrieve notifications from. // // NOTE: This is part of the chain.Interface interface. diff --git a/chain/btcd.go b/chain/btcd.go index 14678853bb..4ddb183c40 100644 --- a/chain/btcd.go +++ b/chain/btcd.go @@ -39,6 +39,10 @@ type RPCClient struct { quitMtx sync.Mutex } +// A compile-time check to ensure that RPCClient satisfies the chain.Interface +// interface. +var _ Interface = (*RPCClient)(nil) + // NewRPCClient creates a client connection to the server described by the // connect string. If disableTLS is false, the remote RPC certificate must be // provided in the certs slice. The connection is not established immediately, diff --git a/chain/interface.go b/chain/interface.go index 6d1300263a..5691e792ee 100644 --- a/chain/interface.go +++ b/chain/interface.go @@ -3,6 +3,7 @@ package chain import ( "time" + "github.com/btcsuite/btcd/btcjson" "github.com/btcsuite/btcd/btcutil" "github.com/btcsuite/btcd/chaincfg/chainhash" "github.com/btcsuite/btcd/rpcclient" @@ -47,6 +48,7 @@ type Interface interface { NotifyBlocks() error Notifications() <-chan interface{} BackEnd() string + TestMempoolAccept([]*wire.MsgTx, float64) ([]*btcjson.TestMempoolAcceptResult, error) } // Notification types. These are defined here and processed from from reading diff --git a/chain/neutrino.go b/chain/neutrino.go index e30e9ac94a..b794a667e5 100644 --- a/chain/neutrino.go +++ b/chain/neutrino.go @@ -6,6 +6,7 @@ import ( "sync" "time" + "github.com/btcsuite/btcd/btcjson" "github.com/btcsuite/btcd/btcutil" "github.com/btcsuite/btcd/btcutil/gcs" "github.com/btcsuite/btcd/btcutil/gcs/builder" @@ -20,6 +21,10 @@ import ( "github.com/lightninglabs/neutrino/headerfs" ) +// ErrUnimplemented is returned when a certain method is not implemented for a +// given interface. +var ErrUnimplemented = errors.New("unimplemented") + // NeutrinoClient is an implementation of the btcwallet chain.Interface interface. type NeutrinoClient struct { CS NeutrinoChainService @@ -63,6 +68,10 @@ type NeutrinoClient struct { clientMtx sync.Mutex } +// A compile-time check to ensure that RPCClient satisfies the chain.Interface +// interface. +var _ Interface = (*NeutrinoClient)(nil) + // NewNeutrinoClient creates a new NeutrinoClient struct with a backing // ChainService. func NewNeutrinoClient(chainParams *chaincfg.Params, @@ -217,6 +226,16 @@ func (s *NeutrinoClient) SendRawTransaction(tx *wire.MsgTx, allowHighFees bool) return &hash, nil } +// TestMempoolAcceptCmd returns result of mempool acceptance tests indicating +// if raw transaction(s) would be accepted by mempool. +// +// NOTE: This is part of the chain.Interface interface. +func (s *NeutrinoClient) TestMempoolAccept(txns []*wire.MsgTx, + maxFeeRate float64) ([]*btcjson.TestMempoolAcceptResult, error) { + + return nil, ErrUnimplemented +} + // FilterBlocks scans the blocks contained in the FilterBlocksRequest for any // addresses of interest. For each requested block, the corresponding compact // filter will first be checked for matches, skipping those that do not report diff --git a/wallet/mock.go b/wallet/mock.go index edcf469831..8c995ebb57 100644 --- a/wallet/mock.go +++ b/wallet/mock.go @@ -3,6 +3,7 @@ package wallet import ( "time" + "github.com/btcsuite/btcd/btcjson" "github.com/btcsuite/btcd/btcutil" "github.com/btcsuite/btcd/chaincfg/chainhash" "github.com/btcsuite/btcd/wire" @@ -83,3 +84,13 @@ func (m *mockChainClient) Notifications() <-chan interface{} { func (m *mockChainClient) BackEnd() string { return "mock" } + +// TestMempoolAcceptCmd returns result of mempool acceptance tests indicating +// if raw transaction(s) would be accepted by mempool. +// +// NOTE: This is part of the chain.Interface interface. +func (m *mockChainClient) TestMempoolAccept(txns []*wire.MsgTx, + maxFeeRate float64) ([]*btcjson.TestMempoolAcceptResult, error) { + + return nil, nil +}