forked from rustyrussell/pettycoin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
features.c
31 lines (27 loc) · 846 Bytes
/
features.c
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
#include "block.h"
#include "features.h"
#include <ccan/array_size/array_size.h>
u8 pending_features(const struct block *block)
{
u32 feature_counts[8] = { 0 };
const struct block *b;
unsigned int i, j;
u8 result = 0;
/* We only update pending features every FEATURE_VOTE_BLOCKS blocks */
if (block_height(&block->bi) % PROTOCOL_FEATURE_VOTE_BLOCKS != 0)
return block->prev->pending_features;
for (b = block, i = 0;
i < PROTOCOL_FEATURE_VOTE_BLOCKS;
i++, b = b->prev) {
for (j = 0; j < ARRAY_SIZE(feature_counts); j++) {
if (b->bi.hdr->features_vote & (1 << j))
feature_counts[j]++;
}
}
/* If 75% of blocks accept feature, we have supermajority. */
for (j = 0; j < ARRAY_SIZE(feature_counts); j++) {
if (feature_counts[j] * 4 / PROTOCOL_FEATURE_VOTE_BLOCKS >= 3)
result |= 1 << j;
}
return result;
}