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*[ type Dependencies*[
Block, Block,
Hash,
Identifier, Identifier,
Signature Signature
] = object ] = object

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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