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

chain: misc BitcoindClient fixes #617

Merged
merged 5 commits into from
May 24, 2019
Merged

chain: misc BitcoindClient fixes #617

merged 5 commits into from
May 24, 2019

Conversation

wpaulino
Copy link
Contributor

@wpaulino wpaulino commented May 10, 2019

Depends on btcsuite/btcd#1428.

…tion

Since defer will copy the function with the parameters evaluated at its
invocation, the RescanFinished notification would be dispatched with the
incorrect block. To fix this, we'll just send the notification at the
end ourselves manually.
@@ -906,8 +914,6 @@ func (c *BitcoindClient) FilterBlocks(
// the client in the watch list. This is called only within a queue processing
// loop.
func (c *BitcoindClient) rescan(start chainhash.Hash) error {
log.Infof("Starting rescan from block %s", start)
Copy link
Contributor

Choose a reason for hiding this comment

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

is this log not useful?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's already logged by the wallet itself, so opted to remove this to avoid the duplicate info.

chain/bitcoind_client.go Show resolved Hide resolved
// Determine if this was an RPC error thrown due to the transaction
// already confirming.
var rpcTxConfirmed bool
if rpcErr, ok := err.(*btcjson.RPCError); ok {
Copy link
Contributor

Choose a reason for hiding this comment

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

Possible to add a unit test for this behavior?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's somewhat already covered here.

Copy link
Contributor

Choose a reason for hiding this comment

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

I was thinking a btcwallet unit test with a mocked chainClient. We could make the mock mimic the behavior of various backends/versions, and ensure we handle the diff errors correctly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since we're doing string matching I'm not sure a unit test with a mock would work here. We'd just be including the same strings in there, which would seem to me like we're testing string.Contains.

wallet/wallet.go Outdated Show resolved Hide resolved
wallet/wallet.go Outdated
// already confirmed to a bitcoind node.
case strings.Contains(err.Error(), "txn-already-known"):
// already confirmed to a btcd node over the P2P network.
case strings.Contains(err.Error(), "transaction already exists"):
Copy link
Contributor

Choose a reason for hiding this comment

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

would prefer if both of these cases were made case insensitive for robustness

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

This unifies the logic of receiving an error when broadcasting a
confirmed transaction through btcd's/bitcoind's RPC interface. The btcd
dependency update is required in order for it to match bitcoind's
behavior. For older nodes that have yet to update, the confirmed
transaction will still be caught by the "transaction already exists"
case. This is not needed for bitcoind however, because its been sending
the same RPC error code for several major releases now.
Copy link
Contributor

@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.

LGTM 👍

Copy link
Contributor

@cfromknecht cfromknecht left a comment

Choose a reason for hiding this comment

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

LGTM 🖖

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 ⏱

@Roasbeef Roasbeef merged commit 192de4e into btcsuite:master May 24, 2019
@wpaulino wpaulino deleted the bitcoind-client-misc-fixes branch May 24, 2019 00:40
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