fixed gcsafe error on createPidFile
This commit is contained in:
parent
1b89a835eb
commit
a526d01ab8
|
@ -6,7 +6,7 @@
|
||||||
# at your option. This file may not be copied, modified, or distributed except according to those terms.
|
# at your option. This file may not be copied, modified, or distributed except according to those terms.
|
||||||
|
|
||||||
import
|
import
|
||||||
std/[os, exitprocs],
|
std/os,
|
||||||
beacon_chain/nimbus_binary_common,
|
beacon_chain/nimbus_binary_common,
|
||||||
beacon_chain/spec/forks,
|
beacon_chain/spec/forks,
|
||||||
beacon_chain/[beacon_chain_db, trusted_node_sync],
|
beacon_chain/[beacon_chain_db, trusted_node_sync],
|
||||||
|
@ -22,22 +22,11 @@ export nimbus_configs
|
||||||
logScope:
|
logScope:
|
||||||
topics = "Consensus layer"
|
topics = "Consensus layer"
|
||||||
|
|
||||||
## Copy paste from nimbus_beacon_node.nim Copied due to the fact that nimbus_beacon_node
|
## following procedures are copies from nimbus_beacon_node.nim.
|
||||||
## contains the programMain.
|
|
||||||
## TODO: extract from that file into a common file
|
## TODO: extract from that file into a common file
|
||||||
var gPidFile: string
|
|
||||||
|
|
||||||
#TODO: Investigate why the commented code triggers GC violation
|
|
||||||
proc createPidFile(filename: string) {.raises: [IOError].} =
|
|
||||||
# writeFile filename, $os.getCurrentProcessId()
|
|
||||||
writeFile filename, "222"
|
|
||||||
# gPidFile = filename
|
|
||||||
# addExitProc proc() {.noconv.} =
|
|
||||||
# ## TODO: changed from original file, fixes dprecation warning
|
|
||||||
# discard io2.removeFile(gPidFile)
|
|
||||||
|
|
||||||
## runs beacon node
|
## runs beacon node
|
||||||
## adpated from nimbus-eth2
|
## adapted from nimbus-eth2
|
||||||
proc doRunBeaconNode(
|
proc doRunBeaconNode(
|
||||||
config: var BeaconNodeConf, rng: ref HmacDrbgContext
|
config: var BeaconNodeConf, rng: ref HmacDrbgContext
|
||||||
) {.raises: [CatchableError].} =
|
) {.raises: [CatchableError].} =
|
||||||
|
@ -59,8 +48,6 @@ proc doRunBeaconNode(
|
||||||
ignoreDeprecatedOption validatorMonitorTotals
|
ignoreDeprecatedOption validatorMonitorTotals
|
||||||
ignoreDeprecatedOption web3ForcePolling
|
ignoreDeprecatedOption web3ForcePolling
|
||||||
|
|
||||||
createPidFile(config.dataDir.string / "beacon_node.pid")
|
|
||||||
|
|
||||||
config.createDumpDirs()
|
config.createDumpDirs()
|
||||||
|
|
||||||
#TODO: We might need to split this on the same file
|
#TODO: We might need to split this on the same file
|
||||||
|
@ -146,6 +133,7 @@ proc doRunTrustedNodeSync(
|
||||||
proc consensusWrapper*(parameters: TaskParameters) {.raises: [CatchableError].} =
|
proc consensusWrapper*(parameters: TaskParameters) {.raises: [CatchableError].} =
|
||||||
let rng = HmacDrbgContext.new()
|
let rng = HmacDrbgContext.new()
|
||||||
var config = parameters.beaconNodeConfigs
|
var config = parameters.beaconNodeConfigs
|
||||||
|
|
||||||
try:
|
try:
|
||||||
doRunBeaconNode(config, rng)
|
doRunBeaconNode(config, rng)
|
||||||
except CatchableError as e:
|
except CatchableError as e:
|
||||||
|
|
|
@ -6,8 +6,9 @@
|
||||||
# at your option. This file may not be copied, modified, or distributed except according to those terms.
|
# at your option. This file may not be copied, modified, or distributed except according to those terms.
|
||||||
|
|
||||||
import
|
import
|
||||||
std/[atomics, os],
|
std/[atomics, os, exitprocs],
|
||||||
chronicles,
|
chronicles,
|
||||||
|
stew/io2,
|
||||||
consensus/consensus_wrapper,
|
consensus/consensus_wrapper,
|
||||||
execution/execution_wrapper,
|
execution/execution_wrapper,
|
||||||
beacon_chain/[conf, conf_common],
|
beacon_chain/[conf, conf_common],
|
||||||
|
@ -61,6 +62,16 @@ proc joinTasks(tasks: var NimbusTasks) =
|
||||||
|
|
||||||
info "\tAll tasks finished"
|
info "\tAll tasks finished"
|
||||||
|
|
||||||
|
#TODO: Investigate if this is really needed? and for what purpose?
|
||||||
|
var gPidFile: string
|
||||||
|
proc createPidFile(filename: string) {.raises: [IOError].} =
|
||||||
|
writeFile filename, $os.getCurrentProcessId()
|
||||||
|
gPidFile = filename
|
||||||
|
addExitProc (
|
||||||
|
proc() =
|
||||||
|
discard io2.removeFile(filename)
|
||||||
|
)
|
||||||
|
|
||||||
# ----
|
# ----
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
|
@ -88,7 +99,6 @@ proc addNewTask*(
|
||||||
|
|
||||||
if currentIndex < 0:
|
if currentIndex < 0:
|
||||||
raise newException(NimbusTasksError, "No free slots on Nimbus Tasks")
|
raise newException(NimbusTasksError, "No free slots on Nimbus Tasks")
|
||||||
|
|
||||||
createThread(tasks.taskList[currentIndex].threadHandler, taskHandler, parameters)
|
createThread(tasks.taskList[currentIndex].threadHandler, taskHandler, parameters)
|
||||||
info "Created task:", task = tasks.taskList[currentIndex].name
|
info "Created task:", task = tasks.taskList[currentIndex].name
|
||||||
|
|
||||||
|
@ -109,7 +119,7 @@ proc monitor*(tasksList: var NimbusTasks, config: NimbusConfig) =
|
||||||
## create running workers
|
## create running workers
|
||||||
proc startTasks*(
|
proc startTasks*(
|
||||||
tasksList: var NimbusTasks, configs: NimbusConfig, beaconConfigs: var BeaconNodeConf
|
tasksList: var NimbusTasks, configs: NimbusConfig, beaconConfigs: var BeaconNodeConf
|
||||||
) =
|
) {.raises: [CatchableError].} =
|
||||||
let
|
let
|
||||||
|
|
||||||
# TODO: extract configs for each task from NimbusConfig
|
# TODO: extract configs for each task from NimbusConfig
|
||||||
|
@ -174,6 +184,6 @@ when isMainModule:
|
||||||
quit(0)
|
quit(0)
|
||||||
|
|
||||||
setControlCHook(controlCHandler)
|
setControlCHook(controlCHandler)
|
||||||
|
createPidFile(beaconNodeConfig.databaseDir.string / "unified.pid")
|
||||||
#start monitoring
|
#start monitoring
|
||||||
tasksList.monitor(nimbusConfigs)
|
tasksList.monitor(nimbusConfigs)
|
||||||
|
|
Loading…
Reference in New Issue