[lbry] blockchain, wire: verify blockheaders using LBRY PoW

This commit is contained in:
Roy Lee 2018-05-28 21:06:46 -07:00
parent 9f479837c1
commit 03989a91d9
2 changed files with 13 additions and 1 deletions

View file

@ -324,7 +324,7 @@ func checkProofOfWork(header *wire.BlockHeader, powLimit *big.Int, flags Behavio
// to avoid proof of work checks is set.
if flags&BFNoPoWCheck != BFNoPoWCheck {
// The block hash must be less than the claimed target.
hash := header.BlockHash()
hash := header.BlockPoWHash()
hashNum := HashToBig(&hash)
if hashNum.Cmp(target) > 0 {
str := fmt.Sprintf("block hash of %064x is higher than "+

View file

@ -59,6 +59,18 @@ func (h *BlockHeader) BlockHash() chainhash.Hash {
return chainhash.DoubleHashH(buf.Bytes())
}
// BlockPoWHash computes the block identifier hash for the given block header.
func (h *BlockHeader) BlockPoWHash() chainhash.Hash {
// Encode the header and double sha256 everything prior to the number of
// transactions. Ignore the error returns since there is no way the
// encode could fail except being out of memory which would cause a
// run-time panic.
buf := bytes.NewBuffer(make([]byte, 0, MaxBlockHeaderPayload))
_ = writeBlockHeader(buf, 0, h)
return chainhash.LbryPoWHashH(buf.Bytes())
}
// BtcDecode decodes r using the bitcoin protocol encoding into the receiver.
// This is part of the Message interface implementation.
// See Deserialize for decoding block headers stored to disk, such as in a