From 27beda872e64e73020da30cdad302604516b8302 Mon Sep 17 00:00:00 2001 From: Peter Bushnell Date: Tue, 27 Jun 2023 05:28:45 +0100 Subject: [PATCH] Move EVM initialisation --- src/init.cpp | 98 +++++++++++++++++++++++++--------------------------- 1 file changed, 48 insertions(+), 50 deletions(-) diff --git a/src/init.cpp b/src/init.cpp index 1f8a40253c..932a9d4d0e 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -1559,56 +1559,6 @@ bool AppInitMain(InitInterfaces& interfaces) return InitError(_("Unable to start HTTP server. See debug log for details.").translated); } - // ********************************************************* Step 4b: application initialization - - /* Start the ETH RPC and gRPC servers. Current API only allows for one ETH - * RPC/gRPC server to bind to one address. By default, we will only take - * the first address, if multiple addresses are specified. - */ - int eth_rpc_port = gArgs.GetArg("-ethrpcport", BaseParams().ETHRPCPort()); - int grpc_port = gArgs.GetArg("-grpcport", BaseParams().GRPCPort()); - std::vector > eth_endpoints; - std::vector > g_endpoints; - - // Determine which addresses to bind to ETH RPC server - if (!(gArgs.IsArgSet("-rpcallowip") && gArgs.IsArgSet("-ethrpcbind"))) { // Default to loopback if not allowing external IPs - eth_endpoints.push_back(std::make_pair("127.0.0.1", eth_rpc_port)); - if (gArgs.IsArgSet("-rpcallowip")) { - LogPrintf("WARNING: option -rpcallowip was specified without -ethrpcbind; this doesn't usually make sense\n"); - } - if (gArgs.IsArgSet("-ethrpcbind")) { - LogPrintf("WARNING: option -ethrpcbind was ignored because -rpcallowip was not specified, refusing to allow everyone to connect\n"); - } - } else if (gArgs.IsArgSet("-ethrpcbind")) { // Specific bind address - for (const std::string& strETHRPCBind : gArgs.GetArgs("-ethrpcbind")) { - int port = eth_rpc_port; - std::string host; - SplitHostPort(strETHRPCBind, port, host); - eth_endpoints.push_back(std::make_pair(host, port)); - } - } - - // Determine which addresses to bind to gRPC server - if (!(gArgs.IsArgSet("-rpcallowip") && gArgs.IsArgSet("-grpcbind"))) { // Default to loopback if not allowing external IPs - g_endpoints.push_back(std::make_pair("127.0.0.1", grpc_port)); - if (gArgs.IsArgSet("-rpcallowip")) { - LogPrintf("WARNING: option -rpcallowip was specified without -grpcbind; this doesn't usually make sense\n"); - } - if (gArgs.IsArgSet("-grpcbind")) { - LogPrintf("WARNING: option -grpcbind was ignored because -rpcallowip was not specified, refusing to allow everyone to connect\n"); - } - } else if (gArgs.IsArgSet("-grpcbind")) { // Specific bind address - for (const std::string& strGRPCBind : gArgs.GetArgs("-grpcbind")) { - int port = grpc_port; - std::string host; - SplitHostPort(strGRPCBind, port, host); - g_endpoints.push_back(std::make_pair(host, port)); - } - } - - // Default to using the first address passed to bind to ETH RPC server and gRPC server - start_servers(eth_endpoints[0].first + ":" + std::to_string(eth_endpoints[0].second), g_endpoints[0].first + "." + std::to_string(g_endpoints[0].second)); - // ********************************************************* Step 5: verify wallet database integrity for (const auto& client : interfaces.chain_clients) { if (!client->verify()) { @@ -1950,6 +1900,54 @@ bool AppInitMain(InitInterfaces& interfaces) } } + /* Start the ETH RPC and gRPC servers. Current API only allows for one ETH + * RPC/gRPC server to bind to one address. By default, we will only take + * the first address, if multiple addresses are specified. + */ + int eth_rpc_port = gArgs.GetArg("-ethrpcport", BaseParams().ETHRPCPort()); + int grpc_port = gArgs.GetArg("-grpcport", BaseParams().GRPCPort()); + std::vector > eth_endpoints; + std::vector > g_endpoints; + + // Determine which addresses to bind to ETH RPC server + if (!(gArgs.IsArgSet("-rpcallowip") && gArgs.IsArgSet("-ethrpcbind"))) { // Default to loopback if not allowing external IPs + eth_endpoints.emplace_back("127.0.0.1", eth_rpc_port); + if (gArgs.IsArgSet("-rpcallowip")) { + LogPrintf("WARNING: option -rpcallowip was specified without -ethrpcbind; this doesn't usually make sense\n"); + } + if (gArgs.IsArgSet("-ethrpcbind")) { + LogPrintf("WARNING: option -ethrpcbind was ignored because -rpcallowip was not specified, refusing to allow everyone to connect\n"); + } + } else if (gArgs.IsArgSet("-ethrpcbind")) { // Specific bind address + for (const std::string& strETHRPCBind : gArgs.GetArgs("-ethrpcbind")) { + int port = eth_rpc_port; + std::string host; + SplitHostPort(strETHRPCBind, port, host); + eth_endpoints.emplace_back(host, port); + } + } + + // Determine which addresses to bind to gRPC server + if (!(gArgs.IsArgSet("-rpcallowip") && gArgs.IsArgSet("-grpcbind"))) { // Default to loopback if not allowing external IPs + g_endpoints.emplace_back("127.0.0.1", grpc_port); + if (gArgs.IsArgSet("-rpcallowip")) { + LogPrintf("WARNING: option -rpcallowip was specified without -grpcbind; this doesn't usually make sense\n"); + } + if (gArgs.IsArgSet("-grpcbind")) { + LogPrintf("WARNING: option -grpcbind was ignored because -rpcallowip was not specified, refusing to allow everyone to connect\n"); + } + } else if (gArgs.IsArgSet("-grpcbind")) { // Specific bind address + for (const std::string& strGRPCBind : gArgs.GetArgs("-grpcbind")) { + int port = grpc_port; + std::string host; + SplitHostPort(strGRPCBind, port, host); + g_endpoints.emplace_back(host, port); + } + } + + // Default to using the first address passed to bind to ETH RPC server and gRPC server + start_servers(eth_endpoints[0].first + ":" + std::to_string(eth_endpoints[0].second), g_endpoints[0].first + "." + std::to_string(g_endpoints[0].second)); + try { LOCK(cs_main); if (!is_coinsview_empty) {