mirror of
https://github.com/logos-storage/nim-mysticeti.git
synced 2026-01-08 00:23:13 +00:00
derive Hash type from Block type
This commit is contained in:
parent
de854cbb5f
commit
ea9e1c01f9
@ -1,6 +1,5 @@
|
|||||||
type Dependencies*[
|
type Dependencies*[
|
||||||
Block,
|
Block,
|
||||||
Hash,
|
|
||||||
Identifier,
|
Identifier,
|
||||||
Signature
|
Signature
|
||||||
] = object
|
] = object
|
||||||
|
|||||||
@ -84,7 +84,9 @@ func addBlock(validator: Validator, signedBlock: SignedBlock) =
|
|||||||
|
|
||||||
func parentBlocks*(validator: Validator): auto =
|
func parentBlocks*(validator: Validator): auto =
|
||||||
mixin id
|
mixin id
|
||||||
var parents: seq[BlockId[Validator.Dependencies.Hash]]
|
type Block = Validator.Dependencies.Block
|
||||||
|
type BlockId = typeof(Block.default.id)
|
||||||
|
var parents: seq[BlockId]
|
||||||
if previous =? validator.rounds.latest.previous:
|
if previous =? validator.rounds.latest.previous:
|
||||||
for slot in previous.slots:
|
for slot in previous.slots:
|
||||||
if slot.proposals.len == 1:
|
if slot.proposals.len == 1:
|
||||||
@ -93,8 +95,9 @@ func parentBlocks*(validator: Validator): auto =
|
|||||||
|
|
||||||
func check*(validator: Validator, signed: SignedBlock): auto =
|
func check*(validator: Validator, signed: SignedBlock): auto =
|
||||||
mixin id
|
mixin id
|
||||||
type BlockCheck = checks.BlockCheck[SignedBlock.Dependencies]
|
type BlockCheck = checks.BlockCheck[Validator.Dependencies]
|
||||||
type BlockId = blocks.BlockId[SignedBlock.Dependencies.Hash]
|
type Block = Validator.Dependencies.Block
|
||||||
|
type BlockId = typeof(Block.default.id)
|
||||||
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.Hash]]
|
missing: seq[typeof(Dependencies.Block.default.id)]
|
||||||
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.Hash]]
|
certificates: seq[typeof(Dependencies.Block.default.id)]
|
||||||
SlotStatus* {.pure.} = enum
|
SlotStatus* {.pure.} = enum
|
||||||
undecided
|
undecided
|
||||||
skip
|
skip
|
||||||
|
|||||||
@ -11,7 +11,6 @@ export blck
|
|||||||
|
|
||||||
type MockDependencies* = Dependencies[
|
type MockDependencies* = Dependencies[
|
||||||
MockBlock,
|
MockBlock,
|
||||||
MockHash,
|
|
||||||
MockIdentifier,
|
MockIdentifier,
|
||||||
MockSignature
|
MockSignature
|
||||||
]
|
]
|
||||||
|
|||||||
@ -4,7 +4,7 @@ import mysticeti/validator/slots
|
|||||||
|
|
||||||
suite "Proposer Slots":
|
suite "Proposer Slots":
|
||||||
|
|
||||||
type BlockId = mysticeti.BlockId[MockDependencies.Hash]
|
type BlockId = mysticeti.BlockId[MockHash]
|
||||||
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]
|
||||||
|
|||||||
@ -9,8 +9,8 @@ suite "Validator Network":
|
|||||||
type Transaction = MockTransaction
|
type Transaction = MockTransaction
|
||||||
type Block = MockBlock
|
type Block = MockBlock
|
||||||
type SignedBlock = blocks.SignedBlock[MockDependencies]
|
type SignedBlock = blocks.SignedBlock[MockDependencies]
|
||||||
type BlockId = blocks.BlockId[MockDependencies.Hash]
|
type BlockId = blocks.BlockId[MockHash]
|
||||||
type Hash = MockDependencies.Hash
|
type Hash = MockHash
|
||||||
|
|
||||||
var simulator: NetworkSimulator
|
var simulator: NetworkSimulator
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user