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

client/asset/btc: work around PublishTransaction delays #1376

Merged
merged 1 commit into from
Jan 13, 2022

Conversation

chappjc
Copy link
Member

@chappjc chappjc commented Dec 31, 2021

Because of (a) what appears to be a neutrino bug, with a fix proposed in lightninglabs/neutrino#240, and (b) that neutrino wallet.PublishTransaction is blocking while inv requests go to peers and getdata responses come back, this PR attempts to avoid an unnecessary delay with BTC SPV when broadcasting transactions.

In all my observations, PublishTransaction uses the entire neutrino.Config.BroadcastTimeout, which is nearly an intolerable delay for many operations.

With neutrino as the wallet's chain service, its chainClient.SendRawTransaction call is blocking for up to neutrino.Config.BroadcastTimeout while peers either respond to the inv request with a getdata, or time out. However, in virtually all cases, we just need to know that btcwallet was able to create and store the transaction record, and pass it to the chain service. This is a yucky workaround to consider until lightninglabs/neutrino#240 is accepted, maybe even complementary to it.

@chappjc chappjc added this to the 0.4 milestone Jan 7, 2022
@chappjc
Copy link
Member Author

chappjc commented Jan 11, 2022

The upstream fix is unlikely to happen this week, and even if it did, we would definitely not want broadcast to consistently block for even 4 seconds, which appears to be most common even when all peers to do respond with getdata and we don't hit the broadcast timeout. Going to wrap this up and fix the tests, but I have been testing regularly in the past week.

In parallel, I'm looking to make certain requests async, with particular focus on not holding up preimage and match_proof requests.

@chappjc chappjc marked this pull request as ready for review January 12, 2022 16:23
Comment on lines +414 to +416
// rebroadcasting. In the future, a new btcwallet method should be added
// that returns after performing its internal actions, but broadcasting
// asynchronously and sending the outcome in a channel or promise.
Copy link
Member Author

@chappjc chappjc Jan 12, 2022

Choose a reason for hiding this comment

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

I hate the guesstimation in this PR using 2 seconds to let it process and queue the txn when 100 ms is more than adequate most of the time, but the proper solution is described on these lines (a different btcwallet method).

// because if an external bug, but even if the resolved, a typical
// inv/getdata round trip is ~4 seconds, so we set this so neutrino does
// not cancel queries too readily.
BroadcastTimeout: 6 * time.Second,
Copy link
Member

@buck54321 buck54321 Jan 12, 2022

Choose a reason for hiding this comment

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

Looks like the default is 5? So we're actually giving neutrino more time, just not waiting around anymore.

Copy link
Member Author

@chappjc chappjc Jan 12, 2022

Choose a reason for hiding this comment

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

Correct. So 10 or even 30 would be fine with this approach, but I figured I would set it to something based on my empirical observations now that I've studied it more in practice. 5 seemed just under the wire to me.

@chappjc chappjc merged commit d3c219c into decred:master Jan 13, 2022
@chappjc
Copy link
Member Author

chappjc commented Jan 13, 2022

We will definitely see a follow up to this in the future in the form of a neutrino update and/or a new btcwallet method that provides partially asynchronous PublishTransaction functionality without waiting for peer responses, only tx recording and queuing.

@chappjc chappjc deleted the btc-spv-send-fast branch January 13, 2022 04:37
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.

3 participants