diff --git a/mysticeti/blocks/blck.nim b/mysticeti/blocks/blck.nim index a376592..133a48a 100644 --- a/mysticeti/blocks/blck.nim +++ b/mysticeti/blocks/blck.nim @@ -6,15 +6,15 @@ type Block*[Dependencies] = ref object author: CommitteeMember round: uint64 - parents: ImmutableSeq[BlockId[Dependencies]] + parents: ImmutableSeq[BlockId[Dependencies.Hash]] transactions: ImmutableSeq[Dependencies.Transaction] - id: ?BlockId[Dependencies] + id: ?BlockId[Dependencies.Hash] func new*[Dependencies]( _: type Block[Dependencies]; author: CommitteeMember, round: uint64, - parents: seq[BlockId[Dependencies]], + parents: seq[BlockId[Dependencies.Hash]], transactions: seq[Dependencies.Transaction] ): auto = Block[Dependencies]( @@ -42,6 +42,6 @@ func id*(blck: Block): auto = mixin hash let blockBytes = Dependencies.Serialization.toBytes(blck) let blockHash = Dependencies.Hash.hash(blockBytes) - id = BlockId[Dependencies].new(blck.author, blck.round, blockHash) + id = BlockId.new(blck.author, blck.round, blockHash) blck.id = some id id diff --git a/mysticeti/blocks/blockid.nim b/mysticeti/blocks/blockid.nim index fc90666..a45de6d 100644 --- a/mysticeti/blocks/blockid.nim +++ b/mysticeti/blocks/blockid.nim @@ -1,17 +1,17 @@ import ../committee -type BlockId*[Dependencies] = object +type BlockId*[Hash] = object author: CommitteeMember round: uint64 - hash: Dependencies.Hash + hash: Hash -func new*[T: BlockId]( - _: type T, +func new*[Hash]( + _: type BlockId, author: CommitteeMember, round: uint64, - hash: T.Dependencies.Hash + hash: Hash ): auto = - T( + BlockId[Hash]( author: author, round: round, hash: hash diff --git a/mysticeti/validator.nim b/mysticeti/validator.nim index 814b955..12364d7 100644 --- a/mysticeti/validator.nim +++ b/mysticeti/validator.nim @@ -89,7 +89,7 @@ proc propose*(validator: Validator, transactions: seq[Validator.Dependencies.Tra let round = validator.rounds.latest if round[validator.membership].proposals.len > 0: return SignedBlock.failure "already proposed this round" - var parents: seq[BlockId[Validator.Dependencies]] + var parents: seq[BlockId[Validator.Dependencies.Hash]] var parentStake: Stake if previous =? round.previous: for slot in previous.slots: @@ -112,7 +112,7 @@ proc propose*(validator: Validator, transactions: seq[Validator.Dependencies.Tra func check*(validator: Validator, signed: SignedBlock): auto = type BlockCheck = checks.BlockCheck[SignedBlock.Dependencies] - type BlockId = blocks.BlockId[SignedBlock.Dependencies] + type BlockId = blocks.BlockId[SignedBlock.Dependencies.Hash] without member =? validator.committee.membership(signed.signer): return BlockCheck.invalid("block is not signed by a committee member") if member != signed.blck.author: diff --git a/mysticeti/validator/checks.nim b/mysticeti/validator/checks.nim index fe0dabc..8c5e05f 100644 --- a/mysticeti/validator/checks.nim +++ b/mysticeti/validator/checks.nim @@ -11,7 +11,7 @@ type of invalid: reason: string of incomplete: - missing: seq[BlockId[Dependencies]] + missing: seq[BlockId[Dependencies.Hash]] of correct: blck: CorrectBlock[Dependencies] CorrectBlock*[Dependencies] = distinct SignedBlock[Dependencies] diff --git a/mysticeti/validator/slots.nim b/mysticeti/validator/slots.nim index df0f873..9574d9e 100644 --- a/mysticeti/validator/slots.nim +++ b/mysticeti/validator/slots.nim @@ -11,7 +11,7 @@ type slot: ProposerSlot[Dependencies] signedBlock: SignedBlock[Dependencies] certifiedBy: Voting - certificates: seq[BlockId[Dependencies]] + certificates: seq[BlockId[Dependencies.Hash]] SlotStatus* {.pure.} = enum undecided skip diff --git a/tests/mysticeti/examples.nim b/tests/mysticeti/examples.nim index 531ad8f..33af532 100644 --- a/tests/mysticeti/examples.nim +++ b/tests/mysticeti/examples.nim @@ -13,8 +13,8 @@ proc example*(T: type CommitteeMember): T = proc example*(T: type BlockId): T = let author = CommitteeMember.example let round = uint64.example - let hash = T.Dependencies.Hash.example - T.new(author, round, hash) + let hash = T.Hash.example + BlockId.new(author, round, hash) proc example*( T: type Block, @@ -22,7 +22,7 @@ proc example*( round = uint64.example ): T = type Transaction = T.Dependencies.Transaction - let parents = seq[BlockId[T.Dependencies]].example + let parents = seq[BlockId[T.Dependencies.Hash]].example let transactions = seq[Transaction].example T.new(author, round, parents, transactions) diff --git a/tests/mysticeti/testBlocks.nim b/tests/mysticeti/testBlocks.nim index bf29c79..5009ea9 100644 --- a/tests/mysticeti/testBlocks.nim +++ b/tests/mysticeti/testBlocks.nim @@ -5,7 +5,7 @@ import mysticeti/blocks suite "Blocks": type Block = mysticeti.Block[MockDependencies] - type BlockId = mysticeti.BlockId[MockDependencies] + type BlockId = mysticeti.BlockId[MockDependencies.Hash] type Identity = MockDependencies.Identity type Transaction = MockDependencies.Transaction type Hash = MockDependencies.Hash diff --git a/tests/mysticeti/validator/testSlots.nim b/tests/mysticeti/validator/testSlots.nim index a7993dc..fa49aa5 100644 --- a/tests/mysticeti/validator/testSlots.nim +++ b/tests/mysticeti/validator/testSlots.nim @@ -4,7 +4,7 @@ import mysticeti/validator/slots suite "Proposer Slots": - type BlockId = mysticeti.BlockId[MockDependencies] + type BlockId = mysticeti.BlockId[MockDependencies.Hash] type SignedBlock = mysticeti.SignedBlock[MockDependencies] type Proposal = slots.Proposal[MockDependencies] type ProposerSlot = slots.ProposerSlot[MockDependencies] diff --git a/tests/mysticeti/validator/testValidatorNetwork.nim b/tests/mysticeti/validator/testValidatorNetwork.nim index aa77e5a..0ab0cba 100644 --- a/tests/mysticeti/validator/testValidatorNetwork.nim +++ b/tests/mysticeti/validator/testValidatorNetwork.nim @@ -11,7 +11,7 @@ suite "Validator Network": type Identity = MockDependencies.Identity type Transaction = MockDependencies.Transaction type Block = blocks.Block[MockDependencies] - type BlockId = blocks.BlockId[MockDependencies] + type BlockId = blocks.BlockId[MockDependencies.Hash] type Hash = MockDependencies.Hash var simulator: NetworkSimulator