mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-01-18 13:25:43 +01:00
bitcoin: Use the block hash we computed while deserializing it
Since we now compute the hash while deserializing the block header we can now just use it, no reason to serialize the header just to hash it again. This also allows us to throw away all the added dynafed fields in the next commit instead of having to carry them around.
This commit is contained in:
parent
fce05d74e1
commit
c99786e720
@ -91,27 +91,7 @@ bitcoin_block_from_hex(const tal_t *ctx, const struct chainparams *chainparams,
|
|||||||
void bitcoin_block_blkid(const struct bitcoin_block *b,
|
void bitcoin_block_blkid(const struct bitcoin_block *b,
|
||||||
struct bitcoin_blkid *out)
|
struct bitcoin_blkid *out)
|
||||||
{
|
{
|
||||||
struct sha256_ctx shactx;
|
*out = b->hdr.hash;
|
||||||
|
|
||||||
sha256_init(&shactx);
|
|
||||||
sha256_le32(&shactx, b->hdr.version);
|
|
||||||
sha256_update(&shactx, &b->hdr.prev_hash, sizeof(b->hdr.prev_hash));
|
|
||||||
sha256_update(&shactx, &b->hdr.merkle_hash, sizeof(b->hdr.merkle_hash));
|
|
||||||
sha256_le32(&shactx, b->hdr.timestamp);
|
|
||||||
|
|
||||||
if (is_elements(chainparams)) {
|
|
||||||
size_t clen = tal_bytelen(b->elements_hdr->proof.challenge);
|
|
||||||
sha256_le32(&shactx, b->elements_hdr->block_height);
|
|
||||||
|
|
||||||
sha256_varint(&shactx, clen);
|
|
||||||
sha256_update(&shactx, b->elements_hdr->proof.challenge, clen);
|
|
||||||
/* The solution is skipped, since that'd create a circular
|
|
||||||
* dependency apparently */
|
|
||||||
} else {
|
|
||||||
sha256_le32(&shactx, b->hdr.target);
|
|
||||||
sha256_le32(&shactx, b->hdr.nonce);
|
|
||||||
}
|
|
||||||
sha256_double_done(&shactx, &out->shad);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* We do the same hex-reversing crud as txids. */
|
/* We do the same hex-reversing crud as txids. */
|
||||||
|
Loading…
Reference in New Issue
Block a user