Skip to content

Commit 9249b69

Browse files
committed
Internal: split chain service (#487)
Problem: the chain service is in charge of providing all chain-related functionalities, namely: verify signature and read/write on chain. It turns out that most use cases of the chain service only care about signature verification, meaning that the dependencies required for the chain service are not necessary most of the time. As we plan on adding more dependencies for chain readers, the chain service is getting too complex for its own good. Solution: split the chain service into a signature verifier class and a chain connector class. This way, the signature verifier can be instantiated without dependencies in all the places where it is required and the chain connector can get a bit more complex without impacting the rest. Other changes: * Removed the conditional import of chain connectors as they must all be installed on each node.
1 parent 6206a7e commit 9249b69

33 files changed

+314
-365
lines changed

src/aleph/api_entrypoint.py

+4-7
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from configmanager import Config
77

88
import aleph.config
9-
from aleph.chains.chain_service import ChainService
9+
from aleph.chains.signature_verifier import SignatureVerifier
1010
from aleph.db.connection import make_engine, make_session_factory
1111
from aleph.services.cache.node_cache import NodeCache
1212
from aleph.services.ipfs import IpfsService
@@ -25,7 +25,7 @@
2525
APP_STATE_STORAGE_SERVICE,
2626
APP_STATE_MQ_CHANNEL,
2727
APP_STATE_MQ_WS_CHANNEL,
28-
APP_STATE_CHAIN_SERVICE,
28+
APP_STATE_SIGNATURE_VERIFIER,
2929
)
3030

3131

@@ -53,9 +53,7 @@ async def configure_aiohttp_app(
5353
ipfs_service=ipfs_service,
5454
node_cache=node_cache,
5555
)
56-
chain_service = ChainService(
57-
storage_service=storage_service, session_factory=session_factory
58-
)
56+
signature_verifier = SignatureVerifier()
5957

6058
app = create_aiohttp_app()
6159

@@ -74,7 +72,7 @@ async def configure_aiohttp_app(
7472
app[APP_STATE_NODE_CACHE] = node_cache
7573
app[APP_STATE_STORAGE_SERVICE] = storage_service
7674
app[APP_STATE_SESSION_FACTORY] = session_factory
77-
app[APP_STATE_CHAIN_SERVICE] = chain_service
75+
app[APP_STATE_SIGNATURE_VERIFIER] = signature_verifier
7876

7977
return app
8078

@@ -95,5 +93,4 @@ async def create_app() -> web.Application:
9593

9694

9795
if __name__ == "__main__":
98-
import asyncio
9996
web.run_app(create_app(), host="127.0.0.1", port=8000)

src/aleph/chains/abc.py

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import abc
2+
3+
from configmanager import Config
4+
5+
from aleph.schemas.pending_messages import BasePendingMessage
6+
from aleph.types.chain_sync import ChainEventType
7+
8+
9+
class Verifier(abc.ABC):
10+
@abc.abstractmethod
11+
async def verify_signature(self, message: BasePendingMessage) -> bool:
12+
...
13+
14+
15+
class ChainReader(abc.ABC):
16+
@abc.abstractmethod
17+
async def fetcher(self, config: Config):
18+
...
19+
20+
21+
class ChainWriter(ChainReader):
22+
@abc.abstractmethod
23+
async def packer(self, config: Config):
24+
...

src/aleph/chains/avalanche.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
from aleph.chains.common import get_verification_buffer
1010
from aleph.schemas.pending_messages import BasePendingMessage
11-
from .connector import Verifier
11+
from .abc import Verifier
1212

1313
LOGGER = logging.getLogger("chains.avalanche")
1414
CHAIN_NAME = "AVAX"

src/aleph/chains/bsc.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from configmanager import Config
33

44
from aleph.chains.chaindata import ChainDataService
5-
from aleph.chains.connector import ChainReader
5+
from aleph.chains.abc import ChainReader
66
from aleph.chains.indexer_reader import AlephIndexerReader
77
from aleph.types.chain_sync import ChainEventType
88
from aleph.types.db_session import DbSessionFactory

src/aleph/chains/chain_service.py

-189
This file was deleted.

0 commit comments

Comments
 (0)