Skip to content

Commit

Permalink
Make sure all protocol constants have PROTOCOL_ prefix.
Browse files Browse the repository at this point in the history
Anything which breaks compatibility with network should have 
a protocol_ prefix.  Some constants are missing them.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
  • Loading branch information
rustyrussell committed Jun 25, 2014
1 parent 4b8e36b commit 629caf4
Show file tree
Hide file tree
Showing 15 changed files with 40 additions and 39 deletions.
2 changes: 1 addition & 1 deletion block.c
Expand Up @@ -234,7 +234,7 @@ invalidate_block_bad_amounts(struct state *state,
unsigned int bad_txoff)
{
struct protocol_pkt_block_tx_bad_amount *req;
union protocol_tx *input[TX_MAX_INPUTS];
union protocol_tx *input[PROTOCOL_TX_MAX_INPUTS];
unsigned int i;
struct protocol_input *inp;

Expand Down
3 changes: 2 additions & 1 deletion chain.c
Expand Up @@ -331,7 +331,8 @@ 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)
+ FEATURE_CONFIRM_DELAY * BLOCK_TARGET_TIME / 2;
+ (PROTOCOL_FEATURE_CONFIRM_DELAY
* PROTOCOL_BLOCK_TARGET_TIME / 2);
struct tm *when;

when = localtime(&impact);
Expand Down
4 changes: 2 additions & 2 deletions check_block.c
Expand Up @@ -310,7 +310,7 @@ shard_validate_txs(struct state *state,
struct tx_shard *shard,
unsigned int *bad_trans,
unsigned int *bad_input_num,
union protocol_tx *inputs[TX_MAX_INPUTS])
union protocol_tx *inputs[PROTOCOL_TX_MAX_INPUTS])
{
unsigned int i;
enum protocol_ecode err;
Expand Down Expand Up @@ -353,7 +353,7 @@ bool check_block_prev_merkles(struct state *state, const struct block *block)
const struct block *prev;

for (i = 0, prev = block->prev;
i < PETTYCOIN_PREV_BLOCK_MERKLES && prev;
i < PROTOCOL_PREV_BLOCK_MERKLES && prev;
i++, prev = prev->prev) {
unsigned int j;

Expand Down
8 changes: 4 additions & 4 deletions check_tx.c
Expand Up @@ -29,7 +29,7 @@ check_tx_normal_basic(struct state *state, const struct protocol_tx_normal *ntx)
if (le32_to_cpu(ntx->change_amount) > MAX_SATOSHI)
return PROTOCOL_ECODE_TX_TOO_LARGE;

if (le32_to_cpu(ntx->num_inputs) > TX_MAX_INPUTS)
if (le32_to_cpu(ntx->num_inputs) > PROTOCOL_TX_MAX_INPUTS)
return PROTOCOL_ECODE_TX_TOO_MANY_INPUTS;

if (le32_to_cpu(ntx->num_inputs) == 0)
Expand Down Expand Up @@ -66,7 +66,7 @@ find_tx_for_ref(struct state *state,
if (ref->txoff >= b->shard_nums[ref->shard])
return PROTOCOL_ECODE_PRIV_BLOCK_BAD_INPUT_REF;

if (le32_to_cpu(b->tailer->timestamp) + TX_HORIZON_SECS
if (le32_to_cpu(b->tailer->timestamp) + PROTOCOL_TX_HORIZON_SECS
< le32_to_cpu(block->tailer->timestamp))
return PROTOCOL_ECODE_PRIV_BLOCK_BAD_INPUT_REF;

Expand Down Expand Up @@ -94,7 +94,7 @@ check_tx_normal_inputs(struct state *state,
const struct block *block,
const struct protocol_input_ref *refs,
unsigned int *inputs_known,
union protocol_tx *inputs[TX_MAX_INPUTS],
union protocol_tx *inputs[PROTOCOL_TX_MAX_INPUTS],
unsigned int *bad_input_num)
{
unsigned int i, num;
Expand Down Expand Up @@ -357,7 +357,7 @@ enum protocol_ecode check_tx(struct state *state,
const union protocol_tx *tx,
const struct block *block,
const struct protocol_input_ref *refs,
union protocol_tx *inputs[TX_MAX_INPUTS],
union protocol_tx *inputs[PROTOCOL_TX_MAX_INPUTS],
unsigned int *bad_input_num)
{
enum protocol_ecode e;
Expand Down
2 changes: 1 addition & 1 deletion check_tx.h
Expand Up @@ -31,7 +31,7 @@ enum protocol_ecode check_tx(struct state *state,
const union protocol_tx *trans,
const struct block *block,
const struct protocol_input_ref *refs,
union protocol_tx *inputs[TX_MAX_INPUTS],
union protocol_tx *inputs[PROTOCOL_TX_MAX_INPUTS],
unsigned int *bad_input_num);

#endif /* PETTYCOIN_CHECK_TX_H */
2 changes: 1 addition & 1 deletion create_refs.c
Expand Up @@ -33,7 +33,7 @@ static bool resolve_input(struct state *state,

/* Don't include any transactions within 1 hour of cutoff. */
if (le32_to_cpu(te->block->tailer->timestamp)
+ TX_HORIZON_SECS - CLOSE_TO_HORIZON
+ PROTOCOL_TX_HORIZON_SECS - CLOSE_TO_HORIZON
< current_time())
return false;

Expand Down
4 changes: 2 additions & 2 deletions difficulty.c
Expand Up @@ -69,8 +69,8 @@ u32 get_difficulty(struct state *state, const struct block *prev)
u32 genesis_exp, genesis_base;
const struct block *genesis = genesis_block(state), *start;

const u32 interval = DIFFICULTY_UPDATE_BLOCKS;
const u64 ideal_time = BLOCK_TARGET_TIME * interval;
const u32 interval = PROTOCOL_DIFFICULTY_UPDATE_BLOCKS;
const u64 ideal_time = PROTOCOL_BLOCK_TARGET_TIME * interval;

prev_difficulty = le32_to_cpu(prev->tailer->difficulty);

Expand Down
6 changes: 3 additions & 3 deletions features.c
Expand Up @@ -10,11 +10,11 @@ u8 pending_features(const struct block *block)
u8 result = 0;

/* We only update pending features every FEATURE_VOTE_BLOCKS blocks */
if (le32_to_cpu(block->hdr->depth) % FEATURE_VOTE_BLOCKS != 0)
if (le32_to_cpu(block->hdr->depth) % PROTOCOL_FEATURE_VOTE_BLOCKS != 0)
return block->prev->pending_features;

for (b = block, i = 0;
i < FEATURE_VOTE_BLOCKS;
i < PROTOCOL_FEATURE_VOTE_BLOCKS;
i++, b = b->prev) {
for (j = 0; j < ARRAY_SIZE(feature_counts); j++) {
if (b->hdr->features_vote & (1 << j))
Expand All @@ -24,7 +24,7 @@ u8 pending_features(const struct block *block)

/* If 75% of blocks accept feature, we have supermajority. */
for (j = 0; j < ARRAY_SIZE(feature_counts); j++) {
if (feature_counts[j] * 4 / FEATURE_VOTE_BLOCKS >= 3)
if (feature_counts[j] * 4 / PROTOCOL_FEATURE_VOTE_BLOCKS >= 3)
result |= 1 << j;
}
return result;
Expand Down
2 changes: 1 addition & 1 deletion peer.c
Expand Up @@ -1109,7 +1109,7 @@ recv_tx(struct peer *peer, const struct protocol_pkt_tx *pkt)
enum protocol_ecode e;
union protocol_tx *tx;
u32 txlen = le32_to_cpu(pkt->len) - sizeof(*pkt);
union protocol_tx *inputs[TX_MAX_INPUTS];
union protocol_tx *inputs[PROTOCOL_TX_MAX_INPUTS];
unsigned int bad_input_num;

tx = (void *)(pkt + 1);
Expand Down
2 changes: 1 addition & 1 deletion pending.c
Expand Up @@ -93,7 +93,7 @@ static size_t recheck_one_shard(struct state *state, u16 shard)
for (i = 0; i < num; i++) {
struct txhash_elem *te;
struct protocol_double_sha sha;
union protocol_tx *inputs[TX_MAX_INPUTS];
union protocol_tx *inputs[PROTOCOL_TX_MAX_INPUTS];
unsigned int bad_input_num;
enum protocol_ecode e;
struct txhash_iter iter;
Expand Down
4 changes: 2 additions & 2 deletions prev_merkles.c
Expand Up @@ -11,7 +11,7 @@ size_t num_prev_merkles(const struct block *prev)
unsigned int i;

for (i = 0;
i < PETTYCOIN_PREV_BLOCK_MERKLES && prev;
i < PROTOCOL_PREV_BLOCK_MERKLES && prev;
i++, prev = prev->prev) {
num += (1 << prev->hdr->shard_order);
}
Expand All @@ -30,7 +30,7 @@ u8 *make_prev_merkles(const tal_t *ctx, const struct block *prev,
p = m = tal_arr(ctx, u8, len);

for (i = 0;
i < PETTYCOIN_PREV_BLOCK_MERKLES && prev;
i < PROTOCOL_PREV_BLOCK_MERKLES && prev;
i++, prev = prev->prev) {
unsigned int j;

Expand Down
14 changes: 7 additions & 7 deletions protocol.h
Expand Up @@ -6,7 +6,7 @@
#include <openssl/ripemd.h>

/* How many previous blocks do we record a merkle for? */
#define PETTYCOIN_PREV_BLOCK_MERKLES 10
#define PROTOCOL_PREV_BLOCK_MERKLES 10

/* How many shards for initial blocks == 1 << PROTOCOL_INITIAL_SHARD_ORDER */
#define PROTOCOL_INITIAL_SHARD_ORDER 2
Expand All @@ -15,22 +15,22 @@
#define PROTOCOL_MAX_SHARD_ORDER 16

/* Maximum inputs in a single transaction. */
#define TX_MAX_INPUTS 4
#define PROTOCOL_TX_MAX_INPUTS 4

/* How long (seconds) until transactions are obsolete (30 days) */
#define TX_HORIZON_SECS (60 * 60 * 24 * 30)
#define PROTOCOL_TX_HORIZON_SECS (60 * 60 * 24 * 30)

/* How long between blocks (seconds) */
#define BLOCK_TARGET_TIME 600
#define PROTOCOL_BLOCK_TARGET_TIME 600

/* How many blocks form a difficulty set (1 fortnight, a-la bitcoin) */
#define DIFFICULTY_UPDATE_BLOCKS 2016
#define PROTOCOL_DIFFICULTY_UPDATE_BLOCKS 2016

/* How many blocks to join together to count features >= 75%. */
#define FEATURE_VOTE_BLOCKS 2016
#define PROTOCOL_FEATURE_VOTE_BLOCKS 2016

/* How many blocks after feature vote to increment version number. */
#define FEATURE_CONFIRM_DELAY 2016
#define PROTOCOL_FEATURE_CONFIRM_DELAY 2016

struct protocol_double_sha {
u8 sha[SHA256_DIGEST_LENGTH /* 32 */ ];
Expand Down
22 changes: 11 additions & 11 deletions sizes.c
Expand Up @@ -36,7 +36,7 @@ int main(int argc, char *argv[])
+ sizeof(struct protocol_input) * AVERAGE_INPUTS;
printf("# Assuming %f average inputs => tsize %llu bytes\n",
AVERAGE_INPUTS, tsize);
trans_per_block = tps * BLOCK_TARGET_TIME;
trans_per_block = tps * PROTOCOL_BLOCK_TARGET_TIME;
printf("Transactions per block: %llu\n", trans_per_block);
/* Increase shard order until shards are half full. */
for (shard_order = PROTOCOL_INITIAL_SHARD_ORDER;
Expand All @@ -52,12 +52,12 @@ int main(int argc, char *argv[])
merkles_per_block = (1 << shard_order);
blocksize = sizeof(struct protocol_block_header)
+ merkles_per_block * sizeof(struct protocol_double_sha)
+ merkles_per_block * PETTYCOIN_PREV_BLOCK_MERKLES
+ merkles_per_block * PROTOCOL_PREV_BLOCK_MERKLES
+ sizeof(struct protocol_block_tailer);
printf("Block size: %llu\n", blocksize);

txbytes_per_sec = tps * tsize;
blockbytes_per_sec = blocksize / BLOCK_TARGET_TIME;
blockbytes_per_sec = blocksize / PROTOCOL_BLOCK_TARGET_TIME;

printf("%-15s%15s%15s%15s %s\n",
"", "Transactions", "Blocks", "Total", "Units");
Expand All @@ -70,10 +70,10 @@ int main(int argc, char *argv[])
"bytes per second");
printf("%-15s%15llu%15llu%25s\n",
"Miners storage",
txbytes_per_sec * TX_HORIZON_SECS,
blockbytes_per_sec * TX_HORIZON_SECS,
format_si(txbytes_per_sec * TX_HORIZON_SECS
+ blockbytes_per_sec * TX_HORIZON_SECS));
txbytes_per_sec * PROTOCOL_TX_HORIZON_SECS,
blockbytes_per_sec * PROTOCOL_TX_HORIZON_SECS,
format_si(txbytes_per_sec * PROTOCOL_TX_HORIZON_SECS
+ blockbytes_per_sec * PROTOCOL_TX_HORIZON_SECS));

/* Minimal node needs two shards + every block. */
txbytes_per_sec >>= shard_order - 1;
Expand All @@ -84,9 +84,9 @@ int main(int argc, char *argv[])
"bytes per second");
printf("%-15s%15llu%15llu%25s\n",
"Minimal storage",
txbytes_per_sec * TX_HORIZON_SECS,
blockbytes_per_sec * TX_HORIZON_SECS,
format_si(txbytes_per_sec * TX_HORIZON_SECS
+ blockbytes_per_sec * TX_HORIZON_SECS));
txbytes_per_sec * PROTOCOL_TX_HORIZON_SECS,
blockbytes_per_sec * PROTOCOL_TX_HORIZON_SECS,
format_si(txbytes_per_sec * PROTOCOL_TX_HORIZON_SECS
+ blockbytes_per_sec * PROTOCOL_TX_HORIZON_SECS));
return 0;
}
2 changes: 1 addition & 1 deletion sync.c
Expand Up @@ -99,7 +99,7 @@ static const struct block *find_horizon(const struct state *state)
/* 11 in a row beyond horizon makes this fairly certain. */
while (b != genesis_block(state)) {
if (le32_to_cpu(b->tailer->timestamp)
+ TX_HORIZON_SECS + CLOSE_TO_HORIZON
+ PROTOCOL_TX_HORIZON_SECS + CLOSE_TO_HORIZON
< current_time()) {
if (!horizon)
horizon = b;
Expand Down
2 changes: 1 addition & 1 deletion test/run-04-create_normal_transaction.c
Expand Up @@ -160,7 +160,7 @@ int main(int argc, char *argv[])
enum protocol_ecode e;
struct update update;
struct protocol_input_ref *refs;
union protocol_tx *intxs[TX_MAX_INPUTS];
union protocol_tx *intxs[PROTOCOL_TX_MAX_INPUTS];

/* We need enough of state to use the real init function here. */
pseudorand_init();
Expand Down

0 comments on commit 629caf4

Please sign in to comment.