Skip to content
This repository has been archived by the owner on Jul 27, 2022. It is now read-only.

Problem (Fix #1069): blocks with multiple txs may fail light client app hash check #1117

Merged
merged 1 commit into from
Feb 24, 2020

Conversation

yihuang
Copy link
Collaborator

@yihuang yihuang commented Feb 21, 2020

Solution:

  • Change BTreeMap to IndexMap

Copy link
Contributor

@tomtau tomtau left a comment

Choose a reason for hiding this comment

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

would be good to add a small test that demonstrates the bug

@yihuang
Copy link
Collaborator Author

yihuang commented Feb 21, 2020

would be good to add a small test that demonstrates the bug

Yeah, I just want to unblock @calvinlauco 's work first, we can add the integration tests like discussed on slack.

@calvinlauyh
Copy link
Contributor

would be good to add a small test that demonstrates the bug

Yeah, I just want to unblock @calvinlauco 's work first, we can add the integration tests like discussed on slack.

Thanks @yihuang , Let me try with this first and get back to you.
@lezzokafka

@yihuang
Copy link
Collaborator Author

yihuang commented Feb 21, 2020

Fixed the unit test build.

@lezzokafka
Copy link
Collaborator

Thanks @yihuang , Let me try with this first and get back to you.
@lezzokafka

Tested, it passed the problematic block :D

@codecov
Copy link

codecov bot commented Feb 21, 2020

Codecov Report

Merging #1117 into master will increase coverage by 0.29%.
The diff coverage is 85.07%.

@@            Coverage Diff             @@
##           master    #1117      +/-   ##
==========================================
+ Coverage   64.37%   64.67%   +0.29%     
==========================================
  Files         148      148              
  Lines       19393    19495     +102     
==========================================
+ Hits        12485    12608     +123     
+ Misses       6908     6887      -21
Impacted Files Coverage Δ
...lient-common/src/tendermint/types/block_results.rs 87% <100%> (+1.59%) ⬆️
client-core/src/wallet/syncer_logic.rs 94.69% <100%> (ø) ⬆️
client-core/src/wallet/syncer.rs 67.13% <84.12%> (+5.28%) ⬆️
chain-storage/src/account/mod.rs 94.11% <0%> (-0.56%) ⬇️
chain-core/src/common/merkle_tree.rs 98.55% <0%> (-0.25%) ⬇️
chain-abci/src/app/mod.rs 87.02% <0%> (-0.07%) ⬇️
chain-abci/src/app/validate_tx.rs 94.52% <0%> (ø) ⬆️
chain-abci/tests/abci_app.rs 94.59% <0%> (ø) ⬆️
chain-abci/src/app/query.rs 58.45% <0%> (+0.29%) ⬆️
chain-core/src/init/params.rs 78.39% <0%> (+0.61%) ⬆️
... and 5 more

Copy link
Collaborator

@calvinaco calvinaco left a comment

Choose a reason for hiding this comment

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

I also verified that it has solved the problem. Should we wait for the test case as it seems complicated to create one. Or we should merge this to fix the current issue first?

@tomtau
Copy link
Contributor

tomtau commented Feb 22, 2020

I also verified that it has solved the problem. Should we wait for the test case as it seems complicated to create one. Or we should merge this to fix the current issue first?

i think there could at least be a small unit test that captures the bug (it may need isolating out some of the sync functionality)

@calvinaco
Copy link
Collaborator

calvinaco commented Feb 22, 2020

would be good to add a small test that demonstrates the bug

Yeah, I just want to unblock @calvinlauco 's work first, we can add the integration tests like discussed on slack.

@yihuang
I have extracted the block data and create a test here
calvinlauyh@18a14ba (TravisCI)

and then I applied your fix here
calvinlauyh@029a065 (TravisCI)

@yihuang
Copy link
Collaborator Author

yihuang commented Feb 22, 2020

I just added a multinode integration test for this and cherry-picked @calvinaco 's unit test.

@lgtm-com
Copy link

lgtm-com bot commented Feb 22, 2020

This pull request introduces 1 alert when merging 53bdae3 into 0bbfbbf - view on LGTM.com

new alerts:

  • 1 for Unused import

@yihuang yihuang force-pushed the issue1069 branch 2 times, most recently from 05d821d to a541d6b Compare February 22, 2020 10:33
Copy link
Contributor

@calvinlauyh calvinlauyh left a comment

Choose a reason for hiding this comment

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

LG2M

@tomtau tomtau self-requested a review February 24, 2020 01:00
Copy link
Contributor

@tomtau tomtau left a comment

Choose a reason for hiding this comment

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

👍 can you squash the commits?

@yihuang
Copy link
Collaborator Author

yihuang commented Feb 24, 2020

👍 can you squash the commits?

Done

@tomtau
Copy link
Contributor

tomtau commented Feb 24, 2020

bors r+

bors bot added a commit that referenced this pull request Feb 24, 2020
1116: Problem: uncommitted chain-abci storage changes may persisted (fixes #885) r=tomtau a=tomtau

Solution: for the TX-related ops, added a temporary map in storage:
- insertions during delivertx will update the temporary map + insert entry into the current db tx
- at commit, the db tx is written and flushed
- lookup extended to indicate whether the caller wants to read the uncommitted change (as in delivertx
-- e.g. if two transactions in the same block want to spend the same utxo,
only the first one is valid, so processing needs to read the uncommitted change from the first one before processing the second one)
or committed change (e.g. in queries)

added two quick unit tests (the first one used to fail with "buffered_write" -- "buffered_write" was removed, as inserts are kind of buffered writes)


1117: Problem (Fix #1069): blocks with multiple txs may fail light client app hash check r=tomtau a=yihuang

Solution:
- Change BTreeMap to IndexMap

Co-authored-by: Tomas Tauber <[email protected]>
Co-authored-by: yihuang <[email protected]>
@@ -56,11 +56,11 @@ pub struct Attribute {

impl BlockResults {
/// Returns transaction ids and the corresponding fees in block results
pub fn fees(&self) -> Result<BTreeMap<TxId, Fee>> {
pub fn fees(&self) -> Result<IndexMap<TxId, Fee>> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

could you add some explanation why "change to IndexMap"?

@bors
Copy link
Contributor

bors bot commented Feb 24, 2020

Build failed (retrying...)

Copy link
Contributor

@tomtau tomtau left a comment

Choose a reason for hiding this comment

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

seems the integration test fails (occasionally) -- I'm ok with just the unit test for now, so could either be removed or fixed (if there's a quick easy and stable fix)

last_height = latest_block_height(rpc)

print('Send multiple tx')
pending_txs = [rpc.wallet.send(transfer1, amount) for _ in addresses]
Copy link
Contributor

Choose a reason for hiding this comment

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

is rpc.wallet.send async?
It seems there needs to be some "wait", otherwise node1 may be started up before everything else?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

is rpc.wallet.send async?
It seems there needs to be some "wait", otherwise node1 may be started up before everything else?

Even if it's async, the tx should be processed eventually? Maybe wait_for_tx need some more timeout?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Changed a little bit, let's see how that works?

Copy link
Contributor

@tomtau tomtau Feb 24, 2020

Choose a reason for hiding this comment

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

Even if it's async, the tx should be processed eventually?

yes, but my guess is that the goal is here is that these TXs end up in mempool while node1 is down, so that they all get picked up for the same block. If node1 starts up before that / while they are being submitted, they may get picked up immediately for different blocks

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Even if it's async, the tx should be processed eventually?

yes, but my guess is that the goal is here is that these TXs end up in mempool while node1 is down, so that they all get picked up for the same block. If node1 starts up before that / while they are being submitted, they may get picked up immediately for different blocks

Yes, I added 1-second sleep for this.

bors bot added a commit that referenced this pull request Feb 24, 2020
1117: Problem (Fix #1069): blocks with multiple txs may fail light client app hash check r=tomtau a=yihuang

Solution:
- Change BTreeMap to IndexMap

Co-authored-by: yihuang <[email protected]>
…t client app hash check

Solution:
- Change BTreeMap to IndexMap

:white_check_mark: Add test case to cover mismatch app hash
@bors
Copy link
Contributor

bors bot commented Feb 24, 2020

Canceled

@tomtau
Copy link
Contributor

tomtau commented Feb 24, 2020

bors r+

@bors
Copy link
Contributor

bors bot commented Feb 24, 2020

@bors bors bot merged commit bd42b37 into crypto-com:master Feb 24, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants