Skip to content

Commit ef04aec

Browse files
committed
BIP 8: Fix timeout logic
1 parent 8e906f1 commit ef04aec

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

bip-0008.mediawiki

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -118,21 +118,16 @@ We remain in the initial state until we reach the start block height.
118118
}
119119
return DEFINED;
120120
121-
After a period in the STARTED state, if we're past the timeout, we switch to LOCKED_IN or FAILING. If not, we tally the bits set,
121+
After a period in the STARTED state, we tally the bits set,
122122
and transition to LOCKED_IN if a sufficient number of blocks in the past period set the deployment bit in their
123123
version numbers. The threshold is ≥1916 blocks (95% of 2016), or ≥1512 for testnet (75% of 2016).
124-
The transition to FAILING takes precedence, as otherwise an ambiguity can arise.
125-
There could be two non-overlapping deployments on the same bit, where the first one transitions to LOCKED_IN while the
126-
other one simultaneously transitions to STARTED, which would mean both would demand setting the bit.
124+
If the threshold hasn't been met, and we reach the timeout, then we either transition to LOCKED_IN state anyway (if lockinontimeout is true), or we transition to FAILING.
127125
128126
Note that a block's state never depends on its own nVersion; only on that of its ancestors.
129127
130128
case STARTED:
131-
if (block.height >= timeoutheight) {
132-
return (lockinontimeout == true) ? LOCKED_IN : FAILING;
133-
134129
int count = 0;
135-
walk = block;
130+
walk = block.parent;
136131
for (i = 0; i < 2016; i++) {
137132
walk = walk.parent;
138133
if (walk.nVersion & 0xE0000000 == 0x20000000 && (walk.nVersion >> bit) & 1 == 1) {
@@ -141,6 +136,8 @@ Note that a block's state never depends on its own nVersion; only on that of its
141136
}
142137
if (count >= threshold) {
143138
return LOCKED_IN;
139+
} else if (block.height >= timeoutheight) {
140+
return (lockinontimeout == true) ? LOCKED_IN : FAILING;
144141
}
145142
return STARTED;
146143

0 commit comments

Comments
 (0)