pub trait PowAlgorithm<B: BlockT> {
    type Difficulty: TotalDifficulty + Default + Encode + Decode + Ord + Clone + Copy;

    // Required methods
    fn difficulty(&self, parent: B::Hash) -> Result<Self::Difficulty, Error<B>>;
    fn verify(
        &self,
        parent: &BlockId<B>,
        pre_hash: &B::Hash,
        pre_digest: Option<&[u8]>,
        seal: &Seal,
        difficulty: Self::Difficulty
    ) -> Result<bool, Error<B>>;

    // Provided methods
    fn preliminary_verify(
        &self,
        _pre_hash: &B::Hash,
        _seal: &Seal
    ) -> Result<Option<bool>, Error<B>> { ... }
    fn break_tie(&self, _own_seal: &Seal, _new_seal: &Seal) -> bool { ... }
}
Expand description

Algorithm used for proof of work.

Required Associated Types§

source

type Difficulty: TotalDifficulty + Default + Encode + Decode + Ord + Clone + Copy

Difficulty for the algorithm.

Required Methods§

source

fn difficulty(&self, parent: B::Hash) -> Result<Self::Difficulty, Error<B>>

Get the next block’s difficulty.

This function will be called twice during the import process, so the implementation should be properly cached.

source

fn verify( &self, parent: &BlockId<B>, pre_hash: &B::Hash, pre_digest: Option<&[u8]>, seal: &Seal, difficulty: Self::Difficulty ) -> Result<bool, Error<B>>

Verify that the difficulty is valid against given seal.

Provided Methods§

source

fn preliminary_verify( &self, _pre_hash: &B::Hash, _seal: &Seal ) -> Result<Option<bool>, Error<B>>

Verify that the seal is valid against given pre hash when parent block is not yet imported.

None means that preliminary verify is not available for this algorithm.

source

fn break_tie(&self, _own_seal: &Seal, _new_seal: &Seal) -> bool

Break a fork choice tie.

By default this chooses the earliest block seen. Using uniform tie breaking algorithms will help to protect against selfish mining.

Returns if the new seal should be considered best block.

Implementors§