-
Notifications
You must be signed in to change notification settings - Fork 188
Preperation to support different database backends #939
Conversation
- still a WIP, tests not yet done - blockchain logic was moved from LevelDBBlockchain to Blockchain class - chain syncs successfully - notification db not yet done
- still WIP - made linter happy
…plement a new database backend
I would also like to reference np-rocksdb which is based on alt-db-support and implements RocksDB as an alternative database backend. It's not fully tested yet though, all the unit tests pass ( fixtures are migrated to RocksDB ) but I have not yet synced a full node. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given that we've already discussed quite some on Discord there's mostly some nitpicks on typo's/documentation and then 2 actual items that need some work.
One more things I encountered when running your LevelDB implementation
|
Another thing that came to mind; we should provide a set of test vectors that new implementations can run against. For example my neo-python/neo/Implementations/Blockchains/LevelDB/LevelDBBlockchain.py Lines 387 to 392 in fe90f62
Meaning it expects a
|
Fixed. |
I have written a few generic tests during the implementation of
I think I am missing something here. A transaction is stored in the value is created from I'll hit you up on discord, to discuss this. |
True, it's not specific anymore. It's just that argument type and format is derived from what was once necessary for leveldb. For example for |
Ok, I understand, that should be covered in the docstrings for |
This branch doesn't seem to sync. Probably because it can't retrieve data
|
I did a quick test run just now and so far looks good 👍 . I'm gonna use your branch to do the audit with as the audit also includes storage comparison. Otherwise I'd have to do that part twice, which doesn't make sense. This does mean it can take a couple of days before it gets merged (fyi) |
Ok perfect, thank you for the response. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As mentioned previously a quick np-prompt
suggested it was working as intended. Today I tried to import blocks for the auditing purpose and I ran into a couple of issues
np-import
doesn't work because the script was not converted to use the new db layer. (probably because it's not covered by the tests- Trying to update that I quickly ran into a circular import error for
neo.Core.Blockchain import Blockchain
import statements . After some dirty fixes I could get it to run, but within importing a couple thousand blocks I received errors like the following:
Traceback (most recent call last):
File "/home/erik/merl/neo/Core/Blockchain.py", line 1100, in Persist
service.ExecutionCompleted(engine, success)
File "/home/erik/merl/neo/SmartContract/StateMachine.py", line 219, in ExecutionCompleted
super(StateMachine, self).ExecutionCompleted(engine, success, error)
File "/home/erik/merl/neo/SmartContract/StateReader.py", line 130, in ExecutionCompleted
tx_hash = engine.ScriptContainer.Hash
AttributeError: 'bytes' object has no attribute 'Hash'
- Having looked closer while keeping performance in mind I believe we should not use the static
ApplicationEngine.Run()
inPersist()
. Reason being is that for each invocation TX that's executed it will try to import the required modules, will setup all requiredDBInterface
's, then execute. In the old setup this was done just once per Block. Imagine a block with 50+ InvocationTransactions and we're going to lose quite some speed.
My suggestion would be for you to update np-import
(== ./neo/bin/import_blocks.py
) to support the new DB layer, then make sure you can import e.g. the first 100K blocks.
…d call of static methond in Persist()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't notice this before, but the --datadir
flag isn't working for np-prompt
.
(venv) erik@erik-linux:~/merl$ np-prompt --datadir test_storage/
Maxpeers set to 5
[I 190612 08:07:54 LevelDBImpl:43] Created DB at /home/erik/.neopython/Chains/SC234
[I 190612 08:07:55 LevelDBImpl:43] Created DB at /home/erik/merl/test_storage/Chains/Test_Notif
[I 190612 08:07:55 NotificationDB:75] Created Notification DB At /home/erik/merl/test_storage/Chains/Test_Notif
[2019-06-12 08:07:55.454651] Running P2P network on localhost 20333
NEO cli. Type 'help' to get started
neo>
Notice how I specified a local folder but it still put it in the default ~/.neopython/
location.
Another thing is the double Test_Notif
location message. Although printed from different classes a double message adds no extra value. Please remove one of them.
Other than that all looks ok. I can import blocks, gather blocks over P2P, query blocks/headers/tx's, still create new tx's (sending assets) and have them stored properly.
When merging the dev branch probably the only PR that will cause a conflict is https://github.com/CityOfZion/neo-python/pull/965/files (because it touched the LevelDB class directly)
500 points |
What current issue(s) does this address, or what feature is it adding?
preperation for #896
closes #895
closes #894
How did you solve this problem?
The whole database access has been reworked and decoupled. Business logic which has been part of
LevelDBBlockchain
has been moved to theBlockchain
class. Afactory
to dynamically generate the database class has been introduced. The class returned by thefactory
handleswrite
read
delete
access to the database, therefore it's completely decoupled from the blockchain business logic. Same thing was done for theNotificationDB
.How did you make sure your solution works?
Synced full node.
Bootstrapped node.
All unit tests pass.
Are there any special changes in the code that we should be aware of?
The whole business logic from
LevelDBBlockchain
has been moved to theBlockchain
class.Please check the following, if applicable:
make lint
?make test
?CHANGELOG.rst
? (if not, please do)