mirror of
https://github.com/logos-storage/logos-storage-nim.git
synced 2026-05-05 19:09:28 +00:00
experiment of moving storing the block and its metadata to NetworkStore
This commit is contained in:
parent
a0d6fbaf02
commit
59c2951940
@ -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)
|
||||
|
||||
@ -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
|
||||
@ -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)
|
||||
|
||||
@ -28,6 +28,7 @@ import ./errors
|
||||
import ./logutils
|
||||
import ./utils/json
|
||||
import ./codextypes
|
||||
from ./merkletree/codex/codex import CodexProof
|
||||
|
||||
export errors, logutils, units, codextypes
|
||||
|
||||
@ -35,6 +36,7 @@ type
|
||||
Block* = ref object of RootObj
|
||||
cid*: Cid
|
||||
data*: seq[byte]
|
||||
proof*: ?CodexProof
|
||||
|
||||
BlockAddress* = object
|
||||
case leaf*: bool
|
||||
|
||||
@ -20,6 +20,7 @@ import ../../utils
|
||||
import ../../rng
|
||||
import ../../errors
|
||||
import ../../blocktype
|
||||
import ../../codextypes
|
||||
|
||||
from ../../utils/digest import digestBytes
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user