Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Fix parallel transactions race-condition #10995

Merged
merged 20 commits into from
Sep 11, 2019
Merged

Fix parallel transactions race-condition #10995

merged 20 commits into from
Sep 11, 2019

Conversation

ngotchac
Copy link
Contributor

@ngotchac ngotchac commented Aug 27, 2019

Closes #9660

This PR should fix the race-condition issue that happens when sending multiple parallel transactions to a node running a dev chain.
To reproduce the issue, simply run a node with:

> parity --config dev --tx-queue-size 60000 --no-persistent-txqueue

and run this NodeJS script https://gist.github.com/ngotchac/8b85622f6396001f243fa2323184104d which sends a random number of transactions in parallel until it hangs.

The issue seems to be that the pending transactions queue was not totally cleared on culled transaction, and multiple blocks at the same height could be produced by the instant sealing engine.

With this PR, we ensure that only one block per height is produced, and to try to seal a new block after importing a new (internal) best block if there are some pending transactions.

@ngotchac ngotchac added A1-onice 🌨 Pull request is reviewed well, but should not yet be merged. M4-core ⛓ Core client code / Rust. labels Aug 27, 2019
Copy link
Collaborator

@tomusdrw tomusdrw left a comment

Choose a reason for hiding this comment

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

Seems it should work fine, since maybe_update_sealing is called when we are sure that the block has already been imported (it's run in a separate task).

ethcore/engines/instant-seal/src/lib.rs Outdated Show resolved Hide resolved
ethcore/engines/instant-seal/src/lib.rs Outdated Show resolved Hide resolved
ethcore/src/miner/mod.rs Outdated Show resolved Hide resolved
miner/src/pool/queue.rs Outdated Show resolved Hide resolved

/// Call `update_sealing` if needed
pub fn maybe_update_sealing<C: miner::BlockChainClient>(&self, chain: &C) {
if self.transaction_queue.has_local_pending_transactions() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not sure about this. The implementation is very specific for NullEngine (i.e. checks local transactions), while we have plenty of other conditions that affect when to seal. Why can't we just call update_sealing instead?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this is still valid.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah sorry, I thought you were talking about the next line, where I first used prepare_and_update_sealing. I just updated it.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I guess then there is no point in adding maybe_update_sealing to the traits and just call update_sealing directly?

@ngotchac ngotchac added A0-pleasereview 🤓 Pull request needs code review. and removed A1-onice 🌨 Pull request is reviewed well, but should not yet be merged. labels Sep 6, 2019
@ngotchac ngotchac marked this pull request as ready for review September 6, 2019 14:10
Copy link
Collaborator

@tomusdrw tomusdrw left a comment

Choose a reason for hiding this comment

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

Looks good, apart from the race.

ethcore/engines/instant-seal/src/lib.rs Outdated Show resolved Hide resolved
@ngotchac
Copy link
Contributor Author

ngotchac commented Sep 9, 2019

Waiting for paritytech/parity-common#218 to be merged.

@ngotchac ngotchac added A1-onice 🌨 Pull request is reviewed well, but should not yet be merged. and removed A0-pleasereview 🤓 Pull request needs code review. labels Sep 9, 2019
ethcore/src/miner/miner.rs Outdated Show resolved Hide resolved
ethcore/src/miner/miner.rs Outdated Show resolved Hide resolved
ethcore/src/miner/miner.rs Show resolved Hide resolved
ethcore/engines/instant-seal/Cargo.toml Outdated Show resolved Hide resolved
Cargo.lock Outdated Show resolved Hide resolved
@ordian ordian added this to the 2.7 milestone Sep 10, 2019
@ordian ordian added B0-patch-stable 🕷 Pull request should also be back-ported to the stable branch. B1-patch-beta 🕷🕷 labels Sep 10, 2019
@dvdplm
Copy link
Collaborator

dvdplm commented Sep 10, 2019

Waiting for paritytech/parity-common#218 to be merged.

Do you need a release&publish of this?

@ordian ordian added A8-looksgood 🦄 Pull request is reviewed well. and removed A1-onice 🌨 Pull request is reviewed well, but should not yet be merged. labels Sep 11, 2019
@ordian
Copy link
Collaborator

ordian commented Sep 11, 2019

Awesome work! Race conditions are hard to debug.

@ngotchac ngotchac merged commit 5e2def1 into master Sep 11, 2019
ordian added a commit that referenced this pull request Sep 12, 2019
s3krit added a commit that referenced this pull request Sep 12, 2019
This was referenced Sep 12, 2019
s3krit added a commit that referenced this pull request Sep 12, 2019
* add more tx tests (#11038)
* Fix parallel transactions race-condition (#10995)
* Add blake2_f precompile (#11017)
* [trace] introduce trace failed to Ext (#11019)
* Edit publish-onchain.sh to use https (#11016)
* Fix deadlock in network-devp2p (#11013)
* EIP 1108: Reduce alt_bn128 precompile gas costs (#11008)
* xDai chain support and nodes list update (#10989)
* EIP 2028: transaction gas lowered from 68 to 16 (#10987)
* EIP-1344 Add CHAINID op-code (#10983)
* manual publish jobs for releases, no changes for nightlies (#10977)
* [blooms-db] Fix benchmarks (#10974)
* Verify transaction against its block during import (#10954)
* Better error message for rpc gas price errors (#10931)
* Fix fork choice (#10837)
* Fix compilation on recent nightlies (#10991)
s3krit added a commit that referenced this pull request Sep 12, 2019
* add more tx tests (#11038)
* Fix parallel transactions race-condition (#10995)
* Add blake2_f precompile (#11017)
* [trace] introduce trace failed to Ext (#11019)
* Edit publish-onchain.sh to use https (#11016)
* Fix deadlock in network-devp2p (#11013)
* EIP 1108: Reduce alt_bn128 precompile gas costs (#11008)
* xDai chain support and nodes list update (#10989)
* EIP 2028: transaction gas lowered from 68 to 16 (#10987)
* EIP-1344 Add CHAINID op-code (#10983)
* manual publish jobs for releases, no changes for nightlies (#10977)
* [blooms-db] Fix benchmarks (#10974)
* Verify transaction against its block during import (#10954)
* Better error message for rpc gas price errors (#10931)
* tx-pool: accept local tx with higher gas price when pool full (#10901)
* Fix fork choice (#10837)
* Cleanup unused vm dependencies (#10787)
* Fix compilation on recent nightlies (#10991)
@niklasad1 niklasad1 deleted the ng-tx-queue-fix branch September 13, 2019 13:19
dvdplm added a commit that referenced this pull request Sep 13, 2019
* master: (70 commits)
  ethcore: remove `test-helper feat` from build (#11047)
  Include test-helpers from ethjson (#11045)
  [ethcore]: cleanup dependencies (#11043)
  add more tx tests (#11038)
  Fix parallel transactions race-condition (#10995)
  [ethcore]: make it compile without `test-helpers` feature (#11036)
  Benchmarks for block verification (#11035)
  Move snapshot related traits to their proper place (#11012)
  cleanup json crate (#11027)
  [spec] add istanbul test spec (#11033)
  [json-spec] make blake2 pricing spec more readable (#11034)
  Add blake2_f precompile (#11017)
  Add new line after writing block to hex file. (#10984)
  fix: remove unused error-chain (#11028)
  fix: remove needless use of itertools (#11029)
  Convert `std::test` benchmarks to use Criterion (#10999)
  Fix block detail updating (#11015)
  [trace] introduce trace failed to Ext (#11019)
  cli: update usage and version headers (#10924)
  [private-tx] remove unused rand (#11024)
  ...
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A8-looksgood 🦄 Pull request is reviewed well. B0-patch-stable 🕷 Pull request should also be back-ported to the stable branch. M4-core ⛓ Core client code / Rust.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

--config=dev doesn't seal properly when transactions are sent in parallel
4 participants