Bump nim-eth to use lrucache for discovery sessions (#1622)
This commit is contained in:
parent
bcbc7acd18
commit
87e3ef7c56
|
@ -1,9 +1,9 @@
|
|||
{.push raises: [Defect].}
|
||||
|
||||
import
|
||||
os, strutils,
|
||||
chronicles, stew/shims/net, stew/results, eth/keys, eth/trie/db, bearssl,
|
||||
eth/p2p/discoveryv5/[enr, protocol, discovery_db, node],
|
||||
std/[os, strutils],
|
||||
chronicles, stew/shims/net, stew/results, bearssl,
|
||||
eth/keys, eth/p2p/discoveryv5/[enr, protocol, node],
|
||||
conf
|
||||
|
||||
type
|
||||
|
@ -37,8 +37,7 @@ proc parseBootstrapAddress*(address: TaintedString):
|
|||
return err "Ignoring unrecognized bootstrap address type"
|
||||
|
||||
proc addBootstrapNode*(bootstrapAddr: string,
|
||||
bootstrapEnrs: var seq[enr.Record],
|
||||
localPubKey: PublicKey) =
|
||||
bootstrapEnrs: var seq[enr.Record]) =
|
||||
let enrRes = parseBootstrapAddress(bootstrapAddr)
|
||||
if enrRes.isOk:
|
||||
bootstrapEnrs.add enrRes.value
|
||||
|
@ -47,14 +46,13 @@ proc addBootstrapNode*(bootstrapAddr: string,
|
|||
bootstrapAddr, reason = enrRes.error
|
||||
|
||||
proc loadBootstrapFile*(bootstrapFile: string,
|
||||
bootstrapEnrs: var seq[enr.Record],
|
||||
localPubKey: PublicKey) =
|
||||
bootstrapEnrs: var seq[enr.Record]) =
|
||||
if bootstrapFile.len == 0: return
|
||||
let ext = splitFile(bootstrapFile).ext
|
||||
if cmpIgnoreCase(ext, ".txt") == 0 or cmpIgnoreCase(ext, ".enr") == 0 :
|
||||
try:
|
||||
for ln in lines(bootstrapFile):
|
||||
addBootstrapNode(ln, bootstrapEnrs, localPubKey)
|
||||
addBootstrapNode(ln, bootstrapEnrs)
|
||||
except IOError as e:
|
||||
error "Could not read bootstrap file", msg = e.msg
|
||||
quit 1
|
||||
|
@ -64,7 +62,7 @@ proc loadBootstrapFile*(bootstrapFile: string,
|
|||
# removal of YAML metadata.
|
||||
try:
|
||||
for ln in lines(bootstrapFile):
|
||||
addBootstrapNode(string(ln.strip()[3..^2]), bootstrapEnrs, localPubKey)
|
||||
addBootstrapNode(string(ln.strip()[3..^2]), bootstrapEnrs)
|
||||
except IOError as e:
|
||||
error "Could not read bootstrap file", msg = e.msg
|
||||
quit 1
|
||||
|
@ -82,19 +80,14 @@ proc new*(T: type Eth2DiscoveryProtocol,
|
|||
# Implement more configuration options:
|
||||
# * for setting up a specific key
|
||||
# * for using a persistent database
|
||||
let
|
||||
ourPubKey = pk.toPublicKey()
|
||||
# TODO: `newMemoryDB()` causes raises: [Exception]
|
||||
db = DiscoveryDB.init(newMemoryDB())
|
||||
|
||||
var bootstrapEnrs: seq[enr.Record]
|
||||
for node in conf.bootstrapNodes:
|
||||
addBootstrapNode(node, bootstrapEnrs, ourPubKey)
|
||||
loadBootstrapFile(string conf.bootstrapNodesFile, bootstrapEnrs, ourPubKey)
|
||||
addBootstrapNode(node, bootstrapEnrs)
|
||||
loadBootstrapFile(string conf.bootstrapNodesFile, bootstrapEnrs)
|
||||
|
||||
let persistentBootstrapFile = conf.dataDir / "bootstrap_nodes.txt"
|
||||
if fileExists(persistentBootstrapFile):
|
||||
loadBootstrapFile(persistentBootstrapFile, bootstrapEnrs, ourPubKey)
|
||||
loadBootstrapFile(persistentBootstrapFile, bootstrapEnrs)
|
||||
|
||||
newProtocol(
|
||||
pk, db, ip, tcpPort, udpPort, enrFields, bootstrapEnrs, rng = rng)
|
||||
pk, ip, tcpPort, udpPort, enrFields, bootstrapEnrs, rng = rng)
|
||||
|
|
|
@ -4,15 +4,15 @@
|
|||
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT).
|
||||
# * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0).
|
||||
# at your option. This file may not be copied, modified, or distributed except according to those terms.
|
||||
import sequtils, strutils, os, tables, options
|
||||
import std/[sequtils, strutils, os, tables, options]
|
||||
import confutils, chronicles, chronos
|
||||
import libp2p/[switch, standard_setup, multiaddress, multicodec, peerinfo]
|
||||
import libp2p/crypto/crypto as lcrypto
|
||||
import libp2p/crypto/secp as lsecp
|
||||
import libp2p/protocols/pubsub/[pubsub, gossipsub]
|
||||
import eth/p2p/discoveryv5/enr as enr
|
||||
import eth/p2p/discoveryv5/[protocol, discovery_db, node]
|
||||
import eth/keys as ethkeys, eth/trie/db
|
||||
import eth/p2p/discoveryv5/[protocol, node]
|
||||
import eth/keys as ethkeys
|
||||
import stew/[results, objects]
|
||||
import stew/byteutils as bu
|
||||
import stew/shims/net
|
||||
|
@ -405,16 +405,15 @@ proc bootstrapDiscovery(conf: InspectorConf,
|
|||
bootnodes: seq[enr.Record],
|
||||
enrFields: Option[ENRFieldPair]): DiscoveryProtocol =
|
||||
var pk = ethkeys.PrivateKey(privkey.skkey)
|
||||
var db = DiscoveryDB.init(newMemoryDB())
|
||||
let udpPort = Port(conf.discoveryPort)
|
||||
let tcpPort = Port(conf.ethPort)
|
||||
let host = host.toIpAddress()
|
||||
if enrFields.isSome():
|
||||
let fields = enrFields.get()
|
||||
let pairs = {"eth2": fields.eth2, "attnets": fields.attnets}
|
||||
result = newProtocol(pk, db, host, tcpPort, udpPort, pairs, bootnodes)
|
||||
result = newProtocol(pk, host, tcpPort, udpPort, pairs, bootnodes)
|
||||
else:
|
||||
result = newProtocol(pk, db, host, tcpPort, udpPort, [], bootnodes)
|
||||
result = newProtocol(pk, host, tcpPort, udpPort, [], bootnodes)
|
||||
result.open()
|
||||
result.start()
|
||||
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit 8e8c982270fe8411aa2173bb4f43af229496acce
|
||||
Subproject commit c9caafb2a4a0e69471bf1335188c54aad27536df
|
Loading…
Reference in New Issue