-
Notifications
You must be signed in to change notification settings - Fork 690
Implement eth.abc module with abstract base classes for public APIs #1805
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
Implement eth.abc module with abstract base classes for public APIs #1805
Conversation
in each receipt. Byzantium+, we only need state roots at the end of the block, | ||
so we *only* call it right before persistance. | ||
|
||
:return: the new state root |
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.
Anywhere like this where the original abc method had a docstring, the docstring was migrated to the new abc base class.
@@ -239,8 +139,8 @@ def persist_block(self, | |||
@classmethod | |||
def _persist_block( | |||
cls, | |||
db: '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.
This resulted in a lot of cleanups like this where we no longer have circular import issues with type hints.
""" | ||
Returns an iterable of transactions for the block speficied by the | ||
given block header. | ||
""" | ||
return self._get_block_transactions(header.transaction_root, transaction_class) | ||
|
||
def get_block_transaction_hashes(self, block_header: BlockHeader) -> Iterable[Hash32]: |
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.
And I found a few places like this where our return types were allowing for things like returning a generator when that is typically a foot-gun.
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.
👍
BTW, the docstring still says iterable
0488967
to
8090364
Compare
Looks like I need to do some cleanup to get the fixture tests passing. |
c40a72a
to
a6c450a
Compare
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 took a very brief scan over this. If you point out any more places (like the Iterable->Tuple
) that have actual changes, I'm happy to give a normal review on those bits. Otherwise: 🚢 on ✔️ tests. 👍
""" | ||
Returns an iterable of transactions for the block speficied by the | ||
given block header. | ||
""" | ||
return self._get_block_transactions(header.transaction_root, transaction_class) | ||
|
||
def get_block_transaction_hashes(self, block_header: BlockHeader) -> Iterable[Hash32]: |
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.
👍
BTW, the docstring still says iterable
_error: VMError = None | ||
|
||
# TODO: use a NamedTuple for log entries |
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.
move to an issue?
backend_class = get_db_backend_class(import_path) | ||
return backend_class(**init_kwargs) | ||
# mypy doesn't understand the constructor of AtomicDatabaseAPI |
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.
Does it work if you add back the explicit @abstractmethod
with __init__
that was in BaseDB
?
@abstractmethod
def __init__(self) -> None:
raise NotImplementedError(
"The `init` method must be implemented by subclasses of 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.
Yes, but I don't believe there is a generic __init__
method for AtomicDatabaseAPI
implementations. We have one right now that wraps another database but I don't think that's the only constructor.
Also, I'm inclined to remove this functionality entirely because I don't think we actually use it in any meaningful way.
a6c450a
to
42752f0
Compare
What was wrong?
While working with the database components of the library in the trinity codebase I found myself wanting real abstract base class APIs to develop against.
How was it fixed?
Created
eth.abc
and created propertABC
base classes for all of the main APIs from the codebase.This should have near zero API changes. The places where APIs changed are minor and have to do with some juggling to define the ABC classes for the
rlp.Serializable
objects.To-Do
Cute Animal Picture