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

Don't Copy The Whole Validator Map each time #5780

Merged
merged 2 commits into from
May 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 0 additions & 3 deletions beacon-chain/core/blocks/block_operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -945,7 +945,6 @@ func ProcessDeposit(
pubKey := deposit.Data.PublicKey
amount := deposit.Data.Amount
index, ok := beaconState.ValidatorIndexByPubkey(bytesutil.ToBytes48(pubKey))
numVals := beaconState.NumValidators()
if !ok {
domain, err := helpers.ComputeDomain(params.BeaconConfig().DomainDeposit, nil, nil)
if err != nil {
Expand Down Expand Up @@ -976,8 +975,6 @@ func ProcessDeposit(
if err := beaconState.AppendBalance(amount); err != nil {
return nil, err
}
numVals++
beaconState.SetValidatorIndexByPubkey(bytesutil.ToBytes48(pubKey), uint64(numVals-1))
} else {
if err := helpers.IncreaseBalance(beaconState, uint64(index), amount); err != nil {
return nil, err
Expand Down
9 changes: 7 additions & 2 deletions beacon-chain/state/setters.go
Original file line number Diff line number Diff line change
Expand Up @@ -666,10 +666,15 @@ func (b *BeaconState) AppendValidator(val *ethpb.Validator) error {
b.lock.Lock()
defer b.lock.Unlock()

// append validator to slice and add
// it to the validator map
b.state.Validators = append(vals, val)
valIdx := uint64(len(b.state.Validators) - 1)
valMap := coreutils.ValidatorIndexMap(b.state.Validators)

b.markFieldAsDirty(validators)
b.AddDirtyIndices(validators, []uint64{uint64(len(b.state.Validators) - 1)})
b.valIdxMap = coreutils.ValidatorIndexMap(b.state.Validators)
b.AddDirtyIndices(validators, []uint64{valIdx})
b.valIdxMap = valMap
return nil
}

Expand Down