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

fix(core-blockchain): discard blocks containing forged tx and stop process queue on fork #1732

Merged
merged 31 commits into from
Dec 17, 2018
Merged

Conversation

spkjp
Copy link
Contributor

@spkjp spkjp commented Dec 15, 2018

Proposed changes

This PR fixes and refactors some issues with block processing and download in general.

  • Move block exception check to the beginning of processBlock
  • When downloading blocks, it can cause a fork at any time. The process queue is not paused immediately and may push one more block for the current round => revertRound hits an assert

See that there's 920,758 after the FORK event:

[2018-12-14 20:20:19][INFO]    : Downloaded 139 new blocks accounting for a total of 1 transaction
[2018-12-14 20:20:19][WARN]    : Downloaded block not accepted: {"id":"15050679645209862619","version":0,"timestamp":54709946,"height":920767,"reward":"200000000","previousBlock":"2018383776580683639","numberOfTransactions":0,"totalAmount":"0","totalFee":"0","payloadLength":0,"payloadHash":"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855","generatorPublicKey":"03d3c6889608074b44155ad2e6577c3368e27e6e129c457418eb3e5ed029544e8d","blockSignature":"30450221008ec05d4bb0d3f5fbe00871736f371173448c4de4f9008e160d6094c2a90320b802206b1072972a46544bcec7f1860b71c03f29f9579942dba7ee6fc132def815554d","ip":"95.179.235.167"}
[2018-12-14 20:20:19][WARN]    : Last block: {"id":"3306179701556476362","version":0,"timestamp":54713664,"height":920766,"reward":"200000000","previousBlock":"16386574835420196172","numberOfTransactions":0,"totalAmount":"0","totalFee":"0","payloadLength":0,"payloadHash":"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855","generatorPublicKey":"029a20963b506afabb2bd805830a46cef8d59218cd88c0dca9d2a0158045b1c3e0","blockSignature":"3045022100ee2f3cdee81733064b17221abfaa964ac2d62dc3bb7a8fa39f146746b25e3d2a02206e7d4f3967cc570709af74e8d08162b2fd565b8cc057571c5d53f8c5d74cfd2d","ip":"167.114.43.52"}
[2018-12-14 20:20:19][DEBUG]   : event 'FORK': {"syncWithNetwork":"downloadBlocks"} -> {"fork":"analysing"} -> actions: [startForkRecovery, analyseFork]
[2018-12-14 20:20:19][DEBUG]   : Delegate xillion (02d2a18dcb0dd7abd0a91ca70cb79d04e1ff7a4e77d1d8beda3d6c0a51b55a5db1) allowed to forge block 920,758 👍
...
[2018-12-14 20:20:20][INFO]    : Undoing block 920,757
(node:31146) UnhandledPromiseRejectionWarning: AssertionError [ERR_ASSERTION]: The expression evaluated to a falsy value:  assert_1.default(this.blocksInCurrentRound.pop().data.id === block.data.id)

This is fixed by ensuring the process queue is stopped first when starting a fork recovery.

Furthermore:

  • When a chained block is received, it is dropped if it contains a forged transaction. (hurts a bit)
  • After database recovery, the blocksInCurrentRound were not updated which caused the same assert failure as above.

Types of changes

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Refactoring (improve a current implementation without adding a new feature or fixing a bug)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Build (changes that affect the build system)
  • Docs (documentation only changes)
  • Test (adding missing tests or fixing existing tests)
  • Other... Please describe:

Checklist

  • I have read the CONTRIBUTING documentation
  • Lint and unit tests pass locally with my changes
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)

@ghost ghost assigned spkjp Dec 15, 2018
@ghost ghost added the review label Dec 15, 2018
@codecov-io
Copy link

codecov-io commented Dec 15, 2018

Codecov Report

Merging #1732 into develop will increase coverage by <.01%.
The diff coverage is 38.59%.

Impacted file tree graph

@@            Coverage Diff             @@
##           develop   #1732      +/-   ##
==========================================
+ Coverage     39.9%   39.9%   +<.01%     
==========================================
  Files          352     352              
  Lines         7665    7685      +20     
  Branches      1100    1091       -9     
==========================================
+ Hits          3059    3067       +8     
- Misses        4590    4604      +14     
+ Partials        16      14       -2
Impacted Files Coverage Δ
packages/core-blockchain/src/state-storage.ts 85.71% <ø> (-0.21%) ⬇️
packages/core-p2p/src/court/guard.ts 0% <0%> (ø) ⬆️
packages/core-p2p/src/monitor.ts 0% <0%> (ø) ⬆️
packages/core-blockchain/src/state-machine.ts 42.92% <37.5%> (-0.89%) ⬇️
packages/core-database/src/interface.ts 28.98% <50%> (+0.72%) ⬆️
packages/core-blockchain/src/blockchain.ts 69.23% <51.72%> (-1.74%) ⬇️
packages/core-deployer/src/utils.ts 0% <0%> (ø) ⬆️
packages/core-logger-winston/src/formatter.ts 0% <0%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update db6590e...f1f7a70. Read the comment docs.

@ghost ghost assigned faustbrian Dec 15, 2018
kristjank
kristjank previously approved these changes Dec 15, 2018
@spkjp spkjp merged commit 35dbb99 into ArkEcosystem:develop Dec 17, 2018
@ghost ghost removed the review label Dec 17, 2018
@spkjp spkjp deleted the blockchain-fixes branch December 17, 2018 16:59
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

4 participants