Skip to content
This repository has been archived by the owner on Jan 22, 2019. It is now read-only.

implement block-retention #47

Merged
merged 17 commits into from
Aug 12, 2018
Merged

implement block-retention #47

merged 17 commits into from
Aug 12, 2018

Conversation

nionis
Copy link
Contributor

@nionis nionis commented Aug 8, 2018

this commit is unfinished / buggy work on block-retention

todo:

  • fix bug: when stopping server in the middle of saving block - reducing new state
  • double check state when resuming

@shrugs
Copy link
Member

shrugs commented Aug 9, 2018

@nionis I added a commit; let me know if you agree with all of the changes there. a manual test on my laptop is working afaik (need to test data consistency, though). I think the bug when ctrl-c has been fixed, somehow.

But I'm doing some testing work as my next focus, which will definitely be testing this behavior.

@@ -64,34 +63,46 @@ class ReducerRunner {
// we're resuming, so replay from store if possible
try {
const latestTransaction = await globalState.store.getLatestTransaction(this.reducer.config.key)
Copy link
Contributor Author

@nionis nionis Aug 9, 2018

Choose a reason for hiding this comment

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

does getLatestTransaction include historicalblocks transactions of the reducer?

Copy link
Member

Choose a reason for hiding this comment

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

it doesn't; this gets the latest Ourbit transaction (which isn't a blockchain transaction, but I didn't have a better name for it :( )

}

try {
const mostRecentHistoricalBlock = historicalBlocks[historicalBlocks.length - 1]

assert.equal(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

lets say last transaction was at block 100
and we let the reducer run until the saved chain has blocks from 101 - 201

this is only okay if getLatestTransaction includes historicalblocks transactions, if it does not include historicalblocks transactions then there is a possibility that the last reducer transaction was done 100 blocks ago

Copy link
Member

Choose a reason for hiding this comment

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

lastTransaction should always be the most recent Ourbit#Transaction, which is produced after a block is found, just like historical blocks. The only time this won't be true is if the process crashing right in the middle of the part where we commitTransaction and saveHistoricalBlock, right? Maybe I'm misunderstanding, sorry

Copy link
Contributor Author

Choose a reason for hiding this comment

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

so if I understand correctly, Ourbit#Transaction will be produced every block since we save the historical block into the db?

Copy link
Member

Choose a reason for hiding this comment

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

An Ourbit#Transaction is the set of all of the patches and operations that were performed in one atomic set (like a blockstream block). So it is produced for every block (after that block has been processed), but not because of the historical blocks; it's job is to track the patches so that we can potentially revert them later.

@nionis
Copy link
Contributor Author

nionis commented Aug 9, 2018

@shrugs The state issue is not fixed, I still get it on my end when I ctrl-c and restart a couple of times, it happens when applying patches

  gnarly-core:runner:ZRX Attempting to reload ourbit state from ca3c505d-d336-4477-9b1f-
...
  gnarly-core:ourbit:ZRX [applyPatch] 08ebe1c6-3be2-4d27-ad81-da806af9664e 3 +168ms
  gnarly-core:ourbit:ZRX [applyPatch] 6f1a4cde-16aa-4bc8-9da7-b43832fd1c57 3 +1ms
  gnarly-core:ourbit:ZRX [applyPatch] ec1b1c96-cff3-4319-9418-c0a487667e14 8 +0ms
  gnarly-core:ourbit:ZRX [applyPatch] 7f3e0cee-a01b-423f-9927-27a4bcea5c21 5 +1ms
  gnarly-core:ourbit:ZRX [applyPatch] a800a1a5-6d52-43ca-bdc9-5cfc04e9ae5f 7 +0ms
  gnarly-core:ourbit:ZRX [applyPatch] d74845fd-9188-4587-a325-f9bf5b3bcf44 10 +0ms
  gnarly-core:ourbit:ZRX [applyPatch] ea3889d0-bb48-4a57-8e23-372d3b7fefaf 2 +0ms
  gnarly-core:ourbit:ZRX [applyPatch] b886805e-b3d2-4131-9b12-e88c54a189d3 10 +0ms
  gnarly-core:ourbit:ZRX [applyPatch] bd258ad5-1691-4b6d-953d-c259ab91abde 4 +1ms
  gnarly-core:ourbit:ZRX [applyPatch] 362204a9-ba8a-4aff-a77b-9c156b70857f 16 +0ms
  gnarly-core:ourbit:ZRX [applyPatch] 4f8fbde3-321f-499f-a0b0-f608b1d82636 10 +0ms
  gnarly-core:ourbit:ZRX [applyPatch] e01d6e54-3612-4c2f-b683-9f3f0c878af9 8 +0ms
  gnarly-core:ourbit:cryptoKitties [applyPatch] 66378039-fb1e-413e-be0d-6b218d3bbbcc 2 +171ms
  gnarly-core:ourbit:cryptoKitties [applyPatch] dc90040f-6daf-4fd4-9e30-f20d173de399 2 +1ms
  gnarly-core:ourbit:cryptoKitties [applyPatch] d0e63b8a-3500-4ffc-9632-a4855ec21ce6 2 +0ms
  gnarly-core:ourbit:cryptoKitties [applyPatch] 6ee2aade-fe4c-4ad4-9bf3-865acd319b7c 3 +0ms
  gnarly-core:ourbit:cryptoKitties [applyPatch] a2557a7c-8132-4fa5-824f-0d221c18f245 1 +0ms
  gnarly-core:ourbit:cryptoKitties [applyPatch] a0d99ada-f1b5-4d36-995e-6a5234a2692f 1 +0ms
  gnarly-core:ourbit:cryptoKitties [applyPatch] 2633f4f2-9626-4c9f-b134-290b9678d427 4 +1ms
  gnarly-core:ourbit:cryptoKitties [applyPatch] 8a7dcd22-ba96-4f36-b22a-0e5f4faf6775 2 +0ms
  gnarly-core:ourbit:cryptoKitties [applyPatch] 78e6601d-1c28-4b03-8fe0-b0768ed7b000 2 +0ms
  gnarly-core:ourbit:cryptoKitties [applyPatch] 7a587fd9-c866-49fc-851a-4c4e0b48ac4f 4 +0ms
  gnarly-core:ourbit:cryptoKitties [applyPatch] c6485cf0-49fe-4402-be9b-7e8566dddf34 2 +0ms
  gnarly-core:ourbit:cryptoKitties [applyPatch] bc29c238-f036-46ac-a60e-d21fb9f53a56 2 +0ms
  gnarly-core:ourbit:cryptoKitties [applyPatch] 275ee6e3-07bd-4b02-825e-ef374a35e746 2 +1ms
  gnarly-core:ourbit:cryptoKitties [applyPatch] 344a4b17-fe93-4ab6-9170-470f3510c43d 1 +0ms
  gnarly-core:ourbit:cryptoKitties [applyPatch] 37f9ddff-fc27-4850-b798-6beca853299d 3 +0ms
  gnarly-core:ourbit:cryptoKitties [applyPatch] b51ba569-2b03-4e41-996a-6a9bbba06e5a 2 +1ms
  gnarly-core:ourbit:cryptoKitties [applyPatch] b4779b0b-a0f8-4741-a16d-822cef31a258 1 +0ms
  gnarly-core:ourbit:cryptoKitties [applyPatch] afbd1f9c-2923-4779-8451-c0fa5472fb2e 1 +0ms
  gnarly-core:ourbit:cryptoKitties [applyPatch] ef51d11a-e774-4d87-ae11-269a3351a57f 1 +0ms
  gnarly-core:ourbit:cryptoKitties [applyPatch] e3e4897c-10a5-4496-b922-a808a24b6b9f 1 +0ms
  gnarly-core:ourbit:cryptoKitties [applyPatch] 15730617-b380-4f96-9c02-28e853f9961b 1 +1ms
  gnarly-core:ourbit:cryptoKitties [applyPatch] bce51aa3-f582-4c25-8c2f-8ccf35f21974 1 +0ms
  gnarly-core:ourbit:cryptoKitties [applyPatch] ef8427d4-b0b3-4f85-a631-fe05aa43f746 1 +0ms
  gnarly-core:ourbit:cryptoKitties [applyPatch] 7f40b069-d6f8-4099-8932-ff96857de7a9 1 +9ms
  gnarly-core:ourbit:cryptoKitties [applyPatch] 8af67961-e511-48ba-882a-c6bd1f40a84a 3 +0ms
  gnarly-core:ourbit:cryptoKitties [applyPatch] f68a36ae-9f66-42a8-ac40-0542c8da7ac7 1 +0ms
  gnarly-core:ourbit:cryptoKitties [applyPatch] 722bb61c-9f25-4d8f-ba5a-e1fd18a58b14 2 +0ms
  gnarly-core:ourbit:blocks finished applying 0 patches +192ms
  gnarly-core:ourbit:cryptoKitties finished applying 49 patches +1ms
  gnarly-core:runner:blocks Done reloading ourbit state. +193ms
  gnarly-core:runner:blocks Attempting to reload blockstream state from 0x1d26748bb16797209e4d6e7d02f66f38934de9c1494a6fb0b10dbd79b72e05d3 +0ms
  gnarly-core:blockstream Initializing history with last historical block 5547496 +108ms
  gnarly-core:runner:ZRX TypeError: Cannot read property 'balanceStr' of undefined
  gnarly-core:runner:ZRX     at Object.replace (/mnt/c/work/projects/gnarly/node_modules/@xlnt/fast-json-patch/lib/core.js:27:26)
  gnarly-core:runner:ZRX     at applyOperation (/mnt/c/work/projects/gnarly/node_modules/@xlnt/fast-json-patch/lib/core.js:231:60)
  gnarly-core:runner:ZRX     at Object.applyPatch (/mnt/c/work/projects/gnarly/node_modules/@xlnt/fast-json-patch/lib/core.js:268:22)
  gnarly-core:runner:ZRX     at txBatch.forEach (/mnt/c/work/projects/gnarly/packages/gnarly-core/src/ourbit/Ourbit.ts:131:9)
  gnarly-core:runner:ZRX     at Array.forEach (<anonymous>)
  gnarly-core:runner:ZRX     at Ourbit.<anonymous> (/mnt/c/work/projects/gnarly/packages/gnarly-core/src/ourbit/Ourbit.ts:127:15)
  gnarly-core:runner:ZRX     at Generator.next (<anonymous>)
  gnarly-core:runner:ZRX     at fulfilled (/mnt/c/work/projects/gnarly/packages/gnarly-core/lib/ourbit/Ourbit.js:4:58) +189ms
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

The issue turns out to be coming from erc20 reducer, and maybe its the use of 2 operations, I am moving this to a new issue #48

@shrugs
Copy link
Member

shrugs commented Aug 9, 2018

I think it's still possible to move this historical block code into the blockstream and take it out of the reducer runner; that way it's the blockstream doing all of the work on itself. It just has to know about the store. Do you think that's a better structure?

@nionis
Copy link
Contributor Author

nionis commented Aug 9, 2018

@shrugs up to you, I don't really know

@shrugs
Copy link
Member

shrugs commented Aug 9, 2018

@nionis I'll try it out on a commit and you can tell me if it looks ok. hopefully I finish before my laptop runs out of battery right now 😂

@nionis nionis changed the title unpolished implemenation of historical blocks implement block-retention Aug 9, 2018
@shrugs
Copy link
Member

shrugs commented Aug 9, 2018

@nionis let me know how you feel about that last commit; not super tested because my laptop is dying, but feel free to change or revert it

@shrugs shrugs changed the base branch from feat/block-retention to master August 11, 2018 18:06
@coveralls
Copy link

Pull Request Test Coverage Report for Build 30

  • 4 of 69 (5.8%) changed or added relevant lines in 4 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-28.2%) to 45.666%

Changes Missing Coverage Covered Lines Changed/Added Lines %
packages/gnarly-core/src/ReducerRunner.ts 2 18 11.11%
packages/gnarly-core/src/stores/sequelize.ts 1 25 4.0%
packages/gnarly-core/src/Blockstream.ts 0 25 0.0%
Totals Coverage Status
Change from base Build 29: -28.2%
Covered Lines: 328
Relevant Lines: 662

💛 - Coveralls

@shrugs
Copy link
Member

shrugs commented Aug 12, 2018

I'm working on https://github.com/XLNT/gnarly/tree/feat/block-retention for now, with some refactor/test commits. Don't want to push them here because they're incomplete, but check them out before you build on top of this branch at the moment.

@shrugs
Copy link
Member

shrugs commented Aug 12, 2018

added a bunch of blockstreamer tests, so that's looking pretty good. any extra cases we should test? I'm sure there are more

@shrugs shrugs merged commit d66431d into XLNT:master Aug 12, 2018
@shrugs
Copy link
Member

shrugs commented Aug 12, 2018

merged 🎉

@shrugs
Copy link
Member

shrugs commented Aug 12, 2018

will flesh out more tests in the coming days, but I'm happy with the suite enough to merge this bigboi pr

This was referenced Aug 12, 2018
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.

3 participants