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

LC Updates by Range to read from DB #14531

Open
wants to merge 44 commits into
base: epf-light-client
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
47fe2d3
change updatebyrange
Inspector-Butters Oct 8, 2024
b446e03
lcupdateresponse from consensus
Inspector-Butters Oct 8, 2024
03fa1e2
Merge branch 'prysmaticlabs:develop' into updates-by-range
Inspector-Butters Oct 9, 2024
5689d45
range altair test
Inspector-Butters Oct 10, 2024
454bcd7
Merge branch 'prysmaticlabs:develop' into updates-by-range
Inspector-Butters Oct 13, 2024
dedfacb
range forks tests
Inspector-Butters Oct 13, 2024
64d978b
Merge branch 'prysmaticlabs:develop' into updates-by-range
Inspector-Butters Oct 14, 2024
b1831ca
finish tests
Inspector-Butters Oct 14, 2024
3bef6f5
changelog
Inspector-Butters Oct 14, 2024
aff629f
remove unused functions
Inspector-Butters Oct 14, 2024
2f16a91
Update beacon-chain/rpc/eth/light-client/handlers.go
Inspector-Butters Oct 14, 2024
5caba41
Update beacon-chain/rpc/eth/light-client/handlers.go
Inspector-Butters Oct 14, 2024
4866873
use slice instead of array
Inspector-Butters Oct 14, 2024
e240505
Merge branch 'develop' into updates-by-range
Inspector-Butters Oct 14, 2024
2c4ea0b
refactor code
Inspector-Butters Oct 15, 2024
e728c22
Merge branch 'develop' into updates-by-range
Inspector-Butters Oct 15, 2024
ccd5106
Merge branch 'develop' into updates-by-range
Inspector-Butters Oct 16, 2024
9dab7a9
refactor tests
Inspector-Butters Oct 16, 2024
3832d95
Merge branch 'develop' into updates-by-range
Inspector-Butters Oct 16, 2024
60f0591
Merge branch 'develop' into updates-by-range
Inspector-Butters Oct 17, 2024
7427c30
refactor tests
Inspector-Butters Oct 17, 2024
a0a2af2
refactor tests
Inspector-Butters Oct 17, 2024
1a8f20c
add configCleanup in tests
Inspector-Butters Oct 21, 2024
52f37ec
refactor missing updates testcase
Inspector-Butters Oct 21, 2024
0e7deff
Light Client - use the new consensus types (#14549)
rkapka Oct 21, 2024
3144e3f
Merge remote-tracking branch 'upstream/epf-light-client' into updates…
Inspector-Butters Oct 21, 2024
fec1678
change updatesByRange to use new structs
Inspector-Butters Oct 21, 2024
497c50a
Light Client - use the new consensus types (#14549)
rkapka Oct 21, 2024
c1d525b
Merge branch 'epf-light-client' into updates-by-range
Inspector-Butters Oct 22, 2024
2300bf9
fix rpc/helpers_test
Inspector-Butters Oct 22, 2024
f8cb14c
Return the correct light client payload proof (#14565)
rkapka Oct 22, 2024
36256e6
merge
Inspector-Butters Oct 23, 2024
172a96a
Merge remote-tracking branch 'upstream/epf-light-client' into updates…
Inspector-Butters Oct 23, 2024
c9c4f46
Set fields of wrapped proto object in light client setters (#14573)
rkapka Oct 23, 2024
c9fedf1
fixing tests...
Inspector-Butters Oct 23, 2024
4ab398f
Merge remote-tracking branch 'upstream/epf-light-client' into updates…
Inspector-Butters Oct 23, 2024
ba64324
core tests fixed
Inspector-Butters Oct 24, 2024
692f827
kv tests fixed
Inspector-Butters Oct 24, 2024
3db34bd
fix TODOs for events (#14570)
rupam-04 Oct 25, 2024
ad95732
Merge remote-tracking branch 'upstream/epf-light-client' into updates…
Inspector-Butters Oct 25, 2024
ba1fac4
tests fixed
Inspector-Butters Oct 25, 2024
59e9acd
remove unused function
Inspector-Butters Oct 25, 2024
03fd48c
fix slice capacity
Inspector-Butters Oct 25, 2024
9c5baed
Merge branch 'epf-light-client' into updates-by-range
Inspector-Butters Oct 26, 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ The format is based on Keep a Changelog, and this project adheres to Semantic Ve
- Make committee aware packing the default by deprecating `--enable-committee-aware-packing`.
- Moved `ConvertKzgCommitmentToVersionedHash` to the `primitives` package.
- reversed the boolean return on `BatchVerifyDepositsSignatures`, from need verification, to all keys successfully verified
- Changed `GetLightClientUpdatesByRange` API to read from the DB instead of computing.
- Fix `engine_exchangeCapabilities` implementation.

### Deprecated
Expand Down
1 change: 1 addition & 0 deletions api/server/structs/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ go_library(
"//proto/eth/v2:go_default_library",
"//proto/migration:go_default_library",
"//proto/prysm/v1alpha1:go_default_library",
"//runtime/version:go_default_library",
"@com_github_ethereum_go_ethereum//common:go_default_library",
"@com_github_ethereum_go_ethereum//common/hexutil:go_default_library",
"@com_github_pkg_errors//:go_default_library",
Expand Down
13 changes: 13 additions & 0 deletions api/server/structs/conversions_lightclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,21 @@ import (
v1 "github.com/prysmaticlabs/prysm/v5/proto/eth/v1"
v2 "github.com/prysmaticlabs/prysm/v5/proto/eth/v2"
"github.com/prysmaticlabs/prysm/v5/proto/migration"
"github.com/prysmaticlabs/prysm/v5/runtime/version"
)

func LightClientUpdateResponseFromConsensus(update *v2.LightClientUpdateWithVersion) (*LightClientUpdateResponse, error) {
data, err := LightClientUpdateFromConsensus(update.Data)
if err != nil {
return nil, err
}

return &LightClientUpdateResponse{
Version: version.String(int(update.Version)),
Data: data,
}, nil
}

func LightClientUpdateFromConsensus(update *v2.LightClientUpdate) (*LightClientUpdate, error) {
attestedHeader, err := lightClientHeaderContainerToJSON(update.AttestedHeader)
if err != nil {
Expand Down
4 changes: 3 additions & 1 deletion beacon-chain/rpc/eth/light-client/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ go_library(
"//config/fieldparams:go_default_library",
"//config/params:go_default_library",
"//consensus-types/interfaces:go_default_library",
"//consensus-types/primitives:go_default_library",
"//monitoring/tracing/trace:go_default_library",
"//network/httputil:go_default_library",
"//proto/eth/v2:go_default_library",
Expand All @@ -46,16 +45,19 @@ go_test(
"//beacon-chain/blockchain/testing:go_default_library",
"//beacon-chain/core/helpers:go_default_library",
"//beacon-chain/core/light-client:go_default_library",
"//beacon-chain/db/kv:go_default_library",
"//beacon-chain/rpc/testutil:go_default_library",
"//beacon-chain/state:go_default_library",
"//config/fieldparams:go_default_library",
"//config/params:go_default_library",
"//consensus-types/blocks:go_default_library",
"//consensus-types/interfaces:go_default_library",
"//consensus-types/primitives:go_default_library",
"//proto/engine/v1:go_default_library",
"//proto/eth/v1:go_default_library",
"//proto/eth/v2:go_default_library",
"//proto/prysm/v1alpha1:go_default_library",
"//runtime/version:go_default_library",
"//testing/assert:go_default_library",
"//testing/require:go_default_library",
"//testing/util:go_default_library",
Expand Down
113 changes: 16 additions & 97 deletions beacon-chain/rpc/eth/light-client/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@ import (
"github.com/prysmaticlabs/prysm/v5/api"
"github.com/prysmaticlabs/prysm/v5/api/server/structs"
"github.com/prysmaticlabs/prysm/v5/beacon-chain/rpc/eth/shared"
"github.com/prysmaticlabs/prysm/v5/beacon-chain/state"
"github.com/prysmaticlabs/prysm/v5/config/params"
"github.com/prysmaticlabs/prysm/v5/consensus-types/interfaces"
types "github.com/prysmaticlabs/prysm/v5/consensus-types/primitives"
"github.com/prysmaticlabs/prysm/v5/monitoring/tracing/trace"
"github.com/prysmaticlabs/prysm/v5/network/httputil"
"github.com/prysmaticlabs/prysm/v5/runtime/version"
Expand Down Expand Up @@ -117,108 +115,29 @@ func (s *Server) GetLightClientUpdatesByRange(w http.ResponseWriter, req *http.R
endPeriod = maxSlot / slotsPerPeriod
}

// Populate updates
var updates []*structs.LightClientUpdateResponse
for period := startPeriod; period <= endPeriod; period++ {
// Get the last known state of the period,
// 1. We wish the block has a parent in the same period if possible
// 2. We wish the block has a state in the same period
lastSlotInPeriod := period*slotsPerPeriod + slotsPerPeriod - 1
if lastSlotInPeriod > maxSlot {
lastSlotInPeriod = maxSlot
}
firstSlotInPeriod := period * slotsPerPeriod

// Let's not use the first slot in the period, otherwise the attested header will be in previous period
firstSlotInPeriod++

var state state.BeaconState
var block interfaces.ReadOnlySignedBeaconBlock
for slot := lastSlotInPeriod; slot >= firstSlotInPeriod; slot-- {
state, err = s.Stater.StateBySlot(ctx, types.Slot(slot))
if err != nil {
continue
}

// Get the block
latestBlockHeader := state.LatestBlockHeader()
latestStateRoot, err := state.HashTreeRoot(ctx)
if err != nil {
continue
}
latestBlockHeader.StateRoot = latestStateRoot[:]
blockRoot, err := latestBlockHeader.HashTreeRoot()
if err != nil {
continue
}

block, err = s.Blocker.Block(ctx, blockRoot[:])
if err != nil || block == nil {
continue
}

syncAggregate, err := block.Block().Body().SyncAggregate()
if err != nil || syncAggregate == nil {
continue
}

if syncAggregate.SyncCommitteeBits.Count()*3 < config.SyncCommitteeSize*2 {
// Not enough votes
continue
}

break
}
// get updates
updatesMap, err := s.BeaconDB.LightClientUpdates(ctx, startPeriod, endPeriod)
if err != nil {
httputil.HandleError(w, "Could not get light client updates from DB: "+err.Error(), http.StatusInternalServerError)
return
}

if block == nil {
// No valid block found for the period
continue
}
updates := make([]*structs.LightClientUpdateResponse, 0, len(updatesMap))

// Get attested state
attestedRoot := block.Block().ParentRoot()
attestedBlock, err := s.Blocker.Block(ctx, attestedRoot[:])
if err != nil || attestedBlock == nil {
continue
for i := startPeriod; i <= endPeriod; i++ {
update, ok := updatesMap[i]
if !ok {
// Only return the first contiguous range of updates
break
}

attestedSlot := attestedBlock.Block().Slot()
attestedState, err := s.Stater.StateBySlot(ctx, attestedSlot)
updateResponse, err := structs.LightClientUpdateResponseFromConsensus(update)
if err != nil {
continue
}

// Get finalized block
var finalizedBlock interfaces.ReadOnlySignedBeaconBlock
finalizedCheckPoint := attestedState.FinalizedCheckpoint()
if finalizedCheckPoint != nil {
finalizedRoot := bytesutil.ToBytes32(finalizedCheckPoint.Root)
finalizedBlock, err = s.Blocker.Block(ctx, finalizedRoot[:])
if err != nil {
finalizedBlock = nil
}
httputil.HandleError(w, "Could not convert light client update: "+err.Error(), http.StatusInternalServerError)
return
}

update, err := newLightClientUpdateFromBeaconState(
ctx,
state,
block,
attestedState,
attestedBlock,
finalizedBlock,
)

if err == nil {
updates = append(updates, &structs.LightClientUpdateResponse{
Version: version.String(attestedState.Version()),
Data: update,
})
}
}

if len(updates) == 0 {
httputil.HandleError(w, "no updates found", http.StatusNotFound)
return
updates = append(updates, updateResponse)
}

httputil.WriteJson(w, updates)
Expand Down
Loading
Loading