Skip to content

add 3sf forkchoice to apply votes and choose head #28

Merged
g11tech merged 18 commits intomainfrom
3sf-fc
Jun 26, 2025
Merged

add 3sf forkchoice to apply votes and choose head #28
g11tech merged 18 commits intomainfrom
3sf-fc

Conversation

@g11tech
Copy link
Copy Markdown
Member

@g11tech g11tech commented Jun 11, 2025

WIP -

  • add 3sf forkchoice and apply votes in block import pipeline
  • add test scenarios

(prev PR #27 got closed by mistaken deletion of the branch whhile doing branch cleanuP)

pub fn init(allocator: Allocator, config: configs.ChainConfig, anchorState: types.BeamState) !Self {
const fork_choice = try fcFactory.ForkChoice.init(allocator, config, anchorState);

var states = std.AutoHashMap(types.Root, types.BeamState).init(allocator);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't see deinit being called anywhere

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

yes, will add later for now it doesn't matter as it's life is as long as program run

Comment on lines +131 to +142
// a super hacky cloning utility for ssz - replace by a better mechanis
// should be upstreated into the ssz lib even with a proper impl
pub fn sszClone(allocator: Allocator, comptime T: type, data: T) !T {
var bytes = std.ArrayList(u8).init(std.testing.allocator);
defer bytes.deinit();

try ssz.serialize(T, data, &bytes);
var cloned: T = undefined;
try ssz.deserialize(T, bytes.items[0..], &cloned, allocator);
return cloned;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ouch, you weren't lying when you said this is hacky. Could it be possible to not do the SSZ serialization and simply implement a clone function on BeamState? That could simply start being just this function, but over time would evolve to be a proper cloning function? I just can't imagine this approach being very efficient (I agree it's easy to maintain, though)

Copy link
Copy Markdown
Member Author

@g11tech g11tech Jun 24, 2025

Choose a reason for hiding this comment

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

yes thats the plan to move to a proper function


const BlockProcessingError = error{MissingPreState};

test "build mock chain" {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I suggest changing this description to explain what is being tested, I'm pretty sure all of our tests will be building a mock chain

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

ah lol good point

@g11tech g11tech merged commit 37304cd into main Jun 26, 2025
4 checks passed
@g11tech g11tech deleted the 3sf-fc branch July 21, 2025 16:56
gballet pushed a commit that referenced this pull request Aug 17, 2025
* add 3sf forkchoice to apply votes and choose head

* some preliminary setup

* enrich mock data

* update test

* add ssz clone util

* setup beamchain processing

* basic block processing

* add vote processing skeleton

* track the latest votes

* compute deltas

* calc and apply deltas due to votes

* some restructuring and add justified to fcstore

* update head completion

* complete fix update head

* fcstore checkpoint update

* add head tracking to mockchain and match it against fchead in the beam chain test

* apply feedback

* improv comment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants