Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modify the algorithm of updateFinalizedBlockRoots #13486

Merged
merged 13 commits into from
Mar 21, 2024
12 changes: 10 additions & 2 deletions beacon-chain/db/kv/finalized_block_roots.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,18 @@ func (s *Store) updateFinalizedBlockRoots(ctx context.Context, tx *bolt.Tx, chec
if i == len(finalized)-1 {
// We don't know the finalized child of the new finalized checkpoint.
// It will be filled out in the next function call.
container = &ethpb.FinalizedBlockRootContainer{}
container = &ethpb.FinalizedBlockRootContainer{
ParentRoot: finalized[i-1],
}
} else if i == 0 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might be better to use a switch statement ? If not handling i in a progressive order is reads better

if i == 0 {
// do something
else if i == len(finalized) -1 {
// do something
} else {
// ...
}

container = &ethpb.FinalizedBlockRootContainer{
ParentRoot: previousFinalizedCheckpoint.Root,
ChildRoot: finalized[i+1],
}
} else {
container = &ethpb.FinalizedBlockRootContainer{
ChildRoot: finalized[i+1],
ParentRoot: finalized[i-1],
ChildRoot: finalized[i+1],
}
}
enc, err := encode(ctx, container)
Expand Down