mirror of
https://github.com/status-im/nimbus-eth1.git
synced 2025-02-23 09:18:29 +00:00
rm --protocol CLI flag (#2793)
This commit is contained in:
parent
1406feab5f
commit
11c875c5c2
@ -117,11 +117,6 @@ type
|
||||
noCommand
|
||||
`import`
|
||||
|
||||
ProtocolFlag* {.pure.} = enum
|
||||
## Protocol flags
|
||||
Eth ## enable eth subprotocol
|
||||
#Snap ## enable snap sub-protocol
|
||||
|
||||
RpcFlag* {.pure.} = enum
|
||||
## RPC flags
|
||||
Eth ## enable eth_ set of RPC API
|
||||
@ -366,14 +361,6 @@ type
|
||||
defaultValueDesc: $NimbusIdent
|
||||
name: "agent-string" .}: string
|
||||
|
||||
protocols {.
|
||||
desc: "Enable specific set of server protocols (available: Eth, " &
|
||||
" None.) This will not affect the sync mode"
|
||||
# " Snap, None.) This will not affect the sync mode"
|
||||
defaultValue: @[]
|
||||
defaultValueDesc: $ProtocolFlag.Eth
|
||||
name: "protocols" .}: seq[string]
|
||||
|
||||
beaconChunkSize* {.
|
||||
hidden
|
||||
desc: "Number of blocks per database transaction for beacon sync"
|
||||
@ -671,23 +658,6 @@ proc getNetworkId(conf: NimbusConf): Option[NetworkId] =
|
||||
error "Failed to parse network name or id", network
|
||||
quit QuitFailure
|
||||
|
||||
proc getProtocolFlags*(conf: NimbusConf): set[ProtocolFlag] =
|
||||
if conf.protocols.len == 0:
|
||||
return {ProtocolFlag.Eth}
|
||||
|
||||
var noneOk = false
|
||||
for item in repeatingList(conf.protocols):
|
||||
case item.toLowerAscii()
|
||||
of "eth": result.incl ProtocolFlag.Eth
|
||||
# of "snap": result.incl ProtocolFlag.Snap
|
||||
of "none": noneOk = true
|
||||
else:
|
||||
error "Unknown protocol", name=item
|
||||
quit QuitFailure
|
||||
if noneOk and 0 < result.len:
|
||||
error "Setting none contradicts wire protocols", names = $result
|
||||
quit QuitFailure
|
||||
|
||||
proc getRpcFlags(api: openArray[string]): set[RpcFlag] =
|
||||
if api.len == 0:
|
||||
return {RpcFlag.Eth}
|
||||
|
@ -63,7 +63,7 @@ proc manageAccounts(nimbus: NimbusNode, conf: NimbusConf) =
|
||||
quit(QuitFailure)
|
||||
|
||||
proc setupP2P(nimbus: NimbusNode, conf: NimbusConf,
|
||||
com: CommonRef, protocols: set[ProtocolFlag]) =
|
||||
com: CommonRef) =
|
||||
## Creating P2P Server
|
||||
let kpres = nimbus.ctx.getNetKeys(conf.netKey, conf.dataDir.string)
|
||||
if kpres.isErr:
|
||||
@ -104,19 +104,9 @@ proc setupP2P(nimbus: NimbusNode, conf: NimbusConf,
|
||||
bindIp = conf.listenAddress,
|
||||
rng = nimbus.ctx.rng)
|
||||
|
||||
# Add protocol capabilities based on protocol flags
|
||||
for w in protocols:
|
||||
case w: # handle all possibilities
|
||||
of ProtocolFlag.Eth:
|
||||
nimbus.ethNode.addEthHandlerCapability(
|
||||
nimbus.ethNode.peerPool,
|
||||
nimbus.chainRef,
|
||||
nimbus.txPool)
|
||||
# Cannot do without minimal `eth` capability
|
||||
if ProtocolFlag.Eth notin protocols:
|
||||
nimbus.ethNode.addEthHandlerCapability(
|
||||
nimbus.ethNode.peerPool,
|
||||
nimbus.chainRef)
|
||||
# Add protocol capabilities
|
||||
nimbus.ethNode.addEthHandlerCapability(
|
||||
nimbus.ethNode.peerPool, nimbus.chainRef, nimbus.txPool)
|
||||
|
||||
# Always initialise beacon syncer
|
||||
nimbus.beaconSyncRef = BeaconSyncRef.init(
|
||||
@ -217,12 +207,10 @@ proc run(nimbus: NimbusNode, conf: NimbusConf) =
|
||||
of NimbusCmd.`import`:
|
||||
importBlocks(conf, com)
|
||||
else:
|
||||
let protocols = conf.getProtocolFlags()
|
||||
|
||||
basicServices(nimbus, conf, com)
|
||||
manageAccounts(nimbus, conf)
|
||||
setupP2P(nimbus, conf, com, protocols)
|
||||
setupRpc(nimbus, conf, com, protocols)
|
||||
setupP2P(nimbus, conf, com)
|
||||
setupRpc(nimbus, conf, com)
|
||||
|
||||
if conf.maxPeers > 0 and conf.engineApiServerEnabled():
|
||||
# Not starting syncer if there is definitely no way to run it. This
|
||||
|
@ -140,7 +140,6 @@ func addHandler(handlers: var seq[RpcHandlerProc],
|
||||
proc addHttpServices(handlers: var seq[RpcHandlerProc],
|
||||
nimbus: NimbusNode, conf: NimbusConf,
|
||||
com: CommonRef, serverApi: ServerAPIRef,
|
||||
protocols: set[ProtocolFlag],
|
||||
address: TransportAddress) =
|
||||
|
||||
# The order is important: graphql, ws, rpc
|
||||
@ -156,16 +155,14 @@ proc addHttpServices(handlers: var seq[RpcHandlerProc],
|
||||
|
||||
if conf.wsEnabled:
|
||||
let server = newRpcWebsocketHandler()
|
||||
var rpcFlags = conf.getWsFlags()
|
||||
if ProtocolFlag.Eth in protocols: rpcFlags.incl RpcFlag.Eth
|
||||
let rpcFlags = conf.getWsFlags() + {RpcFlag.Eth}
|
||||
installRPC(server, nimbus, conf, com, serverApi, rpcFlags)
|
||||
handlers.addHandler(server)
|
||||
info "JSON-RPC WebSocket API enabled", url = "ws://" & $address
|
||||
|
||||
if conf.rpcEnabled:
|
||||
let server = newRpcHttpHandler()
|
||||
var rpcFlags = conf.getRpcFlags()
|
||||
if ProtocolFlag.Eth in protocols: rpcFlags.incl RpcFlag.Eth
|
||||
let rpcFlags = conf.getRpcFlags() + {RpcFlag.Eth}
|
||||
installRPC(server, nimbus, conf, com, serverApi, rpcFlags)
|
||||
handlers.addHandler(server)
|
||||
info "JSON-RPC API enabled", url = "http://" & $address
|
||||
@ -193,7 +190,7 @@ proc addEngineApiServices(handlers: var seq[RpcHandlerProc],
|
||||
|
||||
proc addServices(handlers: var seq[RpcHandlerProc],
|
||||
nimbus: NimbusNode, conf: NimbusConf,
|
||||
com: CommonRef, serverApi: ServerAPIRef, protocols: set[ProtocolFlag],
|
||||
com: CommonRef, serverApi: ServerAPIRef,
|
||||
address: TransportAddress) =
|
||||
|
||||
# The order is important: graphql, ws, rpc
|
||||
@ -215,8 +212,7 @@ proc addServices(handlers: var seq[RpcHandlerProc],
|
||||
info "Engine WebSocket API enabled", url = "ws://" & $address
|
||||
|
||||
if conf.wsEnabled:
|
||||
var rpcFlags = conf.getWsFlags()
|
||||
if ProtocolFlag.Eth in protocols: rpcFlags.incl RpcFlag.Eth
|
||||
let rpcFlags = conf.getWsFlags() + {RpcFlag.Eth}
|
||||
installRPC(server, nimbus, conf, com, serverApi, rpcFlags)
|
||||
info "JSON-RPC WebSocket API enabled", url = "ws://" & $address
|
||||
|
||||
@ -232,8 +228,7 @@ proc addServices(handlers: var seq[RpcHandlerProc],
|
||||
info "Engine API enabled", url = "http://" & $address
|
||||
|
||||
if conf.rpcEnabled:
|
||||
var rpcFlags = conf.getRpcFlags()
|
||||
if ProtocolFlag.Eth in protocols: rpcFlags.incl RpcFlag.Eth
|
||||
let rpcFlags = conf.getRpcFlags() + {RpcFlag.Eth}
|
||||
installRPC(server, nimbus, conf, com, serverApi, rpcFlags)
|
||||
|
||||
info "JSON-RPC API enabled", url = "http://" & $address
|
||||
@ -241,7 +236,7 @@ proc addServices(handlers: var seq[RpcHandlerProc],
|
||||
handlers.addHandler(server)
|
||||
|
||||
proc setupRpc*(nimbus: NimbusNode, conf: NimbusConf,
|
||||
com: CommonRef, protocols: set[ProtocolFlag]) =
|
||||
com: CommonRef) =
|
||||
if not conf.engineApiEnabled:
|
||||
warn "Engine API disabled, the node will not respond to consensus client updates (enable with `--engine-api`)"
|
||||
|
||||
@ -268,7 +263,7 @@ proc setupRpc*(nimbus: NimbusNode, conf: NimbusConf,
|
||||
let hooks: seq[RpcAuthHook] = @[jwtAuthHook, corsHook]
|
||||
var handlers: seq[RpcHandlerProc]
|
||||
let address = initTAddress(conf.httpAddress, conf.httpPort)
|
||||
handlers.addServices(nimbus, conf, com, serverApi, protocols, address)
|
||||
handlers.addServices(nimbus, conf, com, serverApi, address)
|
||||
let res = newHttpServerWithParams(address, hooks, handlers)
|
||||
if res.isErr:
|
||||
fatal "Cannot create RPC server", msg=res.error
|
||||
@ -281,7 +276,7 @@ proc setupRpc*(nimbus: NimbusNode, conf: NimbusConf,
|
||||
let hooks = @[corsHook]
|
||||
var handlers: seq[RpcHandlerProc]
|
||||
let address = initTAddress(conf.httpAddress, conf.httpPort)
|
||||
handlers.addHttpServices(nimbus, conf, com, serverApi, protocols, address)
|
||||
handlers.addHttpServices(nimbus, conf, com, serverApi, address)
|
||||
let res = newHttpServerWithParams(address, hooks, handlers)
|
||||
if res.isErr:
|
||||
fatal "Cannot create RPC server", msg=res.error
|
||||
|
@ -128,15 +128,6 @@ proc configurationMain*() =
|
||||
let cx = cc.getWsFlags()
|
||||
check { RpcFlag.Eth, RpcFlag.Debug } == cx
|
||||
|
||||
test "protocols":
|
||||
let conf = makeTestConfig()
|
||||
let flags = conf.getProtocolFlags()
|
||||
check ProtocolFlag.Eth in flags
|
||||
|
||||
let bb = makeConfig(@["--protocols:eth"])
|
||||
let bx = bb.getProtocolFlags()
|
||||
check ProtocolFlag.Eth in bx
|
||||
|
||||
test "bootstrap-node and bootstrap-file":
|
||||
let conf = makeTestConfig()
|
||||
let bootnodes = conf.getBootNodes()
|
||||
|
Loading…
x
Reference in New Issue
Block a user