Skip to content

Commit

Permalink
Use 'tx' consistently for transaction.
Browse files Browse the repository at this point in the history
We used transaction, trans, and t variously.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
  • Loading branch information
rustyrussell committed Jun 25, 2014
1 parent ee1f7d3 commit 4b8e36b
Show file tree
Hide file tree
Showing 64 changed files with 1,121 additions and 1,141 deletions.
6 changes: 3 additions & 3 deletions Makefile
@@ -1,9 +1,9 @@
PETTYCOIN_OBJS := block.o check_block.o check_transaction.o difficulty.o shadouble.o timestamp.o gateways.o hash_transaction.o pettycoin.o merkle_transactions.o create_transaction.o transaction_cmp.o genesis.o marshall.o hash_block.o prev_merkles.o state.o packet.o dns.o netaddr.o peer.o peer_cache.o pseudorand.o welcome.o log.o generating.o blockfile.o pending.o log_helper.o thash.o signature.o proof.o chain.o features.o todo.o base58.o sync.o create_refs.o shard.o packet_io.o transaction.o
GENERATE_OBJS := generate.o merkle_transactions.o hash_transaction.o transaction_cmp.o shadouble.o marshall.o minimal_log.o timestamp.o
PETTYCOIN_OBJS := block.o check_block.o check_tx.o difficulty.o shadouble.o timestamp.o gateways.o hash_tx.o pettycoin.o merkle_txs.o create_tx.o tx_cmp.o genesis.o marshall.o hash_block.o prev_merkles.o state.o packet.o dns.o netaddr.o peer.o peer_cache.o pseudorand.o welcome.o log.o generating.o blockfile.o pending.o log_helper.o txhash.o signature.o proof.o chain.o features.o todo.o base58.o sync.o create_refs.o shard.o packet_io.o tx.o
GENERATE_OBJS := generate.o merkle_txs.o hash_tx.o tx_cmp.o shadouble.o marshall.o minimal_log.o timestamp.o
MKGENESIS_OBJS := mkgenesis.o shadouble.o marshall.o hash_block.o minimal_log.o
SIZES_OBJS := sizes.o
MKPRIV_OBJS := mkpriv.o
INJECT_OBJS := inject.o base58.o create_transaction.o marshall.o netaddr.o hash_transaction.o minimal_log.o shadouble.o signature.o hash_block.o
INJECT_OBJS := inject.o base58.o create_tx.o marshall.o netaddr.o hash_tx.o minimal_log.o shadouble.o signature.o hash_block.o
CCAN_OBJS := ccan-asort.o ccan-breakpoint.o ccan-tal.o ccan-tal-path.o ccan-tal-str.o ccan-take.o ccan-list.o ccan-str.o ccan-opt-helpers.o ccan-opt.o ccan-opt-parse.o ccan-opt-usage.o ccan-read_write_all.o ccan-htable.o ccan-io-io.o ccan-io-poll.o ccan-timer.o ccan-time.o ccan-noerr.o ccan-hash.o ccan-isaac64.o ccan-net.o ccan-err.o
CCANDIR=../ccan/
VERSION:=$(shell git describe --dirty --always 2>/dev/null || echo Unknown)
Expand Down
180 changes: 90 additions & 90 deletions block.c
Expand Up @@ -8,38 +8,38 @@
#include "pending.h"
#include "packet.h"
#include "proof.h"
#include "transaction.h"
#include "tx.h"
#include "features.h"
#include "shard.h"
#include <string.h>

/* For compactness, struct transaction_shard needs tx and refs adjacent. */
/* For compactness, struct tx_shard needs tx and refs adjacent. */
struct txptr_with_ref txptr_with_ref(const tal_t *ctx,
const union protocol_transaction *tx,
const union protocol_tx *tx,
const struct protocol_input_ref *refs)
{
struct txptr_with_ref txp;
size_t txlen, reflen;
char *p;

txlen = marshall_transaction_len(tx);
txlen = marshall_tx_len(tx);
reflen = num_inputs(tx) * sizeof(struct protocol_input_ref);

p = tal_alloc_(ctx, txlen + reflen, false, "txptr_with_ref");
memcpy(p, tx, txlen);
memcpy(p + txlen, refs, reflen);

txp.tx = (union protocol_transaction *)p;
txp.tx = (union protocol_tx *)p;
return txp;
}

struct transaction_shard *new_shard(const tal_t *ctx, u16 shardnum, u8 num)
struct tx_shard *new_shard(const tal_t *ctx, u16 shardnum, u8 num)
{
struct transaction_shard *s;
struct tx_shard *s;

s = tal_alloc_(ctx,
offsetof(struct transaction_shard, u[num]),
true, "struct transaction_shard");
offsetof(struct tx_shard, u[num]),
true, "struct tx_shard");
s->shardnum = shardnum;
return s;
}
Expand Down Expand Up @@ -127,7 +127,7 @@ bool block_all_known(const struct block *block, unsigned int *shardnum)
struct protocol_input_ref *block_get_refs(const struct block *block,
u16 shardnum, u8 txoff)
{
const struct transaction_shard *s = block->shard[shardnum];
const struct tx_shard *s = block->shard[shardnum];

assert(shardnum < num_shards(block->hdr));
assert(txoff < block->shard_nums[shardnum]);
Expand All @@ -141,12 +141,12 @@ struct protocol_input_ref *block_get_refs(const struct block *block,
refs_for(s->u[txoff].txp));
}

/* If we have the transaction, hash it, otherwise return hash. */
/* If we have the tx, hash it, otherwise return hash. */
const struct protocol_net_txrefhash *
txrefhash_in_shard(const struct block *b, u16 shard, u8 txoff,
struct protocol_net_txrefhash *scratch)
{
const struct transaction_shard *s = b->shard[shard];
const struct tx_shard *s = b->shard[shard];

assert(shard < num_shards(b->hdr));
assert(txoff < b->shard_nums[shard]);
Expand All @@ -155,7 +155,7 @@ txrefhash_in_shard(const struct block *b, u16 shard, u8 txoff,
return NULL;

if (shard_is_tx(s, txoff)) {
const union protocol_transaction *tx = s->u[txoff].txp.tx;
const union protocol_tx *tx = s->u[txoff].txp.tx;
if (!tx)
return NULL;
hash_tx(tx, &scratch->txhash);
Expand Down Expand Up @@ -197,79 +197,79 @@ static void invalidate_block(struct state *state,
static void
invalidate_block_bad_input(struct state *state,
struct block *block,
const union protocol_transaction *trans,
const union protocol_tx *tx,
const struct protocol_input_ref *refs,
unsigned int bad_shardnum,
unsigned int bad_txoff,
unsigned int bad_input,
const union protocol_transaction *intrans)
const union protocol_tx *intx)
{
struct protocol_pkt_block_tx_bad_input *req;

assert(le32_to_cpu(trans->hdr.type) == TRANSACTION_NORMAL);
assert(le32_to_cpu(tx->hdr.type) == TX_NORMAL);
log_unusual(state->log, "Block %u ", le32_to_cpu(block->hdr->depth));
log_add_struct(state->log, struct protocol_double_sha, &block->sha);
log_add(state->log, " invalid due to trans %u in shard %u ",
log_add(state->log, " invalid due to tx %u in shard %u ",
bad_txoff, bad_shardnum);
log_add_struct(state->log, union protocol_transaction, trans);
log_add_struct(state->log, union protocol_tx, tx);
log_add(state->log, " with bad input %u ", bad_input);
log_add_struct(state->log, union protocol_transaction, intrans);
log_add_struct(state->log, union protocol_tx, intx);

req = tal_packet(block, struct protocol_pkt_block_tx_bad_input,
PROTOCOL_PKT_BLOCK_TX_BAD_INPUT);
req->inputnum = cpu_to_le32(bad_input);

tal_packet_append_proof(&req, block, bad_shardnum, bad_txoff);
tal_packet_append_trans(&req, intrans);
tal_packet_append_tx(&req, intx);

invalidate_block(state, block, req);
}

static void
invalidate_block_bad_amounts(struct state *state,
struct block *block,
const union protocol_transaction *trans,
const union protocol_tx *tx,
const struct protocol_input_ref *refs,
unsigned int bad_shardnum,
unsigned int bad_txoff)
{
struct protocol_pkt_block_tx_bad_amount *req;
union protocol_transaction *input[TRANSACTION_MAX_INPUTS];
union protocol_tx *input[TX_MAX_INPUTS];
unsigned int i;
struct protocol_input *inp;

assert(le32_to_cpu(trans->hdr.type) == TRANSACTION_NORMAL);
assert(le32_to_cpu(tx->hdr.type) == TX_NORMAL);
log_unusual(state->log, "Block %u ", le32_to_cpu(block->hdr->depth));
log_add_struct(state->log, struct protocol_double_sha, &block->sha);
log_add(state->log, " invalid amounts in trans %u of shard %u ",
log_add(state->log, " invalid amounts in tx %u of shard %u ",
bad_txoff, bad_shardnum);
log_add_struct(state->log, union protocol_transaction, trans);
log_add_struct(state->log, union protocol_tx, tx);
log_add(state->log, " with inputs: ");

inp = get_normal_inputs(&trans->normal);
inp = get_normal_inputs(&tx->normal);

/* FIXME: What if input is pending? */
for (i = 0; i < le32_to_cpu(trans->normal.num_inputs); i++) {
input[i] = thash_gettrans(&state->thash, &inp[i].input);
log_add_struct(state->log, union protocol_transaction, input[i]);
for (i = 0; i < le32_to_cpu(tx->normal.num_inputs); i++) {
input[i] = txhash_gettx(&state->txhash, &inp[i].input);
log_add_struct(state->log, union protocol_tx, input[i]);
log_add(state->log, " (output %u)", le16_to_cpu(inp[i].output));
}

req = tal_packet(block, struct protocol_pkt_block_tx_bad_amount,
PROTOCOL_PKT_BLOCK_TX_BAD_AMOUNT);
tal_packet_append_proof(&req, block, bad_shardnum, bad_txoff);

for (i = 0; i < num_inputs(trans); i++)
tal_packet_append_trans(&req, input[i]);
for (i = 0; i < num_inputs(tx); i++)
tal_packet_append_tx(&req, input[i]);

invalidate_block(state, block, req);
}

static void
invalidate_block_bad_transaction(struct state *state,
invalidate_block_bad_tx(struct state *state,
struct block *block,
enum protocol_ecode err,
const union protocol_transaction *trans,
const union protocol_tx *tx,
const struct protocol_input_ref *refs,
unsigned int bad_shardnum,
unsigned int bad_txoff)
Expand All @@ -278,9 +278,9 @@ invalidate_block_bad_transaction(struct state *state,

log_unusual(state->log, "Block %u ", le32_to_cpu(block->hdr->depth));
log_add_struct(state->log, struct protocol_double_sha, &block->sha);
log_add(state->log, " invalid due to trans %u ofshard %u ",
log_add(state->log, " invalid due to tx %u ofshard %u ",
bad_txoff, bad_shardnum);
log_add_struct(state->log, union protocol_transaction, trans);
log_add_struct(state->log, union protocol_tx, tx);
log_add(state->log, " error ");
log_add_enum(state->log, enum protocol_ecode, err);

Expand All @@ -300,18 +300,18 @@ void invalidate_block_misorder(struct state *state,
unsigned int bad_shardnum)
{
struct protocol_pkt_block_tx_misorder *req;
const union protocol_transaction *trans1, *trans2;
const union protocol_tx *tx1, *tx2;

trans1 = block_get_tx(block, bad_shardnum, bad_txoff1);
trans2 = block_get_tx(block, bad_shardnum, bad_txoff2);
tx1 = block_get_tx(block, bad_shardnum, bad_txoff1);
tx2 = block_get_tx(block, bad_shardnum, bad_txoff2);

log_unusual(state->log, "Block %u ", le32_to_cpu(block->hdr->depth));
log_add_struct(state->log, struct protocol_double_sha, &block->sha);
log_add(state->log, " invalid due to misorder shard %u trans %u vs %u ",
log_add(state->log, " invalid due to misorder shard %u tx %u vs %u ",
bad_shardnum, bad_txoff1, bad_txoff2);
log_add_struct(state->log, union protocol_transaction, trans1);
log_add_struct(state->log, union protocol_tx, tx1);
log_add(state->log, " vs ");
log_add_struct(state->log, union protocol_transaction, trans2);
log_add_struct(state->log, union protocol_tx, tx2);

req = tal_packet(block, struct protocol_pkt_block_tx_misorder,
PROTOCOL_PKT_BLOCK_TX_MISORDER);
Expand All @@ -322,14 +322,14 @@ void invalidate_block_misorder(struct state *state,
}

static void
invalidate_block_bad_input_ref_trans(struct state *state,
struct block *block,
const union protocol_transaction *trans,
const struct protocol_input_ref *refs,
u16 bad_shard,
u8 bad_txnum,
unsigned int bad_input,
const union protocol_transaction *bad_intrans)
invalidate_block_bad_input_ref_tx(struct state *state,
struct block *block,
const union protocol_tx *tx,
const struct protocol_input_ref *refs,
u16 bad_shard,
u8 bad_txnum,
unsigned int bad_input,
const union protocol_tx *bad_intx)
{
struct protocol_pkt_block_bad_input_ref *req;
const struct protocol_input_ref *bad_ref;
Expand All @@ -340,14 +340,14 @@ invalidate_block_bad_input_ref_trans(struct state *state,

log_unusual(state->log, "Block %u ", le32_to_cpu(block->hdr->depth));
log_add_struct(state->log, struct protocol_double_sha, &block->sha);
log_unusual(state->log, " transaction %u of shard %u ", bad_txnum,
log_unusual(state->log, " tx %u of shard %u ", bad_txnum,
bad_shard);
log_add_struct(state->log, union protocol_transaction, trans);
log_add_struct(state->log, union protocol_tx, tx);
log_add(state->log,
" invalid due to wrong input %u reference %u ago tx %u/%u ",
bad_input, le32_to_cpu(bad_ref->blocks_ago),
le16_to_cpu(bad_ref->shard), bad_ref->txoff);
log_add_struct(state->log, union protocol_transaction, bad_intrans);
log_add_struct(state->log, union protocol_tx, bad_intx);

req = tal_packet(block, struct protocol_pkt_block_bad_input_ref,
PROTOCOL_PKT_BLOCK_BAD_INPUT_REF);
Expand All @@ -360,73 +360,73 @@ invalidate_block_bad_input_ref_trans(struct state *state,
invalidate_block(state, block, req);
}

/* See check_trans_normal_inputs: bad_input and bad_intrans are valid
* iff err = PROTOCOL_ECODE_PRIV_TRANS_BAD_INPUT. */
void invalidate_block_badtrans(struct state *state,
struct block *block,
enum protocol_ecode err,
unsigned int bad_shardnum,
unsigned int bad_txoff,
unsigned int bad_input,
union protocol_transaction *bad_intrans)
/* See check_tx_normal_inputs: bad_input and bad_intx are valid
* iff err = PROTOCOL_ECODE_PRIV_TX_BAD_INPUT. */
void invalidate_block_badtx(struct state *state,
struct block *block,
enum protocol_ecode err,
unsigned int bad_shardnum,
unsigned int bad_txoff,
unsigned int bad_input,
union protocol_tx *bad_intx)
{
union protocol_transaction *trans;
union protocol_tx *tx;
const struct protocol_input_ref *refs;

trans = block_get_tx(block, bad_shardnum, bad_txoff);
tx = block_get_tx(block, bad_shardnum, bad_txoff);
refs = block_get_refs(block, bad_shardnum, bad_txoff);

switch (err) {
case PROTOCOL_ECODE_TRANS_HIGH_VERSION:
case PROTOCOL_ECODE_TRANS_LOW_VERSION:
case PROTOCOL_ECODE_TRANS_UNKNOWN:
case PROTOCOL_ECODE_TOO_LARGE:
case PROTOCOL_ECODE_TRANS_BAD_SIG:
case PROTOCOL_ECODE_TX_HIGH_VERSION:
case PROTOCOL_ECODE_TX_LOW_VERSION:
case PROTOCOL_ECODE_TX_UNKNOWN:
case PROTOCOL_ECODE_TX_TOO_LARGE:
case PROTOCOL_ECODE_TX_BAD_SIG:
break;

case PROTOCOL_ECODE_TRANS_BAD_GATEWAY:
case PROTOCOL_ECODE_TRANS_CROSS_SHARDS:
assert(trans->hdr.type == TRANSACTION_FROM_GATEWAY);
case PROTOCOL_ECODE_TX_BAD_GATEWAY:
case PROTOCOL_ECODE_TX_CROSS_SHARDS:
assert(tx->hdr.type == TX_FROM_GATEWAY);
break;

case PROTOCOL_ECODE_TOO_MANY_INPUTS:
case PROTOCOL_ECODE_TX_TOO_MANY_INPUTS:
case PROTOCOL_ECODE_PRIV_BLOCK_BAD_INPUT_REF:
case PROTOCOL_ECODE_BLOCK_BAD_TX_SHARD:
assert(trans->hdr.type == TRANSACTION_NORMAL);
assert(tx->hdr.type == TX_NORMAL);
break;

case PROTOCOL_ECODE_PRIV_TRANS_BAD_INPUT:
assert(trans->hdr.type == TRANSACTION_NORMAL);
case PROTOCOL_ECODE_PRIV_TX_BAD_INPUT:
assert(tx->hdr.type == TX_NORMAL);
/* FIXME: This means an unknown input. We don't
* complain. */
if (!bad_intrans)
if (!bad_intx)
return;
invalidate_block_bad_input(state, block,
trans, refs, bad_shardnum, bad_txoff,
bad_input, bad_intrans);
tx, refs, bad_shardnum, bad_txoff,
bad_input, bad_intx);
return;

case PROTOCOL_ECODE_PRIV_TRANS_BAD_AMOUNTS:
assert(trans->hdr.type == TRANSACTION_NORMAL);
invalidate_block_bad_amounts(state, block, trans, refs,
case PROTOCOL_ECODE_PRIV_TX_BAD_AMOUNTS:
assert(tx->hdr.type == TX_NORMAL);
invalidate_block_bad_amounts(state, block, tx, refs,
bad_shardnum, bad_txoff);
return;

case PROTOCOL_ECODE_PRIV_BLOCK_BAD_INPUT_REF_TRANS:
assert(trans->hdr.type == TRANSACTION_NORMAL);
invalidate_block_bad_input_ref_trans(state, block, trans, refs,
bad_shardnum, bad_txoff,
bad_input, bad_intrans);
case PROTOCOL_ECODE_PRIV_BLOCK_BAD_INPUT_REF_TX:
assert(tx->hdr.type == TX_NORMAL);
invalidate_block_bad_input_ref_tx(state, block, tx, refs,
bad_shardnum, bad_txoff,
bad_input, bad_intx);
return;

default:
log_broken(state->log,
"Unknown invalidate_block_badtrans error ");
"Unknown invalidate_block_badtx error ");
log_add_enum(state->log, enum protocol_ecode, err);
abort();
}

/* Simple single-transaction error. */
invalidate_block_bad_transaction(state, block, err, trans, refs,
bad_shardnum, bad_txoff);
/* Simple single-transacion error. */
invalidate_block_bad_tx(state, block, err, tx, refs,
bad_shardnum, bad_txoff);
}

0 comments on commit 4b8e36b

Please sign in to comment.