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

btcjson+rpcclient: add compatibility for bitcoind v0.19.0 #1484

Merged
merged 5 commits into from
Nov 9, 2019
Merged

btcjson+rpcclient: add compatibility for bitcoind v0.19.0 #1484

merged 5 commits into from
Nov 9, 2019

Conversation

wpaulino
Copy link
Collaborator

This PR aims to remedy the breaking RPC changes introduced in bitcoind v0.19.0:

This required being able to interpret the backend version the client connects to, which wasn't previously supported. btcd and bitcoind have different methods to expose this, GetInfo and GetNetworkInfo respectively.

Copy link
Collaborator

@halseth halseth left a comment

Choose a reason for hiding this comment

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

This is quite an elegant solution to the problem, looks pretty good 👍

rpcclient/infrastructure.go Show resolved Hide resolved
rpcclient/infrastructure.go Outdated Show resolved Hide resolved
rpcclient/chain.go Show resolved Hide resolved
rpcclient/rawtransactions.go Show resolved Hide resolved
rpcclient/infrastructure.go Show resolved Hide resolved
rpcclient/infrastructure.go Show resolved Hide resolved
@@ -92,7 +92,7 @@ type SoftForkDescription struct {
type Bip9SoftForkDescription struct {
Status string `json:"status"`
Bit uint8 `json:"bit"`
StartTime int64 `json:"startTime"`
StartTime int64 `json:"start_time"`
Copy link
Contributor

Choose a reason for hiding this comment

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

does this break compat with older nodes? or was it always incorrect?

Copy link
Member

Choose a reason for hiding this comment

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

Good question...it would appears that it does, unless the json library falls back to a fuzzy match on the field name within the struct itself?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

does this break compat with older nodes?

It does...

unless the json library falls back to a fuzzy match on the field name within the struct itself?

Doesn't seem to be the case unfortunately due to the _. How should we address this? This same way we did with SoftForks and UnifiedSoftForks in GetBlockChainInfoResult?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we attempt to unmarshal the result into this struct, if start_time is not set, unmarshal into a new struct having the startTime field, and override?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We can. I'm wondering if this is even worth the hassle though, as it would only affect bitcoind < 0.19.0 and it wouldn't affect btcd at all. Also there's no failure from unmarshaling in this case, the StartTime field just wouldn't be set.

Copy link
Member

Choose a reason for hiding this comment

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

Here's an option: remove this field, and add two new fields StartTime1 and StartTime2, then create a new method StartTime that returns the value. This breaks old clients, but gracefully (imo) as they'll likely see a compile error that they're passing in a method, when it's expecting an int64.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done.

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.

First pass through, haven't yet run it yet to verify the open question w.r.t backwards compatibility.

rpcclient/net.go Show resolved Hide resolved
rpcclient/infrastructure.go Show resolved Hide resolved
rpcclient/infrastructure.go Show resolved Hide resolved
@@ -92,7 +92,7 @@ type SoftForkDescription struct {
type Bip9SoftForkDescription struct {
Status string `json:"status"`
Bit uint8 `json:"bit"`
StartTime int64 `json:"startTime"`
StartTime int64 `json:"start_time"`
Copy link
Member

Choose a reason for hiding this comment

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

Good question...it would appears that it does, unless the json library falls back to a fuzzy match on the field name within the struct itself?

Copy link
Collaborator

@halseth halseth left a comment

Choose a reason for hiding this comment

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

Looks more or less good to me now, pending start_time compat

rpcclient/chain_test.go Show resolved Hide resolved
@@ -92,7 +92,7 @@ type SoftForkDescription struct {
type Bip9SoftForkDescription struct {
Status string `json:"status"`
Bit uint8 `json:"bit"`
StartTime int64 `json:"startTime"`
StartTime int64 `json:"start_time"`
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we attempt to unmarshal the result into this struct, if start_time is not set, unmarshal into a new struct having the startTime field, and override?

@wpaulino
Copy link
Collaborator Author

wpaulino commented Nov 7, 2019

rpcclient/chain_test.go:12:20: undefined: unmarshalPartialGetBlockChainInfoResult

Travis failure seems related to some weird caching issue. The test passes locally.

@Roasbeef
Copy link
Member

Roasbeef commented Nov 9, 2019

Cleared the cache, the build passes now.

@@ -92,7 +92,7 @@ type SoftForkDescription struct {
type Bip9SoftForkDescription struct {
Status string `json:"status"`
Bit uint8 `json:"bit"`
StartTime int64 `json:"startTime"`
StartTime int64 `json:"start_time"`
Copy link
Member

Choose a reason for hiding this comment

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

Here's an option: remove this field, and add two new fields StartTime1 and StartTime2, then create a new method StartTime that returns the value. This breaks old clients, but gracefully (imo) as they'll likely see a compile error that they're passing in a method, when it's expecting an int64.

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 👑

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.

4 participants