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

Light Client p2p #14582

Draft
wants to merge 27 commits into
base: epf-light-client
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
ea06554
Set fields of wrapped proto object in light client setters (#14573)
rkapka Oct 23, 2024
ce6388f
Set fields of wrapped proto object in light client setters (#14573)
rkapka Oct 23, 2024
471b0c2
align changelog with develop branch
rkapka Oct 26, 2024
28af3d6
get files from gossip branch
rkapka Oct 26, 2024
6bbdd59
get files from rpc branch
rkapka Oct 26, 2024
0751271
in prog
rkapka Oct 28, 2024
df2bbc8
Revert "Auxiliary commit to revert individual files from fbe143f5635b…
rkapka Oct 31, 2024
95a3bf0
Revert "Auxiliary commit to revert individual files from 19192c68ed1d…
rkapka Oct 31, 2024
aa82d6f
Electra version
rkapka Oct 31, 2024
99dbf1c
fix protos
rkapka Oct 31, 2024
4d60cc3
fix issues
rkapka Oct 31, 2024
ba8578e
poc complete
rkapka Nov 3, 2024
37f2b44
unused ctx
rkapka Nov 3, 2024
0031d64
remove unused structs
rkapka Nov 3, 2024
ca29e37
Beacon API handlers
rkapka Nov 3, 2024
9fdc36b
final changes
rkapka Nov 4, 2024
4e31417
fix some tests
rkapka Nov 4, 2024
79ec529
save update
Inspector-Butters Nov 4, 2024
a64a739
save update
Inspector-Butters Nov 4, 2024
21aa9bf
fix events
rkapka Nov 5, 2024
fa63182
debugging help
rkapka Nov 5, 2024
d393667
move create lc bootstrap to core
Inspector-Butters Nov 5, 2024
97df300
bootstrap db
Inspector-Butters Nov 5, 2024
852b022
save bootstrap
Inspector-Butters Nov 5, 2024
cd69603
Merge remote-tracking branch 'bastin/save-updates' into lc-p2p
rkapka Nov 6, 2024
9d70436
debugging
rkapka Nov 6, 2024
54f51df
bootstrp and updatesByRange working
rkapka Nov 6, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 84 additions & 0 deletions api/server/structs/conversions_lightclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,40 @@ import (
"github.com/prysmaticlabs/prysm/v5/runtime/version"
)

func LightClientBootsrapFromConsensus(bootstrap interfaces.LightClientBootstrap) (*LightClientBootstrap, error) {
header, err := lightClientHeaderToJSON(bootstrap.Header())
if err != nil {
return nil, errors.Wrap(err, "could not marshal light client header")
}

var jsonBranch []string
if bootstrap.Version() >= version.Electra {
branch, err := bootstrap.CurrentSyncCommitteeBranchElectra()
if err != nil {
return nil, err
}
jsonBranch = make([]string, len(branch))
for i, item := range branch {
jsonBranch[i] = hexutil.Encode(item[:])
}
} else {
branch, err := bootstrap.CurrentSyncCommitteeBranch()
if err != nil {
return nil, err
}
jsonBranch = make([]string, len(branch))
for i, item := range branch {
jsonBranch[i] = hexutil.Encode(item[:])
}
}

return &LightClientBootstrap{
Header: header,
CurrentSyncCommittee: SyncCommitteeFromConsensus(bootstrap.CurrentSyncCommittee()),
CurrentSyncCommitteeBranch: jsonBranch,
}, nil
}

func LightClientUpdateFromConsensus(update interfaces.LightClientUpdate) (*LightClientUpdate, error) {
attestedHeader, err := lightClientHeaderToJSON(update.AttestedHeader())
if err != nil {
Expand Down Expand Up @@ -171,9 +205,59 @@ func lightClientHeaderToJSON(header interfaces.LightClientHeader) (json.RawMessa
Execution: execution,
ExecutionBranch: branchToJSON(executionBranch[:]),
}
case version.Electra:
exInterface, err := header.Execution()
if err != nil {
return nil, err
}
ex, ok := exInterface.Proto().(*enginev1.ExecutionPayloadHeaderDeneb)
if !ok {
return nil, fmt.Errorf("execution data is not %T", &enginev1.ExecutionPayloadHeaderDeneb{})
}
execution, err := ExecutionPayloadHeaderDenebFromConsensus(ex)
if err != nil {
return nil, err
}
executionBranch, err := header.ExecutionBranch()
if err != nil {
return nil, err
}
result = &LightClientHeaderDeneb{
Beacon: BeaconBlockHeaderFromConsensus(header.Beacon()),
Execution: execution,
ExecutionBranch: branchToJSON(executionBranch[:]),
}
default:
return nil, fmt.Errorf("unsupported header version %s", version.String(v))
}

return json.Marshal(result)
}

func LightClientBootstrapFromConsensus(bootstrap interfaces.LightClientBootstrap) (*LightClientBootstrap, error) {
header, err := lightClientHeaderToJSON(bootstrap.Header())
if err != nil {
return nil, errors.Wrap(err, "could not marshal light client header")
}

var scBranch [][32]byte
if bootstrap.Version() >= version.Electra {
b, err := bootstrap.CurrentSyncCommitteeBranchElectra()
if err != nil {
return nil, err
}
scBranch = b[:]
} else {
b, err := bootstrap.CurrentSyncCommitteeBranch()
if err != nil {
return nil, err
}
scBranch = b[:]
}

return &LightClientBootstrap{
Header: header,
CurrentSyncCommittee: SyncCommitteeFromConsensus(bootstrap.CurrentSyncCommittee()),
CurrentSyncCommitteeBranch: branchToJSON(scBranch),
}, nil
}
1 change: 1 addition & 0 deletions beacon-chain/blockchain/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ go_library(
"//beacon-chain/forkchoice:go_default_library",
"//beacon-chain/forkchoice/doubly-linked-tree:go_default_library",
"//beacon-chain/forkchoice/types:go_default_library",
"//beacon-chain/light-client:go_default_library",
"//beacon-chain/operations/attestations:go_default_library",
"//beacon-chain/operations/blstoexec:go_default_library",
"//beacon-chain/operations/slashings:go_default_library",
Expand Down
8 changes: 8 additions & 0 deletions beacon-chain/blockchain/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/prysmaticlabs/prysm/v5/beacon-chain/db/filesystem"
"github.com/prysmaticlabs/prysm/v5/beacon-chain/execution"
"github.com/prysmaticlabs/prysm/v5/beacon-chain/forkchoice"
light_client "github.com/prysmaticlabs/prysm/v5/beacon-chain/light-client"
"github.com/prysmaticlabs/prysm/v5/beacon-chain/operations/attestations"
"github.com/prysmaticlabs/prysm/v5/beacon-chain/operations/blstoexec"
"github.com/prysmaticlabs/prysm/v5/beacon-chain/operations/slashings"
Expand Down Expand Up @@ -205,3 +206,10 @@ func WithSyncChecker(checker Checker) Option {
return nil
}
}

func WithLightClientStore(lcs *light_client.Store) Option {
return func(s *Service) error {
s.lcStore = lcs
return nil
}
}
5 changes: 4 additions & 1 deletion beacon-chain/blockchain/process_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@ func (s *Service) postBlockProcess(cfg *postBlockProcessConfig) error {
if s.inRegularSync() {
defer s.handleSecondFCUCall(cfg, fcuArgs)
}
defer s.sendLightClientFeeds(cfg)
if features.Get().EnableLightClient && slots.ToEpoch(s.CurrentSlot()) >= params.BeaconConfig().AltairForkEpoch {
defer s.saveLightClientUpdates(cfg)
defer s.processLightClientUpdates(cfg)
}
defer s.sendStateFeedOnBlock(cfg)
defer reportProcessingTime(startTime)
defer reportAttestationInclusion(cfg.roblock.Block())
Expand Down
Loading
Loading