mirror of
https://github.com/logos-storage/logos-storage-nim-validator.git
synced 2026-02-03 21:23:12 +00:00
replace slot id by request id and slot index
This commit is contained in:
parent
943aa07cd7
commit
f051273d01
@ -1,9 +1,9 @@
|
||||
import ./basics
|
||||
import ./transaction/slotid
|
||||
import ./transaction/storagerequest
|
||||
import ./transaction/period
|
||||
import ./transaction/groth16
|
||||
|
||||
export slotid
|
||||
export storagerequest
|
||||
export period
|
||||
export groth16
|
||||
|
||||
@ -14,9 +14,11 @@ type
|
||||
storageProof
|
||||
missingProof
|
||||
Transaction* = object
|
||||
slotId: SlotId
|
||||
requestId: StorageRequestId
|
||||
slotIndex: uint32
|
||||
period: Period
|
||||
inputs: seq[UInt256]
|
||||
merkleRoot: UInt256
|
||||
challenge: UInt256
|
||||
case kind: TransactionKind
|
||||
of storageProof:
|
||||
proof: Groth16Proof
|
||||
@ -25,43 +27,57 @@ type
|
||||
|
||||
proc storageProof*(
|
||||
_: type Transaction,
|
||||
slotId: SlotId,
|
||||
requestId: StorageRequestId,
|
||||
slotIndex: uint32,
|
||||
period: Period,
|
||||
inputs: seq[UInt256],
|
||||
merkleRoot: UInt256,
|
||||
challenge: UInt256,
|
||||
proof: Groth16Proof
|
||||
): Transaction =
|
||||
Transaction(
|
||||
kind: TransactionKind.storageProof,
|
||||
slotId: slotId,
|
||||
requestId: requestId,
|
||||
period: period,
|
||||
inputs: inputs,
|
||||
slotIndex: slotIndex,
|
||||
merkleRoot: merkleRoot,
|
||||
challenge: challenge,
|
||||
proof: proof
|
||||
)
|
||||
|
||||
proc missingProof*(
|
||||
_: type Transaction,
|
||||
slotId: SlotId,
|
||||
requestId: StorageRequestId,
|
||||
slotIndex: uint32,
|
||||
period: Period,
|
||||
inputs: seq[UInt256],
|
||||
merkleRoot: UInt256,
|
||||
challenge: UInt256,
|
||||
): Transaction =
|
||||
Transaction(
|
||||
kind: TransactionKind.missingProof,
|
||||
slotId: slotId,
|
||||
requestId: requestId,
|
||||
slotIndex: slotIndex,
|
||||
period: period,
|
||||
inputs: inputs
|
||||
merkleRoot: merkleRoot,
|
||||
challenge: challenge
|
||||
)
|
||||
|
||||
func version*(transaction: Transaction): TransactionVersion =
|
||||
TransactionVersion.version0
|
||||
|
||||
func slotId*(transaction: Transaction): SlotId =
|
||||
transaction.slotId
|
||||
func requestId*(transaction: Transaction): StorageRequestId =
|
||||
transaction.requestId
|
||||
|
||||
func slotIndex*(transaction: Transaction): uint32 =
|
||||
transaction.slotIndex
|
||||
|
||||
func period*(transaction: Transaction): Period =
|
||||
transaction.period
|
||||
|
||||
func inputs*(transaction: Transaction): seq[UInt256] =
|
||||
transaction.inputs
|
||||
func merkleRoot*(transaction: Transaction): UInt256 =
|
||||
transaction.merkleRoot
|
||||
|
||||
func challenge*(transaction: Transaction): UInt256 =
|
||||
transaction.challenge
|
||||
|
||||
func proof*(transaction: Transaction): Groth16Proof =
|
||||
transaction.proof
|
||||
|
||||
@ -1,4 +0,0 @@
|
||||
type SlotId* = distinct array[32, byte]
|
||||
|
||||
func `$`*(slotId: SlotId): string {.borrow.}
|
||||
func `==`*(a, b: SlotId): bool {.borrow.}
|
||||
4
codexvalidator/transaction/storagerequest.nim
Normal file
4
codexvalidator/transaction/storagerequest.nim
Normal file
@ -0,0 +1,4 @@
|
||||
type StorageRequestId* = distinct array[32, byte]
|
||||
|
||||
func `$`*(slotId: StorageRequestId): string {.borrow.}
|
||||
func `==`*(a, b: StorageRequestId): bool {.borrow.}
|
||||
@ -16,8 +16,8 @@ proc example*[T](_: type seq[T], length = 0..10): seq[T] =
|
||||
let len = rand(length)
|
||||
newSeqWith(len, T.example)
|
||||
|
||||
proc example*(_: type SlotId): SlotId =
|
||||
SlotId(array[32, byte].example)
|
||||
proc example*(_: type StorageRequestId): StorageRequestId =
|
||||
StorageRequestId(array[32, byte].example)
|
||||
|
||||
proc example*(_: type Period): Period =
|
||||
Period(uint64.example)
|
||||
@ -43,12 +43,27 @@ proc example*(_: type Groth16Proof): Groth16Proof =
|
||||
|
||||
proc example*(_: type Transaction): Transaction =
|
||||
let kind = [TransactionKind.storageProof, TransactionKind.missingProof].sample
|
||||
let slotId = SlotId.example
|
||||
let requestId = StorageRequestId.example
|
||||
let slotIndex = uint32.example
|
||||
let period = Period.example
|
||||
let inputs = seq[UInt256].example
|
||||
let merkleRoot = UInt256.example
|
||||
let challenge = UInt256.example
|
||||
case kind
|
||||
of TransactionKind.missingProof:
|
||||
Transaction.missingProof(slotId, period, inputs)
|
||||
Transaction.missingProof(
|
||||
requestId,
|
||||
slotIndex,
|
||||
period,
|
||||
merkleRoot,
|
||||
challenge
|
||||
)
|
||||
of TransactionKind.storageProof:
|
||||
let proof = Groth16Proof.example
|
||||
Transaction.storageProof(slotId, period, inputs, proof)
|
||||
Transaction.storageProof(
|
||||
requestId,
|
||||
slotIndex,
|
||||
period,
|
||||
merkleRoot,
|
||||
challenge,
|
||||
proof
|
||||
)
|
||||
|
||||
@ -6,21 +6,36 @@ import ./examples
|
||||
suite "Transaction":
|
||||
|
||||
test "a transaction can contain a storage proof":
|
||||
let slotId = SlotId.example
|
||||
let requestId = StorageRequestId.example
|
||||
let slotIndex = uint32.example
|
||||
let period = Period.example
|
||||
let inputs = seq[UInt256].example
|
||||
let merkleRoot = UInt256.example
|
||||
let challenge = UInt256.example
|
||||
let proof = Groth16Proof.example
|
||||
let transaction = Transaction.storageProof(slotId, period, inputs, proof)
|
||||
let transaction = Transaction.storageProof(
|
||||
requestId, slotIndex, period, merkleRoot, challenge, proof
|
||||
)
|
||||
check transaction.requestId == requestId
|
||||
check transaction.slotIndex == slotIndex
|
||||
check transaction.period == period
|
||||
check transaction.merkleRoot == merkleRoot
|
||||
check transaction.challenge == challenge
|
||||
check transaction.proof == proof
|
||||
|
||||
test "a transaction can indicate a missing storage proof":
|
||||
let slotId = SlotId.example
|
||||
let requestId = StorageRequestId.example
|
||||
let slotIndex = uint32.example
|
||||
let period = Period.example
|
||||
let inputs = seq[UInt256].example
|
||||
let transaction = Transaction.missingProof(slotId, period, inputs)
|
||||
check transaction.slotId == slotId
|
||||
let merkleRoot = UInt256.example
|
||||
let challenge = UInt256.example
|
||||
let transaction = Transaction.missingProof(
|
||||
requestId, slotIndex, period, merkleRoot, challenge
|
||||
)
|
||||
check transaction.requestId == requestId
|
||||
check transaction.slotIndex == slotIndex
|
||||
check transaction.period == period
|
||||
check transaction.inputs == inputs
|
||||
check transaction.merkleRoot == merkleRoot
|
||||
check transaction.challenge == challenge
|
||||
|
||||
test "transactions have a fixed version":
|
||||
let transaction = Transaction.example
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user