Browse Source

cleanup: Remove block header fields we don't use

travis-debug
Christian Decker 5 years ago
parent
commit
234252016d
  1. 33
      bitcoin/block.c
  2. 11
      bitcoin/block.h

33
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 {

11
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;
};

Loading…
Cancel
Save