Skip to content

Commit d7bccd4

Browse files
pmmirandapedromiguelmiranda
authored andcommitted
Make nimbus beacon node accessible by threading.
- Add a public entry point to nimbus beacon. - protect database file lock concurrent creation/deletion
1 parent 44ac176 commit d7bccd4

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],
@@ -2169,11 +2169,15 @@ proc run(node: BeaconNode) {.raises: [CatchableError].} =
21692169
# time to say goodbye
21702170
node.stop()
21712171

2172+
var shouldCreatePidFile*: Atomic[bool]
2173+
shouldCreatePidFile.store(true)
2174+
21722175
var gPidFile: string
21732176
proc createPidFile(filename: string) {.raises: [IOError].} =
2174-
writeFile filename, $os.getCurrentProcessId()
2175-
gPidFile = filename
2176-
addExitProc proc {.noconv.} = discard io2.removeFile(gPidFile)
2177+
if shouldCreatePidFile.load():
2178+
writeFile filename, $os.getCurrentProcessId()
2179+
gPidFile = filename
2180+
addExitProc proc {.noconv.} = discard io2.removeFile(gPidFile)
21772181

21782182
proc initializeNetworking(node: BeaconNode) {.async.} =
21792183
node.installMessageValidators()
@@ -2538,7 +2542,7 @@ proc doSlashingInterchange(conf: BeaconNodeConf) {.raises: [CatchableError].} =
25382542
of SlashProtCmd.`import`:
25392543
conf.doSlashingImport()
25402544

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

0 commit comments

Comments
 (0)