track latest nim-libp2p's master branch (#248)

* [build] track nim-libp2p's unstable branch

* cid formatIt change

* track nim-libp2p-unstable

* don't stringify cid

* Fixed testblockexc.nim

1. Assign price to blocks
2. Delete on node1 cached blocks from node2 before buying them again

* add trace logging

* init pricing info

* remove duplicate price setting

* cid serialization in trace logs

* bumping dht to latest main

* bump

Co-authored-by: Dmitriy Ryajov <dryajov@gmail.com>
Co-authored-by: Bulat-Ziganshin <bulat.ziganshin@gmail.com>
This commit is contained in:
Michael Bradley 2022-11-02 12:40:28 -05:00 committed by GitHub
parent 0ecbfcec9f
commit c893b1f0cb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
23 changed files with 57 additions and 39 deletions

1
.gitignore vendored
View File

@ -29,3 +29,4 @@ nimble.paths
.update.timestamp .update.timestamp
codex.nims codex.nims
nimbus-build-system.paths

View File

@ -90,7 +90,7 @@ when isMainModule:
notice "Shutting down after having received SIGTERM" notice "Shutting down after having received SIGTERM"
waitFor server.stop() waitFor server.stop()
c_signal(SIGTERM, SIGTERMHandler) c_signal(ansi_c.SIGTERM, SIGTERMHandler)
waitFor server.start() waitFor server.start()
of StartUpCommand.initNode: of StartUpCommand.initNode:

View File

@ -181,6 +181,12 @@ proc blockPresenceHandler*(
for blk in blocks: for blk in blocks:
if presence =? Presence.init(blk): if presence =? Presence.init(blk):
logScope:
cid = presence.cid
have = presence.have
price = presence.price
trace "Updating precense"
peerCtx.updatePresence(presence) peerCtx.updatePresence(presence)
var var

View File

@ -7,6 +7,9 @@
## This file may not be copied, modified, or distributed except according to ## This file may not be copied, modified, or distributed except according to
## those terms. ## those terms.
import pkg/upraises
push: {.upraises: [].}
import pkg/chronos import pkg/chronos
import pkg/chronicles import pkg/chronicles
import pkg/libp2p import pkg/libp2p
@ -21,6 +24,8 @@ const
MaxMessageSize = 100 * 1 shl 20 # manifest files can be big MaxMessageSize = 100 * 1 shl 20 # manifest files can be big
type type
ConnProvider* = proc(): Future[Connection] {.gcsafe, closure.}
RPCHandler* = proc(peer: NetworkPeer, msg: Message): Future[void] {.gcsafe.} RPCHandler* = proc(peer: NetworkPeer, msg: Message): Future[void] {.gcsafe.}
NetworkPeer* = ref object of RootObj NetworkPeer* = ref object of RootObj

View File

@ -22,6 +22,7 @@ import pkg/libp2pdht/discv5/protocol as discv5
import ./rng import ./rng
import ./errors import ./errors
import ./formats
export discv5 export discv5

View File

@ -210,14 +210,14 @@ proc store*(
return failure("Unable to init block from manifest data!") return failure("Unable to init block from manifest data!")
if isErr (await node.blockStore.putBlock(manifest)): if isErr (await node.blockStore.putBlock(manifest)):
trace "Unable to store manifest", cid = manifest.cid trace "Unable to store manifest", cid = $manifest.cid
return failure("Unable to store manifest " & $manifest.cid) return failure("Unable to store manifest " & $manifest.cid)
without cid =? blockManifest.cid, error: without cid =? blockManifest.cid, error:
trace "Unable to generate manifest Cid!", exc = error.msg trace "Unable to generate manifest Cid!", exc = error.msg
return failure(error.msg) return failure(error.msg)
trace "Stored data", manifestCid = manifest.cid, trace "Stored data", manifestCid = $manifest.cid,
contentCid = cid, contentCid = cid,
blocks = blockManifest.len blocks = blockManifest.len
@ -263,7 +263,7 @@ proc requestStorage*(self: CodexNodeRef,
return failure(error) return failure(error)
if isErr (await self.blockStore.putBlock(encodedBlk)): if isErr (await self.blockStore.putBlock(encodedBlk)):
trace "Unable to store encoded manifest block", cid = encodedBlk.cid trace "Unable to store encoded manifest block", cid = $encodedBlk.cid
return failure("Unable to store encoded manifest block") return failure("Unable to store encoded manifest block")
let request = StorageRequest( let request = StorageRequest(

View File

@ -186,7 +186,7 @@ proc initRestApi*(node: CodexNodeRef, conf: CodexConf): RestRouter =
trace "Excepting streaming blocks", exc = exc.msg trace "Excepting streaming blocks", exc = exc.msg
return RestApiResponse.error(Http500) return RestApiResponse.error(Http500)
finally: finally:
trace "Sent bytes", cid = id.get(), bytes trace "Sent bytes", cid = $id.get(), bytes
if not stream.isNil: if not stream.isNil:
await stream.close() await stream.close()

View File

@ -12,11 +12,11 @@ import pkg/upraises
push: {.upraises: [].} push: {.upraises: [].}
import pkg/libp2p/crypto/crypto import pkg/libp2p/crypto/crypto
import pkg/bearssl import pkg/bearssl/rand
type type
RngSampleError = object of CatchableError RngSampleError = object of CatchableError
Rng* = ref BrHmacDrbgContext Rng* = ref HmacDrbgContext
var rng {.threadvar.}: Rng var rng {.threadvar.}: Rng
@ -25,16 +25,15 @@ proc instance*(t: type Rng): Rng =
rng = newRng() rng = newRng()
rng rng
# Random helpers: similar as in stdlib, but with BrHmacDrbgContext rng # Random helpers: similar as in stdlib, but with HmacDrbgContext rng
# TODO: Move these somewhere else? # TODO: Move these somewhere else?
const randMax = 18_446_744_073_709_551_615'u64 const randMax = 18_446_744_073_709_551_615'u64
proc rand*(rng: Rng, max: Natural): int = proc rand*(rng: Rng, max: Natural): int =
if max == 0: return 0 if max == 0: return 0
var x: uint64
while true: while true:
brHmacDrbgGenerate(addr rng[], addr x, csize_t(sizeof(x))) let x = rng[].generate(uint64)
if x < randMax - (randMax mod (uint64(max) + 1'u64)): # against modulo bias if x < randMax - (randMax mod (uint64(max) + 1'u64)): # against modulo bias
return int(x mod (uint64(max) + 1'u64)) return int(x mod (uint64(max) + 1'u64))

View File

@ -7,7 +7,8 @@
## This file may not be copied, modified, or distributed except according to ## This file may not be copied, modified, or distributed except according to
## those terms. ## those terms.
{.push raises: [Defect].} import pkg/upraises
push: {.upraises: [].}
import pkg/chronos import pkg/chronos
import pkg/chronicles import pkg/chronicles

View File

@ -69,7 +69,7 @@ method readOnce*(
## Return how many bytes were actually read before EOF was encountered. ## Return how many bytes were actually read before EOF was encountered.
## Raise exception if we are already at EOF. ## Raise exception if we are already at EOF.
trace "Reading from manifest", cid = self.manifest.cid.get(), blocks = self.manifest.len trace "Reading from manifest", cid = $self.manifest.cid.get(), blocks = self.manifest.len
if self.atEof: if self.atEof:
raise newLPStreamEOFError() raise newLPStreamEOFError()

View File

@ -15,6 +15,7 @@ import pkg/codex/chunker
import pkg/codex/discovery import pkg/codex/discovery
import pkg/codex/blocktype as bt import pkg/codex/blocktype as bt
import ../../examples
import ../../helpers import ../../helpers
suite "NetworkStore engine - 2 nodes": suite "NetworkStore engine - 2 nodes":
@ -59,6 +60,9 @@ suite "NetworkStore engine - 2 nodes":
pendingBlocks1 = blocks2.mapIt( nodeCmps1.pendingBlocks.getWantHandle( it.cid ) ) pendingBlocks1 = blocks2.mapIt( nodeCmps1.pendingBlocks.getWantHandle( it.cid ) )
pendingBlocks2 = blocks1.mapIt( nodeCmps2.pendingBlocks.getWantHandle( it.cid ) ) pendingBlocks2 = blocks1.mapIt( nodeCmps2.pendingBlocks.getWantHandle( it.cid ) )
pricing1 = Pricing.example()
pricing2 = Pricing.example()
pricing1.address = nodeCmps1.wallet.address pricing1.address = nodeCmps1.wallet.address
pricing2.address = nodeCmps2.wallet.address pricing2.address = nodeCmps2.wallet.address
nodeCmps1.engine.pricing = pricing1.some nodeCmps1.engine.pricing = pricing1.some
@ -144,6 +148,10 @@ suite "NetworkStore engine - 2 nodes":
.withTimeout(100.millis) # should succeed .withTimeout(100.millis) # should succeed
test "Should receive payments for blocks that were sent": test "Should receive payments for blocks that were sent":
# delete on node1 cached blocks from node2
discard await allFinished(
blocks2.mapIt( nodeCmps1.networkStore.delBlock(it.cid) ))
let blocks = await allFinished( let blocks = await allFinished(
blocks2.mapIt( nodeCmps1.networkStore.getBlock(it.cid) )) blocks2.mapIt( nodeCmps1.networkStore.getBlock(it.cid) ))

View File

@ -158,9 +158,6 @@ suite "Network - Senders":
done = newFuture[void]() done = newFuture[void]()
switch1 = newStandardSwitch() switch1 = newStandardSwitch()
switch2 = newStandardSwitch() switch2 = newStandardSwitch()
await switch1.start()
await switch2.start()
network1 = BlockExcNetwork.new( network1 = BlockExcNetwork.new(
switch = switch1) switch = switch1)
switch1.mount(network1) switch1.mount(network1)
@ -169,6 +166,9 @@ suite "Network - Senders":
switch = switch2) switch = switch2)
switch2.mount(network2) switch2.mount(network2)
await switch1.start()
await switch2.start()
await switch1.connect( await switch1.connect(
switch2.peerInfo.peerId, switch2.peerInfo.peerId,
switch2.peerInfo.addrs) switch2.peerInfo.addrs)
@ -271,8 +271,6 @@ suite "Network - Test Limits":
done = newFuture[void]() done = newFuture[void]()
switch1 = newStandardSwitch() switch1 = newStandardSwitch()
switch2 = newStandardSwitch() switch2 = newStandardSwitch()
await switch1.start()
await switch2.start()
network1 = BlockExcNetwork.new( network1 = BlockExcNetwork.new(
switch = switch1, switch = switch1,
@ -283,6 +281,9 @@ suite "Network - Test Limits":
switch = switch2) switch = switch2)
switch2.mount(network2) switch2.mount(network2)
await switch1.start()
await switch2.start()
await switch1.connect( await switch1.connect(
switch2.peerInfo.peerId, switch2.peerInfo.peerId,
switch2.peerInfo.addrs) switch2.peerInfo.addrs)

View File

@ -37,12 +37,11 @@ proc corruptBlocks*(
manifest: Manifest, manifest: Manifest,
blks, bytes: int): Future[seq[int]] {.async.} = blks, bytes: int): Future[seq[int]] {.async.} =
var pos: seq[int] var pos: seq[int]
while true:
if pos.len >= blks:
break
var i = -1 doAssert blks < manifest.len
if (i = Rng.instance.rand(manifest.len - 1); pos.find(i) >= 0): while pos.len < blks:
let i = Rng.instance.rand(manifest.len - 1)
if pos.find(i) >= 0:
continue continue
pos.add(i) pos.add(i)
@ -50,15 +49,12 @@ proc corruptBlocks*(
blk = (await store.getBlock(manifest[i])).tryGet() blk = (await store.getBlock(manifest[i])).tryGet()
bytePos: seq[int] bytePos: seq[int]
while true: doAssert bytes < blk.data.len
if bytePos.len > bytes: while bytePos.len <= bytes:
break let ii = Rng.instance.rand(blk.data.len - 1)
if bytePos.find(ii) >= 0:
var ii = -1
if (ii = Rng.instance.rand(blk.data.len - 1); bytePos.find(ii) >= 0):
continue continue
bytePos.add(ii) bytePos.add(ii)
blk.data[ii] = byte 0 blk.data[ii] = byte 0
return pos return pos

@ -1 +1 @@
Subproject commit 1682096306ddba8185dcfac360a8c3f952d721e4 Subproject commit 7631f7b2ee03398cb1512a79923264e8f9410af6

2
vendor/nim-chronos vendored

@ -1 +1 @@
Subproject commit 17fed89c99beac5a92d3668d0d3e9b0e4ac13936 Subproject commit 8e8263370b51bc9b71916273e3eb956053532c4f

@ -1 +1 @@
Subproject commit 689da19e9e9cfff4ced85e2b25c6b2b5598ed079 Subproject commit e88e231dfcef4585fe3b2fbd9b664dbd28a88040

@ -1 +1 @@
Subproject commit c5f0e2465e8375dfc7aa0f56ccef67cb680bc6b0 Subproject commit e5b18fb710c3d0167ec79f3b892f5a7a1bc6d1a4

2
vendor/nim-libp2p vendored

@ -1 +1 @@
Subproject commit eeb3c210a37408716b6a8b45f578adf87610cef2 Subproject commit a3e9d1ed80c048cd5abc839cbe0863cefcedc702

@ -1 +1 @@
Subproject commit d6d255b4b5d6a4fa56db0eb6677ed7391cbb4897 Subproject commit e4e7a3e11fe635de3f15e37164b3ace96f588993

2
vendor/nim-presto vendored

@ -1 +1 @@
Subproject commit 962bb588d19c7180e39f0d9f18131e75861bab20 Subproject commit 3984431dc0fc829eb668e12e57e90542b041d298

@ -1 +1 @@
Subproject commit fcd0eadadde0ee000a63df8ab21dc4e9f015a790 Subproject commit 493d18b8292fc03aa4f835fd825dea1183f97466

2
vendor/nim-stew vendored

@ -1 +1 @@
Subproject commit 6ad35b876fb6ebe0dfee0f697af173acc47906ee Subproject commit 0c379cf1d8d3d9db07af108cc78ff542b2105914

2
vendor/nim-websock vendored

@ -1 +1 @@
Subproject commit a697e3585d583ab6b91a159ea7d023461002c927 Subproject commit 7b2ed397d6e4c37ea4df08ae82aeac7ff04cd180