mirror of https://github.com/status-im/nim-eth.git
Support compiling with json logging; Drop package_visible_types
This commit is contained in:
parent
a69e52bf3e
commit
f0bf0570d1
|
@ -11,7 +11,6 @@ requires "nim >= 0.19.0",
|
||||||
"byteutils",
|
"byteutils",
|
||||||
"secp256k1",
|
"secp256k1",
|
||||||
"rocksdb",
|
"rocksdb",
|
||||||
"package_visible_types",
|
|
||||||
"chronos",
|
"chronos",
|
||||||
"chronicles",
|
"chronicles",
|
||||||
"std_shims"
|
"std_shims"
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import
|
import
|
||||||
times,
|
times, net,
|
||||||
json_serialization, nimcrypto/hash, eth_types
|
json_serialization, nimcrypto/hash, eth_types
|
||||||
|
|
||||||
proc writeValue*(w: var JsonWriter, a: MDigest) {.inline.} =
|
proc writeValue*(w: var JsonWriter, a: MDigest) {.inline.} =
|
||||||
|
@ -8,6 +8,12 @@ proc writeValue*(w: var JsonWriter, a: MDigest) {.inline.} =
|
||||||
proc readValue*(r: var JsonReader, a: var MDigest) {.inline.} =
|
proc readValue*(r: var JsonReader, a: var MDigest) {.inline.} =
|
||||||
a = fromHex(type(a), r.readValue(string))
|
a = fromHex(type(a), r.readValue(string))
|
||||||
|
|
||||||
|
proc writeValue*(w: var JsonWriter, a: Port) {.inline.} =
|
||||||
|
w.writeValue uint16(a)
|
||||||
|
|
||||||
|
proc readValue*(r: var JsonReader, a: var Port) {.inline.} =
|
||||||
|
a = Port r.readValue(uint16)
|
||||||
|
|
||||||
proc writeValue*(w: var JsonWriter, value: StUint) {.inline.} =
|
proc writeValue*(w: var JsonWriter, value: StUint) {.inline.} =
|
||||||
w.writeValue $value
|
w.writeValue $value
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,8 @@
|
||||||
|
|
||||||
import
|
import
|
||||||
times,
|
times,
|
||||||
chronos, eth/[keys, rlp], stint, nimcrypto, chronicles,
|
chronos, stint, nimcrypto, chronicles,
|
||||||
|
eth/common/eth_types_json_serialization, eth/[keys, rlp],
|
||||||
kademlia, enode
|
kademlia, enode
|
||||||
|
|
||||||
export
|
export
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
|
|
||||||
import
|
import
|
||||||
tables, hashes, times, algorithm, sets, sequtils, random,
|
tables, hashes, times, algorithm, sets, sequtils, random,
|
||||||
chronos, chronicles, eth/keys, stint, nimcrypto,
|
chronos, eth/keys, chronicles, stint, nimcrypto,
|
||||||
enode
|
enode
|
||||||
|
|
||||||
export sets # TODO: This should not be needed, but compilation fails otherwise
|
export sets # TODO: This should not be needed, but compilation fails otherwise
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
import
|
import
|
||||||
deques, tables,
|
deques, tables,
|
||||||
package_visible_types,
|
|
||||||
eth/[rlp, keys], chronos, eth/common/eth_types,
|
eth/[rlp, keys], chronos, eth/common/eth_types,
|
||||||
../enode, ../kademlia, ../discovery, ../options, ../rlpxcrypt
|
../enode, ../kademlia, ../discovery, ../options, ../rlpxcrypt
|
||||||
|
|
||||||
|
|
|
@ -35,8 +35,7 @@ var
|
||||||
template allProtocols*: auto = {.gcsafe.}: gProtocols
|
template allProtocols*: auto = {.gcsafe.}: gProtocols
|
||||||
template devp2pInfo: auto = {.gcsafe.}: gDevp2pInfo
|
template devp2pInfo: auto = {.gcsafe.}: gDevp2pInfo
|
||||||
|
|
||||||
proc `$`*(p: Peer): string {.inline.} =
|
chronicles.formatIt(Peer): $(it.remote)
|
||||||
$p.remote
|
|
||||||
|
|
||||||
proc disconnect*(peer: Peer, reason: DisconnectionReason, notifyOtherPeer = true) {.gcsafe, async.}
|
proc disconnect*(peer: Peer, reason: DisconnectionReason, notifyOtherPeer = true) {.gcsafe, async.}
|
||||||
|
|
||||||
|
|
|
@ -78,9 +78,9 @@ proc currentRequestsCosts*(network: LesNetwork,
|
||||||
if b < 0:
|
if b < 0:
|
||||||
b = 0
|
b = 0
|
||||||
|
|
||||||
result.add ReqCostInfo.init(msgId = msg.id,
|
result.add ReqCostInfo(msgId: msg.id,
|
||||||
baseCost = ReqCostInt(b * 2),
|
baseCost: ReqCostInt(b * 2),
|
||||||
reqCost = ReqCostInt(m * 2))
|
reqCost: ReqCostInt(m * 2))
|
||||||
|
|
||||||
proc persistMessageStats*(db: AbstractChainDB,
|
proc persistMessageStats*(db: AbstractChainDB,
|
||||||
network: LesNetwork) =
|
network: LesNetwork) =
|
||||||
|
@ -278,9 +278,11 @@ proc canMakeRequest(peer: var LesPeer, maxCost: int): (LesTime, float64) =
|
||||||
|
|
||||||
template getRequestCost(peer: LesPeer, localOrRemote: untyped,
|
template getRequestCost(peer: LesPeer, localOrRemote: untyped,
|
||||||
msgId, costQuantity: int): ReqCostInt =
|
msgId, costQuantity: int): ReqCostInt =
|
||||||
template msgCostInfo: untyped = peer.`localOrRemote ReqCosts`[msgId]
|
let
|
||||||
|
baseCost = peer.`localOrRemote ReqCosts`[msgId].baseCost
|
||||||
|
reqCost = peer.`localOrRemote ReqCosts`[msgId].reqCost
|
||||||
|
|
||||||
min(msgCostInfo.baseCost + msgCostInfo.reqCost * costQuantity,
|
min(baseCost + reqCost * costQuantity,
|
||||||
peer.`localOrRemote FlowState`.bufLimit)
|
peer.`localOrRemote FlowState`.bufLimit)
|
||||||
|
|
||||||
proc trackOutgoingRequest*(network: LesNetwork, peer: LesPeer,
|
proc trackOutgoingRequest*(network: LesNetwork, peer: LesPeer,
|
||||||
|
|
|
@ -1,107 +1,105 @@
|
||||||
import
|
import
|
||||||
hashes, tables, sets,
|
hashes, tables, sets,
|
||||||
package_visible_types,
|
|
||||||
eth/common/eth_types
|
eth/common/eth_types
|
||||||
|
|
||||||
packageTypes:
|
type
|
||||||
type
|
AnnounceType* = enum
|
||||||
AnnounceType* = enum
|
None,
|
||||||
None,
|
Simple,
|
||||||
Simple,
|
Signed,
|
||||||
Signed,
|
Unspecified
|
||||||
Unspecified
|
|
||||||
|
|
||||||
ReqCostInfo = object
|
ReqCostInfo* = object
|
||||||
msgId: int
|
msgId*: int
|
||||||
baseCost, reqCost: ReqCostInt
|
baseCost*, reqCost*: ReqCostInt
|
||||||
|
|
||||||
FlowControlState = object
|
FlowControlState* = object
|
||||||
bufValue, bufLimit: int
|
bufValue*, bufLimit*: int
|
||||||
minRecharge: int
|
minRecharge*: int
|
||||||
lastUpdate: LesTime
|
lastUpdate*: LesTime
|
||||||
|
|
||||||
StatsRunningAverage = object
|
StatsRunningAverage* = object
|
||||||
sumX, sumY, sumXX, sumXY: float64
|
sumX*, sumY*, sumXX*, sumXY*: float64
|
||||||
count: int
|
count*: int
|
||||||
|
|
||||||
LesPeer* = ref object
|
LesPeer* = ref object
|
||||||
isServer*: bool
|
isServer*: bool
|
||||||
isClient*: bool
|
isClient*: bool
|
||||||
announceType*: AnnounceType
|
announceType*: AnnounceType
|
||||||
|
|
||||||
bestDifficulty*: DifficultyInt
|
bestDifficulty*: DifficultyInt
|
||||||
bestBlockHash*: KeccakHash
|
bestBlockHash*: KeccakHash
|
||||||
bestBlockNumber*: BlockNumber
|
bestBlockNumber*: BlockNumber
|
||||||
|
|
||||||
hasChainSince: HashOrNum
|
hasChainSince*: HashOrNum
|
||||||
hasStateSince: HashOrNum
|
hasStateSince*: HashOrNum
|
||||||
relaysTransactions: bool
|
relaysTransactions*: bool
|
||||||
|
|
||||||
# The variables below are used to implement the flow control
|
# The variables below are used to implement the flow control
|
||||||
# mechanisms of LES from our point of view as a server.
|
# mechanisms of LES from our point of view as a server.
|
||||||
# They describe how much load has been generated by this
|
# They describe how much load has been generated by this
|
||||||
# particular peer.
|
# particular peer.
|
||||||
reqCount: int # How many outstanding requests are there?
|
reqCount*: int # How many outstanding requests are there?
|
||||||
#
|
#
|
||||||
rechargingPower: int # Do we give this peer any extra priority
|
rechargingPower*: int # Do we give this peer any extra priority
|
||||||
# (implemented as a faster recharning rate)
|
# (implemented as a faster recharning rate)
|
||||||
# 100 is the default. You can go higher and lower.
|
# 100 is the default. You can go higher and lower.
|
||||||
#
|
#
|
||||||
isRecharging: bool # This is true while the peer is not making
|
isRecharging*: bool # This is true while the peer is not making
|
||||||
# any requests
|
# any requests
|
||||||
#
|
#
|
||||||
reqCostGradient: int # Measures the speed of recharging or accumulating
|
reqCostGradient*: int # Measures the speed of recharging or accumulating
|
||||||
# "requests cost" at any given moment.
|
# "requests cost" at any given moment.
|
||||||
#
|
#
|
||||||
reqCostVal: int # The accumulated "requests cost"
|
reqCostVal*: int # The accumulated "requests cost"
|
||||||
#
|
#
|
||||||
rechargingEndsAt: int # When will recharging end?
|
rechargingEndsAt*: int # When will recharging end?
|
||||||
# (the buffer of the Peer will be fully restored)
|
# (the buffer of the Peer will be fully restored)
|
||||||
#
|
#
|
||||||
lastRechargeTime: LesTime # When did we last update the recharging parameters
|
lastRechargeTime*: LesTime # When did we last update the recharging parameters
|
||||||
#
|
#
|
||||||
startReqCostVal: int # TODO
|
startReqCostVal*: int # TODO
|
||||||
|
|
||||||
remoteFlowState: FlowControlState
|
remoteFlowState*: FlowControlState
|
||||||
remoteReqCosts: seq[ReqCostInfo]
|
remoteReqCosts*: seq[ReqCostInfo]
|
||||||
|
|
||||||
# The next variables are used to limit ourselves as a client in order to
|
# The next variables are used to limit ourselves as a client in order to
|
||||||
# not violate the control-flow requirements of the remote LES server.
|
# not violate the control-flow requirements of the remote LES server.
|
||||||
|
|
||||||
pendingReqs: Table[int, ReqCostInt]
|
pendingReqs*: Table[int, ReqCostInt]
|
||||||
pendingReqsCost: int
|
pendingReqsCost*: int
|
||||||
|
|
||||||
localFlowState: FlowControlState
|
localFlowState*: FlowControlState
|
||||||
localReqCosts: seq[ReqCostInfo]
|
localReqCosts*: seq[ReqCostInfo]
|
||||||
|
|
||||||
LesNetwork* = ref object
|
LesNetwork* = ref object
|
||||||
peers: HashSet[LesPeer]
|
peers*: HashSet[LesPeer]
|
||||||
messageStats: seq[StatsRunningAverage]
|
messageStats*: seq[StatsRunningAverage]
|
||||||
ourAnnounceType*: AnnounceType
|
ourAnnounceType*: AnnounceType
|
||||||
|
|
||||||
# The fields below are relevant when serving data.
|
# The fields below are relevant when serving data.
|
||||||
bufferLimit: int
|
bufferLimit*: int
|
||||||
minRechargingRate: int
|
minRechargingRate*: int
|
||||||
|
|
||||||
reqCostSum, maxReqCostSum: ReqCostInt
|
reqCostSum*, maxReqCostSum*: ReqCostInt
|
||||||
reqCount, maxReqCount: int
|
reqCount*, maxReqCount*: int
|
||||||
sumWeigth: int
|
sumWeigth*: int
|
||||||
|
|
||||||
rechargingRate: int
|
rechargingRate*: int
|
||||||
totalRechargedUnits: int
|
totalRechargedUnits*: int
|
||||||
totalRechargingPower: int
|
totalRechargingPower*: int
|
||||||
|
|
||||||
lastUpdate: LesTime
|
lastUpdate*: LesTime
|
||||||
|
|
||||||
KeyValuePair = object
|
KeyValuePair* = object
|
||||||
key: string
|
key*: string
|
||||||
value: Blob
|
value*: Blob
|
||||||
|
|
||||||
HandshakeError = object of Exception
|
HandshakeError* = object of Exception
|
||||||
|
|
||||||
LesTime = int # this is in milliseconds
|
LesTime* = int # this is in milliseconds
|
||||||
BufValueInt = int
|
BufValueInt* = int
|
||||||
ReqCostInt = int
|
ReqCostInt* = int
|
||||||
|
|
||||||
template hash*(peer: LesPeer): Hash = hash(cast[pointer](peer))
|
template hash*(peer: LesPeer): Hash = hash(cast[pointer](peer))
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,8 @@ import
|
||||||
../rlpx, ../kademlia, ../private/p2p_types, ../blockchain_utils,
|
../rlpx, ../kademlia, ../private/p2p_types, ../blockchain_utils,
|
||||||
les/private/les_types, les/flow_control
|
les/private/les_types, les/flow_control
|
||||||
|
|
||||||
les_types.forwardPublicTypes
|
export
|
||||||
|
les_types
|
||||||
|
|
||||||
const
|
const
|
||||||
lesVersion = 2'u
|
lesVersion = 2'u
|
||||||
|
@ -179,7 +180,7 @@ p2pProtocol les(version = lesVersion,
|
||||||
lesNetwork = peer.networkState
|
lesNetwork = peer.networkState
|
||||||
|
|
||||||
template `=>`(k, v: untyped): untyped =
|
template `=>`(k, v: untyped): untyped =
|
||||||
KeyValuePair.init(key = k, value = rlp.encode(v))
|
KeyValuePair(key: k, value: rlp.encode(v))
|
||||||
|
|
||||||
var lesProperties = @[
|
var lesProperties = @[
|
||||||
keyProtocolVersion => lesVersion,
|
keyProtocolVersion => lesVersion,
|
||||||
|
|
Loading…
Reference in New Issue