remove Block's unnecessary dependency on Signing

This commit is contained in:
Mark Spanbroek 2024-10-02 15:58:33 +02:00
parent 75ad9d09d5
commit 9137edbfee
2 changed files with 20 additions and 20 deletions

View File

@ -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

View File

@ -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: