Integrate nim-prompt

This commit is contained in:
Zahary Karadjov 2019-10-02 15:38:14 +03:00 committed by zah
parent 4c0b2a9a32
commit d3f88929da
9 changed files with 56 additions and 4 deletions

10
.gitmodules vendored
View File

@ -121,3 +121,13 @@
url = https://github.com/arnetheduck/nim-result.git
ignore = dirty
branch = master
[submodule "vendor/nim-prompt"]
path = vendor/nim-prompt
url = https://github.com/status-im/nim-prompt.git
ignore = dirty
branch = master
[submodule "vendor/nim-unicodedb"]
path = vendor/nim-unicodedb
url = https://github.com/nitely/nim-unicodedb.git
ignore = dirty
branch = master

View File

@ -29,6 +29,7 @@ requires "nim >= 0.19.0",
"nimcrypto",
"serialization",
"stew",
"prompt",
"web3",
"yaml"

View File

@ -1,9 +1,14 @@
import
# Standard library
net, sequtils, tables, osproc, random, strutils, times, strformat,
# Nimble packages
stew/shims/os, stew/[objects, bitseqs],
chronos, chronicles, confutils, metrics,
json_serialization/std/[options, sets], serialization/errors,
eth/trie/db, eth/trie/backends/rocksdb_backend, eth/async_utils,
# Local modules
spec/[datatypes, digest, crypto, beaconstate, helpers, validator,
state_transition_block, network],
conf, time, state_transition, fork_choice, ssz, beacon_chain_db,
@ -16,6 +21,7 @@ const
networkMetadataFile = "network.json"
genesisFile = "genesis.json"
testnetsBaseUrl = "https://serenity-testnets.status.im"
hasPrompt = not defined(withoutPrompt)
declareGauge beacon_slot, "Latest slot of the beacon chain state"
declareGauge beacon_head_slot, "Slot of the head block of the beacon chain"
@ -825,6 +831,32 @@ proc start(node: BeaconNode, headState: BeaconState) =
node.addLocalValidators(headState)
node.run()
when hasPrompt:
from unicode import Rune
import terminal, prompt
proc providePromptCompletions*(line: seq[Rune], cursorPos: int): seq[string] =
# TODO
# The completions should be generated with the general-purpose command-line
# parsing API of Confutils
result = @[]
proc initPrompt(node: BeaconNode) =
doAssert defaultChroniclesStream.outputs.len > 0
doAssert defaultChroniclesStream.output is DynamicOutput
if isatty(stdout):
var p = Prompt.init("nimbus > ", providePromptCompletions)
p.useHistoryFile()
defaultChroniclesStream.output.writer =
proc (logLevel: LogLevel, msg: LogOutputStr) {.gcsafe.} =
p.writeLine(msg)
else:
defaultChroniclesStream.output.writer =
proc (logLevel: LogLevel, msg: LogOutputStr) {.gcsafe.} =
stdout.writeLine(msg)
when isMainModule:
randomize()
let config = BeaconNodeConf.load(version = fullVersionStr())
@ -855,7 +887,6 @@ when isMainModule:
stderr.write "Please regenerate the deposit files by running makeDeposits again\n"
quit 1
var
startTime = uint64(times.toUnix(times.getTime()) + config.genesisOffset)
initialState = initialize_beacon_state_from_eth1(
@ -933,6 +964,7 @@ when isMainModule:
createPidFile(config.dataDir.string / "beacon_node.pid")
var node = waitFor BeaconNode.init(config)
when hasPrompt: initPrompt(node)
# TODO slightly ugly to rely on node.stateCache state here..
if node.nickname != "":

View File

@ -47,7 +47,7 @@ RUN cd nim-beacon-chain \
-d:"SLOTS_PER_EPOCH=${SLOTS_PER_EPOCH}" \
-d:"SECONDS_PER_SLOT=${SECONDS_PER_SLOT}" \
-d:"chronicles_log_level=DEBUG" \
-d:"chronicles_sinks=json" \
-d:"testnet_docker_node" \
c beacon_chain/beacon_node.nim
# --------------------------------- #

View File

@ -13,6 +13,13 @@
--tlsEmulation:off
@end
@if testnet_docker_node:
-d:"chronicles_sinks=json"
-d:"withoutPrompt"
@else:
-d:"chronicles_default_output_device=dynamic"
@end
--threads:on
--opt:speed
--excessiveStackTrace:on

@ -1 +1 @@
Subproject commit 743f14cf68f213a0cbead5e6dfc00ee3edc7fe1e
Subproject commit a2ea339569878720571bbadabdde72b55c411d78

1
vendor/nim-prompt vendored Submodule

@ -0,0 +1 @@
Subproject commit b0ea27c34ca7aaee42333541f37b182fa239c844

2
vendor/nim-stew vendored

@ -1 +1 @@
Subproject commit 5f1dc751ca436e599c59df939344a641f935dd4d
Subproject commit 2bdd2fab6e9bdcdcb51ea7e09d077f36a29faf4c

1
vendor/nim-unicodedb vendored Submodule

@ -0,0 +1 @@
Subproject commit 2afc384ae17d4bd30078164fbfc2356b06d1a7f4