summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
2a03b7b)
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
derive(0, index, seed, hash);
}
derive(0, index, seed, hash);
}
+shachain_index_t shachain_next_index(const struct shachain *chain)
+{
+ return chain->min_index - 1;
+}
+
void shachain_init(struct shachain *chain)
{
chain->num_valid = 0;
void shachain_init(struct shachain *chain)
{
chain->num_valid = 0;
+ /* This is 0 in the case where SHACHAIN_BITS is 64. */
+ chain->min_index = (shachain_index_t)((UINT64_MAX >> (64 - SHACHAIN_BITS)) + 1);
}
bool shachain_add_hash(struct shachain *chain,
}
bool shachain_add_hash(struct shachain *chain,
unsigned int i, pos;
/* You have to insert them in order! */
unsigned int i, pos;
/* You have to insert them in order! */
- assert(index == chain->min_index - 1 ||
- (index == (shachain_index_t)(UINT64_MAX >> (64 - SHACHAIN_BITS))
- && chain->num_valid == 0));
+ assert(index == shachain_next_index(chain));
pos = count_trailing_zeroes(index);
pos = count_trailing_zeroes(index);
*/
void shachain_init(struct shachain *chain);
*/
void shachain_init(struct shachain *chain);
+/**
+ * shachain_next_index - what's the next index I can add to the shachain?
+ * @chain: the chain
+ *
+ * This returns 0xFFFFFFFFFFFFFFFF (for a freshly
+ * initialized chain), or one less than the previously successfully
+ * added value.
+ */
+shachain_index_t shachain_next_index(const struct shachain *chain);
+
/**
* shachain_add_hash - record the hash for the next index.
* @chain: the chain to add to
* @index: the index of the hash
* @hash: the hash value.
*
/**
* shachain_add_hash - record the hash for the next index.
* @chain: the chain to add to
* @index: the index of the hash
* @hash: the hash value.
*
- * You can only add index 0xFFFFFFFFFFFFFFFF (for a freshly
- * initialized chain), or one less than the previously successfully
- * added value.
+ * You can only add shachain_next_index(@chain).
*
* This can fail (return false without altering @chain) if the hash
* for this index isn't consistent with previous hashes (ie. wasn't
* generated from the same seed), though it can't always detect that.
*
* This can fail (return false without altering @chain) if the hash
* for this index isn't consistent with previous hashes (ie. wasn't
* generated from the same seed), though it can't always detect that.
- * If the hash is inconsistent yet undetected, the next addition will
+ * If the hash is inconsistent yet undetected, a future addition will
uint64_t i, j;
/* This is how many tests you plan to run */
uint64_t i, j;
/* This is how many tests you plan to run */
- plan_tests(NUM_TESTS * 3 + NUM_TESTS * (NUM_TESTS + 1) - 1);
+ plan_tests(NUM_TESTS * 4 + NUM_TESTS * (NUM_TESTS + 1) - 1);
memset(&seed, 0, sizeof(seed));
/* Generate a whole heap. */
memset(&seed, 0, sizeof(seed));
/* Generate a whole heap. */
i--) {
struct sha256 hash;
int expidx = 0xFFFFFFFFFFFFFFFFULL - i;
i--) {
struct sha256 hash;
int expidx = 0xFFFFFFFFFFFFFFFFULL - i;
+ ok1(shachain_next_index(&chain) == i);
ok1(shachain_add_hash(&chain, i, &expect[expidx]));
for (j = i; j != 0; j++) {
ok1(shachain_get_hash(&chain, j, &hash));
ok1(shachain_add_hash(&chain, i, &expect[expidx]));
for (j = i; j != 0; j++) {
ok1(shachain_get_hash(&chain, j, &hash));