derive Hash type from Block type

This commit is contained in:
Mark Spanbroek 2024-12-10 12:28:16 +01:00
parent de854cbb5f
commit ea9e1c01f9
7 changed files with 11 additions and 10 deletions

View File

@ -1,6 +1,5 @@
type Dependencies*[
Block,
Hash,
Identifier,
Signature
] = object

View File

@ -84,7 +84,9 @@ func addBlock(validator: Validator, signedBlock: SignedBlock) =
func parentBlocks*(validator: Validator): auto =
mixin id
var parents: seq[BlockId[Validator.Dependencies.Hash]]
type Block = Validator.Dependencies.Block
type BlockId = typeof(Block.default.id)
var parents: seq[BlockId]
if previous =? validator.rounds.latest.previous:
for slot in previous.slots:
if slot.proposals.len == 1:
@ -93,8 +95,9 @@ func parentBlocks*(validator: Validator): auto =
func check*(validator: Validator, signed: SignedBlock): auto =
mixin id
type BlockCheck = checks.BlockCheck[SignedBlock.Dependencies]
type BlockId = blocks.BlockId[SignedBlock.Dependencies.Hash]
type BlockCheck = checks.BlockCheck[Validator.Dependencies]
type Block = Validator.Dependencies.Block
type BlockId = typeof(Block.default.id)
without member =? validator.committee.membership(signed.signer):
return BlockCheck.invalid("block is not signed by a committee member")
if member != signed.blck.author:

View File

@ -11,7 +11,7 @@ type
of invalid:
reason: string
of incomplete:
missing: seq[BlockId[Dependencies.Hash]]
missing: seq[typeof(Dependencies.Block.default.id)]
of correct:
blck: CorrectBlock[Dependencies]
CorrectBlock*[Dependencies] = distinct SignedBlock[Dependencies]

View File

@ -11,7 +11,7 @@ type
slot: ProposerSlot[Dependencies]
signedBlock: SignedBlock[Dependencies]
certifiedBy: Voting
certificates: seq[BlockId[Dependencies.Hash]]
certificates: seq[typeof(Dependencies.Block.default.id)]
SlotStatus* {.pure.} = enum
undecided
skip

View File

@ -11,7 +11,6 @@ export blck
type MockDependencies* = Dependencies[
MockBlock,
MockHash,
MockIdentifier,
MockSignature
]

View File

@ -4,7 +4,7 @@ import mysticeti/validator/slots
suite "Proposer Slots":
type BlockId = mysticeti.BlockId[MockDependencies.Hash]
type BlockId = mysticeti.BlockId[MockHash]
type SignedBlock = mysticeti.SignedBlock[MockDependencies]
type Proposal = slots.Proposal[MockDependencies]
type ProposerSlot = slots.ProposerSlot[MockDependencies]

View File

@ -9,8 +9,8 @@ suite "Validator Network":
type Transaction = MockTransaction
type Block = MockBlock
type SignedBlock = blocks.SignedBlock[MockDependencies]
type BlockId = blocks.BlockId[MockDependencies.Hash]
type Hash = MockDependencies.Hash
type BlockId = blocks.BlockId[MockHash]
type Hash = MockHash
var simulator: NetworkSimulator