From 4de0d1ca2229f6433b8daca8210dee467aee429b Mon Sep 17 00:00:00 2001 From: Christian Decker Date: Thu, 23 Jan 2020 13:38:13 +0100 Subject: [PATCH] bitcoin: Compute block hash while parsing This avoids having to re-serialize the block header just to compute the hash. It also frees us from having to carry around all the details in the header and we can hand around a minimal version. --- bitcoin/block.c | 2 +- bitcoin/block.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bitcoin/block.c b/bitcoin/block.c index dc478291d..ee929b2f2 100644 --- a/bitcoin/block.c +++ b/bitcoin/block.c @@ -60,7 +60,7 @@ bitcoin_block_from_hex(const tal_t *ctx, const struct chainparams *chainparams, b->hdr.nonce = pull_le32(&p, &len); sha256_le32(&shactx, b->hdr.nonce); } - sha256_double_done(&shactx, &b->hdr.hash); + sha256_double_done(&shactx, &b->hdr.hash.shad); num = pull_varint(&p, &len); b->tx = tal_arr(b, struct bitcoin_tx *, num); diff --git a/bitcoin/block.h b/bitcoin/block.h index cf0c913b5..9ac3592be 100644 --- a/bitcoin/block.h +++ b/bitcoin/block.h @@ -23,7 +23,7 @@ struct bitcoin_block_hdr { le32 timestamp; le32 target; le32 nonce; - struct sha256_double hash; + struct bitcoin_blkid hash; }; struct elements_block_proof {