mirror of
https://github.com/logos-storage/nim-mysticeti.git
synced 2026-01-07 16:13:11 +00:00
simplify BlockId type parameter
This commit is contained in:
parent
183890e2ca
commit
fc3bdde46e
@ -6,15 +6,15 @@ type
|
|||||||
Block*[Dependencies] = ref object
|
Block*[Dependencies] = ref object
|
||||||
author: CommitteeMember
|
author: CommitteeMember
|
||||||
round: uint64
|
round: uint64
|
||||||
parents: ImmutableSeq[BlockId[Dependencies]]
|
parents: ImmutableSeq[BlockId[Dependencies.Hash]]
|
||||||
transactions: ImmutableSeq[Dependencies.Transaction]
|
transactions: ImmutableSeq[Dependencies.Transaction]
|
||||||
id: ?BlockId[Dependencies]
|
id: ?BlockId[Dependencies.Hash]
|
||||||
|
|
||||||
func new*[Dependencies](
|
func new*[Dependencies](
|
||||||
_: type Block[Dependencies];
|
_: type Block[Dependencies];
|
||||||
author: CommitteeMember,
|
author: CommitteeMember,
|
||||||
round: uint64,
|
round: uint64,
|
||||||
parents: seq[BlockId[Dependencies]],
|
parents: seq[BlockId[Dependencies.Hash]],
|
||||||
transactions: seq[Dependencies.Transaction]
|
transactions: seq[Dependencies.Transaction]
|
||||||
): auto =
|
): auto =
|
||||||
Block[Dependencies](
|
Block[Dependencies](
|
||||||
@ -42,6 +42,6 @@ func id*(blck: Block): auto =
|
|||||||
mixin hash
|
mixin hash
|
||||||
let blockBytes = Dependencies.Serialization.toBytes(blck)
|
let blockBytes = Dependencies.Serialization.toBytes(blck)
|
||||||
let blockHash = Dependencies.Hash.hash(blockBytes)
|
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
|
blck.id = some id
|
||||||
id
|
id
|
||||||
|
|||||||
@ -1,17 +1,17 @@
|
|||||||
import ../committee
|
import ../committee
|
||||||
|
|
||||||
type BlockId*[Dependencies] = object
|
type BlockId*[Hash] = object
|
||||||
author: CommitteeMember
|
author: CommitteeMember
|
||||||
round: uint64
|
round: uint64
|
||||||
hash: Dependencies.Hash
|
hash: Hash
|
||||||
|
|
||||||
func new*[T: BlockId](
|
func new*[Hash](
|
||||||
_: type T,
|
_: type BlockId,
|
||||||
author: CommitteeMember,
|
author: CommitteeMember,
|
||||||
round: uint64,
|
round: uint64,
|
||||||
hash: T.Dependencies.Hash
|
hash: Hash
|
||||||
): auto =
|
): auto =
|
||||||
T(
|
BlockId[Hash](
|
||||||
author: author,
|
author: author,
|
||||||
round: round,
|
round: round,
|
||||||
hash: hash
|
hash: hash
|
||||||
|
|||||||
@ -89,7 +89,7 @@ proc propose*(validator: Validator, transactions: seq[Validator.Dependencies.Tra
|
|||||||
let round = validator.rounds.latest
|
let round = validator.rounds.latest
|
||||||
if round[validator.membership].proposals.len > 0:
|
if round[validator.membership].proposals.len > 0:
|
||||||
return SignedBlock.failure "already proposed this round"
|
return SignedBlock.failure "already proposed this round"
|
||||||
var parents: seq[BlockId[Validator.Dependencies]]
|
var parents: seq[BlockId[Validator.Dependencies.Hash]]
|
||||||
var parentStake: Stake
|
var parentStake: Stake
|
||||||
if previous =? round.previous:
|
if previous =? round.previous:
|
||||||
for slot in previous.slots:
|
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 =
|
func check*(validator: Validator, signed: SignedBlock): auto =
|
||||||
type BlockCheck = checks.BlockCheck[SignedBlock.Dependencies]
|
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):
|
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:
|
||||||
|
|||||||
@ -11,7 +11,7 @@ type
|
|||||||
of invalid:
|
of invalid:
|
||||||
reason: string
|
reason: string
|
||||||
of incomplete:
|
of incomplete:
|
||||||
missing: seq[BlockId[Dependencies]]
|
missing: seq[BlockId[Dependencies.Hash]]
|
||||||
of correct:
|
of correct:
|
||||||
blck: CorrectBlock[Dependencies]
|
blck: CorrectBlock[Dependencies]
|
||||||
CorrectBlock*[Dependencies] = distinct SignedBlock[Dependencies]
|
CorrectBlock*[Dependencies] = distinct SignedBlock[Dependencies]
|
||||||
|
|||||||
@ -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]]
|
certificates: seq[BlockId[Dependencies.Hash]]
|
||||||
SlotStatus* {.pure.} = enum
|
SlotStatus* {.pure.} = enum
|
||||||
undecided
|
undecided
|
||||||
skip
|
skip
|
||||||
|
|||||||
@ -13,8 +13,8 @@ proc example*(T: type CommitteeMember): T =
|
|||||||
proc example*(T: type BlockId): T =
|
proc example*(T: type BlockId): T =
|
||||||
let author = CommitteeMember.example
|
let author = CommitteeMember.example
|
||||||
let round = uint64.example
|
let round = uint64.example
|
||||||
let hash = T.Dependencies.Hash.example
|
let hash = T.Hash.example
|
||||||
T.new(author, round, hash)
|
BlockId.new(author, round, hash)
|
||||||
|
|
||||||
proc example*(
|
proc example*(
|
||||||
T: type Block,
|
T: type Block,
|
||||||
@ -22,7 +22,7 @@ proc example*(
|
|||||||
round = uint64.example
|
round = uint64.example
|
||||||
): T =
|
): T =
|
||||||
type Transaction = T.Dependencies.Transaction
|
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
|
let transactions = seq[Transaction].example
|
||||||
T.new(author, round, parents, transactions)
|
T.new(author, round, parents, transactions)
|
||||||
|
|
||||||
|
|||||||
@ -5,7 +5,7 @@ import mysticeti/blocks
|
|||||||
suite "Blocks":
|
suite "Blocks":
|
||||||
|
|
||||||
type Block = mysticeti.Block[MockDependencies]
|
type Block = mysticeti.Block[MockDependencies]
|
||||||
type BlockId = mysticeti.BlockId[MockDependencies]
|
type BlockId = mysticeti.BlockId[MockDependencies.Hash]
|
||||||
type Identity = MockDependencies.Identity
|
type Identity = MockDependencies.Identity
|
||||||
type Transaction = MockDependencies.Transaction
|
type Transaction = MockDependencies.Transaction
|
||||||
type Hash = MockDependencies.Hash
|
type Hash = MockDependencies.Hash
|
||||||
|
|||||||
@ -4,7 +4,7 @@ import mysticeti/validator/slots
|
|||||||
|
|
||||||
suite "Proposer Slots":
|
suite "Proposer Slots":
|
||||||
|
|
||||||
type BlockId = mysticeti.BlockId[MockDependencies]
|
type BlockId = mysticeti.BlockId[MockDependencies.Hash]
|
||||||
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]
|
||||||
|
|||||||
@ -11,7 +11,7 @@ suite "Validator Network":
|
|||||||
type Identity = MockDependencies.Identity
|
type Identity = MockDependencies.Identity
|
||||||
type Transaction = MockDependencies.Transaction
|
type Transaction = MockDependencies.Transaction
|
||||||
type Block = blocks.Block[MockDependencies]
|
type Block = blocks.Block[MockDependencies]
|
||||||
type BlockId = blocks.BlockId[MockDependencies]
|
type BlockId = blocks.BlockId[MockDependencies.Hash]
|
||||||
type Hash = MockDependencies.Hash
|
type Hash = MockDependencies.Hash
|
||||||
|
|
||||||
var simulator: NetworkSimulator
|
var simulator: NetworkSimulator
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user