Skip to content

experiment of moving storing the block and its metadata to NetworkStore #1171

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 2 additions & 22 deletions codex/blockexchange/engine/engine.nim
Original file line number Diff line number Diff line change
Expand Up @@ -396,28 +396,8 @@ proc blocksDeliveryHandler*(
peer = peer
address = bd.address

try:
if err =? self.validateBlockDelivery(bd).errorOption:
warn "Block validation failed", msg = err.msg
continue

if err =? (await self.localStore.putBlock(bd.blk)).errorOption:
error "Unable to store block", err = err.msg
continue

if bd.address.leaf:
without proof =? bd.proof:
warn "Proof expected for a leaf block delivery"
continue
if err =? (
await self.localStore.putCidAndProof(
bd.address.treeCid, bd.address.index, bd.blk.cid, proof
)
).errorOption:
warn "Unable to store proof and cid for a block"
continue
except CatchableError as exc:
warn "Error handling block delivery", error = exc.msg
if err =? self.validateBlockDelivery(bd).errorOption:
warn "Block validation failed", msg = err.msg
continue

validatedBlocksDelivery.add(bd)
Expand Down
4 changes: 4 additions & 0 deletions codex/blockexchange/engine/pendingblocks.nim
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import std/strutils
import pkg/chronos
import pkg/libp2p
import pkg/metrics
import pkg/questionable/results

import ../protobuf/blockexc
import ../../blocktype
Expand Down Expand Up @@ -105,6 +106,9 @@ proc resolve*(
stopTime = getMonoTime().ticks
retrievalDurationUs = (stopTime - startTime) div 1000

if bd.proof.isSome:
bd.blk.proof = bd.proof

blockReq.handle.complete(bd.blk)

codex_block_exchange_retrieval_time_us.set(retrievalDurationUs)
Expand Down
2 changes: 2 additions & 0 deletions codex/blocktype.nim
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,15 @@ import ./errors
import ./logutils
import ./utils/json
import ./codextypes
from ./merkletree/codex/codex import CodexProof

export errors, logutils, units, codextypes

type
Block* = ref object of RootObj
cid*: Cid
data*: seq[byte]
proof*: ?CodexProof

BlockAddress* = object
case leaf*: bool
Expand Down
1 change: 1 addition & 0 deletions codex/merkletree/codex/codex.nim
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import ../../utils
import ../../rng
import ../../errors
import ../../blocktype
import ../../codextypes

from ../../utils/digest import digestBytes

Expand Down
19 changes: 19 additions & 0 deletions codex/stores/networkstore.nim
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,25 @@ method getBlock*(self: NetworkStore, address: BlockAddress): Future[?!Block] {.a
error "Unable to get block from exchange engine", address, err = err.msg
return failure err

if address.leaf:
without proof =? newBlock.proof:
error "Proof expected for a leaf block delivery"
return failure "Proof expected for a leaf block delivery"
if err =? (await self.localStore.putBlock(newBlock)).errorOption:
error "Unable to store block", err = err.msg
return failure err
if err =? (
await self.localStore.putCidAndProof(
address.treeCid, address.index, newBlock.cid, proof
)
).errorOption:
error "Unable to store proof and cid for a block:", err = err.msg
return failure err
else:
if err =? (await self.localStore.putBlock(newBlock)).errorOption:
error "Unable to store block", err = err.msg
return failure err

return success newBlock

return success blk
Expand Down
Loading