mirror of
https://github.com/logos-storage/logos-storage-nim.git
synced 2026-01-07 16:03:13 +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
|
peer = peer
|
||||||
address = bd.address
|
address = bd.address
|
||||||
|
|
||||||
try:
|
if err =? self.validateBlockDelivery(bd).errorOption:
|
||||||
if err =? self.validateBlockDelivery(bd).errorOption:
|
warn "Block validation failed", msg = err.msg
|
||||||
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
|
|
||||||
continue
|
continue
|
||||||
|
|
||||||
validatedBlocksDelivery.add(bd)
|
validatedBlocksDelivery.add(bd)
|
||||||
|
|||||||
@ -16,6 +16,7 @@ import std/strutils
|
|||||||
import pkg/chronos
|
import pkg/chronos
|
||||||
import pkg/libp2p
|
import pkg/libp2p
|
||||||
import pkg/metrics
|
import pkg/metrics
|
||||||
|
import pkg/questionable/results
|
||||||
|
|
||||||
import ../protobuf/blockexc
|
import ../protobuf/blockexc
|
||||||
import ../../blocktype
|
import ../../blocktype
|
||||||
@ -105,6 +106,9 @@ proc resolve*(
|
|||||||
stopTime = getMonoTime().ticks
|
stopTime = getMonoTime().ticks
|
||||||
retrievalDurationUs = (stopTime - startTime) div 1000
|
retrievalDurationUs = (stopTime - startTime) div 1000
|
||||||
|
|
||||||
|
if bd.proof.isSome:
|
||||||
|
bd.blk.proof = bd.proof
|
||||||
|
|
||||||
blockReq.handle.complete(bd.blk)
|
blockReq.handle.complete(bd.blk)
|
||||||
|
|
||||||
codex_block_exchange_retrieval_time_us.set(retrievalDurationUs)
|
codex_block_exchange_retrieval_time_us.set(retrievalDurationUs)
|
||||||
|
|||||||
@ -28,6 +28,7 @@ import ./errors
|
|||||||
import ./logutils
|
import ./logutils
|
||||||
import ./utils/json
|
import ./utils/json
|
||||||
import ./codextypes
|
import ./codextypes
|
||||||
|
from ./merkletree/codex/codex import CodexProof
|
||||||
|
|
||||||
export errors, logutils, units, codextypes
|
export errors, logutils, units, codextypes
|
||||||
|
|
||||||
@ -35,6 +36,7 @@ type
|
|||||||
Block* = ref object of RootObj
|
Block* = ref object of RootObj
|
||||||
cid*: Cid
|
cid*: Cid
|
||||||
data*: seq[byte]
|
data*: seq[byte]
|
||||||
|
proof*: ?CodexProof
|
||||||
|
|
||||||
BlockAddress* = object
|
BlockAddress* = object
|
||||||
case leaf*: bool
|
case leaf*: bool
|
||||||
|
|||||||
@ -20,6 +20,7 @@ import ../../utils
|
|||||||
import ../../rng
|
import ../../rng
|
||||||
import ../../errors
|
import ../../errors
|
||||||
import ../../blocktype
|
import ../../blocktype
|
||||||
|
import ../../codextypes
|
||||||
|
|
||||||
from ../../utils/digest import digestBytes
|
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
|
error "Unable to get block from exchange engine", address, err = err.msg
|
||||||
return failure err
|
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 newBlock
|
||||||
|
|
||||||
return success blk
|
return success blk
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user