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: 8fe6c6624cd2
Choose a base ref
...
head repository: rustyrussell/pettycoin
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: db9bfa2d471f
Choose a head ref
  • 3 commits
  • 13 files changed
  • 1 contributor

Commits on Sep 16, 2014

  1. reward: fix reward modulus calculation.

    Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
    rustyrussell committed Sep 16, 2014
    Copy the full SHA
    0cb301a View commit details
  2. pettycoin-generate: seperate out make_shard_pkt function for easier t…

    …esting.
    
    Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
    rustyrussell committed Sep 16, 2014
    Copy the full SHA
    96732e7 View commit details
  3. inputhash: fix use-after-free which allowed doublespend (Fixes #34)

    When we freed a pending tx, we freed the hash entries for the input
    hash.  We manage those hash entries manually, since they're shared by
    any number of txs (on separate chains).
    
    Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
    rustyrussell committed Sep 16, 2014
    Copy the full SHA
    db9bfa2 View commit details
Showing with 527 additions and 31 deletions.
  1. +1 −1 check_block.c
  2. +5 −4 inputhash.c
  3. +3 −3 inputhash.h
  4. +19 −11 pettycoin-generate.c
  5. +1 −1 reward.c
  6. +1 −0 test/.gitignore
  7. +0 −1 test/run-03-check_block.c
  8. +0 −1 test/run-07-block_swizzle.c
  9. +1 −2 test/run-08-simple-chain.c
  10. +1 −2 test/run-08-tx_shard.c
  11. +492 −0 test/run-10-doublespend.c
  12. +3 −4 tx_in_hashes.c
  13. +0 −1 tx_in_hashes.h
2 changes: 1 addition & 1 deletion check_block.c
Original file line number Diff line number Diff line change
@@ -230,7 +230,7 @@ void put_tx_in_shard(struct state *state,
assert(structeq(shard->u[txoff].hash, &hashes));
shard->hashcount--;

upgrade_tx_in_hashes(state, shard, &hashes.txhash, txp.tx);
upgrade_tx_in_hashes(state, &hashes.txhash, txp.tx);
}

/* Now it's a transaction. */
9 changes: 5 additions & 4 deletions inputhash.c
Original file line number Diff line number Diff line change
@@ -69,17 +69,18 @@ struct inputhash_elem *inputhash_nextval(struct inputhash *inputhash,
i, h);
}

void inputhash_add_tx(struct inputhash *inputhash,
const tal_t *ctx,
const union protocol_tx *tx)
void inputhash_add_tx(struct state *state,
struct inputhash *inputhash, const union protocol_tx *tx)
{
unsigned int i;

for (i = 0; i < num_inputs(tx); i++) {
struct inputhash_elem *ie;
const struct protocol_input *inp = tx_input(tx, i);

ie = tal(ctx, struct inputhash_elem);
/* We allocate off state: we free up manually when
* all txs are removed from txhash */
ie = tal(state, struct inputhash_elem);
ie->output.tx = inp->input;
ie->output.output_num = le16_to_cpu(inp->output);
hash_tx(tx, &ie->used_by);
6 changes: 3 additions & 3 deletions inputhash.h
Original file line number Diff line number Diff line change
@@ -36,9 +36,9 @@ struct inputhash_elem *inputhash_nextval(struct inputhash *inputhash,
u16 output_num,
struct inputhash_iter *i);

void inputhash_add_tx(struct inputhash *inputhash,
const tal_t *ctx,
const union protocol_tx *tx);
struct state;
void inputhash_add_tx(struct state *state,
struct inputhash *inputhash, const union protocol_tx *tx);

void inputhash_del_tx(struct inputhash *inputhash, const union protocol_tx *tx);
#endif /* PETTYCOIN_INPUTHASH_H */
30 changes: 19 additions & 11 deletions pettycoin-generate.c
Original file line number Diff line number Diff line change
@@ -285,29 +285,37 @@ static void read_txs(struct working_block *w)
tal_free(update);
}

static struct protocol_pkt_shard *make_shard_pkt(const struct working_block *w,
u32 shard)
{
struct protocol_pkt_shard *s;
unsigned int i;

s = tal_packet(w, struct protocol_pkt_shard, PROTOCOL_PKT_SHARD);
s->block.sha = w->sha;
s->shard = cpu_to_le16(shard);
s->err = cpu_to_le16(PROTOCOL_ECODE_NONE);

for (i = 0; i < w->bi.num_txs[shard]; i++)
tal_packet_append_txrefhash(&s, &w->trans_hashes[shard][i]);

return s;
}

/* ''Talkin' 'bout my generation...'' */
static void write_block(int fd, const struct working_block *w)
{
struct protocol_pkt_block *b;
struct protocol_pkt_shard *s;
u32 shard, i;
u32 shard;

b = marshal_block(w, &w->bi);
if (!write_all(fd, b, le32_to_cpu(b->len)))
err(1, "''I'm not trying to cause a b-big s-s-sensation''");

/* Write out the shard hashes. */
for (shard = 0; shard < w->num_shards; shard++) {
s = tal_packet(w, struct protocol_pkt_shard,
PROTOCOL_PKT_SHARD);
s->block.sha = w->sha;
s->shard = cpu_to_le16(shard);
s->err = cpu_to_le16(PROTOCOL_ECODE_NONE);

for (i = 0; i < w->bi.num_txs[shard]; i++)
tal_packet_append_txrefhash(&s,
&w->trans_hashes[shard][i]);

s = make_shard_pkt(w, shard);
if (!write_all(fd, s, le32_to_cpu(s->len)))
err(1, "''I'm just talkin' 'bout my g-g-generation''"
" %i", shard);
2 changes: 1 addition & 1 deletion reward.c
Original file line number Diff line number Diff line change
@@ -30,7 +30,7 @@ static u32 num_txs(const struct block *b)

for (i = 0; i < block_num_shards(&b->bi); i++)
total += block_num_txs(&b->bi, i);
return i;
return total;
}

bool reward_get_tx(struct state *state,
1 change: 1 addition & 0 deletions test/.gitignore
Original file line number Diff line number Diff line change
@@ -18,5 +18,6 @@ run-07-block_swizzle
run-08-simple-chain
run-08-tx_shard
run-09-chain
run-10-doublespend
run-20-gateway
easy_genesis.c
1 change: 0 additions & 1 deletion test/run-03-check_block.c
Original file line number Diff line number Diff line change
@@ -231,7 +231,6 @@ struct txhash_elem *txhash_gettx_ancestor(struct state *state,
{ fprintf(stderr, "txhash_gettx_ancestor called!\n"); abort(); }
/* Generated stub for upgrade_tx_in_hashes */
void upgrade_tx_in_hashes(struct state *state,
const tal_t *ctx,
const struct protocol_tx_id *sha,
const union protocol_tx *tx)
{ fprintf(stderr, "upgrade_tx_in_hashes called!\n"); abort(); }
1 change: 0 additions & 1 deletion test/run-07-block_swizzle.c
Original file line number Diff line number Diff line change
@@ -224,7 +224,6 @@ struct txhash_elem *txhash_gettx_ancestor(struct state *state,
{ fprintf(stderr, "txhash_gettx_ancestor called!\n"); abort(); }
/* Generated stub for upgrade_tx_in_hashes */
void upgrade_tx_in_hashes(struct state *state,
const tal_t *ctx,
const struct protocol_tx_id *sha,
const union protocol_tx *tx)
{ fprintf(stderr, "upgrade_tx_in_hashes called!\n"); abort(); }
3 changes: 1 addition & 2 deletions test/run-08-simple-chain.c
Original file line number Diff line number Diff line change
@@ -133,8 +133,7 @@ u8 pending_features(const struct block *block)
void save_block(struct state *state, struct block *new)
{ fprintf(stderr, "save_block called!\n"); abort(); }
/* Generated stub for seek_detached_blocks */
void seek_detached_blocks(struct state *state,
const struct block *block)
void seek_detached_blocks(struct state *state, const struct block *block)
{ fprintf(stderr, "seek_detached_blocks called!\n"); abort(); }
/* Generated stub for todo_forget_about_block */
void todo_forget_about_block(struct state *state,
3 changes: 1 addition & 2 deletions test/run-08-tx_shard.c
Original file line number Diff line number Diff line change
@@ -50,8 +50,7 @@ u8 pending_features(const struct block *block)
void save_block(struct state *state, struct block *new)
{ fprintf(stderr, "save_block called!\n"); abort(); }
/* Generated stub for seek_detached_blocks */
void seek_detached_blocks(struct state *state,
const struct block *block)
void seek_detached_blocks(struct state *state, const struct block *block)
{ fprintf(stderr, "seek_detached_blocks called!\n"); abort(); }
/* Generated stub for update_block_ptrs_new_block */
void update_block_ptrs_new_block(struct state *state, struct block *block)
Loading