Skip to content

Commit f2d0d5d

Browse files
authored
Merge pull request #1533 from carver/light-chain-request-fix
Always use a full chain instance in local server
2 parents f0d2ca6 + c3d65c4 commit f2d0d5d

File tree

3 files changed

+20
-7
lines changed

3 files changed

+20
-7
lines changed

trinity/nodes/base.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
BaseService,
1717
)
1818

19+
from trinity.chains.full import FullChain
1920
from trinity.db.header import (
2021
AsyncHeaderDB,
2122
)
@@ -40,6 +41,8 @@ class Node(BaseService):
4041
Create usable nodes by adding subclasses that define the following
4142
unset attributes.
4243
"""
44+
_full_chain: FullChain = None
45+
4346
def __init__(self, event_bus: Endpoint, trinity_config: TrinityConfig) -> None:
4447
super().__init__()
4548
self.trinity_config = trinity_config
@@ -84,6 +87,13 @@ def chain_config(self) -> ChainConfig:
8487
def get_chain(self) -> BaseChain:
8588
raise NotImplementedError("Node classes must implement this method")
8689

90+
def get_full_chain(self) -> FullChain:
91+
if self._full_chain is None:
92+
chain_class = self.chain_config.full_chain_class
93+
self._full_chain = chain_class(self.db_manager.get_db()) # type: ignore
94+
95+
return self._full_chain
96+
8797
@abstractmethod
8898
def get_peer_pool(self) -> BasePeerPool:
8999
"""

trinity/nodes/full.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,15 @@ def chain_class(self) -> Type[FullChain]:
2828
return self.chain_config.full_chain_class
2929

3030
def get_chain(self) -> FullChain:
31-
if self._chain is None:
32-
self._chain = self.chain_class(self.db_manager.get_db()) # type: ignore
33-
34-
return self._chain
31+
return self.get_full_chain()
3532

3633
def get_p2p_server(self) -> FullServer:
3734
if self._p2p_server is None:
3835
manager = self.db_manager
3936
self._p2p_server = FullServer(
4037
privkey=self._node_key,
4138
port=self._node_port,
42-
chain=self.get_chain(),
39+
chain=self.get_full_chain(),
4340
chaindb=manager.get_chaindb(), # type: ignore
4441
headerdb=self.headerdb,
4542
base_db=manager.get_db(), # type: ignore

trinity/nodes/light.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
)
55

66
from eth_keys.datatypes import PrivateKey
7+
from eth_utils import (
8+
ValidationError,
9+
)
710

811
from lahja import Endpoint
912

@@ -56,7 +59,10 @@ def get_chain(self) -> LightDispatchChain:
5659
if self._chain is None:
5760
if self.chain_class is None:
5861
raise AttributeError("LightNode subclass must set chain_class")
59-
self._chain = self.chain_class(self.headerdb, peer_chain=self._peer_chain)
62+
elif self._peer_chain is None:
63+
raise ValidationError("peer chain is not initialized!")
64+
else:
65+
self._chain = self.chain_class(self.headerdb, peer_chain=self._peer_chain)
6066

6167
return self._chain
6268

@@ -66,7 +72,7 @@ def get_p2p_server(self) -> LightServer:
6672
self._p2p_server = LightServer(
6773
privkey=self._nodekey,
6874
port=self._port,
69-
chain=self.get_chain(),
75+
chain=self.get_full_chain(),
7076
chaindb=manager.get_chaindb(), # type: ignore
7177
headerdb=self.headerdb,
7278
base_db=manager.get_db(), # type: ignore

0 commit comments

Comments
 (0)