Skip to content

Commit

Permalink
Don't Copy The Whole Validator Map each time (#5780)
Browse files Browse the repository at this point in the history
* fix copying issues

* revert some changes
  • Loading branch information
nisdas authored May 8, 2020
1 parent c1a8b41 commit 6fed51d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
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

0 comments on commit 6fed51d

Please sign in to comment.