Portal BeaconLightClientNetwork -> BeaconNetwork renaming (#1832)
This commit is contained in:
parent
7169c846a3
commit
436ef0e40e
|
@ -23,8 +23,8 @@ import
|
|||
rpc_portal_debug_api],
|
||||
./network/state/[state_network, state_content],
|
||||
./network/history/[history_network, history_content],
|
||||
./network/beacon_light_client/[
|
||||
beacon_light_client_init_loader,
|
||||
./network/beacon/[
|
||||
beacon_init_loader,
|
||||
beacon_light_client,
|
||||
],
|
||||
./network/wire/[portal_stream, portal_protocol_config],
|
||||
|
@ -173,30 +173,30 @@ proc run(config: PortalConf) {.raises: [CatchableError].} =
|
|||
let
|
||||
# Portal works only over mainnet data currently
|
||||
networkData = loadNetworkData("mainnet")
|
||||
beaconLightClientDb = LightClientDb.new(
|
||||
networkData, config.dataDir / "db" / "beacon_lc_db")
|
||||
lightClientNetwork = LightClientNetwork.new(
|
||||
beaconDb = BeaconDb.new(
|
||||
networkData, config.dataDir / "db" / "beacon_db")
|
||||
beaconNetwork = BeaconNetwork.new(
|
||||
d,
|
||||
beaconLightClientDb,
|
||||
beaconDb,
|
||||
streamManager,
|
||||
networkData.forks,
|
||||
bootstrapRecords = bootstrapRecords,
|
||||
portalConfig = portalConfig)
|
||||
|
||||
let lc = LightClient.new(
|
||||
lightClientNetwork, rng, networkData,
|
||||
let beaconLightClient = LightClient.new(
|
||||
beaconNetwork, rng, networkData,
|
||||
LightClientFinalizationMode.Optimistic)
|
||||
|
||||
lc.onFinalizedHeader = onFinalizedHeader
|
||||
lc.onOptimisticHeader = onOptimisticHeader
|
||||
lc.trustedBlockRoot = config.trustedBlockRoot
|
||||
beaconLightClient.onFinalizedHeader = onFinalizedHeader
|
||||
beaconLightClient.onOptimisticHeader = onOptimisticHeader
|
||||
beaconLightClient.trustedBlockRoot = config.trustedBlockRoot
|
||||
|
||||
# TODO:
|
||||
# Quite dirty. Use register validate callbacks instead. Or, revisit
|
||||
# the object relationships regarding the beacon light client.
|
||||
lightClientNetwork.processor = lc.processor
|
||||
beaconNetwork.processor = beaconLightClient.processor
|
||||
|
||||
Opt.some(lc)
|
||||
Opt.some(beaconLightClient)
|
||||
else:
|
||||
Opt.none(LightClient)
|
||||
|
||||
|
@ -273,7 +273,7 @@ proc run(config: PortalConf) {.raises: [CatchableError].} =
|
|||
historyNetwork.get().portalProtocol, "history")
|
||||
if beaconLightClient.isSome():
|
||||
rpcHttpServerWithProxy.installPortalApiHandlers(
|
||||
beaconLightClient.get().network.portalProtocol, "beaconLightClient")
|
||||
beaconLightClient.get().network.portalProtocol, "beacon")
|
||||
# TODO: Test proxy with remote node over HTTPS
|
||||
waitFor rpcHttpServerWithProxy.start()
|
||||
|
||||
|
|
|
@ -19,8 +19,8 @@ import
|
|||
beacon_chain/spec/datatypes/[phase0, altair, bellatrix],
|
||||
beacon_chain/spec/forks,
|
||||
beacon_chain/spec/forks_light_client,
|
||||
./beacon_light_client_content,
|
||||
./beacon_light_client_init_loader,
|
||||
./beacon_content,
|
||||
./beacon_init_loader,
|
||||
../wire/portal_protocol
|
||||
|
||||
from beacon_chain/spec/helpers import is_better_update, toMeta
|
||||
|
@ -34,7 +34,7 @@ type
|
|||
putStmt: SqliteStmt[(int64, seq[byte]), void]
|
||||
delStmt: SqliteStmt[int64, void]
|
||||
|
||||
LightClientDb* = ref object
|
||||
BeaconDb* = ref object
|
||||
backend: SqStoreRef
|
||||
kv: KvStoreRef
|
||||
bestUpdates: BestLightClientUpdateStore
|
||||
|
@ -108,9 +108,9 @@ func close(store: var BestLightClientUpdateStore) =
|
|||
store.delStmt.disposeSafe()
|
||||
|
||||
proc new*(
|
||||
T: type LightClientDb, networkData: NetworkInitData,
|
||||
T: type BeaconDb, networkData: NetworkInitData,
|
||||
path: string, inMemory = false):
|
||||
LightClientDb =
|
||||
BeaconDb =
|
||||
let
|
||||
db =
|
||||
if inMemory:
|
||||
|
@ -122,7 +122,7 @@ proc new*(
|
|||
kvStore = kvStore db.openKvStore().expectDb()
|
||||
bestUpdates = initBestUpdatesStore(db, "lcu").expectDb()
|
||||
|
||||
LightClientDb(
|
||||
BeaconDb(
|
||||
backend: db,
|
||||
kv: kvStore,
|
||||
bestUpdates: bestUpdates,
|
||||
|
@ -139,24 +139,24 @@ proc get(kv: KvStoreRef, key: openArray[byte]): results.Opt[seq[byte]] =
|
|||
|
||||
return res
|
||||
|
||||
## Private LightClientDb calls
|
||||
proc get(db: LightClientDb, key: openArray[byte]): results.Opt[seq[byte]] =
|
||||
## Private BeaconDb calls
|
||||
proc get(db: BeaconDb, key: openArray[byte]): results.Opt[seq[byte]] =
|
||||
db.kv.get(key)
|
||||
|
||||
proc put(db: LightClientDb, key, value: openArray[byte]) =
|
||||
proc put(db: BeaconDb, key, value: openArray[byte]) =
|
||||
db.kv.put(key, value).expectDb()
|
||||
|
||||
## Public ContentId based ContentDB calls
|
||||
proc get*(db: LightClientDb, key: ContentId): results.Opt[seq[byte]] =
|
||||
proc get*(db: BeaconDb, key: ContentId): results.Opt[seq[byte]] =
|
||||
# TODO: Here it is unfortunate that ContentId is a uint256 instead of Digest256.
|
||||
db.get(key.toBytesBE())
|
||||
|
||||
proc put*(db: LightClientDb, key: ContentId, value: openArray[byte]) =
|
||||
proc put*(db: BeaconDb, key: ContentId, value: openArray[byte]) =
|
||||
db.put(key.toBytesBE(), value)
|
||||
|
||||
# TODO Add checks that uint64 can be safely casted to int64
|
||||
proc getLightClientUpdates(
|
||||
db: LightClientDb, start: uint64, to: uint64):
|
||||
db: BeaconDb, start: uint64, to: uint64):
|
||||
ForkedLightClientUpdateBytesList =
|
||||
## Get multiple consecutive LightClientUpdates for given periods
|
||||
var updates: ForkedLightClientUpdateBytesList
|
||||
|
@ -168,7 +168,7 @@ proc getLightClientUpdates(
|
|||
return updates
|
||||
|
||||
proc getBestUpdate*(
|
||||
db: LightClientDb, period: SyncCommitteePeriod):
|
||||
db: BeaconDb, period: SyncCommitteePeriod):
|
||||
Result[ForkedLightClientUpdate, string] =
|
||||
## Get the best ForkedLightClientUpdate for given period
|
||||
## Note: Only the best one for a given period is being stored.
|
||||
|
@ -181,7 +181,7 @@ proc getBestUpdate*(
|
|||
return decodeLightClientUpdateForked(db.forkDigests, update)
|
||||
|
||||
proc putBootstrap*(
|
||||
db: LightClientDb,
|
||||
db: BeaconDb,
|
||||
blockRoot: Digest, bootstrap: ForkedLightClientBootstrap) =
|
||||
# Put a ForkedLightClientBootstrap in the db.
|
||||
withForkyBootstrap(bootstrap):
|
||||
|
@ -196,13 +196,13 @@ proc putBootstrap*(
|
|||
db.put(contentId, encodedBootstrap)
|
||||
|
||||
func putLightClientUpdate*(
|
||||
db: LightClientDb, period: uint64, update: seq[byte]) =
|
||||
db: BeaconDb, period: uint64, update: seq[byte]) =
|
||||
# Put an encoded ForkedLightClientUpdate in the db.
|
||||
let res = db.bestUpdates.putStmt.exec((period.int64, update))
|
||||
res.expect("SQL query OK")
|
||||
|
||||
func putBestUpdate*(
|
||||
db: LightClientDb, period: SyncCommitteePeriod,
|
||||
db: BeaconDb, period: SyncCommitteePeriod,
|
||||
update: ForkedLightClientUpdate) =
|
||||
# Put a ForkedLightClientUpdate in the db.
|
||||
doAssert not db.backend.readOnly # All `stmt` are non-nil
|
||||
|
@ -225,7 +225,7 @@ func putBestUpdate*(
|
|||
db.bestUpdates.delStmt.exec(period.int64).expect("SQL query OK")
|
||||
|
||||
proc putUpdateIfBetter*(
|
||||
db: LightClientDb,
|
||||
db: BeaconDb,
|
||||
period: SyncCommitteePeriod, update: ForkedLightClientUpdate) =
|
||||
let currentUpdate = db.getBestUpdate(period).valueOr:
|
||||
# No current update for that period so we can just put this one
|
||||
|
@ -236,7 +236,7 @@ proc putUpdateIfBetter*(
|
|||
db.putBestUpdate(period, update)
|
||||
|
||||
proc putUpdateIfBetter*(
|
||||
db: LightClientDb, period: SyncCommitteePeriod, update: seq[byte]) =
|
||||
db: BeaconDb, period: SyncCommitteePeriod, update: seq[byte]) =
|
||||
let newUpdate = decodeLightClientUpdateForked(db.forkDigests, update).valueOr:
|
||||
# TODO:
|
||||
# Need to go over the usage in offer/accept vs findcontent/content
|
||||
|
@ -245,7 +245,7 @@ proc putUpdateIfBetter*(
|
|||
|
||||
db.putUpdateIfBetter(period, newUpdate)
|
||||
|
||||
proc createGetHandler*(db: LightClientDb): DbGetHandler =
|
||||
proc createGetHandler*(db: BeaconDb): DbGetHandler =
|
||||
return (
|
||||
proc(contentKey: ByteList, contentId: ContentId): results.Opt[seq[byte]] =
|
||||
let contentKey = contentKey.decode().valueOr:
|
||||
|
@ -299,7 +299,7 @@ proc createGetHandler*(db: LightClientDb): DbGetHandler =
|
|||
Opt.none(seq[byte])
|
||||
)
|
||||
|
||||
proc createStoreHandler*(db: LightClientDb): DbStoreHandler =
|
||||
proc createStoreHandler*(db: BeaconDb): DbStoreHandler =
|
||||
return (proc(
|
||||
contentKey: ByteList,
|
||||
contentId: ContentId,
|
|
@ -13,14 +13,13 @@ import
|
|||
beacon_chain/gossip_processing/light_client_processor,
|
||||
beacon_chain/spec/datatypes/altair,
|
||||
beacon_chain/beacon_clock,
|
||||
"."/[beacon_light_client_network, beacon_light_client_manager,
|
||||
beacon_light_client_init_loader]
|
||||
"."/[beacon_init_loader, beacon_network, beacon_light_client_manager]
|
||||
|
||||
export
|
||||
LightClientFinalizationMode,
|
||||
beacon_light_client_network, beacon_light_client_manager
|
||||
beacon_network, beacon_light_client_manager
|
||||
|
||||
logScope: topics = "portal_beacon_lc"
|
||||
logScope: topics = "beacon_lc"
|
||||
|
||||
type
|
||||
LightClientHeaderCallback* =
|
||||
|
@ -28,7 +27,7 @@ type
|
|||
gcsafe, raises: [].}
|
||||
|
||||
LightClient* = ref object
|
||||
network*: LightClientNetwork
|
||||
network*: BeaconNetwork
|
||||
cfg: RuntimeConfig
|
||||
forkDigests: ref ForkDigests
|
||||
getBeaconTime*: GetBeaconTimeFn
|
||||
|
@ -60,7 +59,7 @@ func optimisticHeader*(
|
|||
|
||||
proc new*(
|
||||
T: type LightClient,
|
||||
network: LightClientNetwork,
|
||||
network: BeaconNetwork,
|
||||
rng: ref HmacDrbgContext,
|
||||
dumpEnabled: bool,
|
||||
dumpDirInvalid, dumpDirIncoming: string,
|
||||
|
@ -147,7 +146,7 @@ proc new*(
|
|||
|
||||
proc new*(
|
||||
T: type LightClient,
|
||||
network: LightClientNetwork,
|
||||
network: BeaconNetwork,
|
||||
rng: ref HmacDrbgContext,
|
||||
networkData: NetworkInitData,
|
||||
finalizationMode: LightClientFinalizationMode): T =
|
|
@ -15,8 +15,7 @@ import
|
|||
beacon_chain/spec/[forks_light_client, digest],
|
||||
beacon_chain/beacon_clock,
|
||||
beacon_chain/sync/light_client_sync_helpers,
|
||||
"."/[beacon_light_client_network, beacon_light_client_content,
|
||||
beacon_light_client_db]
|
||||
"."/[beacon_network, beacon_content, beacon_db]
|
||||
|
||||
from beacon_chain/consensus_object_pools/block_pools_types import VerifierError
|
||||
|
||||
|
@ -60,7 +59,7 @@ type
|
|||
proc(): Slot {.gcsafe, raises: [].}
|
||||
|
||||
LightClientManager* = object
|
||||
network: LightClientNetwork
|
||||
network: BeaconNetwork
|
||||
rng: ref HmacDrbgContext
|
||||
getTrustedBlockRoot: GetTrustedBlockRootCallback
|
||||
bootstrapVerifier: BootstrapVerifier
|
||||
|
@ -76,7 +75,7 @@ type
|
|||
|
||||
func init*(
|
||||
T: type LightClientManager,
|
||||
network: LightClientNetwork,
|
||||
network: BeaconNetwork,
|
||||
rng: ref HmacDrbgContext,
|
||||
getTrustedBlockRoot: GetTrustedBlockRootCallback,
|
||||
bootstrapVerifier: BootstrapVerifier,
|
||||
|
@ -114,7 +113,7 @@ proc getOptimisticPeriod(self: LightClientManager): SyncCommitteePeriod =
|
|||
# https://github.com/ethereum/consensus-specs/blob/v1.4.0-beta.1/specs/altair/light-client/p2p-interface.md#getlightclientbootstrap
|
||||
proc doRequest(
|
||||
e: typedesc[Bootstrap],
|
||||
n: LightClientNetwork,
|
||||
n: BeaconNetwork,
|
||||
blockRoot: Eth2Digest
|
||||
): Future[NetRes[ForkedLightClientBootstrap]] =
|
||||
n.getLightClientBootstrap(blockRoot)
|
||||
|
@ -123,7 +122,7 @@ proc doRequest(
|
|||
type LightClientUpdatesByRangeResponse = NetRes[ForkedLightClientUpdateList]
|
||||
proc doRequest(
|
||||
e: typedesc[UpdatesByRange],
|
||||
n: LightClientNetwork,
|
||||
n: BeaconNetwork,
|
||||
key: tuple[startPeriod: SyncCommitteePeriod, count: uint64]
|
||||
): Future[LightClientUpdatesByRangeResponse] {.async.} =
|
||||
let (startPeriod, count) = key
|
||||
|
@ -139,7 +138,7 @@ proc doRequest(
|
|||
# https://github.com/ethereum/consensus-specs/blob/v1.4.0-beta.1/specs/altair/light-client/p2p-interface.md#getlightclientfinalityupdate
|
||||
proc doRequest(
|
||||
e: typedesc[FinalityUpdate],
|
||||
n: LightClientNetwork,
|
||||
n: BeaconNetwork,
|
||||
finalizedSlot: Slot
|
||||
): Future[NetRes[ForkedLightClientFinalityUpdate]] =
|
||||
n.getLightClientFinalityUpdate(
|
||||
|
@ -149,7 +148,7 @@ proc doRequest(
|
|||
# https://github.com/ethereum/consensus-specs/blob/v1.4.0-beta.1/specs/altair/light-client/p2p-interface.md#getlightclientoptimisticupdate
|
||||
proc doRequest(
|
||||
e: typedesc[OptimisticUpdate],
|
||||
n: LightClientNetwork,
|
||||
n: BeaconNetwork,
|
||||
optimisticSlot: Slot
|
||||
): Future[NetRes[ForkedLightClientOptimisticUpdate]] =
|
||||
n.getLightClientOptimisticUpdate(distinctBase(optimisticSlot))
|
||||
|
@ -233,7 +232,7 @@ proc workerTask[E](
|
|||
when E.V is ForkedLightClientBootstrap:
|
||||
withForkyObject(val):
|
||||
when lcDataFork > LightClientDataFork.None:
|
||||
self.network.lightClientDb.putBootstrap(key, val)
|
||||
self.network.beaconDb.putBootstrap(key, val)
|
||||
else:
|
||||
notice "Received value from an unviable fork",
|
||||
endpoint = E.name
|
||||
|
@ -242,7 +241,7 @@ proc workerTask[E](
|
|||
when lcDataFork > LightClientDataFork.None:
|
||||
let period =
|
||||
forkyObject.attested_header.beacon.slot.sync_committee_period
|
||||
self.network.lightClientDb.putUpdateIfBetter(period, val)
|
||||
self.network.beaconDb.putUpdateIfBetter(period, val)
|
||||
else:
|
||||
notice "Received value from an unviable fork",
|
||||
endpoint = E.name
|
|
@ -15,20 +15,20 @@ import
|
|||
beacon_chain/gossip_processing/light_client_processor,
|
||||
../../../nimbus/constants,
|
||||
../wire/[portal_protocol, portal_stream, portal_protocol_config],
|
||||
"."/[beacon_light_client_content, beacon_light_client_db]
|
||||
"."/[beacon_content, beacon_db]
|
||||
|
||||
export beacon_light_client_content, beacon_light_client_db
|
||||
export beacon_content, beacon_db
|
||||
|
||||
logScope:
|
||||
topics = "portal_beacon_network"
|
||||
topics = "beacon_network"
|
||||
|
||||
const
|
||||
lightClientProtocolId* = [byte 0x50, 0x1A]
|
||||
|
||||
type
|
||||
LightClientNetwork* = ref object
|
||||
BeaconNetwork* = ref object
|
||||
portalProtocol*: PortalProtocol
|
||||
lightClientDb*: LightClientDb
|
||||
beaconDb*: BeaconDb
|
||||
processor*: ref LightClientProcessor
|
||||
contentQueue*: AsyncQueue[(Opt[NodeId], ContentKeysList, seq[seq[byte]])]
|
||||
forkDigests*: ForkDigests
|
||||
|
@ -38,7 +38,7 @@ func toContentIdHandler(contentKey: ByteList): results.Opt[ContentId] =
|
|||
ok(toContentId(contentKey))
|
||||
|
||||
proc getContent(
|
||||
n: LightClientNetwork, contentKey: ContentKey):
|
||||
n: BeaconNetwork, contentKey: ContentKey):
|
||||
Future[results.Opt[seq[byte]]] {.async.} =
|
||||
let
|
||||
contentKeyEncoded = encode(contentKey)
|
||||
|
@ -59,7 +59,7 @@ proc getContent(
|
|||
return Opt.some(contentRes.value().content)
|
||||
|
||||
proc getLightClientBootstrap*(
|
||||
n: LightClientNetwork,
|
||||
n: BeaconNetwork,
|
||||
trustedRoot: Digest):
|
||||
Future[results.Opt[ForkedLightClientBootstrap]] {.async.} =
|
||||
let
|
||||
|
@ -82,7 +82,7 @@ proc getLightClientBootstrap*(
|
|||
return Opt.some(decodingResult.value())
|
||||
|
||||
proc getLightClientUpdatesByRange*(
|
||||
n: LightClientNetwork,
|
||||
n: BeaconNetwork,
|
||||
startPeriod: SyncCommitteePeriod,
|
||||
count: uint64):
|
||||
Future[results.Opt[ForkedLightClientUpdateList]] {.async.} =
|
||||
|
@ -106,7 +106,7 @@ proc getLightClientUpdatesByRange*(
|
|||
return Opt.some(decodingResult.value())
|
||||
|
||||
proc getLightClientFinalityUpdate*(
|
||||
n: LightClientNetwork,
|
||||
n: BeaconNetwork,
|
||||
finalizedSlot: uint64
|
||||
): Future[results.Opt[ForkedLightClientFinalityUpdate]] {.async.} =
|
||||
let
|
||||
|
@ -127,7 +127,7 @@ proc getLightClientFinalityUpdate*(
|
|||
return Opt.some(decodingResult.value())
|
||||
|
||||
proc getLightClientOptimisticUpdate*(
|
||||
n: LightClientNetwork,
|
||||
n: BeaconNetwork,
|
||||
optimisticSlot: uint64
|
||||
): Future[results.Opt[ForkedLightClientOptimisticUpdate]] {.async.} =
|
||||
|
||||
|
@ -149,9 +149,9 @@ proc getLightClientOptimisticUpdate*(
|
|||
return Opt.some(decodingResult.value())
|
||||
|
||||
proc new*(
|
||||
T: type LightClientNetwork,
|
||||
T: type BeaconNetwork,
|
||||
baseProtocol: protocol.Protocol,
|
||||
lightClientDb: LightClientDb,
|
||||
beaconDb: BeaconDb,
|
||||
streamManager: StreamManager,
|
||||
forkDigests: ForkDigests,
|
||||
bootstrapRecords: openArray[Record] = [],
|
||||
|
@ -173,20 +173,20 @@ proc new*(
|
|||
portalProtocol = PortalProtocol.new(
|
||||
baseProtocol, lightClientProtocolId,
|
||||
toContentIdHandler,
|
||||
createGetHandler(lightClientDb), stream, bootstrapRecords,
|
||||
createGetHandler(beaconDb), stream, bootstrapRecords,
|
||||
config = portalConfigAdjusted)
|
||||
|
||||
portalProtocol.dbPut = createStoreHandler(lightClientDb)
|
||||
portalProtocol.dbPut = createStoreHandler(beaconDb)
|
||||
|
||||
LightClientNetwork(
|
||||
BeaconNetwork(
|
||||
portalProtocol: portalProtocol,
|
||||
lightClientDb: lightClientDb,
|
||||
beaconDb: beaconDb,
|
||||
contentQueue: contentQueue,
|
||||
forkDigests: forkDigests
|
||||
)
|
||||
|
||||
proc validateContent(
|
||||
n: LightClientNetwork, content: seq[byte], contentKey: ByteList):
|
||||
n: BeaconNetwork, content: seq[byte], contentKey: ByteList):
|
||||
Result[void, string] =
|
||||
let key = contentKey.decode().valueOr:
|
||||
return err("Error decoding content key")
|
||||
|
@ -248,7 +248,7 @@ proc validateContent(
|
|||
ok()
|
||||
|
||||
proc validateContent(
|
||||
n: LightClientNetwork,
|
||||
n: BeaconNetwork,
|
||||
contentKeys: ContentKeysList,
|
||||
contentItems: seq[seq[byte]]): Future[bool] {.async.} =
|
||||
# content passed here can have less items then contentKeys, but not more.
|
||||
|
@ -274,7 +274,7 @@ proc validateContent(
|
|||
|
||||
return true
|
||||
|
||||
proc processContentLoop(n: LightClientNetwork) {.async.} =
|
||||
proc processContentLoop(n: BeaconNetwork) {.async.} =
|
||||
try:
|
||||
while true:
|
||||
let (srcNodeId, contentKeys, contentItems) =
|
||||
|
@ -292,12 +292,12 @@ proc processContentLoop(n: LightClientNetwork) {.async.} =
|
|||
except CancelledError:
|
||||
trace "processContentLoop canceled"
|
||||
|
||||
proc start*(n: LightClientNetwork) =
|
||||
proc start*(n: BeaconNetwork) =
|
||||
info "Starting portal beacon chain network"
|
||||
n.portalProtocol.start()
|
||||
n.processContentLoop = processContentLoop(n)
|
||||
|
||||
proc stop*(n: LightClientNetwork) =
|
||||
proc stop*(n: BeaconNetwork) =
|
||||
n.portalProtocol.stop()
|
||||
|
||||
if not n.processContentLoop.isNil:
|
|
@ -39,22 +39,22 @@ proc portal_historyLocalContent(contentKey: string): string
|
|||
proc portal_historyGossip(contentKey: string, contentValue: string): int
|
||||
|
||||
## Portal Beacon Light Client Network json-rpc calls
|
||||
proc portal_beaconLightClientNodeInfo(): NodeInfo
|
||||
proc portal_beaconLightClientRoutingTableInfo(): RoutingTableInfo
|
||||
proc portal_beaconLightClientAddEnr(enr: Record): bool
|
||||
proc portal_beaconLightClientAddEnrs(enrs: seq[Record]): bool
|
||||
proc portal_beaconLightClientGetEnr(nodeId: NodeId): Record
|
||||
proc portal_beaconLightClientDeleteEnr(nodeId: NodeId): bool
|
||||
proc portal_beaconLightClientLookupEnr(nodeId: NodeId): Record
|
||||
proc portal_beaconLightClientPing(enr: Record): tuple[
|
||||
proc portal_beaconNodeInfo(): NodeInfo
|
||||
proc portal_beaconRoutingTableInfo(): RoutingTableInfo
|
||||
proc portal_beaconAddEnr(enr: Record): bool
|
||||
proc portal_beaconAddEnrs(enrs: seq[Record]): bool
|
||||
proc portal_beaconGetEnr(nodeId: NodeId): Record
|
||||
proc portal_beaconDeleteEnr(nodeId: NodeId): bool
|
||||
proc portal_beaconLookupEnr(nodeId: NodeId): Record
|
||||
proc portal_beaconPing(enr: Record): tuple[
|
||||
enrSeq: uint64, customPayload: string]
|
||||
proc portal_beaconLightClientFindNodes(enr: Record): seq[Record]
|
||||
proc portal_beaconLightClientFindContent(enr: Record, contentKey: string): JsonNode
|
||||
proc portal_beaconLightClientOffer(
|
||||
proc portal_beaconFindNodes(enr: Record): seq[Record]
|
||||
proc portal_beaconFindContent(enr: Record, contentKey: string): JsonNode
|
||||
proc portal_beaconOffer(
|
||||
enr: Record, contentKey: string, contentValue: string): string
|
||||
proc portal_beaconLightClientRecursiveFindNodes(nodeId: NodeId): seq[Record]
|
||||
proc portal_beaconLightClientRecursiveFindContent(contentKey: string): string
|
||||
proc portal_beaconLightClientStore(contentKey: string, contentValue: string): bool
|
||||
proc portal_beaconLightClientLocalContent(contentKey: string): string
|
||||
proc portal_beaconLightClientGossip(contentKey: string, contentValue: string): int
|
||||
proc portal_beaconLightClientRandomGossip(contentKey: string, contentValue: string): int
|
||||
proc portal_beaconRecursiveFindNodes(nodeId: NodeId): seq[Record]
|
||||
proc portal_beaconRecursiveFindContent(contentKey: string): string
|
||||
proc portal_beaconStore(contentKey: string, contentValue: string): bool
|
||||
proc portal_beaconLocalContent(contentKey: string): string
|
||||
proc portal_beaconGossip(contentKey: string, contentValue: string): int
|
||||
proc portal_beaconRandomGossip(contentKey: string, contentValue: string): int
|
||||
|
|
|
@ -21,7 +21,7 @@ import
|
|||
# caused by `readValue` clashing ?
|
||||
# ../../nimbus/common/chain_config
|
||||
../network/history/[history_network, history_content],
|
||||
../network/beacon_light_client/beacon_light_client
|
||||
../network/beacon/beacon_light_client
|
||||
|
||||
# Subset of Eth JSON-RPC API: https://eth.wiki/json-rpc/API
|
||||
# Supported subset will eventually be found here:
|
||||
|
|
|
@ -19,4 +19,4 @@ import
|
|||
./test_beacon_chain_block_proof_capella,
|
||||
./test_beacon_chain_historical_roots,
|
||||
./test_beacon_chain_historical_summaries,
|
||||
./beacon_light_client_tests/all_beacon_light_client_tests
|
||||
./beacon_network_tests/all_beacon_network_tests
|
||||
|
|
|
@ -8,6 +8,6 @@
|
|||
{. warning[UnusedImport]:off .}
|
||||
|
||||
import
|
||||
./test_beacon_light_client_content,
|
||||
./test_beacon_light_client_network,
|
||||
./test_beacon_content,
|
||||
./test_beacon_network,
|
||||
./test_beacon_light_client
|
|
@ -10,40 +10,40 @@ import
|
|||
eth/p2p/discoveryv5/protocol as discv5_protocol,
|
||||
beacon_chain/spec/forks,
|
||||
../../network/wire/[portal_protocol, portal_stream],
|
||||
../../network/beacon_light_client/[
|
||||
beacon_light_client_init_loader,
|
||||
beacon_light_client_network
|
||||
../../network/beacon/[
|
||||
beacon_init_loader,
|
||||
beacon_network
|
||||
],
|
||||
../test_helpers
|
||||
|
||||
type LightClientNode* = ref object
|
||||
type BeaconNode* = ref object
|
||||
discoveryProtocol*: discv5_protocol.Protocol
|
||||
lightClientNetwork*: LightClientNetwork
|
||||
beaconNetwork*: BeaconNetwork
|
||||
|
||||
proc newLCNode*(
|
||||
rng: ref HmacDrbgContext,
|
||||
port: int,
|
||||
networkData: NetworkInitData): LightClientNode =
|
||||
networkData: NetworkInitData): BeaconNode =
|
||||
let
|
||||
node = initDiscoveryNode(rng, PrivateKey.random(rng[]), localAddress(port))
|
||||
db = LightClientDb.new(networkData, "", inMemory = true)
|
||||
db = BeaconDb.new(networkData, "", inMemory = true)
|
||||
streamManager = StreamManager.new(node)
|
||||
network = LightClientNetwork.new(node, db, streamManager, networkData.forks)
|
||||
network = BeaconNetwork.new(node, db, streamManager, networkData.forks)
|
||||
|
||||
return LightClientNode(discoveryProtocol: node, lightClientNetwork: network)
|
||||
return BeaconNode(discoveryProtocol: node, beaconNetwork: network)
|
||||
|
||||
func portalProtocol*(n: LightClientNode): PortalProtocol =
|
||||
n.lightClientNetwork.portalProtocol
|
||||
func portalProtocol*(n: BeaconNode): PortalProtocol =
|
||||
n.beaconNetwork.portalProtocol
|
||||
|
||||
func localNode*(n: LightClientNode): Node =
|
||||
func localNode*(n: BeaconNode): Node =
|
||||
n.discoveryProtocol.localNode
|
||||
|
||||
proc start*(n: LightClientNode) =
|
||||
n.lightClientNetwork.start()
|
||||
proc start*(n: BeaconNode) =
|
||||
n.beaconNetwork.start()
|
||||
|
||||
proc stop*(n: LightClientNode) {.async.} =
|
||||
n.lightClientNetwork.stop()
|
||||
proc stop*(n: BeaconNode) {.async.} =
|
||||
n.beaconNetwork.stop()
|
||||
await n.discoveryProtocol.closeWait()
|
||||
|
||||
proc containsId*(n: LightClientNode, contentId: ContentId): bool =
|
||||
n.lightClientNetwork.lightClientDb.get(contentId).isSome()
|
||||
proc containsId*(n: BeaconNode, contentId: ContentId): bool =
|
||||
n.beaconNetwork.beaconDb.get(contentId).isSome()
|
|
@ -13,10 +13,10 @@ import
|
|||
beacon_chain/spec/forks,
|
||||
beacon_chain/spec/datatypes/altair,
|
||||
../../eth_data/[history_data_ssz_e2s, history_data_json_store],
|
||||
../../network/beacon_light_client/beacon_light_client_content,
|
||||
"."/[light_client_test_data, beacon_light_client_test_helpers]
|
||||
../../network/beacon/beacon_content,
|
||||
"."/light_client_test_data
|
||||
|
||||
suite "Beacon Light Client Content Encodings - Mainnet":
|
||||
suite "Beacon Content Encodings - Mainnet":
|
||||
# These test vectors are generated by eth_data_exporter. The content is taken
|
||||
# from mainnet and encoded as it would be transmitted on Portal Network,
|
||||
# including also the content key.
|
||||
|
@ -179,7 +179,7 @@ suite "Beacon Light Client Content Encodings - Mainnet":
|
|||
check encoded == contentValueEncoded
|
||||
check encode(key).asSeq() == contentKeyEncoded
|
||||
|
||||
suite "Beacon Light Client Content Encodings":
|
||||
suite "Beacon Content Encodings":
|
||||
# TODO: These tests are less useful now and should instead be altered to
|
||||
# use the consensus test vectors to simply test if encoding / decoding works
|
||||
# fine for the different forks.
|
|
@ -14,9 +14,8 @@ import
|
|||
beacon_chain/spec/datatypes/altair,
|
||||
beacon_chain/spec/helpers,
|
||||
../../network/wire/[portal_protocol, portal_stream],
|
||||
../../network/beacon_light_client/[beacon_light_client,
|
||||
beacon_light_client_init_loader],
|
||||
"."/[light_client_test_data, beacon_light_client_test_helpers]
|
||||
../../network/beacon/[beacon_init_loader, beacon_light_client],
|
||||
"."/[light_client_test_data, beacon_test_helpers]
|
||||
|
||||
procSuite "Portal Beacon Light Client":
|
||||
let rng = newRng()
|
||||
|
@ -71,7 +70,7 @@ procSuite "Portal Beacon Light Client":
|
|||
)
|
||||
|
||||
let lc = LightClient.new(
|
||||
lcNode1.lightClientNetwork, rng, networkData,
|
||||
lcNode1.beaconNetwork, rng, networkData,
|
||||
LightClientFinalizationMode.Optimistic)
|
||||
|
||||
lc.onFinalizedHeader = headerCallback(finalizedHeaders)
|
|
@ -11,11 +11,10 @@ import
|
|||
beacon_chain/spec/forks,
|
||||
beacon_chain/spec/datatypes/altair,
|
||||
../../network/wire/portal_protocol,
|
||||
../../network/beacon_light_client/[beacon_light_client_network,
|
||||
beacon_light_client_init_loader],
|
||||
"."/[light_client_test_data, beacon_light_client_test_helpers]
|
||||
../../network/beacon/[beacon_network, beacon_init_loader],
|
||||
"."/[light_client_test_data, beacon_test_helpers]
|
||||
|
||||
procSuite "Beacon Light Client Content Network":
|
||||
procSuite "Beacon Content Network":
|
||||
let rng = newRng()
|
||||
|
||||
asyncTest "Get bootstrap by trusted block hash":
|
||||
|
@ -55,7 +54,7 @@ procSuite "Beacon Light Client Content Network":
|
|||
)
|
||||
|
||||
let bootstrapFromNetworkResult =
|
||||
await lcNode1.lightClientNetwork.getLightClientBootstrap(
|
||||
await lcNode1.beaconNetwork.getLightClientBootstrap(
|
||||
bootstrapHeaderHash
|
||||
)
|
||||
|
||||
|
@ -123,11 +122,11 @@ procSuite "Beacon Light Client Content Network":
|
|||
|
||||
let
|
||||
finalityResult =
|
||||
await lcNode1.lightClientNetwork.getLightClientFinalityUpdate(
|
||||
await lcNode1.beaconNetwork.getLightClientFinalityUpdate(
|
||||
distinctBase(finalizedHeaderSlot),
|
||||
)
|
||||
optimisticResult =
|
||||
await lcNode1.lightClientNetwork.getLightClientOptimisticUpdate(
|
||||
await lcNode1.beaconNetwork.getLightClientOptimisticUpdate(
|
||||
distinctBase(optimisticHeaderSlot)
|
||||
)
|
||||
|
||||
|
@ -182,7 +181,7 @@ procSuite "Beacon Light Client Content Network":
|
|||
)
|
||||
|
||||
let updatesResult =
|
||||
await lcNode1.lightClientNetwork.getLightClientUpdatesByRange(
|
||||
await lcNode1.beaconNetwork.getLightClientUpdatesByRange(
|
||||
startPeriod,
|
||||
uint64(2)
|
||||
)
|
|
@ -31,7 +31,7 @@ import
|
|||
stew/byteutils,
|
||||
eth/async_utils,
|
||||
beacon_chain/spec/eth2_apis/rest_beacon_client,
|
||||
../../network/beacon_light_client/beacon_light_client_content,
|
||||
../../network/beacon/beacon_content,
|
||||
../../rpc/portal_rpc_client,
|
||||
../../logging,
|
||||
../eth_data_exporter/cl_data_exporter,
|
||||
|
@ -79,7 +79,7 @@ proc gossipLCBootstrapUpdate*(
|
|||
try:
|
||||
let
|
||||
contentKeyHex = contentKey.asSeq().toHex()
|
||||
peers = await portalRpcClient.portal_beaconLightClientRandomGossip(
|
||||
peers = await portalRpcClient.portal_beaconRandomGossip(
|
||||
contentKeyHex,
|
||||
content.toHex())
|
||||
info "Beacon LC bootstrap gossiped", peers,
|
||||
|
@ -133,7 +133,7 @@ proc gossipLCUpdates*(
|
|||
try:
|
||||
let
|
||||
contentKeyHex = contentKey.asSeq().toHex()
|
||||
peers = await portalRpcClient.portal_beaconLightClientRandomGossip(
|
||||
peers = await portalRpcClient.portal_beaconRandomGossip(
|
||||
contentKeyHex,
|
||||
content.toHex())
|
||||
info "Beacon LC update gossiped", peers,
|
||||
|
@ -189,7 +189,7 @@ proc gossipLCFinalityUpdate*(
|
|||
try:
|
||||
let
|
||||
contentKeyHex = contentKey.asSeq().toHex()
|
||||
peers = await portalRpcClient.portal_beaconLightClientRandomGossip(
|
||||
peers = await portalRpcClient.portal_beaconRandomGossip(
|
||||
contentKeyHex,
|
||||
content.toHex())
|
||||
info "Beacon LC finality update gossiped", peers,
|
||||
|
@ -239,7 +239,7 @@ proc gossipLCOptimisticUpdate*(
|
|||
try:
|
||||
let
|
||||
contentKeyHex = contentKey.asSeq().toHex()
|
||||
peers = await portalRpcClient.portal_beaconLightClientRandomGossip(
|
||||
peers = await portalRpcClient.portal_beaconRandomGossip(
|
||||
contentKeyHex,
|
||||
content.toHex())
|
||||
info "Beacon LC optimistic update gossiped", peers,
|
||||
|
|
|
@ -85,7 +85,7 @@ import
|
|||
../../../nimbus/rpc/rpc_types,
|
||||
../../rpc/[portal_rpc_client, eth_rpc_client],
|
||||
../../network/history/[history_content, history_network],
|
||||
../../network/beacon_light_client/beacon_light_client_content,
|
||||
../../network/beacon/beacon_content,
|
||||
../../common/common_types,
|
||||
../../nimbus/db/core_db,
|
||||
./beacon_lc_bridge_conf
|
||||
|
@ -545,7 +545,7 @@ proc run(config: BeaconBridgeConf) {.raises: [CatchableError].} =
|
|||
let
|
||||
root = hash_tree_root(forkyObject.header)
|
||||
contentKey = encode(bootstrapContentKey(root))
|
||||
contentId = beacon_light_client_content.toContentId(contentKey)
|
||||
contentId = beacon_content.toContentId(contentKey)
|
||||
forkDigest = forkDigestAtEpoch(
|
||||
forkDigests[], epoch(forkyObject.header.beacon.slot), cfg)
|
||||
content = encodeBootstrapForked(
|
||||
|
@ -557,7 +557,7 @@ proc run(config: BeaconBridgeConf) {.raises: [CatchableError].} =
|
|||
try:
|
||||
let
|
||||
contentKeyHex = contentKey.asSeq().toHex()
|
||||
peers = await portalRpcClient.portal_beaconLightClientGossip(
|
||||
peers = await portalRpcClient.portal_beaconGossip(
|
||||
contentKeyHex,
|
||||
content.toHex())
|
||||
info "Beacon LC bootstrap gossiped", peers,
|
||||
|
@ -578,7 +578,7 @@ proc run(config: BeaconBridgeConf) {.raises: [CatchableError].} =
|
|||
let
|
||||
period = forkyObject.attested_header.beacon.slot.sync_committee_period
|
||||
contentKey = encode(updateContentKey(period.uint64, uint64(1)))
|
||||
contentId = beacon_light_client_content.toContentId(contentKey)
|
||||
contentId = beacon_content.toContentId(contentKey)
|
||||
forkDigest = forkDigestAtEpoch(
|
||||
forkDigests[], epoch(forkyObject.attested_header.beacon.slot), cfg)
|
||||
content = encodeLightClientUpdatesForked(
|
||||
|
@ -590,7 +590,7 @@ proc run(config: BeaconBridgeConf) {.raises: [CatchableError].} =
|
|||
try:
|
||||
let
|
||||
contentKeyHex = contentKey.asSeq().toHex()
|
||||
peers = await portalRpcClient.portal_beaconLightClientGossip(
|
||||
peers = await portalRpcClient.portal_beaconGossip(
|
||||
contentKeyHex,
|
||||
content.toHex())
|
||||
info "Beacon LC bootstrap gossiped", peers,
|
||||
|
@ -613,7 +613,7 @@ proc run(config: BeaconBridgeConf) {.raises: [CatchableError].} =
|
|||
let
|
||||
slot = forkyObject.signature_slot
|
||||
contentKey = encode(optimisticUpdateContentKey(slot.uint64))
|
||||
contentId = beacon_light_client_content.toContentId(contentKey)
|
||||
contentId = beacon_content.toContentId(contentKey)
|
||||
forkDigest = forkDigestAtEpoch(
|
||||
forkDigests[], epoch(forkyObject.attested_header.beacon.slot), cfg)
|
||||
content = encodeOptimisticUpdateForked(
|
||||
|
@ -625,7 +625,7 @@ proc run(config: BeaconBridgeConf) {.raises: [CatchableError].} =
|
|||
try:
|
||||
let
|
||||
contentKeyHex = contentKey.asSeq().toHex()
|
||||
peers = await portalRpcClient.portal_beaconLightClientGossip(
|
||||
peers = await portalRpcClient.portal_beaconGossip(
|
||||
contentKeyHex,
|
||||
content.toHex())
|
||||
info "Beacon LC bootstrap gossiped", peers,
|
||||
|
@ -647,7 +647,7 @@ proc run(config: BeaconBridgeConf) {.raises: [CatchableError].} =
|
|||
let
|
||||
finalizedSlot = forkyObject.finalized_header.beacon.slot
|
||||
contentKey = encode(finalityUpdateContentKey(finalizedSlot.uint64))
|
||||
contentId = beacon_light_client_content.toContentId(contentKey)
|
||||
contentId = beacon_content.toContentId(contentKey)
|
||||
forkDigest = forkDigestAtEpoch(
|
||||
forkDigests[], epoch(forkyObject.attested_header.beacon.slot), cfg)
|
||||
content = encodeFinalityUpdateForked(
|
||||
|
@ -659,7 +659,7 @@ proc run(config: BeaconBridgeConf) {.raises: [CatchableError].} =
|
|||
try:
|
||||
let
|
||||
contentKeyHex = contentKey.asSeq().toHex()
|
||||
peers = await portalRpcClient.portal_beaconLightClientGossip(
|
||||
peers = await portalRpcClient.portal_beaconGossip(
|
||||
contentKeyHex,
|
||||
content.toHex())
|
||||
info "Beacon LC bootstrap gossiped", peers,
|
||||
|
|
|
@ -14,7 +14,7 @@ import
|
|||
beacon_chain/networking/network_metadata,
|
||||
beacon_chain/spec//eth2_apis/rest_beacon_client,
|
||||
beacon_chain/beacon_clock,
|
||||
../../network/beacon_light_client/beacon_light_client_content,
|
||||
../../network/beacon/beacon_content,
|
||||
./exporter_common
|
||||
|
||||
export beacon_clock
|
||||
|
@ -205,7 +205,7 @@ proc exportLCFinalityUpdate*(
|
|||
let
|
||||
finalizedSlot = forkyObject.finalized_header.beacon.slot
|
||||
contentKey = encode(finalityUpdateContentKey(finalizedSlot.uint64))
|
||||
contentId = beacon_light_client_content.toContentId(contentKey)
|
||||
contentId = beacon_content.toContentId(contentKey)
|
||||
forkDigest = forkDigestAtEpoch(
|
||||
forkDigests[], epoch(forkyObject.attested_header.beacon.slot), cfg)
|
||||
content = encodeFinalityUpdateForked(
|
||||
|
@ -262,7 +262,7 @@ proc exportLCOptimisticUpdate*(
|
|||
let
|
||||
slot = forkyObject.signature_slot
|
||||
contentKey = encode(optimisticUpdateContentKey(slot.uint64))
|
||||
contentId = beacon_light_client_content.toContentId(contentKey)
|
||||
contentId = beacon_content.toContentId(contentKey)
|
||||
forkDigest = forkDigestAtEpoch(
|
||||
forkDigests[], epoch(forkyObject.attested_header.beacon.slot), cfg)
|
||||
content = encodeOptimisticUpdateForked(
|
||||
|
|
Loading…
Reference in New Issue