Skip to content

Commit 6a504d5

Browse files
committed
Separate plugins between trinity and trinity-beacon
trinity and trinity-beacon are two different pieces of software that just share a common code base. Hence they need to be bootstrapped with different built-in plugins. Relates to: #1545
1 parent dfcbf3c commit 6a504d5

File tree

5 files changed

+32
-21
lines changed

5 files changed

+32
-21
lines changed
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from trinity.plugins.registry import (
2-
get_all_plugins
2+
discover_plugins
33
)
44
# This plugin is external to this code base and installed by tox
55
# In order to install it locally run:
@@ -8,5 +8,5 @@
88

99

1010
def test_plugin_discovery():
11-
plugins = [type(plugin) for plugin in get_all_plugins()]
11+
plugins = [type(plugin) for plugin in discover_plugins()]
1212
assert PeerCountReporterPlugin in plugins

trinity/bootstrap.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,11 @@
4040
ROPSTEN_NETWORK_ID,
4141
)
4242
from trinity.extensibility import (
43+
BasePlugin,
4344
BaseManagerProcessScope,
4445
MainAndIsolatedProcessScope,
4546
PluginManager,
4647
)
47-
from trinity.plugins.registry import (
48-
get_all_plugins,
49-
)
5048
from trinity.utils.ipc import (
5149
kill_process_gracefully,
5250
)
@@ -108,13 +106,14 @@
108106
], None]
109107

110108

111-
def main_entry(trinity_boot: BootFn) -> None:
109+
def main_entry(trinity_boot: BootFn, plugins: Iterable[BasePlugin]) -> None:
112110
event_bus = EventBus(ctx)
113111
main_endpoint = event_bus.create_endpoint(MAIN_EVENTBUS_ENDPOINT)
114112
main_endpoint.connect_no_wait()
115113

116114
plugin_manager = setup_plugins(
117-
MainAndIsolatedProcessScope(event_bus, main_endpoint)
115+
MainAndIsolatedProcessScope(event_bus, main_endpoint),
116+
plugins
118117
)
119118
plugin_manager.amend_argparser_config(parser, subparser)
120119
args = parser.parse_args()
@@ -211,11 +210,9 @@ def main_entry(trinity_boot: BootFn) -> None:
211210
)
212211

213212

214-
def setup_plugins(scope: BaseManagerProcessScope) -> PluginManager:
213+
def setup_plugins(scope: BaseManagerProcessScope, plugins: Iterable[BasePlugin]) -> PluginManager:
215214
plugin_manager = PluginManager(scope)
216-
# TODO: most plugins should check if they are in eth1 / eth2 context
217-
# and only start when appropriate
218-
plugin_manager.register(get_all_plugins())
215+
plugin_manager.register(plugins)
219216

220217
return plugin_manager
221218

trinity/main.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from typing import (
66
Any,
77
Dict,
8+
Iterable,
89
)
910

1011
from lahja import (
@@ -32,9 +33,15 @@
3233
ShutdownRequest
3334
)
3435
from trinity.extensibility import (
36+
BasePlugin,
3537
PluginManager,
3638
SharedProcessScope,
3739
)
40+
from trinity.plugins.registry import (
41+
BASE_PLUGINS,
42+
discover_plugins,
43+
ETH1_NODE_PLUGINS,
44+
)
3845
from trinity.utils.ipc import (
3946
wait_for_ipc,
4047
kill_process_gracefully,
@@ -53,8 +60,12 @@
5360
)
5461

5562

63+
def get_all_plugins() -> Iterable[BasePlugin]:
64+
return BASE_PLUGINS + ETH1_NODE_PLUGINS + discover_plugins()
65+
66+
5667
def main() -> None:
57-
main_entry(trinity_boot)
68+
main_entry(trinity_boot, get_all_plugins())
5869

5970

6071
def trinity_boot(args: Namespace,
@@ -142,7 +153,7 @@ def launch_node(args: Namespace, trinity_config: TrinityConfig, endpoint: Endpoi
142153

143154
endpoint.connect_no_wait(loop)
144155
# This is a second PluginManager instance governing plugins in a shared process.
145-
plugin_manager = setup_plugins(SharedProcessScope(endpoint))
156+
plugin_manager = setup_plugins(SharedProcessScope(endpoint), get_all_plugins())
146157
plugin_manager.prepare(args, trinity_config)
147158

148159
asyncio.ensure_future(handle_networking_exit(node, plugin_manager, endpoint), loop=loop)

trinity/main_beacon.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@
2828
from trinity.extensibility import (
2929
PluginManager,
3030
)
31+
from trinity.plugins.registry import (
32+
BASE_PLUGINS,
33+
)
3134
from trinity.utils.ipc import (
3235
wait_for_ipc,
3336
kill_process_gracefully,
@@ -38,7 +41,7 @@
3841

3942

4043
def main_beacon() -> None:
41-
main_entry(trinity_boot)
44+
main_entry(trinity_boot, BASE_PLUGINS)
4245

4346

4447
def trinity_boot(args: Namespace,

trinity/plugins/registry.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,14 @@ def is_ipython_available() -> bool:
3535
return True
3636

3737

38-
BUILTIN_PLUGINS = (
39-
AttachPlugin() if is_ipython_available() else AttachPlugin(use_ipython=False),
40-
EthstatsPlugin(),
38+
BASE_PLUGINS: Tuple[BasePlugin, ...] = (
39+
AttachPlugin(use_ipython=is_ipython_available()),
4140
FixUncleanShutdownPlugin(),
41+
)
42+
43+
44+
ETH1_NODE_PLUGINS: Tuple[BasePlugin, ...] = (
45+
EthstatsPlugin(),
4246
JsonRpcServerPlugin(),
4347
LightPeerChainBridgePlugin(),
4448
TxPlugin(),
@@ -52,7 +56,3 @@ def discover_plugins() -> Tuple[BasePlugin, ...]:
5256
return tuple(
5357
entry_point.load()() for entry_point in pkg_resources.iter_entry_points('trinity.plugins')
5458
)
55-
56-
57-
def get_all_plugins() -> Tuple[BasePlugin, ...]:
58-
return BUILTIN_PLUGINS + discover_plugins()

0 commit comments

Comments
 (0)