Skip to content

Commit

Permalink
Revert "Don't read scripts if we don't need them."
Browse files Browse the repository at this point in the history
Makes basically no difference in performance now we're using a
bump allocator, and AJ points out that we skipped some important
cases where we needed them.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
  • Loading branch information
rustyrussell committed Jan 4, 2016
1 parent b306d82 commit f72fdfb
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 34 deletions.
12 changes: 2 additions & 10 deletions iterate.c
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,7 @@ int main(int argc, char *argv[])
*inputfmt = NULL, *outputfmt = NULL, *cachedir = NULL;
size_t i, block_count = 0;
off_t last_discard;
bool quiet = false, needs_utxo, read_scripts, needs_fee;
bool quiet = false, needs_utxo, needs_fee;
unsigned long block_start = 0, block_end = -1UL;
struct block *b, *best, *genesis = NULL, *next, *start = NULL;
struct block_map block_map;
Expand Down Expand Up @@ -948,13 +948,6 @@ int main(int argc, char *argv[])

utxo_map_init(&utxo_map);

/* Optimization: figure out if we need input/output scripts. */
read_scripts = false;
if (inputfmt && strstr(inputfmt, "%is"))
read_scripts = true;
if (outputfmt && strstr(outputfmt, "%os"))
read_scripts = true;

/* Optimization: figure out of we have to maintain UTXO map */
needs_utxo = false;

Expand Down Expand Up @@ -1038,8 +1031,7 @@ int main(int argc, char *argv[])
off_t txoff = off;

read_bitcoin_transaction(&space, &tx[i],
block_file(b->filenum), &off,
read_scripts);
block_file(b->filenum), &off);

if (!start && txfmt)
print_format(txfmt, &utxo_map, b, &tx[i], i,
Expand Down
31 changes: 9 additions & 22 deletions parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,42 +75,29 @@ static void pull_hash(struct file *f, off_t *poff, u8 dst[32])
}

static void read_input(struct space *space, struct file *f, off_t *poff,
struct bitcoin_transaction_input *input,
bool read_scripts)
struct bitcoin_transaction_input *input)
{
pull_hash(f, poff, input->hash);
input->index = pull_u32(f, poff);
input->script_length = pull_varint(f, poff);
if (read_scripts) {
input->script = space_alloc(space, input->script_length);
pull_bytes(f, poff, input->script, input->script_length);
} else {
input->script = NULL;
*poff += input->script_length;
}
input->script = space_alloc(space, input->script_length);
pull_bytes(f, poff, input->script, input->script_length);

input->sequence_number = pull_u32(f, poff);
}

static void read_output(struct space *space, struct file *f, off_t *poff,
struct bitcoin_transaction_output *output,
bool read_scripts)
struct bitcoin_transaction_output *output)
{
output->amount = pull_u64(f, poff);
output->script_length = pull_varint(f, poff);
if (read_scripts) {
output->script = space_alloc(space, output->script_length);
pull_bytes(f, poff, output->script, output->script_length);
} else {
output->script = NULL;
*poff += output->script_length;
}
output->script = space_alloc(space, output->script_length);
pull_bytes(f, poff, output->script, output->script_length);
}

void read_bitcoin_transaction(struct space *space,
struct bitcoin_transaction *trans,
struct file *f, off_t *poff,
bool read_scripts)
struct file *f, off_t *poff)
{
size_t i;
off_t start = *poff;
Expand All @@ -122,13 +109,13 @@ void read_bitcoin_transaction(struct space *space,
struct bitcoin_transaction_input,
trans->input_count);
for (i = 0; i < trans->input_count; i++)
read_input(space, f, poff, trans->input + i, read_scripts);
read_input(space, f, poff, trans->input + i);
trans->output_count = pull_varint(f, poff);
trans->output = space_alloc_arr(space,
struct bitcoin_transaction_output,
trans->output_count);
for (i = 0; i < trans->output_count; i++)
read_output(space, f, poff, trans->output + i, read_scripts);
read_output(space, f, poff, trans->output + i);
trans->lock_time = pull_u32(f, poff);

/* Bitcoin uses double sha (it's not quite known why...) */
Expand Down
3 changes: 1 addition & 2 deletions parse.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,5 @@ void skip_bitcoin_transactions(const struct bitcoin_block *b,
/* ... read them in (call this repeatedly). Allocates off ctx. */
void read_bitcoin_transaction(struct space *space,
struct bitcoin_transaction *t,
struct file *f, off_t *off,
bool read_scripts);
struct file *f, off_t *off);
#endif /* BITCOIN_PARSE_PARSE_H */

0 comments on commit f72fdfb

Please sign in to comment.