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

* fix copying issues

* revert some changes
This commit is contained in:
Nishant Das 2020-05-08 18:14:18 +08:00 committed by GitHub
parent c1a8b41347
commit 6fed51d380
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 5 deletions

View File

@ -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 {
@ -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

View File

@ -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
}