mirror of
https://github.com/logos-storage/nim-mysticeti.git
synced 2026-01-02 13:43:09 +00:00
simplify BlockId type parameter
This commit is contained in:
parent
183890e2ca
commit
fc3bdde46e
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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:
|
||||
|
||||
@ -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]
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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)
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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]
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user