Skip to content

Commit 5973746

Browse files
mratsimzah
authored andcommitted
Fork choice update for HF1
1 parent 3d25f0d commit 5973746

File tree

3 files changed

+206
-222
lines changed

3 files changed

+206
-222
lines changed

beacon_chain/fork_choice/fork_choice.nim

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ proc compute_slots_since_epoch_start(slot: Slot): uint64 =
9797

9898
proc on_tick(self: var Checkpoints, dag: ChainDAGRef, time: Slot): FcResult[void] =
9999
if self.time > time:
100-
return err(ForkChoiceError(kind: fcInconsistentTick))
100+
return err ForkChoiceError(kind: fcInconsistentTick)
101101

102102
let newEpoch = self.time.epoch() != time.epoch()
103103
self.time = time
@@ -106,8 +106,9 @@ proc on_tick(self: var Checkpoints, dag: ChainDAGRef, time: Slot): FcResult[void
106106
self.best_justified.epoch > self.justified.epoch:
107107
let blck = dag.getRef(self.best_justified.root)
108108
if blck.isNil:
109-
return err(ForkChoiceError(
110-
kind: fcJustifiedNodeUnknown, block_root: self.best_justified.root))
109+
return err ForkChoiceError(
110+
kind: fcJustifiedNodeUnknown,
111+
blockRoot: self.best_justified.root)
111112

112113
let epochRef = dag.getEpochRef(blck, self.best_justified.epoch)
113114
self.justified = BalanceCheckpoint(
@@ -117,6 +118,7 @@ proc on_tick(self: var Checkpoints, dag: ChainDAGRef, time: Slot): FcResult[void
117118
ok()
118119

119120
proc process_attestation_queue(self: var ForkChoice) {.gcsafe.}
121+
120122
proc update_time(self: var ForkChoice, dag: ChainDAGRef, time: Slot): FcResult[void] =
121123
if time > self.checkpoints.time:
122124
while time > self.checkpoints.time:
@@ -209,8 +211,9 @@ proc should_update_justified_checkpoint(
209211
justified_blck = dag.getRef(new_justified_checkpoint.root)
210212

211213
if justified_blck.isNil:
212-
return err(ForkChoiceError(
213-
kind: fcJustifiedNodeUnknown, block_root: new_justified_checkpoint.root))
214+
return err ForkChoiceError(
215+
kind: fcJustifiedNodeUnknown,
216+
blockRoot: new_justified_checkpoint.root)
214217

215218
let justified_ancestor = justified_blck.atSlot(justified_slot)
216219

@@ -275,7 +278,7 @@ proc process_block*(self: var ForkChoiceBackend,
275278
parent_root: Eth2Digest,
276279
justified_epoch: Epoch,
277280
finalized_epoch: Epoch): FcResult[void] =
278-
self.proto_array.on_block(
281+
self.proto_array.onBlock(
279282
block_root, parent_root, justified_epoch, finalized_epoch)
280283

281284
proc process_block*(self: var ForkChoice,
@@ -336,15 +339,15 @@ proc find_head*(
336339
)
337340

338341
# Apply score changes
339-
? self.proto_array.apply_score_changes(
342+
? self.proto_array.applyScoreChanges(
340343
deltas, justified_epoch, finalized_epoch
341344
)
342345

343346
self.balances = justified_state_balances
344347

345348
# Find the best block
346349
var new_head{.noInit.}: Eth2Digest
347-
? self.proto_array.find_head(new_head, justified_root)
350+
? self.proto_array.findHead(new_head, justified_root)
348351

349352
{.noSideEffect.}:
350353
trace "Fork choice requested",
@@ -425,8 +428,7 @@ func compute_deltas(
425428
if index >= deltas.len:
426429
return err ForkChoiceError(
427430
kind: fcInvalidNodeDelta,
428-
index: index
429-
)
431+
index: index)
430432
deltas[index] -= Delta old_balance
431433
# Note that delta can be negative
432434
# TODO: is int64 big enough?
@@ -436,8 +438,7 @@ func compute_deltas(
436438
if index >= deltas.len:
437439
return err ForkChoiceError(
438440
kind: fcInvalidNodeDelta,
439-
index: index
440-
)
441+
index: index)
441442
deltas[index] += Delta new_balance
442443
# Note that delta can be negative
443444
# TODO: is int64 big enough?

beacon_chain/fork_choice/fork_choice_types.nim

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ type
7676
case kind*: fcKind
7777
of fcFinalizedNodeUnknown,
7878
fcJustifiedNodeUnknown:
79-
block_root*: Eth2Digest
79+
blockRoot*: Eth2Digest
8080
of fcInvalidFinalizedRootChange,
8181
fcInconsistentTick:
8282
discard
@@ -95,18 +95,18 @@ type
9595
deltasLen*: int
9696
indicesLen*: int
9797
of fcRevertedFinalizedEpoch:
98-
current_finalized_epoch*: Epoch
98+
currentFinalizedEpoch*: Epoch
9999
new_finalized_epoch*: Epoch
100100
of fcInvalidBestNode:
101-
start_root*: Eth2Digest
102-
justified_epoch*: Epoch
103-
finalized_epoch*: Epoch
104-
head_root*: Eth2Digest
105-
head_justified_epoch*: Epoch
106-
head_finalized_epoch*: Epoch
101+
startRoot*: Eth2Digest
102+
justifiedEpoch*: Epoch
103+
finalizedEpoch*: Epoch
104+
headRoot*: Eth2Digest
105+
headJustifiedEpoch*: Epoch
106+
headFinalizedEpoch*: Epoch
107107
of fcUnknownParent:
108-
child_root*: Eth2Digest
109-
parent_root*: Eth2Digest
108+
childRoot*: Eth2Digest
109+
parentRoot*: Eth2Digest
110110
of fcPruningFromOutdatedFinalizedRoot:
111111
finalizedRoot*: Eth2Digest
112112

@@ -119,19 +119,19 @@ type
119119
## to get the physical index
120120

121121
ProtoArray* = object
122-
justified_epoch*: Epoch
123-
finalized_epoch*: Epoch
122+
justifiedEpoch*: Epoch
123+
finalizedEpoch*: Epoch
124124
nodes*: Protonodes
125125
indices*: Table[Eth2Digest, Index]
126126

127127
ProtoNode* = object
128128
root*: Eth2Digest
129129
parent*: Option[Index]
130-
justified_epoch*: Epoch
131-
finalized_epoch*: Epoch
130+
justifiedEpoch*: Epoch
131+
finalizedEpoch*: Epoch
132132
weight*: int64
133-
best_child*: Option[Index]
134-
best_descendant*: Option[Index]
133+
bestChild*: Option[Index]
134+
bestDescendant*: Option[Index]
135135

136136
BalanceCheckpoint* = object
137137
blck*: BlockRef

0 commit comments

Comments
 (0)