Skip to content

Commit 454ead7

Browse files
author
pmmiranda
committed
Make nimbus beacon node accessible by threading.
- Add a public entry point to nimbus beacon. - protect database file lock concurrent creation/deletion
1 parent b7129e0 commit 454ead7

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

beacon_chain/nimbus_beacon_node.nim

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
{.push raises: [].}
99

1010
import
11-
std/[os, random, terminal, times, exitprocs],
11+
std/[os, random, terminal, times, exitprocs, atomics],
1212
chronos, chronicles,
1313
metrics, metrics/chronos_httpserver,
1414
stew/[byteutils, io2],
@@ -2166,11 +2166,15 @@ proc run(node: BeaconNode) {.raises: [CatchableError].} =
21662166
# time to say goodbye
21672167
node.stop()
21682168

2169+
var shouldCreatePidFile*: Atomic[bool]
2170+
shouldCreatePidFile.store(true)
2171+
21692172
var gPidFile: string
21702173
proc createPidFile(filename: string) {.raises: [IOError].} =
2171-
writeFile filename, $os.getCurrentProcessId()
2172-
gPidFile = filename
2173-
addExitProc proc {.noconv.} = discard io2.removeFile(gPidFile)
2174+
if shouldCreatePidFile.load():
2175+
writeFile filename, $os.getCurrentProcessId()
2176+
gPidFile = filename
2177+
addExitProc proc {.noconv.} = discard io2.removeFile(gPidFile)
21742178

21752179
proc initializeNetworking(node: BeaconNode) {.async.} =
21762180
node.installMessageValidators()
@@ -2535,7 +2539,7 @@ proc doSlashingInterchange(conf: BeaconNodeConf) {.raises: [CatchableError].} =
25352539
of SlashProtCmd.`import`:
25362540
conf.doSlashingImport()
25372541

2538-
proc handleStartUpCmd(config: var BeaconNodeConf) {.raises: [CatchableError].} =
2542+
proc handleStartUpCmd*(config: var BeaconNodeConf) {.raises: [CatchableError].} =
25392543
# Single RNG instance for the application - will be seeded on construction
25402544
# and avoid using system resources (such as urandom) after that
25412545
let rng = HmacDrbgContext.new()

0 commit comments

Comments
 (0)