-
Notifications
You must be signed in to change notification settings - Fork 686
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
Adding a new db wrapper - TrackedDB #204
Conversation
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.
Have you looked into how this is going to interact with the JournalDB
or whether this should be integrated with that class in some way. If an internal call within a transaction touches some state and then those state changes are reverted due to an evm exception, do the touched parts still remain in the read/write list? My assumption is yes, but if not, we need to take that into account.
evm/db/state.py
Outdated
@@ -217,3 +218,86 @@ def _get_account(self, address): | |||
|
|||
def _set_account(self, address, account): | |||
self._trie[address] = rlp.encode(account, sedes=Account) | |||
|
|||
|
|||
class StateDB(BaseDB): |
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.
Can I suggest we move this to it's own module since it's a low level DB wrapper.
I would also suggest we rename this to something more descriptive. Here are some names that come to mind.
StenographerDB
(A stenographer is the person in a courtroom who types everything that people say).TrackedDB
- tracks changes, touches, etc.LedgerDB
- keeps a ledger of the db read/write
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.
Sure!
In pyethereum
, a similar db wrapper is called ListeningDB
. IMO StenographerDB
is cool but a bit too long. I like TrackedDB
.
My assumption is that in the stateless client use case,
p.s. I am writing some more detailed description and will comment on #195 |
I want to leave the modification of |
evm/db/tracked.py
Outdated
try: | ||
current_value = self.wrapped_db.get(key) | ||
except KeyError: | ||
raise |
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.
This whole try/except/else
block is equivalent to the same code without the try/except/else
since except
just re-raises.
current_value = self.wrapped_db.get(key)
self._reads[key] = current_value
return current_value
evm/db/tracked.py
Outdated
# do not need to be added in writes | ||
pass | ||
else: | ||
self._writes[key] = current_value |
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.
Should this instead be set to something like None
to indicate that it's been deleted?
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.
Good, using None
would be more clear :)
And I think the delete
function don't need to return something?
Can I just modify it to:
def delete(self, key):
"""
Delete the key and update writes dict.
"""
self.wrapped_db.delete(key)
self._writes[key] = None
evm/db/tracked.py
Outdated
|
||
def get_reads(self, key=None): | ||
""" | ||
Return the whole or the specific value of reads dict. |
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'm thinking that we can accomplish the same by just exposing reads
as a property.
all_reads = db.get_reads()
single_read = db.get_reads(key=b'cow')
# becomes the following if `reads` is a public property
all_reads = db.reads
single_read = db.reads.get(key=b'cow')
Alternatively, I'd be more comfortable with this API if it only did one of these two things (preferrably returning all reads).
evm/db/tracked.py
Outdated
|
||
def get_writes(self, key=None): | ||
""" | ||
Return the whole or the specific value of writes dict. |
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.
Same thoughts as with the get_reads
API
if |
1. Set `reads` and `writes` properties for accessing `_reads` and `writes` 2. Modified the `exsits` and `deletes` to store the accessed key-value result in dicts
|
What was wrong?
This PR is part of #195
The first step: database wrapper
How was it fixed?
Adding a new database wrapper
TrackedDB
.TrackedDB
has two dicts:_writes
: keeps track of the nodes that are accessed byTrackedDB.put(key, value)
_reads
: keeps track of that are accessed byTrackedDB.get(key)
Some new class properties of
TrackedDB
:@property def reads(self)
: returns the whole_reads
dict@property def writes(self)
: returns the whole_writes
dictCute Animal Picture