From 9137edbfeed3634f14d0eec45d2327b0f9333213 Mon Sep 17 00:00:00 2001 From: Mark Spanbroek Date: Wed, 2 Oct 2024 15:58:33 +0200 Subject: [PATCH] remove Block's unnecessary dependency on Signing --- mysticeti/blocks.nim | 14 +++++++------- mysticeti/validator.nim | 26 +++++++++++++------------- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/mysticeti/blocks.nim b/mysticeti/blocks.nim index 33205aa..0c4544f 100644 --- a/mysticeti/blocks.nim +++ b/mysticeti/blocks.nim @@ -5,12 +5,12 @@ import ./committee type Transaction* = object type - Block*[Signing, Hashing] = object + Block*[Hashing] = object author: CommitteeMember round: uint64 - parents: seq[BlockId[Signing, Hashing]] + parents: seq[BlockId[Hashing]] transactions: seq[Transaction] - BlockId*[Signing, Hashing] = object + BlockId*[Hashing] = object author: CommitteeMember round: uint64 hash: Hash[Hashing] @@ -22,7 +22,7 @@ func new*( parents: seq[BlockId], transactions: seq[Transaction] ): auto = - Block[BlockId.Signing, BlockId.Hashing]( + Block[BlockId.Hashing]( author: author, round: round, parents: parents, @@ -42,18 +42,18 @@ func toBytes(blck: Block): seq[byte] = cast[seq[byte]]($blck) # TODO: proper serialization func id*(blck: Block): auto = - BlockId[Block.Signing, Block.Hashing]( + BlockId[Block.Hashing]( author: blck.author, round: blck.round, hash: Block.Hashing.hash(blck.toBytes) ) type SignedBlock*[Signing, Hashing] = object - blck: Block[Signing, Hashing] + blck: Block[Hashing] signature: Signature[Signing] func new*(_: type SignedBlock, blck: Block, signature: Signature): auto = - SignedBlock[Block.Signing, Block.Hashing](blck: blck, signature: signature) + SignedBlock[Signature.Signing, Block.Hashing](blck: blck, signature: signature) func blck*(signed: SignedBlock): auto = signed.blck diff --git a/mysticeti/validator.nim b/mysticeti/validator.nim index a8afe04..41a0b3a 100644 --- a/mysticeti/validator.nim +++ b/mysticeti/validator.nim @@ -8,19 +8,19 @@ type identity: Identity[Signing] committee: Committee[Signing] membership: CommitteeMember - first, last: Round[Signing, Hashing] - Round[Signing, Hashing] = ref object + first, last: Round[Hashing] + Round[Hashing] = ref object number: uint64 - previous, next: ?Round[Signing, Hashing] - slots: seq[ProposerSlot[Signing, Hashing]] - ProposerSlot[Signing, Hashing] = ref object - proposals: seq[Proposal[Signing, Hashing]] + previous, next: ?Round[Hashing] + slots: seq[ProposerSlot[Hashing]] + ProposerSlot[Hashing] = ref object + proposals: seq[Proposal[Hashing]] skippedBy: Stake status: SlotStatus - Proposal[Signing, Hashing] = ref object - blck: Block[Signing, Hashing] + Proposal[Hashing] = ref object + blck: Block[Hashing] certifiedBy: Stake - certificates: seq[BlockId[Signing, Hashing]] + certificates: seq[BlockId[Hashing]] SlotStatus* {.pure.} = enum undecided skip @@ -28,12 +28,12 @@ type committed func new*(T: type Round, number: uint64, committee: Committee): T = - type Slot = ProposerSlot[T.Signing, T.Hashing] + type Slot = ProposerSlot[T.Hashing] let slots = newSeqWith(committee.size, Slot.new()) T(number: number, slots: slots) func new*(T: type Validator; identity: Identity, committee: Committee): ?!T = - let round = Round[T.Signing, T.Hashing].new(0, committee) + let round = Round[T.Hashing].new(0, committee) without membership =? committee.membership(identity.identifier): return T.failure "identity is not a member of the committee" success T( @@ -48,7 +48,7 @@ func `[]`(round: Round, member: CommitteeMember): auto = round.slots[int(member)] func init(_: type Proposal, blck: Block): auto = - Proposal[Block.Signing, Block.Hashing](blck: blck) + Proposal[Block.Hashing](blck: blck) func identifier*(validator: Validator): auto = validator.identity.identifier @@ -119,7 +119,7 @@ func updateCertified(validator: Validator, certificate: Block) = proc propose*(validator: Validator, transactions: seq[Transaction]): auto = assert validator.last[validator.membership].proposals.len == 0 - var parents: seq[BlockId[Validator.Signing, Validator.Hashing]] + var parents: seq[BlockId[Validator.Hashing]] if previous =? validator.last.previous: for slot in previous.slots: if slot.proposals.len == 1: