forked from rustyrussell/pettycoin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
chain.h
59 lines (46 loc) · 1.75 KB
/
chain.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/* Helpers for navigating the block chain(s) */
#ifndef PETTYCOIN_CHAIN_H
#define PETTYCOIN_CHAIN_H
#include "config.h"
#include "block.h"
#include <ccan/short_types/short_types.h>
#include <stdbool.h>
struct block;
struct state;
/* Is a in the chain before b (or == b)? */
static inline bool block_preceeds(const struct block *a, const struct block *b)
{
if (a == b)
return true;
if (le32_to_cpu(a->bi.hdr->height)
>= le32_to_cpu(b->bi.hdr->height))
return false;
return block_preceeds(a, b->prev);
}
/* Follow ->prev count times. */
static inline struct block *block_ancestor(const struct block *a,
unsigned int count)
{
struct block *b;
/* FIXME: Slow! Optimize if both on main chain! */
for (b = cast_const(struct block *, a); count && b; count--)
b = b->prev;
return b;
}
/* Find common ancestor of curr and target, then first descendent
* towards target. NULL if curr == target (or a descendent). */
struct block *step_towards(const struct block *curr, const struct block *target);
/* We've added a new block; update state->longest_chains, state->longest_knowns,
state->longest_known_descendents as required. */
void update_block_ptrs_new_block(struct state *state, struct block *block);
/* We've added a new shard; update state->longest_chains, state->longest_knowns,
state->longest_known_descendents as required. */
void update_block_ptrs_new_shard(struct state *state, struct block *block,
u16 shardnum);
/* We've invalidated a block. */
void update_block_ptrs_invalidated(struct state *state, const struct block *block);
/* Are enough predecessors known that we can mine? */
bool predecessors_all_known(const struct block *b);
/* Debugging check */
void check_chains(struct state *state, bool all);
#endif /* PETTYCOIN_CHAIN_H */