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

EIP-6110: Supply validator deposits on chain #13944

Merged
merged 92 commits into from
Jun 29, 2024
Merged
Show file tree
Hide file tree
Changes from 65 commits
Commits
Show all changes
92 commits
Select commit Hold shift + click to select a range
5ad0a86
wip changes
james-prysm May 1, 2024
3572a53
wip changes refactoring deposit functions
james-prysm May 1, 2024
be6e19c
Merge branch 'develop' into eip6110
james-prysm May 2, 2024
bd3a92e
wip on deposit functions
james-prysm May 2, 2024
7666f65
wip changes to fix deposit processing
james-prysm May 2, 2024
51a2282
more wip function logic
james-prysm May 3, 2024
db031bd
gaz
james-prysm May 3, 2024
393e1a8
Merge branch 'develop' into eip6110
james-prysm May 6, 2024
9ccbaca
Merge branch 'develop' into eip6110
james-prysm May 6, 2024
ee0ad99
Merge branch 'develop' into eip6110
james-prysm May 7, 2024
550d366
Merge branch 'develop' into eip6110
james-prysm May 7, 2024
7f2bdf5
Merge branch 'develop' into eip6110
james-prysm May 7, 2024
c24e80c
wip refactoring deposit changes
james-prysm May 7, 2024
6287e3c
Merge branch 'develop' into eip6110
james-prysm May 7, 2024
be66a2d
Merge branch 'develop' into eip6110
james-prysm May 7, 2024
e3f50e9
removing circlular dependency and other small fix
james-prysm May 7, 2024
560ef11
Merge branch 'develop' into eip6110
james-prysm May 8, 2024
822cf02
fixing circular dependencies
james-prysm May 8, 2024
91eadef
fixing validators file
james-prysm May 8, 2024
8ffcb16
fixing more tests
james-prysm May 8, 2024
e4efcab
fixing unit tests
james-prysm May 8, 2024
babebea
Merge branch 'develop' into eip6110
james-prysm May 8, 2024
3469f6b
wip deposit packing
james-prysm May 9, 2024
d000211
refactoring packing
james-prysm May 9, 2024
4ba45f0
changing packing code some more
james-prysm May 9, 2024
c5189a7
fixing packing change
james-prysm May 9, 2024
935baca
updating more tests
james-prysm May 9, 2024
210a129
Merge branch 'develop' into eip6110
james-prysm May 9, 2024
d884737
removing comment
james-prysm May 9, 2024
b659925
fixing transition code for eip6110
james-prysm May 9, 2024
db5743f
Merge branch 'develop' into eip6110
james-prysm May 9, 2024
358ae04
including inserts for validator index cache
james-prysm May 9, 2024
1843ee5
Merge branch 'develop' into eip6110
james-prysm May 10, 2024
ade6c30
Merge branch 'develop' into eip6110
james-prysm May 12, 2024
32bc6b4
adding tests and placeholder test
james-prysm May 12, 2024
dd24d42
Merge branch 'develop' into eip6110
james-prysm May 13, 2024
ee52e22
moving deposit related unit tests over
james-prysm May 13, 2024
d8608d1
adding in test for electra proposer packing
james-prysm May 13, 2024
ef10964
Merge branch 'develop' into eip6110
james-prysm May 13, 2024
918ca0e
spec test wip
james-prysm May 14, 2024
e2af855
moving cache saving to the correct spot
james-prysm May 14, 2024
b6c1c37
eip-6110: deposit spectests
prestonvanloon May 14, 2024
8f554db
adding deposit receipt spec tests
james-prysm May 15, 2024
d08900f
Merge branch 'develop' into eip6110
james-prysm May 15, 2024
2c02712
reverting altair operations in this pr and will be handled separately
james-prysm May 15, 2024
ae4d911
Merge branch 'develop' into eip6110
james-prysm May 16, 2024
edc7198
Merge branch 'develop' into eip6110
james-prysm May 21, 2024
99a0aff
Merge branch 'develop' into eip6110
james-prysm May 24, 2024
f9b56d1
Merge branch 'develop' into eip6110
james-prysm Jun 5, 2024
261809b
Merge branch 'develop' into eip6110
james-prysm Jun 10, 2024
7a0a7a4
Merge branch 'develop' into eip6110
james-prysm Jun 12, 2024
c322c09
Merge branch 'develop' into eip6110
james-prysm Jun 12, 2024
3200781
fixing renames but need to refactor process deposits
james-prysm Jun 12, 2024
e0ae765
gaz
james-prysm Jun 12, 2024
fa3a689
fixing names
james-prysm Jun 13, 2024
278d80c
fixing linting
james-prysm Jun 13, 2024
69f77e7
Merge branch 'develop' into eip6110
james-prysm Jun 13, 2024
a39e014
fixing unit test
james-prysm Jun 13, 2024
56f0728
fixing a test and updating test util
james-prysm Jun 13, 2024
ffe5260
bal never used
james-prysm Jun 13, 2024
12fe34c
fixing more tests
james-prysm Jun 13, 2024
212ef50
fixing one more test
james-prysm Jun 14, 2024
644f938
Merge branch 'develop' into eip6110
james-prysm Jun 14, 2024
afc037b
Merge branch 'develop' into eip6110
james-prysm Jun 14, 2024
575ae4c
addressing feedback
james-prysm Jun 17, 2024
940d8e3
refactoring process deposits to be part of their own fork instead of …
james-prysm Jun 20, 2024
e34cd2f
adding new tests to cover functions and removing redundancies
james-prysm Jun 20, 2024
83eacc0
Merge branch 'develop' into eip6110
james-prysm Jun 20, 2024
a45c7e7
removing comment based on feedback
james-prysm Jun 20, 2024
f919a8d
Merge branch 'develop' into eip6110
james-prysm Jun 20, 2024
c819897
resolving easy deepsource issue
james-prysm Jun 20, 2024
d7bd167
Merge branch 'develop' into eip6110
james-prysm Jun 21, 2024
3cb4c5f
refactoring for appropriate aliasing and readability
james-prysm Jun 21, 2024
1582be9
Merge branch 'develop' into eip6110
james-prysm Jun 24, 2024
c09cd25
reverting some changes to simplify diff
james-prysm Jun 24, 2024
dc38405
Merge branch 'develop' into eip6110
james-prysm Jun 24, 2024
9b5a925
Merge branch 'develop' into eip6110
james-prysm Jun 25, 2024
bccfa0b
small edit to comment
james-prysm Jun 25, 2024
aff2231
fixing linting
james-prysm Jun 25, 2024
04372f5
Merge branch 'develop' into eip6110
james-prysm Jun 26, 2024
a9a7aed
Merge branch 'develop' into eip6110
james-prysm Jun 26, 2024
f2be21f
Merge branch 'develop' into eip6110
james-prysm Jun 26, 2024
502a721
Merge branch 'develop' into eip6110
james-prysm Jun 27, 2024
43912e9
Merge branch 'develop' into eip6110
james-prysm Jun 27, 2024
7fa467a
fixing merge changes and review comments
james-prysm Jun 27, 2024
3e5f08b
Merge branch 'develop' into eip6110
james-prysm Jun 28, 2024
2bb28d3
Update beacon-chain/rpc/prysm/v1alpha1/validator/proposer_deposits.go
james-prysm Jun 28, 2024
7fa48d1
Merge branch 'develop' into eip6110
james-prysm Jun 28, 2024
45e9eb2
partial review comments
james-prysm Jun 28, 2024
0dc3473
addressing slack feedback
james-prysm Jun 28, 2024
649e94b
moving function from deposits to validator.go
james-prysm Jun 28, 2024
f2da526
adding in batch verification and improving logs
james-prysm Jun 28, 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
22 changes: 15 additions & 7 deletions beacon-chain/blockchain/receive_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,13 +169,8 @@ func (s *Service) ReceiveBlock(ctx context.Context, block interfaces.ReadOnlySig
}
// Send finalized events and finalized deposits in the background
if newFinalized {
finalized := s.cfg.ForkChoiceStore.FinalizedCheckpoint()
go s.sendNewFinalizedEvent(ctx, postState)
depCtx, cancel := context.WithTimeout(context.Background(), depositDeadline)
go func() {
s.insertFinalizedDeposits(depCtx, finalized.Root)
cancel()
}()
// hook to process all post state finalization tasks
s.executePostFinalizationTasks(ctx, postState)
james-prysm marked this conversation as resolved.
Show resolved Hide resolved
}

// If slasher is configured, forward the attestations in the block via an event feed for processing.
Expand Down Expand Up @@ -224,6 +219,19 @@ func (s *Service) ReceiveBlock(ctx context.Context, block interfaces.ReadOnlySig
return nil
}

func (s *Service) executePostFinalizationTasks(ctx context.Context, finalizedState state.BeaconState) {
finalized := s.cfg.ForkChoiceStore.FinalizedCheckpoint()
go func() {
finalizedState.SaveValidatorIndices() // used to handle Validator index invariant from EIP6110
s.sendNewFinalizedEvent(ctx, finalizedState)
}()
depCtx, cancel := context.WithTimeout(context.Background(), depositDeadline)
go func() {
s.insertFinalizedDeposits(depCtx, finalized.Root)
cancel()
}()
}

// ReceiveBlockBatch processes the whole block batch at once, assuming the block batch is linear ,transitioning
// the state, performing batch verification of all collected signatures and then performing the appropriate
// actions for a block post-transition.
Expand Down
2 changes: 2 additions & 0 deletions beacon-chain/blockchain/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,8 @@ func (s *Service) StartFromSavedState(saved state.BeaconState) error {
return errors.Wrap(err, "failed to initialize blockchain service")
}

saved.SaveValidatorIndices() // used to handle Validator index invariant from EIP6110
Copy link
Contributor Author

Choose a reason for hiding this comment

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

double check this spot as well...


return nil
}

Expand Down
1 change: 1 addition & 0 deletions beacon-chain/core/altair/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ go_test(
],
embed = [":go_default_library"],
deps = [
"//beacon-chain/core/blocks:go_default_library",
"//beacon-chain/core/epoch:go_default_library",
"//beacon-chain/core/epoch/precompute:go_default_library",
"//beacon-chain/core/helpers:go_default_library",
Expand Down
23 changes: 1 addition & 22 deletions beacon-chain/core/altair/deposit.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,31 +25,10 @@ func ProcessDeposits(
if deposit == nil || deposit.Data == nil {
return nil, errors.New("got a nil deposit in block")
}
beaconState, err = ProcessDeposit(beaconState, deposit, batchVerified)
beaconState, err = blocks.ProcessDeposit(beaconState, deposit, batchVerified)
if err != nil {
return nil, errors.Wrapf(err, "could not process deposit from %#x", bytesutil.Trunc(deposit.Data.PublicKey))
}
}
return beaconState, nil
}

// ProcessDeposit processes validator deposit for beacon state Altair.
func ProcessDeposit(beaconState state.BeaconState, deposit *ethpb.Deposit, verifySignature bool) (state.BeaconState, error) {
beaconState, isNewValidator, err := blocks.ProcessDeposit(beaconState, deposit, verifySignature)
if err != nil {
return nil, err
}
if isNewValidator {
if err := beaconState.AppendInactivityScore(0); err != nil {
return nil, err
}
if err := beaconState.AppendPreviousParticipationBits(0); err != nil {
return nil, err
}
if err := beaconState.AppendCurrentParticipationBits(0); err != nil {
return nil, err
}
}

return beaconState, nil
}
3 changes: 2 additions & 1 deletion beacon-chain/core/altair/deposit_fuzz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

fuzz "github.com/google/gofuzz"
"github.com/prysmaticlabs/prysm/v5/beacon-chain/core/altair"
b "github.com/prysmaticlabs/prysm/v5/beacon-chain/core/blocks"
state_native "github.com/prysmaticlabs/prysm/v5/beacon-chain/state/state-native"
ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1"
"github.com/prysmaticlabs/prysm/v5/testing/require"
Expand Down Expand Up @@ -40,7 +41,7 @@ func TestFuzzProcessDeposit_10000(t *testing.T) {
fuzzer.Fuzz(deposit)
s, err := state_native.InitializeFromProtoUnsafeAltair(state)
require.NoError(t, err)
r, err := altair.ProcessDeposit(s, deposit, true)
r, err := b.ProcessDeposit(s, deposit, true)
if err != nil && r != nil {
t.Fatalf("return value should be nil on err. found: %v on error: %v for state: %v and block: %v", r, err, state, deposit)
}
Expand Down
5 changes: 3 additions & 2 deletions beacon-chain/core/altair/deposit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"testing"

"github.com/prysmaticlabs/prysm/v5/beacon-chain/core/altair"
b "github.com/prysmaticlabs/prysm/v5/beacon-chain/core/blocks"
"github.com/prysmaticlabs/prysm/v5/beacon-chain/core/signing"
state_native "github.com/prysmaticlabs/prysm/v5/beacon-chain/state/state-native"
"github.com/prysmaticlabs/prysm/v5/config/params"
Expand Down Expand Up @@ -183,7 +184,7 @@ func TestProcessDeposit_AddsNewValidatorDeposit(t *testing.T) {
},
})
require.NoError(t, err)
newState, err := altair.ProcessDeposit(beaconState, dep[0], true)
newState, err := b.ProcessDeposit(beaconState, dep[0], true)
require.NoError(t, err, "Process deposit failed")
require.Equal(t, 2, len(newState.Validators()), "Expected validator list to have length 2")
require.Equal(t, 2, len(newState.Balances()), "Expected validator balances list to have length 2")
Expand Down Expand Up @@ -226,7 +227,7 @@ func TestProcessDeposit_SkipsInvalidDeposit(t *testing.T) {
},
})
require.NoError(t, err)
newState, err := altair.ProcessDeposit(beaconState, dep[0], true)
newState, err := b.ProcessDeposit(beaconState, dep[0], true)
require.NoError(t, err, "Expected invalid block deposit to be ignored without error")

if newState.Eth1DepositIndex() != 1 {
Expand Down
2 changes: 1 addition & 1 deletion beacon-chain/core/blocks/block_operations_fuzz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ func TestFuzzProcessDeposit_10000(t *testing.T) {
fuzzer.Fuzz(deposit)
s, err := state_native.InitializeFromProtoUnsafePhase0(state)
require.NoError(t, err)
r, _, err := ProcessDeposit(s, deposit, true)
r, err := ProcessDeposit(s, deposit, true)
if err != nil && r != nil {
t.Fatalf("return value should be nil on err. found: %v on error: %v for state: %v and block: %v", r, err, state, deposit)
}
Expand Down
Loading
Loading