From 234252016da8c40afe37e26b7162a45180719939 Mon Sep 17 00:00:00 2001 From: Christian Decker Date: Sat, 25 Jan 2020 13:14:34 +0100 Subject: [PATCH] cleanup: Remove block header fields we don't use --- bitcoin/block.c | 33 ++++++++++++++++----------------- bitcoin/block.h | 11 ----------- 2 files changed, 16 insertions(+), 28 deletions(-) diff --git a/bitcoin/block.c b/bitcoin/block.c index de652dfc3..424f4f52b 100644 --- a/bitcoin/block.c +++ b/bitcoin/block.c @@ -94,9 +94,10 @@ bitcoin_block_from_hex(const tal_t *ctx, const struct chainparams *chainparams, struct bitcoin_block *b; u8 *linear_tx; const u8 *p; - size_t len, i, num; + size_t len, i, num, templen; struct sha256_ctx shactx; bool is_dynafed; + u32 height; if (hexlen && hex[hexlen-1] == '\n') hexlen--; @@ -127,26 +128,24 @@ bitcoin_block_from_hex(const tal_t *ctx, const struct chainparams *chainparams, if (is_elements(chainparams)) { /* A dynafed block is signalled by setting the MSB of the version. */ is_dynafed = (b->hdr.version >> 31 == 1); - b->elements_hdr = tal(b, struct elements_block_hdr); - b->elements_hdr->block_height = pull_le32(&p, &len); - sha256_le32(&shactx, b->elements_hdr->block_height); + + /* elements_header.height */ + height = pull_le32(&p, &len); + sha256_le32(&shactx, height); if (is_dynafed) { bitcoin_block_pull_dynafed_details(&p, &len, &shactx); } else { - size_t challenge_len = pull_varint(&p, &len); - sha256_varint(&shactx, challenge_len); - sha256_update(&shactx, p, challenge_len); - b->elements_hdr->proof.challenge = - tal_arr(b->elements_hdr, u8, challenge_len); - pull(&p, &len, b->elements_hdr->proof.challenge, - challenge_len); - - size_t solution_len = pull_varint(&p, &len); - b->elements_hdr->proof.solution = - tal_arr(b->elements_hdr, u8, solution_len); - pull(&p, &len, b->elements_hdr->proof.solution, - solution_len); + /* elemens_header.challenge */ + templen = pull_varint(&p, &len); + sha256_varint(&shactx, templen); + sha256_update(&shactx, p, templen); + pull(&p, &len, NULL, templen); + + /* elements_header.solution. Not hashed since it'd be + * a circular dependency. */ + templen = pull_varint(&p, &len); + pull(&p, &len, NULL, templen); } } else { diff --git a/bitcoin/block.h b/bitcoin/block.h index 8654ed5a1..7f82b8aa5 100644 --- a/bitcoin/block.h +++ b/bitcoin/block.h @@ -32,19 +32,8 @@ struct bitcoin_block_hdr { struct bitcoin_blkid hash; }; -struct elements_block_proof { - u8 *challenge; - u8 *solution; -}; - -struct elements_block_hdr { - u32 block_height; - struct elements_block_proof proof; -}; - struct bitcoin_block { struct bitcoin_block_hdr hdr; - struct elements_block_hdr *elements_hdr; /* tal_count shows now many */ struct bitcoin_tx **tx; };