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: cbfe0cac566e^
Choose a base ref
...
head repository: rustyrussell/pettycoin
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 95c00a253188
Choose a head ref
  • 20 commits
  • 69 files changed
  • 1 contributor

Commits on Sep 15, 2014

  1. recv_block: log block height when we get error.

    Usually it's UNKNOWN_PREV (ie. we're syncing); it's good to know what
    block we're up to.
    
    Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
    rustyrussell committed Sep 15, 2014
    Copy the full SHA
    cbfe0ca View commit details
  2. peer: remove erroneous peers from the cache.

    We kept reconnecting to a peer when a bug caused a bad welcome.  Rename
    close_peer to close_bad_peer to make it really clear.
    
    Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
    rustyrussell committed Sep 15, 2014
    Copy the full SHA
    59114ca View commit details
  3. peer: change peer port when they give is a listen port.

    This way we match the cache; the actual port they connected from is in
    the log prefix already.
    
    Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
    rustyrussell committed Sep 15, 2014
    Copy the full SHA
    df2b2dc View commit details
  4. protocol: fix endian annotation on listen_port.

    We treat it as le16 everywhere, the definition is wrong.
    
    Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
    rustyrussell committed Sep 15, 2014
    Copy the full SHA
    2b0d537 View commit details
  5. difficulty: more helper functions.

    Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
    rustyrussell committed Sep 15, 2014
    Copy the full SHA
    4fb3d3e View commit details
  6. protocol: add multiple previous block hashes to block hash (BREAKS PR…

    …OTOCOL)
    
    Include the hashes of multiple previous blocks, not just the height-1
    block.
    
    The idea of such a structure (sometimes called an SPV skipchain) came
    from bitcoin discussions, but it's particularly powerful for coins
    with a horizon like pettycoin.
    
    It allows discarding of some most blocks while maintaining proof that
    work was done.  With a 10 second block time, we generate 3,153,600
    blocks a year: 3.2GB with 1k blocks.  Using the skipchain we can weed
    this down by a factor of 10 (more if we're lucky, a bit less if we're
    unlucky).
    
    I came across this idea in Mark Friedenbach's post on Compact SPV proofs:
      http://sourceforge.net/p/bitcoin/mailman/message/32111357/
    
    But he traces the original idea to Andrew Miller's "The High-Value-Hash
    Highway":
      https://bitcointalk.org/index.php?topic=98986.0
    
    Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
    rustyrussell committed Sep 15, 2014
    Copy the full SHA
    3888f64 View commit details
  7. protocol: check prev field on new blocks.

    Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
    rustyrussell committed Sep 15, 2014
    Copy the full SHA
    81e87a1 View commit details
  8. protocol: fixed 8k interest bitmap (BREAKS PROTOCOL)

    Might as well spell it out; it's only 8k.
    
    Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
    rustyrussell committed Sep 15, 2014
    Copy the full SHA
    d0b20ca View commit details
  9. Move detached block handing into its own file.

    We'll want this for syncing, too.
    
    Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
    rustyrussell committed Sep 15, 2014
    Copy the full SHA
    ba1a944 View commit details
  10. recv_block: handle blocks which aren't inside protocol_pkt_block.

    We're going to change protocol_pkt_welcome to include a marshaled block,
    but all the code assumes a protocol_pkt_block.  Remove this assumption,
    though we still need to pass in the tal'ed ptr, so we can steal it.
    
    This lets us fix a wart in the submitblock JSON API, too: it doesn't
    need the protocol_pkt_block header any more.
    
    Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
    rustyrussell committed Sep 15, 2014
    Copy the full SHA
    14fe8bb View commit details
  11. num_prevs() function.

    Helper to calculate how many (non-zero) previous hashes we have.
    
    Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
    rustyrussell committed Sep 15, 2014
    Copy the full SHA
    57e47bc View commit details
  12. protocol: Make welcome include "best" block (BREAKS PROTOCOL)

    This approach is inspired by Gregory Maxwell's Reverse_header-fetching_sync:
    https://en.bitcoin.it/wiki/User:Gmaxwell/Reverse_header-fetching_sync
    
    It's made more powerful by the presence of multiple previous block
    pointers, so we can get much more parallelism.
    
    We don't currently compare results across different peers, so we could
    be lead down the garden path by some peer.
    
    Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
    rustyrussell committed Sep 15, 2014
    Copy the full SHA
    93af978 View commit details
  13. pending: Remove incorrect comment, document weird behaviour.

    I noticed that after a json sendrawtransaction injection, the node
    was doing a PROTOCOL_PKT_GET_TX for transactions it already had.  This is
    because add_pending_tx() returns ECODE_INPUT_UNKNOWN as it doesn't look
    in the pending queue for inputs.
    
    It's a wart, but it's not a fatal flaw.
    
    Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
    rustyrussell committed Sep 15, 2014
    Copy the full SHA
    fc3c883 View commit details
  14. recv_block: get as many ancestors as we can at once.

    This has the advantage that the queries can spread across multiple peers.
    
    Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
    rustyrussell committed Sep 15, 2014
    Copy the full SHA
    c34b4d2 View commit details
  15. protocol: hash children for syncing (BREAKS PROTOCOL)

    This makes sure we've got the correct tree, rather than just using a
    counter.
    
    Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
    rustyrussell committed Sep 15, 2014
    Copy the full SHA
    f5912be View commit details
  16. recv_block: calculate minimum possible difficulty.

    Using 1/16 of last block's difficulty is wrong for very old blocks:
    get more sophisticated by calculating minimum based on what we do
    know.
    
    Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
    rustyrussell committed Sep 15, 2014
    Copy the full SHA
    ba2623f View commit details
  17. protocol: fix fee calculation (BREAKS PROTOCOL)

    We should charge 0.3% of the actual transferred amount (ie. not
    including change).
    
    Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
    rustyrussell committed Sep 15, 2014
    Copy the full SHA
    98e98b0 View commit details
  18. pettycoin-generate: don't need timestamp.o

    Use ccan/time directly, too.
    
    Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
    rustyrussell committed Sep 15, 2014
    Copy the full SHA
    26616e5 View commit details
  19. Rename shard_nums to num_txs

    Simple renaming: it really is the number of transactions within
    each shard, so num_txs[] is clearer.
    
    Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
    rustyrussell committed Sep 15, 2014
    Copy the full SHA
    070f983 View commit details
  20. block_info: structure to contain block on the wire.

    Since we're going to change it for merge mining, encapsulate it now to
    avoid massive refactor confusing the block structure.
    
    Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
    rustyrussell committed Sep 15, 2014
    Copy the full SHA
    95c00a2 View commit details
Showing with 1,151 additions and 982 deletions.
  1. +2 −2 Makefile.in
  2. +4 −4 TODO.md
  3. +15 −27 block.c
  4. +3 −10 block.h
  5. +3 −2 block_shard.c
  6. +1 −1 block_shard.h
  7. +5 −15 blockfile.c
  8. +29 −24 chain.c
  9. +2 −1 chain.h
  10. +36 −30 check_block.c
  11. +2 −6 check_block.h
  12. +3 −3 check_tx.c
  13. +6 −6 complain.c
  14. +4 −4 create_refs.c
  15. +66 −0 detached_block.c
  16. +22 −0 detached_block.h
  17. +73 −13 difficulty.c
  18. +6 −0 difficulty.h
  19. +2 −2 features.c
  20. +10 −7 generating.c
  21. +2 −1 getinfo.c
  22. +2 −2 gettransaction.c
  23. +3 −3 hash_block.c
  24. +5 −4 input_refs.c
  25. +2 −2 listtransactions.c
  26. +26 −42 marshal.c
  27. +5 −21 marshal.h
  28. +11 −9 mkgenesis.c
  29. +91 −77 peer.c
  30. +9 −0 peer.h
  31. +4 −6 peer_wants.c
  32. +3 −3 pending.c
  33. +39 −35 pettycoin-generate.c
  34. +27 −0 prev_blocks.c
  35. +11 −0 prev_blocks.h
  36. +3 −3 prev_txhashes.c
  37. +3 −3 proof.c
  38. +8 −3 protocol.h
  39. +1 −0 protocol_ecode.h
  40. +12 −39 protocol_net.h
  41. +123 −109 recv_block.c
  42. +4 −0 recv_block.h
  43. +1 −1 recv_tx.c
  44. +9 −9 reward.c
  45. +1 −1 state.c
  46. +1 −1 state.h
  47. +58 −100 sync.c
  48. +0 −11 sync.h
  49. +3 −5 tal_packet.c
  50. +3 −3 tal_packet.h
  51. +4 −1 test/blackbox/test-01-sync.sh
  52. +73 −8 test/run-01-difficulty.c
  53. +24 −25 test/run-01-marshal.c
  54. +27 −21 test/run-02-generate.c
  55. +18 −11 test/run-02-prev_txhashes.c
  56. +28 −23 test/run-03-check_block.c
  57. +28 −23 test/run-04-create_normal_transaction.c
  58. +38 −33 test/run-05-create_to_gateway_transaction.c
  59. +19 −14 test/run-05-proof.c
  60. +39 −41 test/run-07-block_swizzle.c
  61. +15 −8 test/run-08-simple-chain.c
  62. +6 −6 test/run-08-tx_shard.c
  63. +16 −9 test/run-09-chain.c
  64. +1 −7 timestamp.c
  65. +6 −2 timestamp.h
  66. +23 −0 tx.c
  67. +4 −1 tx.h
  68. +15 −97 welcome.c
  69. +3 −2 welcome.h
4 changes: 2 additions & 2 deletions Makefile.in
Original file line number Diff line number Diff line change
@@ -7,8 +7,8 @@
# blackbox-check: run the blackbox tests
# update-mocks: regenerate the mocks for the unit tests.

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 merkle_recurse.o tx_cmp.o genesis.o marshal.o hash_block.o prev_txhashes.o state.o tal_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 complain.o block_shard.o recv_block.o input_refs.o peer_wants.o inputhash.o tx_in_hashes.o merkle_hashes.o recv_tx.o reward.o recv_complain.o json.o jsonrpc.o getinfo.o ecode_names.o sendrawtransaction.c pettycoin_dir.o pkt_names.o hex.o listtransactions.o json_add_tx.o gettransaction.o
PETTYCOIN_GENERATE_OBJS := pettycoin-generate.o merkle_hashes.o merkle_recurse.o hash_tx.o tx_cmp.o shadouble.o marshal.o minimal_log.o timestamp.o tal_packet.o hex.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 merkle_recurse.o tx_cmp.o genesis.o marshal.o hash_block.o prev_txhashes.o state.o tal_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 complain.o block_shard.o recv_block.o input_refs.o peer_wants.o inputhash.o tx_in_hashes.o merkle_hashes.o recv_tx.o reward.o recv_complain.o json.o jsonrpc.o getinfo.o ecode_names.o sendrawtransaction.c pettycoin_dir.o pkt_names.o hex.o listtransactions.o json_add_tx.o gettransaction.o prev_blocks.o detached_block.o
PETTYCOIN_GENERATE_OBJS := pettycoin-generate.o merkle_hashes.o merkle_recurse.o hash_tx.o tx_cmp.o shadouble.o marshal.o minimal_log.o tal_packet.o hex.o
MKGENESIS_OBJS := mkgenesis.o shadouble.o hash_block.o merkle_hashes.o merkle_recurse.o minimal_log.o
SIZES_OBJS := sizes.o
MKPRIV_OBJS := mkpriv.o
8 changes: 4 additions & 4 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -54,16 +54,16 @@ Before Alpha02:

* Include power of 2 previous blocks in prev
* Would allow SPV-style block skips which would enable foldover reward on ancient blocks.
* Multiple gateways
* Requires a mechanism to create new gateways.
* Simplify welcome message to have 64k bits always.
* 8k simply isn't that much, and it's simpler.
* Complaint for tx in wrong shard.
* If someone managed to sneak this into the network presently, there'd
be no way for nodes to report it.
* Fix fee calculation
* It's currently 3/1024 of the total, it should be 0.3% of the non-change
amount.
* Multiple gateways
* Requires a mechanism to create new gateways.
* Simplify welcome message to have 64k bits always.
* 8k simply isn't that much, and it's simpler.
* Merge mining
* Means larger blocks, but we'll want this eventually.
* Network time consensus
42 changes: 15 additions & 27 deletions block.c
Original file line number Diff line number Diff line change
@@ -32,30 +32,23 @@ static void destroy_block(struct block *b)
static struct block *new_block(const tal_t *ctx,
BIGNUM *prev_work,
const struct protocol_block_id *sha,
const struct protocol_block_header *hdr,
const u8 *shard_nums,
const struct protocol_double_sha *merkles,
const u8 *prev_txhashes,
const struct protocol_block_tailer *tailer)
const struct block_info *bi)
{
struct block *block = tal(ctx, struct block);
unsigned int i;

total_work_done(le32_to_cpu(tailer->difficulty),
total_work_done(le32_to_cpu(bi->tailer->difficulty),
prev_work, &block->total_work);

block->hdr = hdr;
block->shard_nums = shard_nums;
block->merkles = merkles;
block->prev_txhashes = prev_txhashes;
block->tailer = tailer;
block->bi = *bi;
block->all_known = false;
list_head_init(&block->children);
block->sha = *sha;
block->shard = tal_arr(block, struct block_shard *, num_shards(hdr));
for (i = 0; i < num_shards(hdr); i++)
block->shard = tal_arr(block, struct block_shard *,
num_shards(bi->hdr));
for (i = 0; i < num_shards(bi->hdr); i++)
block->shard[i] = new_block_shard(block->shard, i,
shard_nums[i]);
bi->num_txs[i]);

/* In case we destroy before block_add(), eg. testing. */
block->prev = NULL;
@@ -67,20 +60,15 @@ static struct block *new_block(const tal_t *ctx,
struct block *block_add(struct state *state,
struct block *prev,
const struct protocol_block_id *sha,
const struct protocol_block_header *hdr,
const u8 *shard_nums,
const struct protocol_double_sha *merkles,
const u8 *prev_txhashes,
const struct protocol_block_tailer *tailer)
const struct block_info *bi)
{
u32 height = le32_to_cpu(hdr->height);
u32 height = le32_to_cpu(bi->hdr->height);
struct block *block;

log_debug(state->log, "Adding block %u ", height);
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);
block = new_block(state, &prev->total_work, sha, bi);
block->prev = prev;

/* Add to list for that generation. */
@@ -149,7 +137,7 @@ bool block_all_known(const struct block *block)
{
unsigned int i;

for (i = 0; i < num_shards(block->hdr); i++) {
for (i = 0; i < num_shards(block->bi.hdr); i++) {
if (!shard_all_known(block->shard[i]))
return false;
}
@@ -161,7 +149,7 @@ struct protocol_input_ref *block_get_refs(const struct block *block,
{
const struct block_shard *s = block->shard[shardnum];

assert(shardnum < num_shards(block->hdr));
assert(shardnum < num_shards(block->bi.hdr));
assert(txoff < s->size);

if (!shard_is_tx(s, txoff))
@@ -176,7 +164,7 @@ union protocol_tx *block_get_tx(const struct block *block,
{
const struct block_shard *s = block->shard[shardnum];

assert(shardnum < num_shards(block->hdr));
assert(shardnum < num_shards(block->bi.hdr));
assert(txoff < s->size);

if (!shard_is_tx(s, txoff))
@@ -189,8 +177,8 @@ bool block_empty(const struct block *block)
{
unsigned int i;

for (i = 0; i < num_shards(block->hdr); i++) {
if (block->shard_nums[i] != 0)
for (i = 0; i < num_shards(block->bi.hdr); i++) {
if (block->bi.num_txs[i] != 0)
return false;
}
return true;
13 changes: 3 additions & 10 deletions block.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef PETTYCOIN_BLOCK_H
#define PETTYCOIN_BLOCK_H
#include "config.h"
#include "block_info.h"
#include "block_shard.h"
#include "protocol.h"
#include "protocol_net.h"
@@ -34,11 +35,7 @@ struct block {
struct block *prev;

/* The block itself: */
const struct protocol_block_header *hdr;
const u8 *shard_nums;
const struct protocol_double_sha *merkles;
const u8 *prev_txhashes;
const struct protocol_block_tailer *tailer;
struct block_info bi;

/* This is set if there's a problem with the block (or ancestor). */
const void *complaint;
@@ -70,11 +67,7 @@ static inline const struct block *genesis_block(const struct state *state)
struct block *block_add(struct state *state,
struct block *prev,
const struct protocol_block_id *sha,
const struct protocol_block_header *hdr,
const u8 *shard_nums,
const struct protocol_double_sha *merkles,
const u8 *prev_txhashes,
const struct protocol_block_tailer *tailer);
const struct block_info *bi);

/* Get tx_idx'th tx inside shard shardnum inside block. */
union protocol_tx *block_get_tx(const struct block *block, u16 shardnum,
5 changes: 3 additions & 2 deletions block_shard.c
Original file line number Diff line number Diff line change
@@ -75,7 +75,7 @@ void check_block_shard(struct state *state,
{
unsigned int i, txcount = 0, hashcount = 0;

assert(shard->size == block->shard_nums[shard->shardnum]);
assert(shard->size == block_num_txs(&block->bi, shard->shardnum));

if (shard_all_hashes(shard))
assert(!shard->proof);
@@ -123,7 +123,8 @@ void check_block_shard(struct state *state,
if (txcount + hashcount == shard->size) {
struct protocol_double_sha sha;
merkle_txs(shard, &sha);
assert(structeq(&sha, &block->merkles[shard->shardnum]));
assert(structeq(&sha, block_merkle(&block->bi,
shard->shardnum)));
}
}

2 changes: 1 addition & 1 deletion block_shard.h
Original file line number Diff line number Diff line change
@@ -30,7 +30,7 @@ struct block_shard {
/* How many transaction hashes do we have? */
u8 hashcount;

/* What's our max (== block->shard_nums[shard->shardnum]) */
/* What's our max (== block->num_txs[shard->shardnum]) */
u8 size;

/* If we don't know all hashes, we store array of proofs here. */
20 changes: 5 additions & 15 deletions blockfile.c
Original file line number Diff line number Diff line change
@@ -24,26 +24,18 @@ static bool load_block(struct state *state, struct protocol_net_hdr *pkt)
{
struct block *prev, *block;
enum protocol_ecode e;
const u8 *shard_nums;
const struct protocol_double_sha *merkles;
const u8 *prev_txhashes;
const struct protocol_block_tailer *tailer;
const struct protocol_block_header *hdr;
struct block_info bi;
struct protocol_block_id sha;

e = unmarshal_block(state->log, (void *)pkt,
&hdr, &shard_nums, &merkles, &prev_txhashes,
&tailer);
e = unmarshal_block(state->log, (void *)pkt, &bi);
if (e != PROTOCOL_ECODE_NONE)
return false;

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

block = block_add(state, prev, &sha,
hdr, shard_nums, merkles, prev_txhashes, tailer);
block = block_add(state, prev, &sha, &bi);

/* Now new block owns the packet. */
tal_steal(block, pkt);
@@ -170,9 +162,7 @@ void save_block(struct state *state, struct block *new)
if (state->blockfd == -1)
return;

blk = marshal_block(state,
new->hdr, new->shard_nums, new->merkles,
new->prev_txhashes, new->tailer);
blk = marshal_block(state, &new->bi);
len = le32_to_cpu(blk->len);

if (!write_all(state->blockfd, blk, len))
53 changes: 29 additions & 24 deletions chain.c
Original file line number Diff line number Diff line change
@@ -7,6 +7,7 @@
#include "jsonrpc.h"
#include "peer.h"
#include "pending.h"
#include "prev_blocks.h"
#include "shard.h"
#include "tal_arr.h"
#include "todo.h"
@@ -28,15 +29,15 @@ struct block *step_towards(const struct block *curr, const struct block *target)
const struct block *prev_target;

/* Move back towards target. */
while (le32_to_cpu(curr->hdr->height) > le32_to_cpu(target->hdr->height))
while (block_height(&curr->bi) > block_height(&target->bi))
curr = curr->prev;

/* Already past it, or equal to it */
if (curr == target)
return NULL;

/* Move target back towards curr. */
while (le32_to_cpu(target->hdr->height) > le32_to_cpu(curr->hdr->height)) {
while (block_height(&target->bi) > block_height(&curr->bi)) {
prev_target = target;
target = target->prev;
}
@@ -129,14 +130,17 @@ void check_chains(struct state *state, bool all)
num_next_level = 0;
list_for_each(state->block_height[n], i, list) {
const struct block *b;
assert(le32_to_cpu(i->hdr->height) == n);
assert(block_height(&i->bi) == n);
assert(num_this_level);
num_this_level--;
if (n == 0)
assert(i == genesis_block(state));
else {
assert(structeq(&i->hdr->prev_block,
&i->prev->sha));
struct protocol_block_id prevs
[PROTOCOL_NUM_PREV_IDS];
make_prev_blocks(b->prev, prevs);
assert(memcmp(block_prev(&i->bi, 0), prevs,
sizeof(prevs) == 0));
if (i->prev->complaint)
assert(i->complaint);
}
@@ -332,7 +336,7 @@ static void new_longest(struct state *state, const struct block *block)
{
if (block->pending_features && !state->upcoming_features) {
/* Be conservative, halve estimate of time to confirm feature */
time_t impact = le32_to_cpu(block->tailer->timestamp)
time_t impact = block_timestamp(&block->bi)
+ (PROTOCOL_FEATURE_CONFIRM_DELAY
* PROTOCOL_BLOCK_TARGET_TIME(state->test_net) / 2);
struct tm *when;
@@ -407,8 +411,8 @@ void update_block_ptrs_new_block(struct state *state, struct block *block)
* update_block_ptrs_new_shard() directly, since that would
* call update_known multiple times if block completely
* known, which breaks the longest_known[] calc. */
for (i = 0; i < num_shards(block->hdr); i++) {
if (block->shard_nums[i] == 0)
for (i = 0; i < num_shards(block->bi.hdr); i++) {
if (block->bi.num_txs[i] == 0)
update_block_ptrs_new_shard_or_empty(state, block, i);
}
if (block_all_known(block)) {
@@ -526,32 +530,33 @@ static char *json_getblock(struct json_connection *jcon,

json_object_start(response, NULL);
json_add_block_id(response, "hash", &b->sha);
json_add_num(response, "version", b->hdr->version);
json_add_num(response, "features_vote", b->hdr->features_vote);
json_add_num(response, "shard_order", b->hdr->shard_order);
json_add_num(response, "nonce1", le32_to_cpu(b->tailer->nonce1));
json_add_hex(response, "nonce2", b->hdr->nonce2,
sizeof(b->hdr->nonce2));
json_add_num(response, "height", le32_to_cpu(b->hdr->height));
json_add_num(response, "version", b->bi.hdr->version);
json_add_num(response, "features_vote", b->bi.hdr->features_vote);
json_add_num(response, "shard_order", b->bi.hdr->shard_order);
json_add_num(response, "nonce1", le32_to_cpu(b->bi.tailer->nonce1));
json_add_hex(response, "nonce2", b->bi.hdr->nonce2,
sizeof(b->bi.hdr->nonce2));
json_add_num(response, "height", block_height(&b->bi));
json_add_address(response, "fees_to",
jcon->state->test_net, &b->hdr->fees_to);
json_add_num(response, "timestamp",
le32_to_cpu(b->tailer->timestamp));
json_add_num(response, "difficulty",
le32_to_cpu(b->tailer->difficulty));
json_add_block_id(response, "prev", &b->hdr->prev_block);
jcon->state->test_net, &b->bi.hdr->fees_to);
json_add_num(response, "timestamp", block_timestamp(&b->bi));
json_add_num(response, "difficulty", block_difficulty(&b->bi));
json_array_start(response, "prevs");
for (i = 0; i < PROTOCOL_NUM_PREV_IDS; i++)
json_add_block_id(response, NULL, block_prev(&b->bi, i));
json_array_end(response);
json_array_start(response, "next");
list_for_each(&b->children, b2, sibling)
json_add_block_id(response, NULL, &b2->sha);
json_array_end(response);

json_array_start(response, "merkles");
for (shardnum = 0; shardnum < num_shards(b->hdr); shardnum++)
json_add_double_sha(response, NULL, &b->merkles[shardnum]);
for (shardnum = 0; shardnum < num_shards(b->bi.hdr); shardnum++)
json_add_double_sha(response, NULL, &b->bi.merkles[shardnum]);
json_array_end(response);

json_array_start(response, "shards");
for (shardnum = 0; shardnum < num_shards(b->hdr); shardnum++) {
for (shardnum = 0; shardnum < num_shards(b->bi.hdr); shardnum++) {
struct block_shard *s = b->shard[shardnum];

json_array_start(response, NULL);
3 changes: 2 additions & 1 deletion chain.h
Original file line number Diff line number Diff line change
@@ -15,7 +15,8 @@ static inline bool block_preceeds(const struct block *a, const struct block *b)
if (a == b)
return true;

if (le32_to_cpu(a->hdr->height) >= le32_to_cpu(b->hdr->height))
if (le32_to_cpu(a->bi.hdr->height)
>= le32_to_cpu(b->bi.hdr->height))
return false;

return block_preceeds(a, b->prev);
Loading