-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Add deposit index to beacon state #2232
Add deposit index to beacon state #2232
Conversation
@@ -47,17 +46,7 @@ func (s *InitialSync) processState(msg p2p.Message) { | |||
return | |||
} | |||
|
|||
exists, blkNum, err := s.powchain.BlockExists(ctx, bytesutil.ToBytes32(finalizedState.LatestEth1Data.BlockHash32)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why remove this? dont we still want to verify that the block exists?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch, adding it back. My mistake.
// Deposits must be processed in order | ||
if deposit.MerkleTreeIndex != beaconState.DepositIndex { | ||
return fmt.Errorf( | ||
"expected deposit merkle branch index to match beacon state deposit index, wanted: %d, received: %d", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Merkle branch index or merkle tree index?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch, thank you. Changed to merkle tree index.
beacon-chain/db/pending_deposits.go
Outdated
@@ -113,7 +113,7 @@ func (db *BeaconDB) PrunePendingDeposits(ctx context.Context, b *big.Int) { | |||
// added deposit and works backwards. | |||
idx := -1 | |||
for i := depositListSize - 1; i >= 0; i-- { | |||
if db.pendingDeposits[i].block.Cmp(b) == -1 { | |||
if db.pendingDeposits[i].deposit.MerkleTreeIndex < merkleTreeIndex { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this relies on the pending deposits being sorted by their indexes, right now they are sorted by the block in which the deposit is logged in
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point!
beacon-chain/core/state/state.go
Outdated
@@ -146,6 +147,8 @@ func GenesisBeaconState( | |||
if err != nil { | |||
return nil, fmt.Errorf("could not process validator deposit: %v", err) | |||
} | |||
|
|||
state.DepositIndex++ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you should not increment it here, it should be in the ProcessDeposit
function
@@ -17,18 +17,18 @@ test_cases: | |||
num_slots: 64 # Testing advancing state to exactly slot == SlotsPerEpoch | |||
deposits: | |||
- slot: 9223372036854775809 | |||
amount: 32 | |||
merkle_index: 0 | |||
amount: 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wait , what is going on here ? why is this 1.
the same below. We always use 32 eth
Codecov Report
@@ Coverage Diff @@
## master #2232 +/- ##
==========================================
- Coverage 69.57% 68.86% -0.71%
==========================================
Files 116 116
Lines 9080 8882 -198
==========================================
- Hits 6317 6117 -200
+ Misses 2111 2108 -3
- Partials 652 657 +5 |
Progress so far, I believe it's mostly done except with some bugs on the RPC side. Too late now so I'll resume tomorrow. Also, @nisdas and I don't think the RPC should only return
Shouldn't it at least include the current deposit index, so the validators can send it? |
…fix-deposits-sync
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks amazing. Let's try in cluster before merge.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
var pendingDeps []*pbp2p.Deposit | ||
for _, dep := range allPendingDeps { | ||
if dep.MerkleTreeIndex >= beaconState.DepositIndex { | ||
pendingDeps = append(pendingDeps, dep) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this isnt ordered, we want the indexes to be sorted in an ascending order.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nvm , ignore it, its sorted by the PendingDeposits function
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great job on this, looks good to me
var pendingDeps []*pbp2p.Deposit | ||
for _, dep := range allPendingDeps { | ||
if dep.MerkleTreeIndex >= beaconState.DepositIndex { | ||
pendingDeps = append(pendingDeps, dep) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nvm , ignore it, its sorted by the PendingDeposits function
276b784
…v/prysm into fix-deposits-sync
Looks great, awesome job on this non-trivial feature! |
…v/prysm into fix-deposits-sync
Resolves #2199
Currently, we have an issue that we don't properly make sure deposits aren't duplicated. The spec has recently implemented a deposit_index in the beacon state that maintains what deposit index has been processed for the sake of ensuring duplicate deposits aren't sent in.
Changes made:
Beacon State now has DepositIndex which is:
MerkleBranchHash32S -> MerkleProofHash32S