Skip to content

Reduce cs_main locks during ConnectTip/SyncWithWallets#7946

Merged
sipa merged 1 commit intobitcoin:masterfrom
jonasschnelli:2016/04/cs_main_wallet
Aug 15, 2016
Merged

Reduce cs_main locks during ConnectTip/SyncWithWallets#7946
sipa merged 1 commit intobitcoin:masterfrom
jonasschnelli:2016/04/cs_main_wallet

Conversation

@jonasschnelli
Copy link
Contributor

DisconnectTip and AcceptToMempool are still holding cs_main (not intended to improve this in this PR)

src/main.cpp Outdated
Copy link
Member

Choose a reason for hiding this comment

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

This is not correct, it needs to iterate through all the blocks that got connected, not just the new tip.

@jonasschnelli jonasschnelli force-pushed the 2016/04/cs_main_wallet branch 2 times, most recently from fdbee7d to 22d9380 Compare April 26, 2016 13:31
@jonasschnelli
Copy link
Contributor Author

As always when you want to improve the locking a little bit, the change gets quickly more invasive.

Update serval things:

  • Fixed @sipa point (iterate though all connected blocks).
  • Removed the CBlock * parameter from the SyncTransaction signal and added CBlockIndex* together with int posInBlock.
  • Updated the wallet logic that it can handle the slightly different signal.

@jonasschnelli jonasschnelli force-pushed the 2016/04/cs_main_wallet branch 2 times, most recently from 6416d91 to 086654e Compare April 26, 2016 20:25
@kazcw
Copy link
Contributor

kazcw commented Apr 27, 2016

ActivateBestChainStep reuses a vector for ConnectTip's txConflicted to combine results from multiple blocks. ConnectTip passes txConflicted to mempoool.removeForBlock every time.

src/main.cpp Outdated
Copy link
Contributor

Choose a reason for hiding this comment

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

Could put the new loops below this comment with the other non-cs_main notifications

@jonasschnelli jonasschnelli force-pushed the 2016/04/cs_main_wallet branch from 6fc0be6 to e8ea3dd Compare May 6, 2016 09:47
@jonasschnelli
Copy link
Contributor Author

@kazcw Thanks for the detailed code review!

Added a squashme commit with fixed for issues found by @kazcw.

@kazcw
Copy link
Contributor

kazcw commented May 6, 2016

You know what, I misread. txConflicted is an out-only parameter all the way down the call stack, so it was fine without the txConflictedCurrent. Sorry about that.

@sipa
Copy link
Member

sipa commented May 25, 2016

Needs rebase.

src/main.cpp Outdated
Copy link
Member

Choose a reason for hiding this comment

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

Use std::tuple instead?

@jonasschnelli jonasschnelli force-pushed the 2016/04/cs_main_wallet branch from e8ea3dd to 9471f32 Compare May 25, 2016 14:33
@jonasschnelli
Copy link
Contributor Author

jonasschnelli commented May 25, 2016

Rebased, fixed sipas found issue and switched to std::tuple

src/main.cpp Outdated
Copy link
Member

@sipa sipa May 25, 2016

Choose a reason for hiding this comment

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

Why a temporary variable, and not just pass vchConflicted to mempool.removeForBlock()? txConflictedCurrent is not used elsewhere.

Copy link
Contributor Author

@jonasschnelli jonasschnelli May 25, 2016

Choose a reason for hiding this comment

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

Without a temporary variable, mempool.removeForBlock would always work though the combined list txConflicted that was initialized here.

Although I'm not sure if this would be a problem, but at least it would slightly change current masters behavior.

Copy link
Member

Choose a reason for hiding this comment

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

"Work through"? All that function does is append deleted CTransactions to it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. Your right. Removed the temp. var.

@jonasschnelli jonasschnelli force-pushed the 2016/04/cs_main_wallet branch from 9471f32 to 580a665 Compare May 25, 2016 14:47
src/main.cpp Outdated
Copy link
Member

Choose a reason for hiding this comment

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

Sorry for changing my mind, but can you define a struct for this instead? Larger tuples don't really have good readability.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

IMO tuple is ideal for a such use case. It's only a temporary variable and its scope is very small. IMO an custom struct seems to be over complex.

Copy link
Member

Choose a reason for hiding this comment

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

Fair enough.

Copy link
Member

Choose a reason for hiding this comment

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

c++ needs collections.namedtuple :)

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

given the repeated use, maybe just typedef the std::tuple? tuple has some nice conveniences over a struct alternative.

@jonasschnelli jonasschnelli force-pushed the 2016/04/cs_main_wallet branch from 580a665 to fdf8a5e Compare May 25, 2016 15:58
Copy link
Member

Choose a reason for hiding this comment

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

This cs_main is unfortunate, but I guess we can get rid of it in a follow-up.

@sipa
Copy link
Member

sipa commented May 25, 2016

utACK fdf8a5efe03004f4a581ba41b87737a4e1f1ff44

@dcousens
Copy link
Contributor

dcousens commented Jun 3, 2016

utACK fdf8a5e

@laanwj
Copy link
Member

laanwj commented Jun 10, 2016

utACK fdf8a5e, but the squashme commits need squashing

@jonasschnelli jonasschnelli force-pushed the 2016/04/cs_main_wallet branch from fdf8a5e to d31dd19 Compare June 10, 2016 15:09
@jonasschnelli
Copy link
Contributor Author

Squashed.

TheBlueMatt added a commit to TheBlueMatt/bitcoin that referenced this pull request Jul 11, 2017
This runs BlockConnectedDisconnected, TransactionAddedToMempool,
SetBestChain, and Inventory on the background scheduler thread.

This partially reverts bitcoin#9583, re-enabling some of the gains from
 bitcoin#7946. This does not, however, re-enable the gains achieved by
repeatedly releasing cs_main between each transaction processed.
TheBlueMatt added a commit to TheBlueMatt/bitcoin that referenced this pull request Aug 14, 2017
This runs BlockConnectedDisconnected, TransactionAddedToMempool,
SetBestChain, and Inventory on the background scheduler thread.

This partially reverts bitcoin#9583, re-enabling some of the gains from
 bitcoin#7946. This does not, however, re-enable the gains achieved by
repeatedly releasing cs_main between each transaction processed.
TheBlueMatt added a commit to TheBlueMatt/bitcoin that referenced this pull request Aug 17, 2017
This runs BlockConnectedDisconnected, TransactionAddedToMempool,
SetBestChain, and Inventory on the background scheduler thread.

This partially reverts bitcoin#9583, re-enabling some of the gains from
 bitcoin#7946. This does not, however, re-enable the gains achieved by
repeatedly releasing cs_main between each transaction processed.
TheBlueMatt added a commit to TheBlueMatt/bitcoin that referenced this pull request Sep 12, 2017
This runs BlockConnectedDisconnected, TransactionAddedToMempool,
SetBestChain, and Inventory on the background scheduler thread.

This partially reverts bitcoin#9583, re-enabling some of the gains from
 bitcoin#7946. This does not, however, re-enable the gains achieved by
repeatedly releasing cs_main between each transaction processed.
jnewbery pushed a commit to jnewbery/bitcoin that referenced this pull request Sep 13, 2017
This runs BlockConnectedDisconnected, TransactionAddedToMempool,
SetBestChain, and Inventory on the background scheduler thread.

This partially reverts bitcoin#9583, re-enabling some of the gains from
 bitcoin#7946. This does not, however, re-enable the gains achieved by
repeatedly releasing cs_main between each transaction processed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants