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