-
Notifications
You must be signed in to change notification settings - Fork 969
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
Fix Up SSZ Cache Branch Recomputation #4558
Conversation
@rauljordan tests failing
|
return rt, nil | ||
} | ||
|
||
hashKey := hashutil.FastSum256(hashKeyElements) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This cache will never get hit. Arrays always typically get one element added each slot.
} | ||
|
||
hashKey := hashutil.FastSum256(hashKeyElements) | ||
if hashKey != emptyKey && h.rootsCache != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here
for i := 0; i < len(changedIndices); i++ { | ||
rt, err = recomputeRoot(changedIndices[i], chunks, fieldName) | ||
if err != nil { | ||
return [32]byte{}, err | ||
} | ||
} | ||
lock.Lock() | ||
leavesCache[fieldName] = chunks |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was part of the problem, we had to update some cached values after recomputing the root
@@ -29,21 +37,6 @@ func TestState_FieldCount(t *testing.T) { | |||
} | |||
} | |||
|
|||
func TestHashTreeRootEquality(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test will never pass due to #4526 (comment). We will need --define ssz=minimal
on this test target for it to pass.
shared/featureconfig/flags.go
Outdated
@@ -18,6 +18,11 @@ var ( | |||
Name: "enable-attestation-cache", | |||
Usage: "Enable unsafe cache mechanism. See https://github.com/prysmaticlabs/prysm/issues/3106", | |||
} | |||
// EnableSSZCache -- | |||
EnableSSZCache = cli.BoolFlag{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you un-export this and change the name to enableSSZCacheFlag? No need to export it, that's what the config is for.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do
shared/stateutil/state_root.go
Outdated
@@ -8,14 +8,17 @@ import ( | |||
"github.com/pkg/errors" | |||
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1" | |||
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1" | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fuzzStateRootCache(t, 3, 100000) | ||
} | ||
|
||
func TestStateRootCacheFuzz_1000000(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why were the larger cases removed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They take way too long to run now. Now, when doing HTR(state.BlockRoots), we pad the slice to params.BeaconConfig().SlotsPerHistoricalRoot, and the fuzz tests don't really make much use of the cache so much because the inputs change on every iteration, so they take almost 10s to run the 10k fuzz test, let alone the 100k one.
func init() { | ||
config := &featureconfig.Flags{ | ||
EnableSSZCache: true, | ||
} | ||
featureconfig.Init(config) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this being used? Hard to tell.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep! It is because it is picked up by the internal stateutil.HashTreeRoot function as being enabled
@@ -82,7 +75,7 @@ func BenchmarkHashTreeRootState_Generic_512(b *testing.B) { | |||
genesisState := setupGenesisState(b, 512) | |||
b.StartTimer() | |||
for i := 0; i < b.N; i++ { | |||
if _, err := stateutil.HashTreeRootState(genesisState); err != nil { | |||
if _, err := ssz.HashTreeRoot(genesisState); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These 3 tests here say BenchmarkHashTreeRootState
when it's HashTreeRoot
being tested instead, can you update the test names?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
Codecov Report
@@ Coverage Diff @@
## master #4558 +/- ##
=========================================
Coverage ? 43.58%
=========================================
Files ? 193
Lines ? 13708
Branches ? 0
=========================================
Hits ? 5975
Misses ? 6729
Partials ? 1004 |
* e2e ssz cache busting * use ssz cache for e2e * caching ensure * fix up the cache even more * gazelle * formatting * formatting * add back cache for val registry * sync * fix up commented item * add attestations * Merge branch 'master' into e2e-ssz-cache * Merge branch 'master' into e2e-ssz-cache * Merge branch 'e2e-ssz-cache' of github.com:prysmaticlabs/prysm into e2e-ssz-cache * formatting * gaz * Merge branch 'master' into e2e-ssz-cache * resolve comments * Merge branch 'master' into e2e-ssz-cache * naming of test * Merge refs/heads/master into e2e-ssz-cache * Merge refs/heads/master into e2e-ssz-cache
* e2e ssz cache busting * use ssz cache for e2e * caching ensure * fix up the cache even more * gazelle * formatting * formatting * add back cache for val registry * sync * fix up commented item * add attestations * Merge branch 'master' into e2e-ssz-cache * Merge branch 'master' into e2e-ssz-cache * Merge branch 'e2e-ssz-cache' of github.com:prysmaticlabs/prysm into e2e-ssz-cache * formatting * gaz * Merge branch 'master' into e2e-ssz-cache * resolve comments * Merge branch 'master' into e2e-ssz-cache * naming of test * Merge refs/heads/master into e2e-ssz-cache * Merge refs/heads/master into e2e-ssz-cache
Part of #4445
Description
Write why you are making the changes in this pull request
Our old SSZ array roots cache was not recomputing branches if indices changed, instead, it would recompute the entire trie.
Write a summary of the changes you are making
This PR fixes up ssz cache, enables it for e2e tests, and adds a feature flag to enable the flag
--enable-ssz-cache
Works at runtime and properly recomputes branches if they change: