From 8d7acdc3673b19fd445bc89c54f40dbd0e09d109 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Thu, 2 Mar 2017 22:51:49 +1030 Subject: [PATCH] struct topology -> struct chain_topology Topology also refers to the lightning network, be clear. Signed-off-by: Rusty Russell --- daemon/chaintopology.c | 62 ++++++++++++++++++++--------------------- daemon/chaintopology.h | 28 +++++++++---------- daemon/lightningd.h | 2 +- daemon/peer.c | 6 ++-- daemon/watch.c | 14 +++++----- daemon/watch.h | 18 ++++++------ lightningd/lightningd.c | 4 +-- 7 files changed, 67 insertions(+), 67 deletions(-) diff --git a/daemon/chaintopology.c b/daemon/chaintopology.c index 8e90b9d94..2529d32c8 100644 --- a/daemon/chaintopology.c +++ b/daemon/chaintopology.c @@ -16,9 +16,9 @@ #include #include -static void start_poll_chaintip(struct topology *topo); +static void start_poll_chaintip(struct chain_topology *topo); -static void next_topology_timer(struct topology *topo) +static void next_topology_timer(struct chain_topology *topo) { if (topo->startup) { topo->startup = false; @@ -38,7 +38,7 @@ static int cmp_times(const u32 *a, const u32 *b, void *unused) } /* Mediantime is median of this and previous 10 blocks. */ -static u32 get_mediantime(const struct topology *topo, const struct block *b) +static u32 get_mediantime(const struct chain_topology *topo, const struct block *b) { unsigned int i; u32 times[11]; @@ -64,7 +64,7 @@ static void add_tx_to_block(struct block *b, const struct sha256_double *txid, c b->txnums[n] = txnum; } -static bool we_broadcast(const struct topology *topo, +static bool we_broadcast(const struct chain_topology *topo, const struct sha256_double *txid) { const struct outgoing_tx *otx; @@ -77,7 +77,7 @@ static bool we_broadcast(const struct topology *topo, } /* Fills in prev, height, mediantime. */ -static void connect_block(struct topology *topo, +static void connect_block(struct chain_topology *topo, struct block *prev, struct block *b) { @@ -136,7 +136,7 @@ static bool tx_in_block(const struct block *b, } /* FIXME: Use hash table. */ -static struct block *block_for_tx(const struct topology *topo, +static struct block *block_for_tx(const struct chain_topology *topo, const struct sha256_double *txid) { struct block *b; @@ -148,7 +148,7 @@ static struct block *block_for_tx(const struct topology *topo, return NULL; } -size_t get_tx_depth(const struct topology *topo, +size_t get_tx_depth(const struct chain_topology *topo, const struct sha256_double *txid) { const struct block *b; @@ -199,7 +199,7 @@ static void broadcast_remainder(struct bitcoind *bitcoind, /* FIXME: This is dumb. We can group txs and avoid bothering bitcoind * if any one tx is in the main chain. */ -static void rebroadcast_txs(struct topology *topo, struct command *cmd) +static void rebroadcast_txs(struct chain_topology *topo, struct command *cmd) { /* Copy txs now (peers may go away, and they own txs). */ size_t num_txs = 0; @@ -247,7 +247,7 @@ static void broadcast_done(struct bitcoind *bitcoind, } } -void broadcast_tx(struct topology *topo, +void broadcast_tx(struct chain_topology *topo, struct peer *peer, const struct bitcoin_tx *tx, void (*failed)(struct peer *peer, int exitstatus, const char *err)) @@ -272,7 +272,7 @@ void broadcast_tx(struct topology *topo, broadcast_done, otx); } -static void free_blocks(struct topology *topo, struct block *b) +static void free_blocks(struct chain_topology *topo, struct block *b) { struct block *next; @@ -290,7 +290,7 @@ static void free_blocks(struct topology *topo, struct block *b) } static void update_fee(struct bitcoind *bitcoind, u64 rate, - struct topology *topo) + struct chain_topology *topo) { log_debug(topo->log, "Feerate %"PRIu64" (was %"PRIu64")", rate, topo->feerate); @@ -298,7 +298,7 @@ static void update_fee(struct bitcoind *bitcoind, u64 rate, } /* B is the new chain (linked by ->next); update topology */ -static void topology_changed(struct topology *topo, +static void topology_changed(struct chain_topology *topo, struct block *prev, struct block *b) { @@ -323,7 +323,7 @@ static void topology_changed(struct topology *topo, bitcoind_estimate_fee(topo->bitcoind, update_fee, topo); } -static struct block *new_block(struct topology *topo, +static struct block *new_block(struct chain_topology *topo, struct bitcoin_block *blk, struct block *next) { @@ -351,7 +351,7 @@ static struct block *new_block(struct topology *topo, } static void add_block(struct bitcoind *bitcoind, - struct topology *topo, + struct chain_topology *topo, struct bitcoin_block *blk, struct block *next); @@ -363,7 +363,7 @@ static void gather_previous_blocks(struct bitcoind *bitcoind, } static void add_block(struct bitcoind *bitcoind, - struct topology *topo, + struct chain_topology *topo, struct bitcoin_block *blk, struct block *next) { @@ -386,14 +386,14 @@ static void add_block(struct bitcoind *bitcoind, static void rawblock_tip(struct bitcoind *bitcoind, struct bitcoin_block *blk, - struct topology *topo) + struct chain_topology *topo) { add_block(bitcoind, topo, blk, NULL); } static void check_chaintip(struct bitcoind *bitcoind, const struct sha256_double *tipid, - struct topology *topo) + struct chain_topology *topo) { /* 0 is the main tip. */ if (!structeq(tipid, &topo->tip->blkid)) @@ -403,7 +403,7 @@ static void check_chaintip(struct bitcoind *bitcoind, next_topology_timer(topo); } -static void start_poll_chaintip(struct topology *topo) +static void start_poll_chaintip(struct chain_topology *topo) { if (!list_empty(&topo->bitcoind->pending)) { log_unusual(topo->log, @@ -415,7 +415,7 @@ static void start_poll_chaintip(struct topology *topo) static void init_topo(struct bitcoind *bitcoind, struct bitcoin_block *blk, - struct topology *topo) + struct chain_topology *topo) { topo->root = new_block(topo, blk, NULL); topo->root->height = topo->first_blocknum; @@ -428,13 +428,13 @@ static void init_topo(struct bitcoind *bitcoind, static void get_init_block(struct bitcoind *bitcoind, const struct sha256_double *blkid, - struct topology *topo) + struct chain_topology *topo) { bitcoind_getrawblock(bitcoind, blkid, init_topo, topo); } static void get_init_blockhash(struct bitcoind *bitcoind, u32 blockcount, - struct topology *topo) + struct chain_topology *topo) { /* Start back before any reasonable forks. */ if (blockcount < 100) @@ -447,7 +447,7 @@ static void get_init_blockhash(struct bitcoind *bitcoind, u32 blockcount, get_init_block, topo); } -u32 get_tx_mediantime(const struct topology *topo, +u32 get_tx_mediantime(const struct chain_topology *topo, const struct sha256_double *txid) { struct block *b; @@ -460,17 +460,17 @@ u32 get_tx_mediantime(const struct topology *topo, tal_hexstr(topo, txid, sizeof(*txid))); } -u32 get_tip_mediantime(const struct topology *topo) +u32 get_tip_mediantime(const struct chain_topology *topo) { return topo->tip->mediantime; } -u32 get_block_height(const struct topology *topo) +u32 get_block_height(const struct chain_topology *topo) { return topo->tip->height; } -u64 get_feerate(const struct topology *topo) +u64 get_feerate(const struct chain_topology *topo) { if (topo->override_fee_rate) { log_debug(topo->log, "Forcing fee rate, ignoring estimate"); @@ -483,7 +483,7 @@ u64 get_feerate(const struct topology *topo) return topo->feerate; } -struct txlocator *locate_tx(const void *ctx, const struct topology *topo, +struct txlocator *locate_tx(const void *ctx, const struct chain_topology *topo, const struct sha256_double *txid) { struct block *block = block_for_tx(topo, txid); @@ -504,7 +504,7 @@ struct txlocator *locate_tx(const void *ctx, const struct topology *topo, } void json_dev_broadcast(struct command *cmd, - struct topology *topo, + struct chain_topology *topo, const char *buffer, const jsmntok_t *params) { jsmntok_t *enabletok; @@ -535,7 +535,7 @@ void json_dev_broadcast(struct command *cmd, /* On shutdown, peers get deleted last. That frees from our list, so * do it now instead. */ -static void destroy_outgoing_txs(struct topology *topo) +static void destroy_outgoing_txs(struct chain_topology *topo) { struct outgoing_tx *otx; @@ -543,9 +543,9 @@ static void destroy_outgoing_txs(struct topology *topo) tal_free(otx); } -struct topology *new_topology(const tal_t *ctx, struct log *log) +struct chain_topology *new_topology(const tal_t *ctx, struct log *log) { - struct topology *topo = tal(ctx, struct topology); + struct chain_topology *topo = tal(ctx, struct chain_topology); block_map_init(&topo->block_map); list_head_init(&topo->outgoing_txs); @@ -559,7 +559,7 @@ struct topology *new_topology(const tal_t *ctx, struct log *log) return topo; } -void setup_topology(struct topology *topo, struct bitcoind *bitcoind, +void setup_topology(struct chain_topology *topo, struct bitcoind *bitcoind, struct timers *timers, struct timerel poll_time, u32 first_peer_block) { diff --git a/daemon/chaintopology.h b/daemon/chaintopology.h index 68f04eb1e..110f50c40 100644 --- a/daemon/chaintopology.h +++ b/daemon/chaintopology.h @@ -27,7 +27,7 @@ struct outgoing_tx { struct sha256_double txid; void (*failed)(struct peer *peer, int exitstatus, const char *err); /* FIXME: Remove this. */ - struct topology *topo; + struct chain_topology *topo; }; struct block { @@ -58,7 +58,7 @@ struct block { struct bitcoin_tx **full_txs; /* FIXME: Remove this. */ - struct topology *topo; + struct chain_topology *topo; }; /* Hash blocks by sha */ @@ -81,7 +81,7 @@ static inline bool block_eq(const struct block *b, const struct sha256_double *k } HTABLE_DEFINE_TYPE(struct block, keyof_block_map, hash_sha, block_eq, block_map); -struct topology { +struct chain_topology { struct block *root; struct block *tip; struct block_map block_map; @@ -132,41 +132,41 @@ struct txlocator { /* This is the number of blocks which would have to be mined to invalidate * the tx. */ -size_t get_tx_depth(const struct topology *topo, +size_t get_tx_depth(const struct chain_topology *topo, const struct sha256_double *txid); /* Get the mediantime of the block including this tx (must be one!) */ -u32 get_tx_mediantime(const struct topology *topo, +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 topology *topo); +u32 get_tip_mediantime(const struct chain_topology *topo); /* Get highest block number. */ -u32 get_block_height(const struct topology *topo); +u32 get_block_height(const struct chain_topology *topo); /* Get fee rate. */ -u64 get_feerate(const struct topology *topo); +u64 get_feerate(const struct chain_topology *topo); /* Broadcast a single tx, and rebroadcast as reqd (copies tx). * If failed is non-NULL, call that and don't rebroadcast. */ -void broadcast_tx(struct topology *topo, +void broadcast_tx(struct chain_topology *topo, struct peer *peer, const struct bitcoin_tx *tx, void (*failed)(struct peer *peer, int exitstatus, const char *err)); -struct topology *new_topology(const tal_t *ctx, struct log *log); -void setup_topology(struct topology *topology, struct bitcoind *bitcoind, +struct chain_topology *new_topology(const tal_t *ctx, struct log *log); +void setup_topology(struct chain_topology *topology, struct bitcoind *bitcoind, struct timers *timers, struct timerel poll_time, u32 first_peer_block); -struct txlocator *locate_tx(const void *ctx, const struct topology *topo, const struct sha256_double *txid); +struct txlocator *locate_tx(const void *ctx, const struct chain_topology *topo, const struct sha256_double *txid); -void notify_new_block(struct topology *topo, unsigned int height); +void notify_new_block(struct chain_topology *topo, unsigned int height); void json_dev_broadcast(struct command *cmd, - struct topology *topo, + struct chain_topology *topo, const char *buffer, const jsmntok_t *params); #endif /* LIGHTNING_DAEMON_CRYPTOPKT_H */ diff --git a/daemon/lightningd.h b/daemon/lightningd.h index 45c3f2462..56dca1dbf 100644 --- a/daemon/lightningd.h +++ b/daemon/lightningd.h @@ -87,7 +87,7 @@ struct lightningd_state { struct timers timers; /* Cached block topology. */ - struct topology *topology; + struct chain_topology *topology; /* Our peers. */ struct list_head peers; diff --git a/daemon/peer.c b/daemon/peer.c index 585b87bf4..38ceb5632 100644 --- a/daemon/peer.c +++ b/daemon/peer.c @@ -3403,7 +3403,7 @@ static enum watch_result anchor_depthchange(struct peer *peer, return KEEP_WATCHING; } -void notify_new_block(struct topology *topo, unsigned int height) +void notify_new_block(struct chain_topology *topo, unsigned int height) { struct lightningd_state *dstate = tal_parent(topo); /* This is where we check for anchor timeouts. */ @@ -3880,7 +3880,7 @@ static void resolve_their_htlc(struct peer *peer, unsigned int out_num) static void resolve_our_unilateral(struct peer *peer) { unsigned int i; - struct topology *topo = peer->dstate->topology; + struct chain_topology *topo = peer->dstate->topology; const struct bitcoin_tx *tx = peer->onchain.tx; /* This only works because we always watch for a long time before @@ -4315,7 +4315,7 @@ unknown_spend: void peer_watch_anchor(struct peer *peer, int depth) { - struct topology *topo = peer->dstate->topology; + struct chain_topology *topo = peer->dstate->topology; log_debug_struct(peer->log, "watching for anchor %s", struct sha256_double, &peer->anchor.txid); diff --git a/daemon/watch.c b/daemon/watch.c index 717f2eb22..0e7fcacda 100644 --- a/daemon/watch.c +++ b/daemon/watch.c @@ -86,7 +86,7 @@ static void destroy_txwatch(struct txwatch *w) } struct txwatch *watch_txid_(const tal_t *ctx, - struct topology *topo, + struct chain_topology *topo, struct peer *peer, const struct sha256_double *txid, enum watch_result (*cb)(struct peer *peer, @@ -111,14 +111,14 @@ struct txwatch *watch_txid_(const tal_t *ctx, return w; } -bool watching_txid(const struct topology *topo, +bool watching_txid(const struct chain_topology *topo, const struct sha256_double *txid) { return txwatch_hash_get(&topo->txwatches, txid) != NULL; } struct txwatch *watch_tx_(const tal_t *ctx, - struct topology *topo, + struct chain_topology *topo, struct peer *peer, const struct bitcoin_tx *tx, enum watch_result (*cb)(struct peer *peer, @@ -134,7 +134,7 @@ struct txwatch *watch_tx_(const tal_t *ctx, } struct txowatch *watch_txo_(const tal_t *ctx, - struct topology *topo, + struct chain_topology *topo, struct peer *peer, const struct sha256_double *txid, unsigned int output, @@ -159,7 +159,7 @@ struct txowatch *watch_txo_(const tal_t *ctx, return w; } -void txwatch_fire(struct topology *topo, +void txwatch_fire(struct chain_topology *topo, const struct sha256_double *txid, unsigned int depth) { @@ -186,7 +186,7 @@ void txwatch_fire(struct topology *topo, } } -void txowatch_fire(struct topology *topo, +void txowatch_fire(struct chain_topology *topo, const struct txowatch *txow, const struct bitcoin_tx *tx, size_t input_num) @@ -216,7 +216,7 @@ void txowatch_fire(struct topology *topo, fatal("txowatch callback %p returned %i\n", txow->cb, r); } -void watch_topology_changed(struct topology *topo) +void watch_topology_changed(struct chain_topology *topo) { struct txwatch_hash_iter i; struct txwatch *w; diff --git a/daemon/watch.h b/daemon/watch.h index 17c7fabf8..37281c2ec 100644 --- a/daemon/watch.h +++ b/daemon/watch.h @@ -23,7 +23,7 @@ struct txwatch_output { /* Watching an output */ struct txowatch { - struct topology *topo; + struct chain_topology *topo; /* Peer who owns us. */ struct peer *peer; @@ -48,7 +48,7 @@ HTABLE_DEFINE_TYPE(struct txowatch, txowatch_keyof, txo_hash, txowatch_eq, txowatch_hash); struct txwatch { - struct topology *topo; + struct chain_topology *topo; /* Peer who owns us. */ struct peer *peer; @@ -72,7 +72,7 @@ HTABLE_DEFINE_TYPE(struct txwatch, txwatch_keyof, txid_hash, txwatch_eq, struct txwatch *watch_txid_(const tal_t *ctx, - struct topology *topo, + struct chain_topology *topo, struct peer *peer, const struct sha256_double *txid, enum watch_result (*cb)(struct peer *peer, @@ -91,7 +91,7 @@ struct txwatch *watch_txid_(const tal_t *ctx, (cbdata)) struct txwatch *watch_tx_(const tal_t *ctx, - struct topology *topo, + struct chain_topology *topo, struct peer *peer, const struct bitcoin_tx *tx, enum watch_result (*cb)(struct peer *peer, @@ -110,7 +110,7 @@ struct txwatch *watch_tx_(const tal_t *ctx, (cbdata)) struct txowatch *watch_txo_(const tal_t *ctx, - struct topology *topo, + struct chain_topology *topo, struct peer *peer, const struct sha256_double *txid, unsigned int output, @@ -129,16 +129,16 @@ struct txowatch *watch_txo_(const tal_t *ctx, size_t), \ (cbdata)) -void txwatch_fire(struct topology *topo, +void txwatch_fire(struct chain_topology *topo, const struct sha256_double *txid, unsigned int depth); -void txowatch_fire(struct topology *topo, +void txowatch_fire(struct chain_topology *topo, const struct txowatch *txow, const struct bitcoin_tx *tx, size_t input_num); -bool watching_txid(const struct topology *topo, +bool watching_txid(const struct chain_topology *topo, const struct sha256_double *txid); -void watch_topology_changed(struct topology *topo); +void watch_topology_changed(struct chain_topology *topo); #endif /* LIGHTNING_DAEMON_WATCH_H */ diff --git a/lightningd/lightningd.c b/lightningd/lightningd.c index e8e3190ee..f536ed495 100644 --- a/lightningd/lightningd.c +++ b/lightningd/lightningd.c @@ -42,7 +42,7 @@ struct peer *find_peer(struct lightningd_state *dstate, const struct pubkey *id) FIXME_IMPLEMENT(); } -size_t get_tx_depth(const struct topology *topo, +size_t get_tx_depth(const struct chain_topology *topo, const struct sha256_double *txid) { FIXME_IMPLEMENT(); @@ -54,7 +54,7 @@ void debug_dump_peers(struct lightningd_state *dstate) FIXME_IMPLEMENT(); } -u32 get_block_height(const struct topology *topo) +u32 get_block_height(const struct chain_topology *topo) { /* FIXME_IMPLEMENT(); */ return 0;