public static Bytes serializeHeader(
      final BlockHeader header,
      final Supplier<Bytes> extraDataSerializer,
      final BftExtraDataCodec bftExtraDataCodec) {

    // create a block header which is a copy of the header supplied as parameter except of the
    // extraData field
    final BlockHeaderBuilder builder = BlockHeaderBuilder.fromHeader(header);
    builder.blockHeaderFunctions(BftBlockHeaderFunctions.forOnchainBlock(bftExtraDataCodec));

    // set the extraData field using the supplied extraDataSerializer if the block height is not 0
    if (header.getNumber() == BlockHeader.GENESIS_BLOCK_NUMBER) {
      builder.extraData(header.getExtraData());
    } else {
      builder.extraData(extraDataSerializer.get());
    }

    final BytesValueRLPOutput out = new BytesValueRLPOutput();
    builder.buildBlockHeader().writeTo(out);
    return out.encoded();
  }
Serialize header bytes.

@param header the header
@param extraDataSerializer the extra data serializer
@param bftExtraDataCodec the bft extra data codec
@return the bytes
consensus/common/src/main/java/org/hyperledger/besu/consensus/common/bft/BftBlockHashing.java