Merge pull request #520 from status-im/fix_compilation_error
fix random_keys crash
This commit is contained in:
commit
6078ff3a62
10
Makefile
10
Makefile
|
@ -15,16 +15,8 @@ BUILD_SYSTEM_DIR := vendor/nimbus-build-system
|
|||
|
||||
# debugging tools + testing tools
|
||||
TOOLS := \
|
||||
premix \
|
||||
persist \
|
||||
debug \
|
||||
dumper \
|
||||
hunter \
|
||||
regress \
|
||||
tracerTestGen \
|
||||
persistBlockTestGen
|
||||
test_tools_build
|
||||
TOOLS_DIRS := \
|
||||
premix \
|
||||
tests
|
||||
# comma-separated values for the "clean" target
|
||||
TOOLS_CSV := $(subst $(SPACE),$(COMMA),$(TOOLS))
|
||||
|
|
|
@ -11,7 +11,7 @@ import
|
|||
parseopt, strutils, macros, os, times, json, stew/[byteutils],
|
||||
chronos, eth/[keys, common, p2p, net/nat], chronicles, nimcrypto/hash,
|
||||
eth/p2p/bootnodes, eth/p2p/rlpx_protocols/whisper_protocol,
|
||||
./db/select_backend, ./random_keys,
|
||||
./db/select_backend, eth/keys,
|
||||
./vm/interpreter/vm_forks
|
||||
|
||||
const
|
||||
|
@ -150,6 +150,9 @@ type
|
|||
debug*: DebugConfiguration ## Debug configuration
|
||||
shh*: WhisperConfig ## Whisper configuration
|
||||
customGenesis*: CustomGenesisConfig ## Custom Genesis Configuration
|
||||
# You should only create one instance of the RNG per application / library
|
||||
# Ref is used so that it can be shared between components
|
||||
rng*: ref BrHmacDrbgContext
|
||||
|
||||
CustomGenesisConfig = object
|
||||
chainId*: uint
|
||||
|
@ -832,6 +835,8 @@ proc getDefaultDataDir*(): string =
|
|||
proc initConfiguration(): NimbusConfiguration =
|
||||
## Allocates and initializes `NimbusConfiguration` with default values
|
||||
result = new NimbusConfiguration
|
||||
result.rng = newRng()
|
||||
|
||||
## RPC defaults
|
||||
result.rpc.flags = {}
|
||||
result.rpc.binds = @[initTAddress("127.0.0.1:8545")]
|
||||
|
@ -847,7 +852,7 @@ proc initConfiguration(): NimbusConfiguration =
|
|||
result.net.ident = NimbusIdent
|
||||
result.net.nat = NatAny
|
||||
result.net.protocols = defaultProtocols
|
||||
result.net.nodekey = randomPrivateKey()
|
||||
result.net.nodekey = random(PrivateKey, result.rng[])
|
||||
|
||||
const dataDir = getDefaultDataDir()
|
||||
|
||||
|
|
|
@ -1,17 +1,10 @@
|
|||
import eth/keys as ethkeys
|
||||
import eth/keys, config
|
||||
|
||||
# You should only create one instance of the RNG per application / library
|
||||
# Ref is used so that it can be shared between components
|
||||
|
||||
var theRNG {.threadvar.}: ref BrHmacDrbgContext
|
||||
|
||||
proc getRng*(): ref BrHmacDrbgContext {.gcsafe.} =
|
||||
if theRNG.isNil:
|
||||
theRNG = newRng()
|
||||
theRNG
|
||||
proc getRng*(): ref BrHmacDrbgContext =
|
||||
getConfiguration().rng
|
||||
|
||||
proc randomPrivateKey*(): PrivateKey =
|
||||
random(PrivateKey, theRNG[])
|
||||
random(PrivateKey, getRng()[])
|
||||
|
||||
proc randomKeyPair*(): KeyPair =
|
||||
random(KeyPair, theRNG[])
|
||||
random(KeyPair, getRng()[])
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
# nimbus
|
||||
# Copyright (c) 2018 Status Research & Development GmbH
|
||||
# Licensed and distributed under either of
|
||||
# * MIT license: [LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT
|
||||
# * Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)
|
||||
# at your option. This file may not be copied, modified, or distributed except according to those terms.
|
||||
|
||||
# this module helps CI save time
|
||||
# when try to test buildability of these tools.
|
||||
# They never run in the CI so it is ok to combine them
|
||||
|
||||
{. warning[UnusedImport]:off .}
|
||||
|
||||
import
|
||||
../premix/premix,
|
||||
../premix/persist,
|
||||
../premix/debug,
|
||||
../premix/dumper,
|
||||
../premix/hunter,
|
||||
../premix/regress,
|
||||
./tracerTestGen,
|
||||
./persistBlockTestGen
|
|
@ -11,7 +11,8 @@ import
|
|||
chronos, chronicles, nimcrypto/[utils, hmac, pbkdf2, hash, sysrand], tables,
|
||||
stew/ranges/ptr_arith, eth/[keys, rlp, p2p, async_utils],
|
||||
eth/p2p/rlpx_protocols/whisper_protocol,
|
||||
eth/p2p/[peer_pool, bootnodes, whispernodes], ../nimbus/rpc/key_storage
|
||||
eth/p2p/[peer_pool, bootnodes, whispernodes], ../nimbus/rpc/key_storage,
|
||||
../nimbus/random_keys
|
||||
|
||||
# TODO: lots of overlap with Nimbus Whisper RPC here, however not all
|
||||
# the same due to type conversion (no use of Option and such). Perhaps some
|
||||
|
@ -24,7 +25,7 @@ type
|
|||
|
||||
CReceivedMessage* = object
|
||||
decoded*: ptr byte
|
||||
decodedLen*: csize
|
||||
decodedLen*: int # csize_t
|
||||
source*: ptr byte
|
||||
recipientPublicKey*: ptr byte
|
||||
timestamp*: uint32
|
||||
|
@ -48,9 +49,9 @@ type
|
|||
ttl*: uint32
|
||||
topic*: Topic
|
||||
payload*: ptr byte
|
||||
payloadLen*: csize
|
||||
payloadLen*: int # csize_t
|
||||
padding*: ptr byte
|
||||
paddingLen*: csize
|
||||
paddingLen*: int # csize_t
|
||||
powTime*: float64
|
||||
powTarget*: float64
|
||||
|
||||
|
@ -93,11 +94,12 @@ proc nimbus_start(port: uint16, startListening: bool, enableDiscovery: bool,
|
|||
|
||||
var keypair: KeyPair
|
||||
if privateKey.isNil:
|
||||
var kp = KeyPair.random()
|
||||
if kp.isErr:
|
||||
error "Can't generate keypair", err = kp.error
|
||||
return false
|
||||
keypair = kp[]
|
||||
#var kp = KeyPair.random()
|
||||
#if kp.isErr:
|
||||
#error "Can't generate keypair", err = kp.error
|
||||
#return false
|
||||
#keypair = kp[]
|
||||
keypair = randomKeyPair()
|
||||
else:
|
||||
let
|
||||
privKey = PrivateKey.fromRaw(makeOpenArray(privateKey, 32))
|
||||
|
@ -165,7 +167,7 @@ proc nimbus_new_keypair(id: var Identifier): bool
|
|||
|
||||
id = generateRandomID()
|
||||
try:
|
||||
whisperKeys.asymKeys.add(id.toHex(), KeyPair.random().tryGet())
|
||||
whisperKeys.asymKeys.add(id.toHex(), randomKeyPair())
|
||||
result = true
|
||||
except CatchableError:
|
||||
# Don't think this can actually happen, comes from the `getPublicKey` part
|
||||
|
@ -180,11 +182,12 @@ proc nimbus_add_keypair(privateKey: ptr byte, id: var Identifier):
|
|||
|
||||
var keypair: KeyPair
|
||||
if privateKey.isNil:
|
||||
var kp = KeyPair.random()
|
||||
if kp.isErr:
|
||||
error "Can't generate keypair", err = kp.error
|
||||
return false
|
||||
keypair = kp[]
|
||||
#var kp = KeyPair.random()
|
||||
#if kp.isErr:
|
||||
#error "Can't generate keypair", err = kp.error
|
||||
#return false
|
||||
#keypair = kp[]
|
||||
keypair = randomKeyPair()
|
||||
else:
|
||||
let
|
||||
privKey = PrivateKey.fromRaw(makeOpenArray(privateKey, 32))
|
||||
|
@ -373,7 +376,7 @@ proc nimbus_subscribe_filter(options: ptr CFilterOptions,
|
|||
proc c_handler(msg: ReceivedMessage) {.gcsafe.} =
|
||||
var cmsg = CReceivedMessage(
|
||||
decoded: unsafeAddr msg.decoded.payload[0],
|
||||
decodedLen: csize msg.decoded.payload.len(),
|
||||
decodedLen: msg.decoded.payload.len(),
|
||||
timestamp: msg.timestamp,
|
||||
ttl: msg.ttl,
|
||||
topic: msg.topic,
|
||||
|
@ -451,7 +454,7 @@ proc nimbus_join_public_chat(channel: cstring,
|
|||
proc c_handler(msg: ReceivedMessage) =
|
||||
var cmsg = CReceivedMessage(
|
||||
decoded: unsafeAddr msg.decoded.payload[0],
|
||||
decodedLen: csize msg.decoded.payload.len(),
|
||||
decodedLen: msg.decoded.payload.len(),
|
||||
timestamp: msg.timestamp,
|
||||
ttl: msg.ttl,
|
||||
topic: msg.topic,
|
||||
|
|
Loading…
Reference in New Issue