2

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!

3
  • 1
    Your code seems to be ok. I modified the PoW node Sha3Algorithm to be identical to your code and it compiles on my machine under v0.9.35. Could you provide the literal error printout ? Is it service.rs that fails to compile ? Commented Sep 1, 2023 at 20:52
  • Thanks, I updated the dependencies but I got other errors in the file now with InherentDataProviders and sc_consensus. I was wondering if you could make the hybrid consensus work recently? Commented Sep 4, 2023 at 7:52
  • You could try to kick your project off out of github.com/Polkadot-Blockchain-Academy/Academy-PoW. I'm not sure how updated that repo is, things change quickly as for Substrate development, you'll probably need to do a bit of research of the Host's sources and update your code accordingly to newer APIs. Commented Sep 4, 2023 at 13:45

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.