Browse Source

daemon/peer: keep our own node connection information.

Note that the base fee is in millisatoshi, the proportional fee is
in microsatoshi per satoshi. ie. 1,000,000 means charge 1 satoshi for
every satoshi carried.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ppa-0.6.1
Rusty Russell 8 years ago
parent
commit
f994a44827
  1. 36
      daemon/lightningd.c
  2. 4
      daemon/lightningd.h
  3. 17
      daemon/peer.c
  4. 3
      daemon/peer.h

36
daemon/lightningd.c

@ -59,6 +59,22 @@ static char *opt_set_u32(const char *arg, u32 *u)
return NULL; return NULL;
} }
static char *opt_set_s32(const char *arg, s32 *u)
{
char *endp;
long l;
/* This is how the manpage says to do it. Yech. */
errno = 0;
l = strtol(arg, &endp, 0);
if (*endp || !arg[0])
return tal_fmt(NULL, "'%s' is not a number", arg);
*u = l;
if (errno || *u != l)
return tal_fmt(NULL, "'%s' is out of range", arg);
return NULL;
}
static void opt_show_u64(char buf[OPT_SHOW_LEN], const u64 *u) static void opt_show_u64(char buf[OPT_SHOW_LEN], const u64 *u)
{ {
snprintf(buf, OPT_SHOW_LEN, "%"PRIu64, *u); snprintf(buf, OPT_SHOW_LEN, "%"PRIu64, *u);
@ -69,6 +85,11 @@ static void opt_show_u32(char buf[OPT_SHOW_LEN], const u32 *u)
snprintf(buf, OPT_SHOW_LEN, "%"PRIu32, *u); snprintf(buf, OPT_SHOW_LEN, "%"PRIu32, *u);
} }
static void opt_show_s32(char buf[OPT_SHOW_LEN], const s32 *u)
{
snprintf(buf, OPT_SHOW_LEN, "%"PRIi32, *u);
}
static void config_register_opts(struct lightningd_state *dstate) static void config_register_opts(struct lightningd_state *dstate)
{ {
opt_register_arg("--locktime-blocks", opt_set_u32, opt_show_u32, opt_register_arg("--locktime-blocks", opt_set_u32, opt_show_u32,
@ -107,6 +128,13 @@ static void config_register_opts(struct lightningd_state *dstate)
opt_register_arg("--commit-time", opt_set_time, opt_show_time, opt_register_arg("--commit-time", opt_set_time, opt_show_time,
&dstate->config.commit_time, &dstate->config.commit_time,
"Time after changes before sending out COMMIT"); "Time after changes before sending out COMMIT");
opt_register_arg("--fee-base", opt_set_u32, opt_show_u32,
&dstate->config.fee_base,
"Millisatoshi minimum to charge for HTLC");
opt_register_arg("--fee-per-satoshi", opt_set_s32, opt_show_s32,
&dstate->config.fee_per_satoshi,
"Microsatoshi fee for every satoshi in HTLC");
} }
static void default_config(struct config *config) static void default_config(struct config *config)
@ -157,6 +185,11 @@ static void default_config(struct config *config)
/* Send commit 10msec after receiving; almost immediately. */ /* Send commit 10msec after receiving; almost immediately. */
config->commit_time = time_from_msec(10); config->commit_time = time_from_msec(10);
/* Discourage dust payments */
config->fee_base = 546000;
/* Take 0.001% */
config->fee_per_satoshi = 10;
} }
static void check_config(struct lightningd_state *dstate) static void check_config(struct lightningd_state *dstate)
@ -294,7 +327,8 @@ int main(int argc, char *argv[])
/* Set up node ID and private key. */ /* Set up node ID and private key. */
secrets_init(dstate); secrets_init(dstate);
new_node(dstate, &dstate->id);
/* Initialize block topology. */ /* Initialize block topology. */
setup_topology(dstate); setup_topology(dstate);

4
daemon/lightningd.h

@ -40,6 +40,10 @@ struct config {
/* Minimum/maximum time for an expiring HTLC (blocks). */ /* Minimum/maximum time for an expiring HTLC (blocks). */
u32 min_htlc_expiry, max_htlc_expiry; u32 min_htlc_expiry, max_htlc_expiry;
/* Fee rates. */
u32 fee_base;
s32 fee_per_satoshi;
/* How long between polling bitcoind. */ /* How long between polling bitcoind. */
struct timerel poll_time; struct timerel poll_time;

17
daemon/peer.c

@ -110,8 +110,22 @@ void peer_open_complete(struct peer *peer, const char *problem)
{ {
if (problem) if (problem)
log_unusual(peer->log, "peer open failed: %s", problem); log_unusual(peer->log, "peer open failed: %s", problem);
else else {
struct lightningd_state *dstate = peer->dstate;
struct node *n;
log_debug(peer->log, "peer open complete"); log_debug(peer->log, "peer open complete");
assert(!peer->nc);
n = get_node(dstate, &peer->id);
if (!n)
n = new_node(dstate, &peer->id);
peer->nc = add_connection(dstate,
get_node(dstate, &dstate->id), n,
dstate->config.fee_base,
dstate->config.fee_per_satoshi,
dstate->config.min_htlc_expiry,
dstate->config.min_htlc_expiry);
}
} }
static void set_peer_state(struct peer *peer, enum state newstate, static void set_peer_state(struct peer *peer, enum state newstate,
@ -824,6 +838,7 @@ static struct peer *new_peer(struct lightningd_state *dstate,
peer->closing_onchain.resolved = NULL; peer->closing_onchain.resolved = NULL;
peer->closing_onchain.ci = NULL; peer->closing_onchain.ci = NULL;
peer->commit_timer = NULL; peer->commit_timer = NULL;
peer->nc = NULL;
/* Make it different from other node (to catch bugs!), but a /* Make it different from other node (to catch bugs!), but a
* round number for simple eyeballing. */ * round number for simple eyeballing. */
peer->htlc_id_counter = pseudorand(1ULL << 32) * 1000; peer->htlc_id_counter = pseudorand(1ULL << 32) * 1000;

3
daemon/peer.h

@ -211,6 +211,9 @@ struct peer {
/* Private keys for dealing with this peer. */ /* Private keys for dealing with this peer. */
struct peer_secrets *secrets; struct peer_secrets *secrets;
/* Our route connection to peer: NULL until we are in normal mode. */
struct node_connection *nc;
/* For testing. */ /* For testing. */
bool fake_close; bool fake_close;
bool output_enabled; bool output_enabled;

Loading…
Cancel
Save