Skip to content
This repository has been archived by the owner on Jul 1, 2021. It is now read-only.

Commit

Permalink
Merge pull request #616 from ChihChengLiang/clean-up-chain-db
Browse files Browse the repository at this point in the history
Clean up chain db
  • Loading branch information
ChihChengLiang authored May 16, 2019
2 parents 15958c3 + 34fd07a commit a37f26c
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 34 deletions.
34 changes: 6 additions & 28 deletions eth2/beacon/db/chain.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,6 @@ def get_canonical_block_by_slot(self,
block_class: Type[BaseBeaconBlock]) -> BaseBeaconBlock:
pass

@abstractmethod
def get_canonical_block_root_by_slot(self, slot: int) -> Hash32:
pass

@abstractmethod
def get_canonical_head(self, block_class: Type[BaseBeaconBlock]) -> BaseBeaconBlock:
pass
Expand Down Expand Up @@ -263,26 +259,9 @@ def _get_canonical_block_by_slot(
db: BaseDB,
slot: int,
block_class: Type[BaseBeaconBlock]) -> BaseBeaconBlock:
canonical_block_root = cls._get_canonical_block_root_by_slot(db, slot)
canonical_block_root = cls._get_canonical_block_root(db, slot)
return cls._get_block_by_root(db, canonical_block_root, block_class)

def get_canonical_block_root_by_slot(self, slot: int) -> Hash32:
"""
Return the block root with the given slot in the canonical chain.
Raise BlockNotFound if there's no block with the given slot in the
canonical chain.
"""
return self._get_canonical_block_root_by_slot(self.db, slot)

@classmethod
def _get_canonical_block_root_by_slot(
cls,
db: BaseDB,
slot: int) -> Hash32:
validate_slot(slot)
return cls._get_canonical_block_root(db, slot)

def get_canonical_head(self, block_class: Type[BaseBeaconBlock]) -> BaseBeaconBlock:
"""
Return the current block at the head of the chain.
Expand Down Expand Up @@ -323,8 +302,8 @@ def _get_finalized_head(cls,
finalized_head_root = cls._get_finalized_head_root(db)
return cls._get_block_by_root(db, Hash32(finalized_head_root), block_class)

@classmethod
def _get_finalized_head_root(cls, db: BaseDB) -> Hash32:
@staticmethod
def _get_finalized_head_root(db: BaseDB) -> Hash32:
try:
finalized_head_root = db[SchemaV1.make_finalized_head_root_lookup_key()]
except KeyError:
Expand All @@ -344,8 +323,8 @@ def _get_justified_head(cls,
justified_head_root = cls._get_justified_head_root(db)
return cls._get_block_by_root(db, Hash32(justified_head_root), block_class)

@classmethod
def _get_justified_head_root(cls, db: BaseDB) -> Hash32:
@staticmethod
def _get_justified_head_root(db: BaseDB) -> Hash32:
try:
justified_head_root = db[SchemaV1.make_justified_head_root_lookup_key()]
except KeyError:
Expand Down Expand Up @@ -426,9 +405,8 @@ def persist_block_chain(
with self.db.atomic_batch() as db:
return self._persist_block_chain(db, blocks, block_class)

@classmethod
@staticmethod
def _set_block_scores_to_db(
cls,
db: BaseDB,
block: BaseBeaconBlock
) -> int:
Expand Down
1 change: 0 additions & 1 deletion tests/core/p2p-proto/bcc/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ class FakeAsyncBeaconChainDB(BaseAsyncBeaconChainDB, BeaconChainDB):
coro_persist_block = async_passthrough('persist_block')
coro_get_canonical_block_root = async_passthrough('get_canonical_block_root')
coro_get_canonical_block_by_slot = async_passthrough('get_canonical_block_by_slot')
coro_get_canonical_block_root_by_slot = async_passthrough('get_canonical_block_root_by_slot')
coro_get_canonical_head = async_passthrough('get_canonical_head')
coro_get_canonical_head_root = async_passthrough('get_canonical_head_root')
coro_get_finalized_head = async_passthrough('get_finalized_head')
Expand Down
5 changes: 0 additions & 5 deletions trinity/db/beacon/chain.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,6 @@ async def coro_get_canonical_block_by_slot(
block_class: Type[BaseBeaconBlock]) -> BaseBeaconBlock:
pass

@abstractmethod
async def coro_get_canonical_block_root_by_slot(self, slot: int) -> Hash32:
pass

@abstractmethod
async def coro_get_canonical_head(self, block_class: Type[BaseBeaconBlock]) -> BaseBeaconBlock:
pass
Expand Down Expand Up @@ -126,7 +122,6 @@ class AsyncBeaconChainDBPreProxy(BaseAsyncBeaconChainDB):
coro_persist_block = async_method('persist_block')
coro_get_canonical_block_root = async_method('get_canonical_block_root')
coro_get_canonical_block_by_slot = async_method('get_canonical_block_by_slot')
coro_get_canonical_block_root_by_slot = async_method('get_canonical_block_root_by_slot')
coro_get_canonical_head = async_method('get_canonical_head')
coro_get_canonical_head_root = async_method('get_canonical_head_root')
coro_get_finalized_head = async_method('get_finalized_head')
Expand Down

0 comments on commit a37f26c

Please sign in to comment.