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

merge with prysm upstream #28

Open
wants to merge 175 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
175 commits
Select commit Hold shift + click to select a range
9ec45a4
(-) Port changes from previous repo
Nov 18, 2022
c6e8410
(-) Fix rebase error
Nov 18, 2022
4807395
(-) Patch bazel deps
Nov 18, 2022
f6b3d97
(-) More bazel
Nov 18, 2022
c7a08cf
(-) Address comments
qinlz2 Nov 22, 2022
efc98ce
feat: light client store init
Nov 21, 2022
2e77bb0
chore: reduce stutter
Nov 21, 2022
6e1c5b1
feat: implement finality update minus validation
Nov 21, 2022
618b9d3
feat: is*update() helpers
Nov 22, 2022
f78671f
feat: partial is_better_update impl
Nov 22, 2022
b228c50
feat: make LightClientUpdate an interface to avoid copying
Nov 22, 2022
ed801f5
feat: implement is_better_update
Nov 22, 2022
7073b7d
feat: finish utilities relavant to LightClientUpdate
Nov 22, 2022
6647585
feat: finish store helpers
Nov 22, 2022
7d73520
doc: port missing comments
Nov 22, 2022
6f23da7
chore: use Slot type everywhere
Nov 22, 2022
c453da5
chore: make signature slot Slot types
Nov 22, 2022
a24b3c1
chore: simplify import
Nov 22, 2022
3f415dd
feat: implement update validation
Nov 22, 2022
74c82ca
feat: optimistic update
Nov 22, 2022
a8c86b3
feat: force update
Nov 22, 2022
010655b
feat: make store/update encodable
Nov 22, 2022
af8dccd
fix: review comments
Nov 28, 2022
af3b13d
fix: review round 2
Nov 29, 2022
bee90b0
fix: remove all consts available in config
Nov 29, 2022
aeb5706
chore: consolidate indices in proto
Nov 29, 2022
249181b
fix: optimize bits loop
Nov 29, 2022
1ff3e4e
fix: read domain sync committee from config
Nov 29, 2022
5f896ea
doc: add comments for store fiels
7AC Nov 29, 2022
e4e3c7c
fix: safety threshold calculation
7AC Nov 29, 2022
fc73b06
chore: fix imports
7AC Nov 29, 2022
bca7814
fix: comment format
Nov 29, 2022
8be5ce1
chore: make ProcessUpdate() public
Nov 29, 2022
04cedad
fix: typoe
Nov 29, 2022
38379f6
fix: pass bootstrap by pointer
Nov 30, 2022
ceb63fa
(-) Add LightClientUpdatesByRange req/rsp proto
qinlz2 Nov 19, 2022
96b57a4
(-) Add RPC skeleton
qinlz2 Nov 30, 2022
b0aade4
(-) Hook REST responses
qinlz2 Nov 19, 2022
9896959
(-) Try dummy non-array response
qinlz2 Nov 20, 2022
626560e
(-) Handle slice input correctly
qinlz2 Nov 20, 2022
80ac107
(-) Return array instead of gRPC format
qinlz2 Nov 20, 2022
0d5a10b
(-) Refactor to be standard coding style
qinlz2 Nov 30, 2022
8de0591
(-) struct renaming to spec standard
qinlz2 Nov 30, 2022
8b4d7d8
(-) Initial impl for create light client update
qinlz2 Nov 22, 2022
b79b960
(-) Fix sync committee generalized index issue
qinlz2 Nov 21, 2022
5bd718e
(-) Add merkle proof verification
qinlz2 Nov 21, 2022
662f0ac
(-) Fix NPE
qinlz2 Nov 22, 2022
4e17d34
(-) Handle no updates case
qinlz2 Nov 22, 2022
3fb66b1
(-) Remove unused func
qinlz2 Nov 22, 2022
0e91f80
(-) Add consts
qinlz2 Nov 22, 2022
4a90039
(-) Change comments
qinlz2 Nov 22, 2022
26f284b
(-) Add full spec create snapshot implementation
qinlz2 Nov 22, 2022
cc1f1b8
(-) Add full spec finality update implementation
qinlz2 Nov 30, 2022
5d77b72
(-) Add full spec optimisitc update implementation
qinlz2 Nov 30, 2022
cc03423
(-) Better handle errors
qinlz2 Nov 22, 2022
2378be6
(-) Move helper functions to their pkg
qinlz2 Nov 22, 2022
90048ec
(-) Use the helpers function for events
qinlz2 Nov 30, 2022
81f2c0b
(-) Rebase to latest develop branch
qinlz2 Nov 30, 2022
efc5b9f
(-) Fix more rebase errors
qinlz2 Nov 30, 2022
14214e6
(-) Handle cognitive complexity issues
qinlz2 Nov 30, 2022
c9a6aaa
(-) Simplify logic
qinlz2 Nov 30, 2022
f2f97fb
(-) Fix NPE
qinlz2 Dec 1, 2022
d4b04c0
(-) Address comments (Move to Go style constructor function)
qinlz2 Dec 2, 2022
994f762
(-) Method renaming to distinguish from default constructor
qinlz2 Dec 2, 2022
a68fabe
feat: generic update marshaling
Dec 2, 2022
c128934
chore: marshaling should be implitic
Dec 2, 2022
0de7d78
chore: rename util
Dec 2, 2022
b937f1d
chore: use consts for type names
Dec 5, 2022
4944239
chore: make update type names public
Dec 5, 2022
1da0654
feat: add marshalable light client config
Dec 6, 2022
511cf4a
fix: add json tag for config
Dec 6, 2022
43fe2be
fix: do not marshal config in updates
Dec 6, 2022
1c50ecc
chore: consolidate updates into a single type
Dec 7, 2022
b34e393
chore: fix lint
Dec 7, 2022
5004631
fix: reset next sync committee for finality/optimistic updates
Dec 7, 2022
dd84b02
fix: do not populate all fields for updates
Dec 7, 2022
c6177e5
fix: use specific updates for API
Dec 7, 2022
30d96c7
feat: reject malformed finality/optimistic updates
Dec 7, 2022
a1b58fa
chore: be consistent with lightclient naming
Dec 7, 2022
a4ad32a
feat: Genesis, Bootstrap and ExecutionPayloadHeader constructors from…
Dec 8, 2022
8848588
feat:LightClientUpdate from JSON
Dec 8, 2022
56437e2
chore: move genesis to v1 package
Dec 8, 2022
ddcc6fa
chore: move apimiddleware helpers to their own package to fix cycle
Dec 8, 2022
55b95be
fix: big int conversions
Dec 8, 2022
8e93fc3
chore: goimports
Dec 8, 2022
378ca48
chore: add Response in LightClientUpdateResponseJson
Dec 8, 2022
b350ae1
fix: lint
Dec 8, 2022
513a5b9
fix: do not panic if store creation fails
Dec 8, 2022
edebf45
fix: stop being explict about branch depth
Dec 8, 2022
51f3ba4
fix: revert hex conversion
Dec 8, 2022
dac7560
chore: move helpers outside of Update
Dec 9, 2022
d856a5f
feat: support bellatrix fork
Dec 9, 2022
1a31f71
fix: account for empty finalized header
Dec 9, 2022
2935a49
fix: do not assume finalized header is set when validating updates
Dec 9, 2022
372e676
fix: assume empty means nil
Dec 9, 2022
9e83900
fix: misc empty checks
Dec 9, 2022
d462b07
fix: use ethpbv2.LightClientUpdate in public APIs
Dec 9, 2022
83a3c57
fix: lint
Dec 9, 2022
f04c5d5
fix: use correct index in finality update check
Dec 9, 2022
34f48d7
fix: revert update types in protobuf
Dec 9, 2022
0d70c3d
fix: restore typed results for light client update endpoints
Dec 9, 2022
5aa74e3
feat: typed light client update for serialization
Dec 9, 2022
df6d160
fix: json update type name
Dec 9, 2022
859ddcb
feat: add generic LightClient.Update interface
Dec 9, 2022
f100631
feat: generic update processing API
Dec 10, 2022
ced364d
feat: unmarshaling logic from typed JSON to generic update
Dec 10, 2022
2421d34
fix: unmarshal to pointers
Dec 10, 2022
3cfa478
chore: generic update constructors from JSON
Dec 12, 2022
c3ddb4e
feat: support capella fork
Dec 12, 2022
71d0cab
feat: JSON light client config
Dec 13, 2022
bc28c6e
fix: use marshaler interface
Dec 13, 2022
e0f1196
fix: domain sync committee
Dec 13, 2022
8ba6089
chore: remove unused tags
Dec 13, 2022
b7c3677
fix: typed update data field
Dec 13, 2022
1424d81
chore: remove unused constructor
Dec 13, 2022
b6654ab
fix: re-add json tags
Dec 13, 2022
ae59eb4
fix: bellatrix value
Dec 14, 2022
a47d7cf
chore: remove unused tags
Dec 14, 2022
70d6335
fix: do not panic decoding hex
Dec 14, 2022
0dad5f1
fix: trusted root check
Dec 15, 2022
9aabbee
fix: finality branch and sync committees unmarshaling
Dec 15, 2022
03b9412
fix: fork versions in config
Dec 16, 2022
c849307
chore: make sync committee and finality update checks public
Dec 16, 2022
7279578
fix: import loop for FloorLog2()
Dec 16, 2022
34e9dfd
feat: generate ssz logic for SyncCommittee
Dec 22, 2022
df89746
chore: add missing source file to BUILD
Dec 22, 2022
fd02fed
fix: deepsource
Dec 22, 2022
1f0fc20
chore: more validation for bootstrap and updates
Dec 28, 2022
5ef27c2
feat: add ability to validate and process separately
Dec 28, 2022
b40b8cc
fix: complexity of onBlock()
Dec 28, 2022
ef993e0
(-) base fee per gas needs to be 32 bytes
qinlz2 Dec 30, 2022
e9651d8
(-) Base fee per gas is little-endian
qinlz2 Dec 30, 2022
4201b52
fix: deepsourced
Jan 3, 2023
25c8f8e
(-) Fix a comment
qinlz2 Jan 3, 2023
3cc6d47
feat: clone method for light client store
Jan 10, 2023
1daf176
fix: deepsource
Jan 11, 2023
4c7ecac
fix: correct pkg name from rebase
qinlz2 Feb 1, 2023
7d3a00a
fix: update protogen file for IDE
qinlz2 Feb 1, 2023
9f933b5
fix: rollback partial change in
qinlz2 Feb 2, 2023
321ade5
fix: deepsource complains unused receiver variable
qinlz2 Feb 7, 2023
80ab7e4
fix: sync committee hash tree root generation issue
qinlz2 Feb 8, 2023
bab2d9e
refactor: remove unused arguments in
qinlz2 Feb 18, 2023
91d24bc
refactor: remove unused argument in NewLightClientFinalityUpdateFromB…
qinlz2 Feb 18, 2023
229a776
fix: patch light_client_optimisitc_update to return a result satisifies
qinlz2 Feb 18, 2023
e37dc84
refactor: more efficien code
qinlz2 Feb 19, 2023
d15da8a
refactor: better performance code
qinlz2 Feb 20, 2023
e5cb922
fix: ligth client finality endpoint need super majority of signatures
qinlz2 Feb 20, 2023
12b3719
refactor: consolidate duplicate logics
qinlz2 Feb 21, 2023
e46776c
fix: light client finality stream needs super majority
qinlz2 Feb 21, 2023
dadf633
refactor: try to solve lint problem
qinlz2 Feb 21, 2023
8d37df7
refactor: address comments
qinlz2 Feb 22, 2023
a5cdea3
fix: guard start period in LC full update endpoints
qinlz2 Feb 21, 2023
8b887cb
fix: light client full updates need super majority
qinlz2 Feb 21, 2023
d0c9a13
chore: upgrade go-libp2p
Feb 24, 2023
126d15a
chore: upgrade go-libp2p-pubsub to match go-libp2p
Feb 24, 2023
296209f
chore: remove identify.IDDelta
Feb 24, 2023
68b3487
fix: convert p2p protocols to strings
Feb 24, 2023
75bd49c
fix: goimpots
Feb 24, 2023
cb1829d
fix: node_test
Feb 24, 2023
a79ef49
fix: unused method receivers
Feb 24, 2023
ecc8ae3
fix: change light client related block type usage to `readonly` version
qinlz2 Feb 24, 2023
104f815
chore: allow protocol
Feb 24, 2023
a75be31
fix: remove useless conversion
Feb 24, 2023
afa86f5
fix: patch GetLightClientUpdatesByRange
qinlz2 Mar 22, 2023
9d3c24d
refactor: address comments
qinlz2 Mar 22, 2023
00a6188
fix: pass protocols as protocols
Apr 11, 2023
115a3c8
merge with prysm upstream
dshiell Jul 14, 2023
6fe0efd
Merge remote-tracking branch 'upstream/develop' into ds/merge_upstream
dshiell Jul 15, 2023
ce0e037
chore: regenerate protobufs
Aug 9, 2023
fde090a
chore: remove duplicate deps
Aug 9, 2023
32a8b2b
fix: remove dup src
Aug 9, 2023
27c4add
fix: more merge fallout
Aug 9, 2023
0437ce4
feat: JSON parsing for capella header
Aug 10, 2023
bb21e5e
chore: remove changes specific to fast devnet
Aug 10, 2023
6fb1d78
fix: linter
Aug 10, 2023
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
17 changes: 17 additions & 0 deletions api/gateway/apimiddleware/process_field.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,23 @@ func processField(s interface{}, processors []fieldProcessor) error {
t := reflect.TypeOf(s).Elem()
v := reflect.Indirect(reflect.ValueOf(s))

if t.Kind() == reflect.Struct {
err := processStructField(t, v, processors)
return err
} else if t.Kind() == reflect.Slice {
for i := 0; i < v.Len(); i++ {
if err := processField(v.Index(i).Interface(), processors); err != nil {
return errors.Wrapf(err, "could not process field '%s'", t.Name())
}
}
} else {
return fmt.Errorf("processing fields of kind '%v' is unsupported", t.Kind())
}

return nil
}

func processStructField(t reflect.Type, v reflect.Value, processors []fieldProcessor) error {
for i := 0; i < t.NumField(); i++ {
switch v.Field(i).Kind() {
case reflect.Slice:
Expand Down
5 changes: 5 additions & 0 deletions beacon-chain/blockchain/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ go_library(
"//beacon-chain/startup:go_default_library",
"//beacon-chain/state:go_default_library",
"//beacon-chain/state/stategen:go_default_library",
"//beacon-chain/rpc/eth/helpers/lightclient:go_default_library",
"//config/features:go_default_library",
"//config/fieldparams:go_default_library",
"//config/params:go_default_library",
Expand All @@ -75,6 +76,8 @@ go_library(
"//monitoring/tracing:go_default_library",
"//proto/engine/v1:go_default_library",
"//proto/eth/v1:go_default_library",
"//proto/eth/v2:go_default_library",
"//proto/migration:go_default_library",
"//proto/prysm/v1alpha1:go_default_library",
"//proto/prysm/v1alpha1/attestation:go_default_library",
"//runtime/version:go_default_library",
Expand Down Expand Up @@ -140,6 +143,7 @@ go_test(
"//beacon-chain/p2p:go_default_library",
"//beacon-chain/state/state-native:go_default_library",
"//beacon-chain/state/stateutil:go_default_library",
"//beacon-chain/rpc/eth/helpers/lightclient:go_default_library",
"//config/fieldparams:go_default_library",
"//config/params:go_default_library",
"//consensus-types/blocks:go_default_library",
Expand Down Expand Up @@ -196,6 +200,7 @@ go_test(
"//beacon-chain/execution/testing:go_default_library",
"//beacon-chain/forkchoice/types:go_default_library",
"//beacon-chain/p2p:go_default_library",
"//beacon-chain/rpc/eth/helpers/lightclient:go_default_library",
"//config/params:go_default_library",
"//consensus-types/blocks:go_default_library",
"//consensus-types/blocks/testing:go_default_library",
Expand Down
6 changes: 6 additions & 0 deletions beacon-chain/blockchain/chain_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/pkg/errors"
"github.com/prysmaticlabs/prysm/v4/beacon-chain/core/helpers"
"github.com/prysmaticlabs/prysm/v4/beacon-chain/forkchoice"
doublylinkedtree "github.com/prysmaticlabs/prysm/v4/beacon-chain/forkchoice/doubly-linked-tree"
forkchoicetypes "github.com/prysmaticlabs/prysm/v4/beacon-chain/forkchoice/types"
"github.com/prysmaticlabs/prysm/v4/beacon-chain/state"
Expand Down Expand Up @@ -333,6 +334,11 @@ func (s *Service) HeadValidatorIndexToPublicKey(_ context.Context, index primiti
return v.PublicKey(), nil
}

// ForkChoicer returns the forkchoice interface.
func (s *Service) ForkChoicer() forkchoice.ForkChoicer {
return s.cfg.ForkChoiceStore
}

// IsOptimistic returns true if the current head is optimistic.
func (s *Service) IsOptimistic(_ context.Context) (bool, error) {
if slots.ToEpoch(s.CurrentSlot()) < params.BeaconConfig().BellatrixForkEpoch {
Expand Down
130 changes: 130 additions & 0 deletions beacon-chain/blockchain/process_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
coreTime "github.com/prysmaticlabs/prysm/v4/beacon-chain/core/time"
"github.com/prysmaticlabs/prysm/v4/beacon-chain/core/transition"
forkchoicetypes "github.com/prysmaticlabs/prysm/v4/beacon-chain/forkchoice/types"
lightclienthelpers "github.com/prysmaticlabs/prysm/v4/beacon-chain/rpc/eth/helpers/lightclient"
"github.com/prysmaticlabs/prysm/v4/beacon-chain/state"
"github.com/prysmaticlabs/prysm/v4/config/features"
"github.com/prysmaticlabs/prysm/v4/config/params"
Expand All @@ -22,6 +23,7 @@ import (
"github.com/prysmaticlabs/prysm/v4/crypto/bls"
"github.com/prysmaticlabs/prysm/v4/encoding/bytesutil"
"github.com/prysmaticlabs/prysm/v4/monitoring/tracing"
ethpbv2 "github.com/prysmaticlabs/prysm/v4/proto/eth/v2"
ethpb "github.com/prysmaticlabs/prysm/v4/proto/prysm/v1alpha1"
"github.com/prysmaticlabs/prysm/v4/proto/prysm/v1alpha1/attestation"
"github.com/prysmaticlabs/prysm/v4/runtime/version"
Expand All @@ -39,6 +41,97 @@ const depositDeadline = 20 * time.Second
// This defines size of the upper bound for initial sync block cache.
var initialSyncBlockCacheSize = uint64(2 * params.BeaconConfig().SlotsPerEpoch)

// sendLightClientFinalityUpdate sends a light client finality update notification of to the state feed.
func (s *Service) sendLightClientFinalityUpdate(ctx context.Context, signed interfaces.ReadOnlySignedBeaconBlock,
postState state.BeaconState) (int, error) {
// Determine slots per period
config := params.BeaconConfig()

// Get attested state
attestedRoot := signed.Block().ParentRoot()
attestedState, err := s.cfg.StateGen.StateByRoot(ctx, attestedRoot)
if err != nil {
return 0, errors.Wrap(err, "could not get attested state")
}

// Get finalized block
var finalizedBlock interfaces.ReadOnlySignedBeaconBlock
finalizedCheckPoint := attestedState.FinalizedCheckpoint()
if finalizedCheckPoint != nil {
finalizedRoot := bytesutil.ToBytes32(finalizedCheckPoint.Root)
finalizedBlock, err = s.cfg.BeaconDB.Block(ctx, finalizedRoot)
if err != nil {
finalizedBlock = nil
}
}

update, err := lightclienthelpers.NewLightClientFinalityUpdateFromBeaconState(
ctx,
config,
postState,
signed,
attestedState,
finalizedBlock,
)

if err != nil {
return 0, errors.Wrap(err, "could not create light client update")
}

finalityUpdate := lightclienthelpers.NewLightClientFinalityUpdateFromUpdate(update)

// Return the result
result := &ethpbv2.LightClientFinalityUpdateResponse{
Version: ethpbv2.Version(signed.Version()),
Data: finalityUpdate,
}

// Send event
return s.cfg.StateNotifier.StateFeed().Send(&feed.Event{
Type: statefeed.LightClientFinalityUpdate,
Data: result,
}), nil
}

// sendLightClientOptimisticUpdate sends a light client optimistic update notification of to the state feed.
func (s *Service) sendLightClientOptimisticUpdate(ctx context.Context, signed interfaces.ReadOnlySignedBeaconBlock,
postState state.BeaconState) (int, error) {
// Determine slots per period
config := params.BeaconConfig()

// Get attested state
attestedRoot := signed.Block().ParentRoot()
attestedState, err := s.cfg.StateGen.StateByRoot(ctx, attestedRoot)
if err != nil {
return 0, errors.Wrap(err, "could not get attested state")
}

update, err := lightclienthelpers.NewLightClientOptimisticUpdateFromBeaconState(
ctx,
config,
postState,
signed,
attestedState,
)

if err != nil {
return 0, errors.Wrap(err, "could not create light client update")
}

optimisticUpdate := lightclienthelpers.NewLightClientOptimisticUpdateFromUpdate(update)

// Return the result
result := &ethpbv2.LightClientOptimisticUpdateResponse{
Version: ethpbv2.Version(signed.Version()),
Data: optimisticUpdate,
}

return s.cfg.StateNotifier.StateFeed().Send(&feed.Event{
Type: statefeed.LightClientOptimisticUpdate,
Data: result,
}), nil
}

// postBlockProcess is called when a gossip block is received. This function performs
// several duties most importantly informing the engine if head was updated,
// saving the new head information to the blockchain package and database and
Expand Down Expand Up @@ -118,6 +211,16 @@ func (s *Service) postBlockProcess(ctx context.Context, signed interfaces.ReadOn
},
})

if _, err := s.sendLightClientOptimisticUpdate(ctx, signed, postState); err != nil {
log.WithError(err)
}

// Save finalized check point to db and more.
finalized := s.ForkChoicer().FinalizedCheckpoint()

// LightClientFinalityUpdate needs super majority
s.tryPublishLightClientFinalityUpdate(ctx, signed, finalized, postState)

defer reportAttestationInclusion(b)
if err := s.handleEpochBoundary(ctx, postState, blockRoot[:]); err != nil {
return err
Expand All @@ -126,6 +229,33 @@ func (s *Service) postBlockProcess(ctx context.Context, signed interfaces.ReadOn
return nil
}

func (s *Service) tryPublishLightClientFinalityUpdate(ctx context.Context, signed interfaces.ReadOnlySignedBeaconBlock, finalized *forkchoicetypes.Checkpoint, postState state.BeaconState) {
if finalized.Epoch <= s.lastPublishedLightClientEpoch {
return
}

config := params.BeaconConfig()
if finalized.Epoch < config.AltairForkEpoch {
return
}

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

if syncAggregate.SyncCommitteeBits.Count()*3 < config.SyncCommitteeSize*2 {
return
}

_, err = s.sendLightClientFinalityUpdate(ctx, signed, postState)
if err != nil {
log.WithError(err)
} else {
s.lastPublishedLightClientEpoch = finalized.Epoch
}
}

func getStateVersionAndPayload(st state.BeaconState) (int, interfaces.ExecutionData, error) {
if st == nil {
return 0, nil, errors.New("nil state")
Expand Down
14 changes: 6 additions & 8 deletions beacon-chain/blockchain/process_block_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,42 +212,40 @@ func (s *Service) fillInForkChoiceMissingBlocks(ctx context.Context, blk interfa

// inserts finalized deposits into our finalized deposit trie, needs to be
// called in the background
func (s *Service) insertFinalizedDeposits(ctx context.Context, fRoot [32]byte) {
func (s *Service) insertFinalizedDeposits(ctx context.Context, fRoot [32]byte) error {
ctx, span := trace.StartSpan(ctx, "blockChain.insertFinalizedDeposits")
defer span.End()
startTime := time.Now()

// Update deposit cache.
finalizedState, err := s.cfg.StateGen.StateByRoot(ctx, fRoot)
if err != nil {
log.WithError(err).Error("could not fetch finalized state")
return
return errors.Wrap(err, "could not fetch finalized state")
}
// We update the cache up to the last deposit index in the finalized block's state.
// We can be confident that these deposits will be included in some block
// because the Eth1 follow distance makes such long-range reorgs extremely unlikely.
eth1DepositIndex, err := mathutil.Int(finalizedState.Eth1DepositIndex())
if err != nil {
log.WithError(err).Error("could not cast eth1 deposit index")
return
return errors.Wrap(err, "could not cast eth1 deposit index")
}
// The deposit index in the state is always the index of the next deposit
// to be included(rather than the last one to be processed). This was most likely
// done as the state cannot represent signed integers.
finalizedEth1DepIdx := eth1DepositIndex - 1
if err = s.cfg.DepositCache.InsertFinalizedDeposits(ctx, int64(finalizedEth1DepIdx)); err != nil {
log.WithError(err).Error("could not insert finalized deposits")
return
return errors.Wrap(err, "could not insert finalized deposits")
}
// Deposit proofs are only used during state transition and can be safely removed to save space.
if err = s.cfg.DepositCache.PruneProofs(ctx, int64(finalizedEth1DepIdx)); err != nil {
log.WithError(err).Error("could not prune deposit proofs")
return errors.Wrap(err, "could not prune deposit proofs")
}
// Prune deposits which have already been finalized, the below method prunes all pending deposits (non-inclusive) up
// to the provided eth1 deposit index.
s.cfg.DepositCache.PrunePendingDeposits(ctx, int64(eth1DepositIndex)) // lint:ignore uintcast -- Deposit index should not exceed int64 in your lifetime.

log.WithField("duration", time.Since(startTime).String()).Debug("Finalized deposit insertion completed")
return nil
}

// This ensures that the input root defaults to using genesis root instead of zero hashes. This is needed for handling
Expand Down
4 changes: 3 additions & 1 deletion beacon-chain/blockchain/receive_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,9 @@ func (s *Service) ReceiveBlock(ctx context.Context, block interfaces.ReadOnlySig
go s.sendNewFinalizedEvent(ctx, blockCopy, postState, finalized)
depCtx, cancel := context.WithTimeout(context.Background(), depositDeadline)
go func() {
s.insertFinalizedDeposits(depCtx, finalized.Root)
if err := s.insertFinalizedDeposits(depCtx, finalized.Root); err != nil {
log.WithError(err).Error("Could not insert finalized deposits.")
}
cancel()
}()
}
Expand Down
33 changes: 17 additions & 16 deletions beacon-chain/blockchain/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,22 +46,23 @@ import (
// Service represents a service that handles the internal
// logic of managing the full PoS beacon chain.
type Service struct {
cfg *config
ctx context.Context
cancel context.CancelFunc
genesisTime time.Time
head *head
headLock sync.RWMutex
originBlockRoot [32]byte // genesis root, or weak subjectivity checkpoint root, depending on how the node is initialized
nextEpochBoundarySlot primitives.Slot
boundaryRoots [][32]byte
checkpointStateCache *cache.CheckpointStateCache
initSyncBlocks map[[32]byte]interfaces.ReadOnlySignedBeaconBlock
initSyncBlocksLock sync.RWMutex
wsVerifier *WeakSubjectivityVerifier
clockSetter startup.ClockSetter
clockWaiter startup.ClockWaiter
syncComplete chan struct{}
cfg *config
ctx context.Context
cancel context.CancelFunc
genesisTime time.Time
head *head
headLock sync.RWMutex
originBlockRoot [32]byte // genesis root, or weak subjectivity checkpoint root, depending on how the node is initialized
nextEpochBoundarySlot primitives.Slot
boundaryRoots [][32]byte
checkpointStateCache *cache.CheckpointStateCache
initSyncBlocks map[[32]byte]interfaces.ReadOnlySignedBeaconBlock
initSyncBlocksLock sync.RWMutex
wsVerifier *WeakSubjectivityVerifier
clockSetter startup.ClockSetter
clockWaiter startup.ClockWaiter
syncComplete chan struct{}
lastPublishedLightClientEpoch primitives.Epoch
}

// config options for the service.
Expand Down
4 changes: 4 additions & 0 deletions beacon-chain/core/feed/state/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ const (
NewHead
// MissedSlot is sent when we need to notify users that a slot was missed.
MissedSlot
// LightClientFinalityUpdate event
LightClientFinalityUpdate
// LightClientOptimisticUpdate event
LightClientOptimisticUpdate
)

// BlockProcessedData is the data sent with BlockProcessed events.
Expand Down
13 changes: 13 additions & 0 deletions beacon-chain/lightclient/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
load("@prysm//tools/go:def.bzl", "go_library")

go_library(
name = "go_default_library",
srcs = [
"config.go",
"helpers.go",
"store.go",
"update.go",
],
importpath = "github.com/prysmaticlabs/prysm/v3/beacon-chain/lightclient",
visibility = ["//visibility:public"],
)
Loading
Loading