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

Reduce attester state copies #6025

Merged
merged 6 commits into from
May 28, 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
1 change: 1 addition & 0 deletions beacon-chain/cache/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ go_library(
deps = [
"//beacon-chain/state:go_default_library",
"//proto/beacon/p2p/v1:go_default_library",
"//shared/featureconfig:go_default_library",
"//shared/hashutil:go_default_library",
"//shared/params:go_default_library",
"//shared/sliceutil:go_default_library",
Expand Down
8 changes: 8 additions & 0 deletions beacon-chain/cache/attestation_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
"github.com/prysmaticlabs/prysm/beacon-chain/state"
"github.com/prysmaticlabs/prysm/shared/featureconfig"
"k8s.io/client-go/tools/cache"
)

Expand Down Expand Up @@ -97,6 +99,9 @@ func (c *AttestationCache) Get(ctx context.Context, req *ethpb.AttestationDataRe

if exists && item != nil && item.(*attestationReqResWrapper).res != nil {
attestationCacheHit.Inc()
if featureconfig.Get().ReduceAttesterStateCopy {
return state.CopyAttestationData(item.(*attestationReqResWrapper).res), nil
}
return item.(*attestationReqResWrapper).res, nil
}
attestationCacheMiss.Inc()
Expand Down Expand Up @@ -162,6 +167,9 @@ func wrapperToKey(i interface{}) (string, error) {
}

func reqToKey(req *ethpb.AttestationDataRequest) (string, error) {
if featureconfig.Get().ReduceAttesterStateCopy {
return fmt.Sprintf("%d", req.Slot), nil
}
return fmt.Sprintf("%d-%d", req.CommitteeIndex, req.Slot), nil
}

Expand Down
6 changes: 6 additions & 0 deletions beacon-chain/rpc/validator/attester.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ func (vs *Server) GetAttestationData(ctx context.Context, req *ethpb.Attestation
return nil, status.Errorf(codes.Internal, "Could not retrieve data from attestation cache: %v", err)
}
if res != nil {
if featureconfig.Get().ReduceAttesterStateCopy {
res.CommitteeIndex = req.CommitteeIndex
}
return res, nil
}

Expand All @@ -59,6 +62,9 @@ func (vs *Server) GetAttestationData(ctx context.Context, req *ethpb.Attestation
if res == nil {
return nil, status.Error(codes.DataLoss, "A request was in progress and resolved to nil")
}
if featureconfig.Get().ReduceAttesterStateCopy {
res.CommitteeIndex = req.CommitteeIndex
}
return res, nil
}
return nil, status.Errorf(codes.Internal, "Could not mark attestation as in-progress: %v", err)
Expand Down
5 changes: 5 additions & 0 deletions shared/featureconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ type Flags struct {
WaitForSynced bool // WaitForSynced uses WaitForSynced in validator startup to ensure it can communicate with the beacon node as soon as possible.
SkipRegenHistoricalStates bool // SkipRegenHistoricalState skips regenerating historical states from genesis to last finalized. This enables a quick switch over to using new-state-mgmt.
EnableInitSyncWeightedRoundRobin bool // EnableInitSyncWeightedRoundRobin enables weighted round robin fetching optimization in initial syncing.
ReduceAttesterStateCopy bool // ReduceAttesterStateCopy reduces head state copies for attester rpc.

// DisableForkChoice disables using LMD-GHOST fork choice to update
// the head of the chain based on attestations and instead accepts any valid received block
Expand Down Expand Up @@ -215,6 +216,10 @@ func ConfigureBeaconChain(ctx *cli.Context) {
log.Warn("Disabling state reference copy")
cfg.EnableStateRefCopy = false
}
if ctx.Bool(reduceAttesterStateCopy.Name) {
log.Warn("Enabling feature that reduces attester state copy")
cfg.ReduceAttesterStateCopy = true
}
Init(cfg)
}

Expand Down
7 changes: 7 additions & 0 deletions shared/featureconfig/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,12 +157,17 @@ var (
Name: "enable-init-sync-wrr",
Usage: "Enables weighted round robin fetching optimization",
}
reduceAttesterStateCopy = &cli.BoolFlag{
Name: "reduce-attester-state-copy",
Usage: "Reduces the amount of state copies for attester rpc",
}
)

// devModeFlags holds list of flags that are set when development mode is on.
var devModeFlags = []cli.Flag{
enableNewStateMgmt,
enableInitSyncWeightedRoundRobin,
reduceAttesterStateCopy,
}

// Deprecated flags list.
Expand Down Expand Up @@ -481,6 +486,7 @@ var BeaconChainFlags = append(deprecatedFlags, []cli.Flag{
enableInitSyncWeightedRoundRobin,
disableFieldTrie,
disableStateRefCopy,
reduceAttesterStateCopy,
}...)

// E2EBeaconChainFlags contains a list of the beacon chain feature flags to be tested in E2E.
Expand All @@ -490,4 +496,5 @@ var E2EBeaconChainFlags = []string{
"--check-head-state",
"--enable-new-state-mgmt",
"--enable-init-sync-wrr",
"--reduce-attester-state-copy",
}