Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add gettxspendingprevout for btcd and fix version check #2125

Merged
merged 9 commits into from
Mar 1, 2024

Conversation

yyforyongyu
Copy link
Contributor

This PR adds the RPC gettxspendingprevout for btcd so we can do mempool lookups. This RPC is also ported to the rpcclient to replace the raw request made on the btcwallet side.

In addition, we now start to track btcd versions in rpcclient to make sure RPC updates are handled properly.

@coveralls
Copy link

coveralls commented Feb 23, 2024

Pull Request Test Coverage Report for Build 8077551462

Details

  • -76 of 169 (55.03%) changed or added relevant lines in 7 files are covered.
  • 1 unchanged line in 1 file lost coverage.
  • Overall coverage increased (+0.03%) to 56.753%

Changes Missing Coverage Covered Lines Changed/Added Lines %
rpcclient/infrastructure.go 0 9 0.0%
rpcclient/backend_version.go 43 65 66.15%
rpcclient/rawtransactions.go 0 45 0.0%
Files with Coverage Reduction New Missed Lines %
rpcclient/infrastructure.go 1 39.21%
Totals Coverage Status
Change from base Build 8057525961: 0.03%
Covered Lines: 29284
Relevant Lines: 51599

💛 - Coveralls

Copy link
Member

@Roasbeef Roasbeef left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🌂

rpcserver.go Show resolved Hide resolved
rpcserver_test.go Show resolved Hide resolved
@@ -1648,6 +1658,9 @@ func parseBitcoindVersion(version string) BackendVersion {
case version < bitcoind22Str:
return BitcoindPre22

case version < bitcoind24Str:
return BitcoindPre24
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIUC, we need to start to check this in btcwallet? FWIW, didn't see it in the latest PR of yours in that repo.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we'll need to check this in lnd at the callsite. If we check it in btcwallet, then it's another error to be returned to the caller. On the other hand, I think the rpcclient package should be put in btcwallet instead to keep btcd "pure" - came up with a draft PR for this when I was dealing with updating errors returned from TestMempoolAccept, will put more details there.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the rpcclient package should be put in btcwallet instead to keep btcd "pure" - came up with a draft PR for this when I was dealing with updating errors returned from TestMempoolAccept, will put more details there.

Don't think I agree with this, rpcclient as is does generic JSON-RPC for conformant Bitcoin nodes. We even use the client to test directly against (in itests) the server-side implementation of the various RPC calls.

I don't see why the check can't just be in the wallet though. We already have that check for bitcoind when we wan to use the newer set of RPC calls.

integration/chain_test.go Outdated Show resolved Hide resolved
integration/chain_test.go Outdated Show resolved Hide resolved
rpcclient/chain.go Show resolved Hide resolved
This commit adds the RPC method `gettxspendingprevout` for btcd.
We need this for `gettxspendingprevout`.
This commit adds a new interface, `BackendVersion`, to support checking
versions for multiple both btcd and bitcoind. Once neutrino version is
also pinned here, it should also be checked.
Copy link
Member

@Roasbeef Roasbeef left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🎒

@saubyk
Copy link

saubyk commented Feb 29, 2024

cc: @Crypt-iQ for review

@saubyk
Copy link

saubyk commented Feb 29, 2024

cc: @guggero

@Chinwendu20
Copy link

Chinwendu20 commented Mar 1, 2024

Nice pr @yyforyongyu I like the progression.

question/suggestion: Do you think we should separate the implementations of the Backend version interface into separate files? like bitcoin.go and btcd.go in the same folder. In the future if we want to track more backends we just create a new file and that way it is easier to follow?

Copy link
Collaborator

@guggero guggero left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice, LGTM 🎉

@@ -3906,6 +3907,49 @@ func handleTestMempoolAccept(s *rpcServer, cmd interface{},
return results, nil
}

// handleGetTxSpendingPrevOut implements the gettxspendingprevout command.
func handleGetTxSpendingPrevOut(s *rpcServer, cmd interface{},
closeChan <-chan struct{}) (interface{}, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: since closeChan is unused, should we just use _ as the argument name?


// Call the method handler and assert the error is returned.
closeChan := make(chan struct{})
results, err := handleGetTxSpendingPrevOut(s, cmd, closeChan)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: could just pass in nil since closeChan is not used anyway.

type BackendVersion uint8
// BackendVersion defines an interface to handle the version of the backend
// used by the client.
type BackendVersion interface {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice 🤩

c.backendVersion = &version
return *c.backendVersion, nil
version := parseBtcdVersion(info.Version)
c.backendVersion = version
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: why not c.backendVersion = parseBtcdVersion(info.Version) directly?

@Roasbeef
Copy link
Member

Roasbeef commented Mar 1, 2024

Do you think we should separate the implementations of the Backend version interface into separate files? like bitcoin.go and btcd.go in the same folder. In the future if we want to track more backends we just create a new file and that way it is easier to follow?

@Chinwendu20, I think if we did that, we'd want to add a version prefix/suffix to the file names, so it's clear that this is code for parsing the versions, rather than a bitcoind specific implementation of something.

@Roasbeef Roasbeef merged commit 1a2b599 into btcsuite:master Mar 1, 2024
3 checks passed
@yyforyongyu yyforyongyu deleted the add-gettxspendingprevout branch March 2, 2024 06:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants