mirror of
https://github.com/status-im/nim-codex.git
synced 2025-01-10 10:55:48 +00:00
b3e57a37e2
* wire prover into node * stricter case object checks * return correct proof * misc renames * adding usefull traces * fix nodes and tolerance to match expected params * format challenges in logs * add circom compat to solidity groth16 convertion * update * bump time to give nodes time to load with all circom artifacts * misc * misc * use correct dataset geometry in erasure * make errors more searchable * use parens around `=? (await...)` calls * styling * styling * use push raises * fix to match constructor arguments * merge master * merge master * integration: fix proof parameters for a test Increased times due to ZK proof generation. Increased storage requirement because we're now hosting 5 slots instead of 1. * sales: calculate initial proof at start of period reason: this ensures that the period (and therefore the challenge) doesn't change while we're calculating the proof * integration: fix proof parameters for tests Increased times due to waiting on next period. Fixed data to be of right size. Updated expected payout due to hosting 5 slots. * sales: wait for stable proof challenge When the block pointer is nearing the wrap-around point, we wait another period before calculating a proof. * fix merge conflict --------- Co-authored-by: Dmitriy Ryajov <dryajov@gmail.com> Co-authored-by: Eric <5089238+emizzle@users.noreply.github.com>
107 lines
2.8 KiB
Nim
107 lines
2.8 KiB
Nim
|
|
import std/times
|
|
|
|
import pkg/libp2p
|
|
import pkg/chronos
|
|
|
|
import pkg/codex/codextypes
|
|
import pkg/codex/chunker
|
|
import pkg/codex/slots
|
|
|
|
import ../../asynctest
|
|
|
|
proc toTimesDuration*(d: chronos.Duration): times.Duration =
|
|
initDuration(seconds = d.seconds)
|
|
|
|
proc drain*(
|
|
stream: LPStream | Result[lpstream.LPStream, ref CatchableError]):
|
|
Future[seq[byte]] {.async.} =
|
|
|
|
let
|
|
stream =
|
|
when typeof(stream) is Result[lpstream.LPStream, ref CatchableError]:
|
|
stream.tryGet()
|
|
else:
|
|
stream
|
|
|
|
defer:
|
|
await stream.close()
|
|
|
|
var data: seq[byte]
|
|
while not stream.atEof:
|
|
var
|
|
buf = newSeq[byte](DefaultBlockSize.int)
|
|
res = await stream.readOnce(addr buf[0], DefaultBlockSize.int)
|
|
check res <= DefaultBlockSize.int
|
|
buf.setLen(res)
|
|
data &= buf
|
|
|
|
data
|
|
|
|
proc pipeChunker*(stream: BufferStream, chunker: Chunker) {.async.} =
|
|
try:
|
|
while (
|
|
let chunk = await chunker.getBytes();
|
|
chunk.len > 0):
|
|
await stream.pushData(chunk)
|
|
finally:
|
|
await stream.pushEof()
|
|
await stream.close()
|
|
|
|
template setupAndTearDown*() {.dirty.} =
|
|
var
|
|
file: File
|
|
chunker: Chunker
|
|
switch: Switch
|
|
wallet: WalletRef
|
|
network: BlockExcNetwork
|
|
clock: Clock
|
|
localStore: RepoStore
|
|
localStoreRepoDs: DataStore
|
|
localStoreMetaDs: DataStore
|
|
engine: BlockExcEngine
|
|
store: NetworkStore
|
|
node: CodexNodeRef
|
|
blockDiscovery: Discovery
|
|
peerStore: PeerCtxStore
|
|
pendingBlocks: PendingBlocksManager
|
|
discovery: DiscoveryEngine
|
|
|
|
let
|
|
path = currentSourcePath().parentDir
|
|
|
|
setup:
|
|
file = open(path /../ "" /../ "fixtures" / "test.jpg")
|
|
chunker = FileChunker.new(file = file, chunkSize = DefaultBlockSize)
|
|
switch = newStandardSwitch()
|
|
wallet = WalletRef.new(EthPrivateKey.random())
|
|
network = BlockExcNetwork.new(switch)
|
|
|
|
clock = SystemClock.new()
|
|
localStoreMetaDs = SQLiteDatastore.new(Memory).tryGet()
|
|
localStoreRepoDs = SQLiteDatastore.new(Memory).tryGet()
|
|
localStore = RepoStore.new(localStoreRepoDs, localStoreMetaDs, clock = clock)
|
|
await localStore.start()
|
|
|
|
blockDiscovery = Discovery.new(
|
|
switch.peerInfo.privateKey,
|
|
announceAddrs = @[MultiAddress.init("/ip4/127.0.0.1/tcp/0")
|
|
.expect("Should return multiaddress")])
|
|
peerStore = PeerCtxStore.new()
|
|
pendingBlocks = PendingBlocksManager.new()
|
|
discovery = DiscoveryEngine.new(localStore, peerStore, network, blockDiscovery, pendingBlocks)
|
|
engine = BlockExcEngine.new(localStore, wallet, network, discovery, peerStore, pendingBlocks)
|
|
store = NetworkStore.new(engine, localStore)
|
|
node = CodexNodeRef.new(
|
|
switch = switch,
|
|
networkStore = store,
|
|
engine = engine,
|
|
prover = Prover.none,
|
|
discovery = blockDiscovery)
|
|
|
|
await node.start()
|
|
|
|
teardown:
|
|
close(file)
|
|
await node.stop()
|