Skip to content

Conversation

pipermerriam
Copy link
Member

@pipermerriam pipermerriam commented Jul 31, 2019

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 propert ABC 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

  • Clean up commit history

Cute Animal Picture

put a cute animal picture link inside the parentheses

@pipermerriam pipermerriam requested review from cburgdorf and carver July 31, 2019 20:04
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
Copy link
Member Author

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',
Copy link
Member Author

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]:
Copy link
Member Author

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.

Copy link
Contributor

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

@pipermerriam pipermerriam force-pushed the piper/proper-abc-base-classes branch from 0488967 to 8090364 Compare July 31, 2019 20:09
@pipermerriam
Copy link
Member Author

Looks like I need to do some cleanup to get the fixture tests passing.

@pipermerriam pipermerriam force-pushed the piper/proper-abc-base-classes branch 2 times, most recently from c40a72a to a6c450a Compare July 31, 2019 20:41
@pipermerriam pipermerriam requested review from carver and cburgdorf July 31, 2019 20:41
Copy link
Contributor

@carver carver left a 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]:
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

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"	
        )

Copy link
Member Author

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.

@pipermerriam pipermerriam force-pushed the piper/proper-abc-base-classes branch from a6c450a to 42752f0 Compare August 1, 2019 17:38
@pipermerriam pipermerriam merged commit 3b0bcc2 into ethereum:master Aug 1, 2019
@pipermerriam pipermerriam deleted the piper/proper-abc-base-classes branch August 1, 2019 17:43
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.

2 participants