I try to implement the hybrid consensus from the substrate recipes book but it keeps failing. I tried to use the sha3 algorithm for PoW but I keep getting this error:
"the trait
PowAlgorithm<_>
is not implemented for `MinimalSha3Algorithm"
This is my code in rust:
#[derive(Clone)]
pub struct MinimalSha3Algorithm;
// Here we implement the general PowAlgorithm trait for our concrete Sha3Algorithm
impl<B: BlockT<Hash = H256>> PowAlgorithm<B> for MinimalSha3Algorithm {
type Difficulty = U256;
fn difficulty(&self, _parent: B::Hash) -> Result<Self::Difficulty, Error<B>> {
// Fixed difficulty hardcoded here
Ok(U256::from(1_000_000))
}
fn verify(
&self,
_parent: &BlockId<B>,
pre_hash: &H256,
_pre_digest: Option<&[u8]>,
seal: &RawSeal,
difficulty: Self::Difficulty,
) -> Result<bool, Error<B>> {
// Try to construct a seal object by decoding the raw seal given
let seal = match Seal::decode(&mut &seal[..]) {
Ok(seal) => seal,
Err(_) => return Ok(false),
};
// See whether the hash meets the difficulty requirement. If not, fail fast.
if !hash_meets_difficulty(&seal.work, difficulty) {
return Ok(false);
}
// Make sure the provided work actually comes from the correct pre_hash
let compute = Compute {
difficulty,
pre_hash: *pre_hash,
nonce: seal.nonce,
};
if compute.compute() != seal {
return Ok(false);
}
Ok(true)
}
}
I'd appreciate any help!
Sha3Algorithm
to be identical to your code and it compiles on my machine underv0.9.35
. Could you provide the literal error printout ? Is itservice.rs
that fails to compile ?