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

mempool: remove only valid (Code==0) txs on Update #3625

Merged
merged 4 commits into from
May 7, 2019

Conversation

melekes
Copy link
Contributor

@melekes melekes commented May 6, 2019

so evil proposers can't drop valid txs in Commit stage.

Also remove invalid (Code!=0) txs from the cache so they can be
resubmitted.

Fixes #3322

@rickyyangz:

In the end of commit stage, we will update mempool to remove all the txs
in current block.

// Update mempool.
err = blockExec.mempool.Update(
	block.Height,
	block.Txs,
	TxPreCheck(state),
	TxPostCheck(state),
)

Assum an account has 3 transactions in the mempool, the sequences are
100, 101 and 102 separately, So an evil proposal can only package the
101 and 102 transactions into its proposal block, and leave 100 still in
mempool, then the two txs will be removed from all validators' mempool
when commit. So the account lost the two valid txs.

@ebuchman:

In the longer term we may want to do something like #2639 so we can
validate txs before we commit the block. But even in this case we'd only
want to run the equivalent of CheckTx, which means the DeliverTx could
still fail even if the CheckTx passes depending on how the app handles
the ABCI Code semantics. So more work will be required around the ABCI
code. See also #2185

  • Updated all relevant documentation in docs
  • Updated all code comments where relevant
  • Wrote tests
  • Updated CHANGELOG_PENDING.md

so evil proposers can't drop valid txs in Commit stage.

Also remove invalid (Code!=0) txs from the cache so they can be
resubmitted.

Fixes #3322

@rickyyangz:

In the end of commit stage, we will update mempool to remove all the txs
in current block.

// Update mempool.
err = blockExec.mempool.Update(
	block.Height,
	block.Txs,
	TxPreCheck(state),
	TxPostCheck(state),
)

Assum an account has 3 transactions in the mempool, the sequences are
100, 101 and 102 separately, So an evil proposal can only package the
101 and 102 transactions into its proposal block, and leave 100 still in
mempool, then the two txs will be removed from all validators' mempool
when commit. So the account lost the two valid txs.

@ebuchman:

In the longer term we may want to do something like #2639 so we can
validate txs before we commit the block. But even in this case we'd only
want to run the equivalent of CheckTx, which means the DeliverTx could
still fail even if the CheckTx passes depending on how the app handles
the ABCI Code semantics. So more work will be required around the ABCI
code. See also #2185
@codecov-io
Copy link

codecov-io commented May 6, 2019

Codecov Report

Merging #3625 into develop will decrease coverage by 0.11%.
The diff coverage is 88.88%.

@@            Coverage Diff             @@
##           develop   #3625      +/-   ##
==========================================
- Coverage    63.31%   63.2%   -0.12%     
==========================================
  Files          218     217       -1     
  Lines        18253   18165      -88     
==========================================
- Hits         11557   11481      -76     
+ Misses        5737    5717      -20     
- Partials       959     967       +8
Impacted Files Coverage Δ
mempool/mempool.go 84.21% <ø> (ø) ⬆️
state/execution.go 73.41% <100%> (+0.11%) ⬆️
mempool/clist_mempool.go 81.54% <87.5%> (-0.43%) ⬇️
privval/signer_validator_endpoint.go 75.55% <0%> (-10%) ⬇️
privval/socket_listeners.go 86.2% <0%> (-6.9%) ⬇️
privval/signer_service_endpoint.go 85.45% <0%> (-3.64%) ⬇️
privval/signer_remote.go 80% <0%> (-2%) ⬇️
blockchain/reactor.go 70.56% <0%> (-0.94%) ⬇️
consensus/replay.go 70.2% <0%> (-0.82%) ⬇️
consensus/reactor.go 70.6% <0%> (-0.71%) ⬇️
... and 7 more

@melekes melekes marked this pull request as ready for review May 6, 2019 11:42
@melekes melekes requested review from ebuchman and xla as code owners May 6, 2019 11:42
// Block, proposed by evil proposer:
// 101 -> 102
// Mempool (if you remove txs):
// 100
Copy link
Contributor

@liamsi liamsi May 6, 2019

Choose a reason for hiding this comment

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

Can we write this down as a test case (which fails without the changes)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

TestMempoolUpdate will fail without the changes

Copy link
Contributor

Choose a reason for hiding this comment

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

I understand but I wondered if we should have the above example in a test instead of what is there in TestMempoolUpdate. But NVM. TestMempoolUpdate is actually better as it is more minimalistic!

@melekes melekes self-assigned this May 7, 2019
Copy link
Contributor

@liamsi liamsi left a comment

Choose a reason for hiding this comment

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

LGTM

@melekes melekes merged commit 27909e5 into develop May 7, 2019
@melekes melekes deleted the 3322-evil-proposers branch May 7, 2019 08:25
@melekes melekes mentioned this pull request May 30, 2019
44 tasks
melekes added a commit that referenced this pull request Jun 1, 2019
Otherwise, we'll be trying to include them in each consecutive block.

The downside is that evil proposers will be able to drop valid
transactions (see #3322).

Reverts #3625

Fixes #3699
ebuchman pushed a commit that referenced this pull request Jun 3, 2019
Otherwise, we'll be trying to include them in each consecutive block.

The downside is that evil proposers will be able to drop valid
transactions (see #3322).

Reverts #3625

Fixes #3699
brapse pushed a commit to brapse/tendermint that referenced this pull request Jun 5, 2019
* mempool: remove only valid (Code==0) txs on Update

so evil proposers can't drop valid txs in Commit stage.

Also remove invalid (Code!=0) txs from the cache so they can be
resubmitted.

Fixes tendermint#3322

@rickyyangz:

In the end of commit stage, we will update mempool to remove all the txs
in current block.

// Update mempool.
err = blockExec.mempool.Update(
	block.Height,
	block.Txs,
	TxPreCheck(state),
	TxPostCheck(state),
)

Assum an account has 3 transactions in the mempool, the sequences are
100, 101 and 102 separately, So an evil proposal can only package the
101 and 102 transactions into its proposal block, and leave 100 still in
mempool, then the two txs will be removed from all validators' mempool
when commit. So the account lost the two valid txs.

@ebuchman:

In the longer term we may want to do something like #2639 so we can
validate txs before we commit the block. But even in this case we'd only
want to run the equivalent of CheckTx, which means the DeliverTx could
still fail even if the CheckTx passes depending on how the app handles
the ABCI Code semantics. So more work will be required around the ABCI
code. See also tendermint#2185

* add changelog entry and tests

* improve changelog message

* reformat code
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.

None yet

3 participants