From 0067e52b1e6b0beeb01c95835b685ce34c3f6ef1 Mon Sep 17 00:00:00 2001 From: Nishant Das Date: Sun, 14 Jun 2020 14:34:33 +0800 Subject: [PATCH] Revert "Remove Excess State Copies" (#6240) * Revert "remove excess copies (#6142)" This reverts commit c956905cf07734d228ed70c7f0795084f8d88a44. --- beacon-chain/blockchain/process_attestation_helpers.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/beacon-chain/blockchain/process_attestation_helpers.go b/beacon-chain/blockchain/process_attestation_helpers.go index ecbe90fda..9fa4eab37 100644 --- a/beacon-chain/blockchain/process_attestation_helpers.go +++ b/beacon-chain/blockchain/process_attestation_helpers.go @@ -45,6 +45,7 @@ func (s *Service) getAttPreState(ctx context.Context, c *ethpb.Checkpoint) (*sta } if helpers.StartSlot(c.Epoch) > baseState.Slot() { + baseState = baseState.Copy() baseState, err = state.ProcessSlots(ctx, baseState, helpers.StartSlot(c.Epoch)) if err != nil { return nil, errors.Wrapf(err, "could not process slots up to %d", helpers.StartSlot(c.Epoch)) @@ -90,22 +91,23 @@ func (s *Service) getAttPreState(ctx context.Context, c *ethpb.Checkpoint) (*sta } if helpers.StartSlot(c.Epoch) > baseState.Slot() { - baseState, err = state.ProcessSlots(ctx, baseState, helpers.StartSlot(c.Epoch)) + savedState := baseState.Copy() + savedState, err = state.ProcessSlots(ctx, savedState, helpers.StartSlot(c.Epoch)) if err != nil { return nil, errors.Wrapf(err, "could not process slots up to %d", helpers.StartSlot(c.Epoch)) } if err := s.checkpointState.AddCheckpointState(&cache.CheckpointState{ Checkpoint: c, - State: baseState, + State: savedState.Copy(), }); err != nil { return nil, errors.Wrap(err, "could not saved checkpoint state to cache") } - return baseState, nil + return savedState, nil } if err := s.checkpointState.AddCheckpointState(&cache.CheckpointState{ Checkpoint: c, - State: baseState, + State: baseState.Copy(), }); err != nil { return nil, errors.Wrap(err, "could not saved checkpoint state to cache") }