diff --git a/blockchain/validate.go b/blockchain/validate.go index f41d54e6..f7831469 100644 --- a/blockchain/validate.go +++ b/blockchain/validate.go @@ -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 "+ diff --git a/wire/blockheader.go b/wire/blockheader.go index b4d0531e..ee45ec3b 100644 --- a/wire/blockheader.go +++ b/wire/blockheader.go @@ -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