Browse Source

chaintopology: remove routines unnecessary for modern daemon.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ppa-0.6.1
Rusty Russell 7 years ago
committed by Christian Decker
parent
commit
d1378fe1a5
  1. 46
      daemon/chaintopology.c
  2. 10
      daemon/chaintopology.h

46
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;

10
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);

Loading…
Cancel
Save