From d1378fe1a5316cdfe6a6a76edc2da7b549d39b11 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Tue, 29 Aug 2017 01:26:01 +0930 Subject: [PATCH] chaintopology: remove routines unnecessary for modern daemon. Signed-off-by: Rusty Russell --- daemon/chaintopology.c | 46 ------------------------------------------ daemon/chaintopology.h | 10 --------- 2 files changed, 56 deletions(-) diff --git a/daemon/chaintopology.c b/daemon/chaintopology.c index c36082d30..f848aa99e 100644 --- a/daemon/chaintopology.c +++ b/daemon/chaintopology.c @@ -27,31 +27,6 @@ static void next_topology_timer(struct chain_topology *topo) start_poll_chaintip, topo); } -static int cmp_times(const u32 *a, const u32 *b, void *unused) -{ - if (*a > *b) - return -1; - else if (*b > * a) - return 1; - return 0; -} - -/* Mediantime is median of this and previous 10 blocks. */ -static u32 get_mediantime(const struct chain_topology *topo, const struct block *b) -{ - unsigned int i; - u32 times[11]; - - for (i = 0; i < ARRAY_SIZE(times); i++) { - if (!b) - return 0; - times[i] = le32_to_cpu(b->hdr.timestamp); - b = b->prev; - } - asort(times, ARRAY_SIZE(times), cmp_times, NULL); - return times[ARRAY_SIZE(times) / 2]; -} - /* FIXME: Remove tx from block when peer done. */ static void add_tx_to_block(struct block *b, const struct bitcoin_tx *tx, const u32 txnum) @@ -84,13 +59,11 @@ static void connect_block(struct chain_topology *topo, size_t i; assert(b->height == -1); - assert(b->mediantime == 0); assert(b->prev == NULL); assert(prev->next == b); b->prev = prev; b->height = b->prev->height + 1; - b->mediantime = get_mediantime(topo, b); block_map_add(&topo->block_map, b); @@ -363,7 +336,6 @@ static struct block *new_block(struct chain_topology *topo, /* We fill these out in topology_changed */ b->height = -1; - b->mediantime = 0; b->prev = NULL; b->hdr = blk->hdr; @@ -472,24 +444,6 @@ static void get_init_blockhash(struct bitcoind *bitcoind, u32 blockcount, get_init_block, topo); } -u32 get_tx_mediantime(const struct chain_topology *topo, - const struct sha256_double *txid) -{ - struct block *b; - - b = block_for_tx(topo, txid, NULL); - if (b) - return b->mediantime; - - fatal("Tx %s not found for get_tx_mediantime", - tal_hexstr(topo, txid, sizeof(*txid))); -} - -u32 get_tip_mediantime(const struct chain_topology *topo) -{ - return topo->tip->mediantime; -} - u32 get_block_height(const struct chain_topology *topo) { return topo->tip->height; diff --git a/daemon/chaintopology.h b/daemon/chaintopology.h index 2eb690e0e..863c45006 100644 --- a/daemon/chaintopology.h +++ b/daemon/chaintopology.h @@ -45,9 +45,6 @@ struct block { /* Key for hash table */ struct sha256_double blkid; - /* 0 if not enough predecessors. */ - u32 mediantime; - /* Transactions in this block we care about */ const struct bitcoin_tx **txs; @@ -136,13 +133,6 @@ size_t get_tx_depth(const struct chain_topology *topo, const struct sha256_double *txid, const struct bitcoin_tx **tx); -/* Get the mediantime of the block including this tx (must be one!) */ -u32 get_tx_mediantime(const struct chain_topology *topo, - const struct sha256_double *txid); - -/* Get mediantime of the tip; if more than one, pick greatest time. */ -u32 get_tip_mediantime(const struct chain_topology *topo); - /* Get highest block number. */ u32 get_block_height(const struct chain_topology *topo);