Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: rustyrussell/pettycoin
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: ed62a32f985a
Choose a base ref
...
head repository: rustyrussell/pettycoin
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: d9a5640ee0e1
Choose a head ref
  • 13 commits
  • 76 files changed
  • 1 contributor

Commits on Aug 27, 2014

  1. tools: fix update-ccan.sh

    We need to ignore ccan/Makefile.
    
    Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
    rustyrussell committed Aug 27, 2014
    Copy the full SHA
    8bee460 View commit details

Commits on Aug 29, 2014

  1. ccan: update

    In particular, I saw an assert() in ccan/io.
    
    Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
    rustyrussell committed Aug 29, 2014
    Copy the full SHA
    b4c4bce View commit details
  2. peer: remove welcome_blocks.

    We we only need it within welcome_received().
    
    Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
    rustyrussell committed Aug 29, 2014
    Copy the full SHA
    c81e2aa View commit details
  3. protocol: remove block_find().

    An old relic, unused.
    
    Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
    rustyrussell committed Aug 29, 2014
    Copy the full SHA
    cc95605 View commit details
  4. test/easygenesis.c: generate automatically.

    We can generate it, so we should.
    
    Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
    rustyrussell committed Aug 29, 2014
    Copy the full SHA
    dd588b3 View commit details
  5. protocol: clean up header comments.

    Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
    rustyrussell committed Aug 29, 2014
    Copy the full SHA
    6315dcc View commit details
  6. cleanup: make an explicit protocol_block_id and protocol_tx_id types.

    They're just normal double SHAs, but it's a bit more typesafe.
    
    Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
    rustyrussell committed Aug 29, 2014
    Copy the full SHA
    e18ec40 View commit details
  7. json, logging, packet: add helpers for protocol_block_id/protocol_tx_id

    Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
    rustyrussell committed Aug 29, 2014
    Copy the full SHA
    6b56723 View commit details
  8. protocol: use the protocol_block_id type.

    No changes on the wire.
    
    Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
    rustyrussell committed Aug 29, 2014
    Copy the full SHA
    4aec084 View commit details
  9. check_block: make sure difficulty value is valid.

    This becomes more important as we start keeping blocks where we don't
    know all the ancestors, hence don't immediately validate difficulty.
    
    Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
    rustyrussell committed Aug 29, 2014
    Copy the full SHA
    72ff829 View commit details
  10. peer: don't log connection until after we've checked for dups.

    This happens a lot during testing, and it's confusing.
    
    Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
    rustyrussell committed Aug 29, 2014
    Copy the full SHA
    cef65d5 View commit details
  11. log: don't call strlen on LOG_IO buffers.

    As found by valgrind.
    
    Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
    rustyrussell committed Aug 29, 2014
    Copy the full SHA
    2a6a111 View commit details
  12. pettycoin-generate: quit as soon as stdin closes.

    I noticed that I was getting:
    
    	pettycoin-generate: ''I'm not trying to cause a b-big s-s-sensation'': Broken pipe
    
    Which can happen if pettycoin-generate is supposed to close *just* as
    it is writing the solution, but should be extremely rare.
    
    In practice, it was ignoring the zero reads from stdin, which it shouldn't;
    it should ignore EWOULDBLOCK.  I renamed the function and didn't use it
    where unnecessary, for increased clarity.
    
    Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
    rustyrussell committed Aug 29, 2014
    Copy the full SHA
    d9a5640 View commit details
Showing with 572 additions and 460 deletions.
  1. +4 −17 block.c
  2. +3 −5 block.h
  3. +2 −2 blockfile.c
  4. +1 −1 ccan/README
  5. +14 −14 ccan/ccan/endian/endian.h
  6. +3 −2 ccan/ccan/io/backend.h
  7. +2 −1 ccan/ccan/io/io.c
  8. +15 −29 ccan/ccan/io/poll.c
  9. +34 −1 ccan/ccan/list/list.h
  10. +14 −1 ccan/ccan/list/test/run.c
  11. +2 −2 ccan/ccan/tal/str/_info
  12. +8 −8 chain.c
  13. +8 −6 check_block.c
  14. +1 −1 check_tx.c
  15. +5 −5 complain.c
  16. +1 −1 create_refs.c
  17. +1 −1 create_tx.c
  18. +1 −1 create_tx.h
  19. +19 −0 difficulty.h
  20. +1 −1 dumbwallet.c
  21. +1 −1 generating.c
  22. +1 −1 getinfo.c
  23. +1 −1 gettransaction.c
  24. +2 −3 hash_tx.c
  25. +3 −3 hash_tx.h
  26. +3 −3 inputhash.c
  27. +4 −4 inputhash.h
  28. +12 −0 json.c
  29. +8 −0 json.h
  30. +4 −4 json_add_tx.c
  31. +10 −2 log.c
  32. +9 −3 log_helper.c
  33. +1 −1 merkle_hashes.c
  34. +1 −1 merkle_txs.c
  35. +5 −5 mkgenesis.c
  36. +27 −27 peer.c
  37. +0 −3 peer.h
  38. +3 −3 pending.c
  39. +1 −1 pending.h
  40. +8 −23 pettycoin-generate.c
  41. +5 −5 pettycoin-tx.c
  42. +1 −1 proof.c
  43. +23 −5 protocol.h
  44. +1 −0 protocol_ecode.h
  45. +14 −14 protocol_net.h
  46. +16 −17 recv_block.c
  47. +4 −4 recv_complain.c
  48. +2 −2 recv_tx.c
  49. +1 −1 reward.c
  50. +5 −5 sendrawtransaction.c
  51. +9 −10 sync.c
  52. +13 −1 tal_packet.c
  53. +13 −1 tal_packet.h
  54. +1 −0 test/.gitignore
  55. +8 −0 test/Makefile
  56. +0 −51 test/easy_genesis.c
  57. +1 −1 test/run-01-create_gateway_transaction.c
  58. +6 −6 test/run-02-generate.c
  59. +11 −4 test/run-02-prev_txhashes.c
  60. +18 −11 test/run-03-check_block.c
  61. +15 −8 test/run-04-create_normal_transaction.c
  62. +16 −9 test/run-05-create_to_gateway_transaction.c
  63. +14 −7 test/run-05-proof.c
  64. +1 −2 test/run-06-log.c
  65. +21 −14 test/run-07-block_swizzle.c
  66. +11 −4 test/run-08-simple-chain.c
  67. +12 −5 test/run-09-chain.c
  68. +35 −32 todo.c
  69. +13 −14 todo.h
  70. +1 −1 tools/update-ccan.sh
  71. +9 −9 tx_in_hashes.c
  72. +5 −5 tx_in_hashes.h
  73. +6 −6 txhash.c
  74. +12 −11 txhash.h
  75. +5 −5 welcome.c
  76. +1 −1 welcome.h
21 changes: 4 additions & 17 deletions block.c
Original file line number Diff line number Diff line change
@@ -31,7 +31,7 @@ static void destroy_block(struct block *b)
/* This allocates the block but doesn't sew it into data structures. */
static struct block *new_block(const tal_t *ctx,
BIGNUM *prev_work,
const struct protocol_double_sha *sha,
const struct protocol_block_id *sha,
const struct protocol_block_header *hdr,
const u8 *shard_nums,
const struct protocol_double_sha *merkles,
@@ -64,22 +64,9 @@ static struct block *new_block(const tal_t *ctx,
return block;
}

struct block *block_find(struct block *start, const u8 lower_sha[4])
{
struct block *b = start;

while (b) {
if (memcmp(b->sha.sha, lower_sha, 4) == 0)
break;

b = b->prev;
}
return b;
}

struct block *block_add(struct state *state,
struct block *prev,
const struct protocol_double_sha *sha,
const struct protocol_block_id *sha,
const struct protocol_block_header *hdr,
const u8 *shard_nums,
const struct protocol_double_sha *merkles,
@@ -90,7 +77,7 @@ struct block *block_add(struct state *state,
struct block *block;

log_debug(state->log, "Adding block %u ", height);
log_add_struct(state->log, struct protocol_double_sha, sha);
log_add_struct(state->log, struct protocol_block_id, sha);

block = new_block(state, &prev->total_work, sha, hdr, shard_nums,
merkles, prev_txhashes, tailer);
@@ -143,7 +130,7 @@ struct block *block_add(struct state *state,

/* FIXME: use hash table. */
struct block *block_find_any(struct state *state,
const struct protocol_double_sha *sha)
const struct protocol_block_id *sha)
{
int i, n = tal_count(state->block_height);
struct block *b;
8 changes: 3 additions & 5 deletions block.h
Original file line number Diff line number Diff line change
@@ -44,18 +44,16 @@ struct block {
const void *complaint;

/* Cache double SHA of block */
struct protocol_double_sha sha;
struct protocol_block_id sha;
/* Transactions: may not be fully populated. */
struct block_shard **shard;
};

/* Find on this chain. */
struct state;
struct block *block_find(struct block *start, const u8 lower_sha[4]);

/* Find anywhere. */
struct block *block_find_any(struct state *state,
const struct protocol_double_sha *sha);
const struct protocol_block_id *sha);

/* Do we have every tx in this block? */
bool block_all_known(const struct block *block);
@@ -71,7 +69,7 @@ static inline const struct block *genesis_block(const struct state *state)
/* Create a new block and add into the state structure. */
struct block *block_add(struct state *state,
struct block *prev,
const struct protocol_double_sha *sha,
const struct protocol_block_id *sha,
const struct protocol_block_header *hdr,
const u8 *shard_nums,
const struct protocol_double_sha *merkles,
4 changes: 2 additions & 2 deletions blockfile.c
Original file line number Diff line number Diff line change
@@ -29,7 +29,7 @@ static bool load_block(struct state *state, struct protocol_net_hdr *pkt)
const u8 *prev_txhashes;
const struct protocol_block_tailer *tailer;
const struct protocol_block_header *hdr;
struct protocol_double_sha sha;
struct protocol_block_id sha;

e = unmarshal_block(state->log, (void *)pkt,
&hdr, &shard_nums, &merkles, &prev_txhashes,
@@ -38,7 +38,7 @@ static bool load_block(struct state *state, struct protocol_net_hdr *pkt)
return false;

e = check_block_header(state, hdr, shard_nums, merkles, prev_txhashes,
tailer, &prev, &sha);
tailer, &prev, &sha.sha);
if (e != PROTOCOL_ECODE_NONE)
return false;

2 changes: 1 addition & 1 deletion ccan/README
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
CCAN imported from http://ccodearchive.net.

CCAN version: init-1901-g8976261
CCAN version: init-1909-gf3c9280
28 changes: 14 additions & 14 deletions ccan/ccan/endian/endian.h
Original file line number Diff line number Diff line change
@@ -16,8 +16,8 @@
* };
*/
#define BSWAP_16(val) \
((((uint16_t)val & 0x00ff) << 8) \
| (((uint16_t)val & 0xff00) >> 8))
((((uint16_t)(val) & 0x00ff) << 8) \
| (((uint16_t)(val) & 0xff00) >> 8))

/**
* BSWAP_32 - reverse bytes in a constant uint32_t value.
@@ -31,10 +31,10 @@
* };
*/
#define BSWAP_32(val) \
((((uint32_t)val & 0x000000ff) << 24) \
| (((uint32_t)val & 0x0000ff00) << 8) \
| (((uint32_t)val & 0x00ff0000) >> 8) \
| (((uint32_t)val & 0xff000000) >> 24))
((((uint32_t)(val) & 0x000000ff) << 24) \
| (((uint32_t)(val) & 0x0000ff00) << 8) \
| (((uint32_t)(val) & 0x00ff0000) >> 8) \
| (((uint32_t)(val) & 0xff000000) >> 24))

/**
* BSWAP_64 - reverse bytes in a constant uint64_t value.
@@ -48,14 +48,14 @@
* };
*/
#define BSWAP_64(val) \
((((uint64_t)val & 0x00000000000000ffULL) << 56) \
| (((uint64_t)val & 0x000000000000ff00ULL) << 40) \
| (((uint64_t)val & 0x0000000000ff0000ULL) << 24) \
| (((uint64_t)val & 0x00000000ff000000ULL) << 8) \
| (((uint64_t)val & 0x000000ff00000000ULL) >> 8) \
| (((uint64_t)val & 0x0000ff0000000000ULL) >> 24) \
| (((uint64_t)val & 0x00ff000000000000ULL) >> 40) \
| (((uint64_t)val & 0xff00000000000000ULL) >> 56))
((((uint64_t)(val) & 0x00000000000000ffULL) << 56) \
| (((uint64_t)(val) & 0x000000000000ff00ULL) << 40) \
| (((uint64_t)(val) & 0x0000000000ff0000ULL) << 24) \
| (((uint64_t)(val) & 0x00000000ff000000ULL) << 8) \
| (((uint64_t)(val) & 0x000000ff00000000ULL) >> 8) \
| (((uint64_t)(val) & 0x0000ff0000000000ULL) >> 24) \
| (((uint64_t)(val) & 0x00ff000000000000ULL) >> 40) \
| (((uint64_t)(val) & 0xff00000000000000ULL) >> 56))

#if HAVE_BYTESWAP_H
#include <byteswap.h>
5 changes: 3 additions & 2 deletions ccan/ccan/io/backend.h
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@
#include <stdbool.h>
#include <poll.h>
#include "io_plan.h"
#include <ccan/list/list.h>

struct fd {
int fd;
@@ -62,8 +63,8 @@ struct io_conn {
/* For duplex to save. */
bool debug_saved;

/* always or closing list. */
struct io_conn *list;
/* always and closing lists. */
struct list_node always, closing;

void (*finish)(struct io_conn *, void *arg);
void *finish_arg;
3 changes: 2 additions & 1 deletion ccan/ccan/io/io.c
Original file line number Diff line number Diff line change
@@ -92,7 +92,8 @@ struct io_conn *io_new_conn_(const tal_t *ctx, int fd,
conn->fd.fd = fd;
conn->finish = NULL;
conn->finish_arg = NULL;
conn->list = NULL;
list_node_init(&conn->always);
list_node_init(&conn->closing);
conn->debug = false;

if (!add_conn(conn))
44 changes: 15 additions & 29 deletions ccan/ccan/io/poll.c
Original file line number Diff line number Diff line change
@@ -8,14 +8,14 @@
#include <sys/socket.h>
#include <limits.h>
#include <errno.h>
#include <ccan/list/list.h>
#include <ccan/time/time.h>
#include <ccan/timer/timer.h>

static size_t num_fds = 0, max_fds = 0, num_waiting = 0;
static struct pollfd *pollfds = NULL;
static struct fd **fds = NULL;
static struct io_conn *closing = NULL, *always = NULL;
static LIST_HEAD(closing);
static LIST_HEAD(always);

static bool add_fd(struct fd *fd, short events)
{
@@ -96,31 +96,21 @@ bool add_listener(struct io_listener *l)

void remove_from_always(struct io_conn *conn)
{
struct io_conn **p = &always;

while (*p != conn)
p = &(*p)->list;

*p = conn->list;
list_del_init(&conn->always);
}

void backend_new_closing(struct io_conn *conn)
{
/* Already on always list? Remove it. */
if (conn->list)
remove_from_always(conn);

conn->list = closing;
closing = conn;
/* In case it's on always list, remove it. */
list_del_init(&conn->always);
list_add_tail(&closing, &conn->closing);
}

void backend_new_always(struct io_conn *conn)
{
/* May already be in always list (other plan), or closing. */
if (!conn->list) {
conn->list = always;
always = conn;
}
/* In case it's already in always list. */
list_del(&conn->always);
list_add_tail(&always, &conn->always);
}

void backend_new_plan(struct io_conn *conn)
@@ -202,14 +192,12 @@ static void accept_conn(struct io_listener *l)
static bool close_conns(void)
{
bool ret = false;
struct io_conn *conn;

while (closing) {
struct io_conn *conn = closing;

while ((conn = list_pop(&closing, struct io_conn, closing)) != NULL) {
assert(conn->plan[IO_IN].status == IO_CLOSING);
assert(conn->plan[IO_OUT].status == IO_CLOSING);

closing = closing->list;
del_conn(conn);
ret = true;
}
@@ -219,16 +207,14 @@ static bool close_conns(void)
static bool handle_always(void)
{
bool ret = false;
struct io_conn *conn;

while (always) {
struct io_conn *conn = always;

while ((conn = list_pop(&always, struct io_conn, always)) != NULL) {
assert(conn->plan[IO_IN].status == IO_ALWAYS
|| conn->plan[IO_OUT].status == IO_ALWAYS);

/* Remove from list, and mark it so it knows that. */
always = always->list;
conn->list = NULL;
/* Re-initialize, for next time. */
list_node_init(&conn->always);
io_do_always(conn);
ret = true;
}
35 changes: 34 additions & 1 deletion ccan/ccan/list/list.h
Original file line number Diff line number Diff line change
@@ -145,6 +145,18 @@ static inline void list_head_init(struct list_head *h)
h->n.next = h->n.prev = &h->n;
}

/**
* list_node_init - initialize a list_node
* @n: the list_node to link to itself.
*
* You don't need to use this normally! But it lets you list_del(@n)
* safely.
*/
static inline void list_node_init(struct list_node *n)
{
n->next = n->prev = n;
}

/**
* list_add - add an entry at the start of a linked list.
* @h: the list_head to add the node to
@@ -237,7 +249,7 @@ static inline bool list_empty_nodebug(const struct list_head *h)
* another list, but not deleted again.
*
* See also:
* list_del_from()
* list_del_from(), list_del_init()
*
* Example:
* list_del(&child->list);
@@ -255,6 +267,27 @@ static inline void list_del_(struct list_node *n, const char* abortstr)
#endif
}

/**
* list_del_init - delete a node, and reset it so it can be deleted again.
* @n: the list_node to be deleted.
*
* list_del(@n) or list_del_init() again after this will be safe,
* which can be useful in some cases.
*
* See also:
* list_del_from(), list_del()
*
* Example:
* list_del_init(&child->list);
* parent->num_children--;
*/
#define list_del_init(n) list_del_init_(n, LIST_LOC)
static inline void list_del_init_(struct list_node *n, const char *abortstr)
{
list_del_(n, abortstr);
list_node_init(n);
}

/**
* list_del_from - delete an entry from a known linked list.
* @h: the list_head the node is in.
15 changes: 14 additions & 1 deletion ccan/ccan/list/test/run.c
Original file line number Diff line number Diff line change
@@ -25,7 +25,7 @@ int main(int argc, char *argv[])
opaque_t *q, *nq;
struct list_head opaque_list = LIST_HEAD_INIT(opaque_list);

plan_tests(68);
plan_tests(70);
/* Test LIST_HEAD, LIST_HEAD_INIT, list_empty and check_list */
ok1(list_empty(&static_list));
ok1(list_check(&static_list, NULL));
@@ -155,6 +155,19 @@ int main(int argc, char *argv[])
ok1(i == 3);
ok1(list_empty(&parent.children));

/* Test list_node_init: safe to list_del after this. */
list_node_init(&c->list);
list_del(&c->list);

/* Test list_del_init */
list_add(&parent.children, &c->list);
ok1(!list_empty(&parent.children));
list_del_init(&c->list);
ok1(list_empty(&parent.children));
/* We can call this as many times as we like. */
list_del_init(&c->list);
list_del_init(&c->list);

/* Test list_for_each_off. */
list_add_tail(&opaque_list,
(struct list_node *)create_opaque_blob());
4 changes: 2 additions & 2 deletions ccan/ccan/tal/str/_info
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@
*
* Example:
* #include <ccan/tal/str/str.h>
* #include <ccan/grab_file/grab_file.h>
* #include <ccan/tal/grab_file/grab_file.h>
* #include <err.h>
*
* // Dumb demo program to double-linespace a file.
@@ -21,7 +21,7 @@
* char **lines;
*
* // Grab lines in file.
* textfile = grab_file(NULL, argv[1], NULL);
* textfile = grab_file(NULL, argv[1]);
* if (!textfile)
* err(1, "Failed reading %s", argv[1]);
* lines = tal_strsplit(textfile, textfile, "\n", STR_EMPTY_OK);
Loading