Skip to content

Commit 24cf930

Browse files
Upgrade ristretto to v2.2.0 (#15170)
* Upgrade ristretto to v2.2.0 * Added the changelog * gazelle * Run goimports and gofmt * Fix build * Fix tests * fix some golangci-lint violations --------- Co-authored-by: Preston Van Loon <preston@pvl.dev>
1 parent 97a95dd commit 24cf930

File tree

12 files changed

+46
-54
lines changed

12 files changed

+46
-54
lines changed

beacon-chain/db/kv/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ go_library(
5959
"//runtime/version:go_default_library",
6060
"//time:go_default_library",
6161
"//time/slots:go_default_library",
62-
"@com_github_dgraph_io_ristretto//:go_default_library",
62+
"@com_github_dgraph_io_ristretto_v2//:go_default_library",
6363
"@com_github_ethereum_go_ethereum//common:go_default_library",
6464
"@com_github_ethereum_go_ethereum//common/hexutil:go_default_library",
6565
"@com_github_golang_snappy//:go_default_library",

beacon-chain/db/kv/blocks.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func (s *Store) Block(ctx context.Context, blockRoot [32]byte) (interfaces.ReadO
4040

4141
func (s *Store) getBlock(ctx context.Context, blockRoot [32]byte, tx *bolt.Tx) (interfaces.ReadOnlySignedBeaconBlock, error) {
4242
if v, ok := s.blockCache.Get(string(blockRoot[:])); v != nil && ok {
43-
return v.(interfaces.ReadOnlySignedBeaconBlock), nil
43+
return v, nil
4444
}
4545
// This method allows the caller to pass in its tx if one is already open.
4646
// Or if a nil value is used, a transaction will be managed intenally.

beacon-chain/db/kv/kv.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@ import (
1313
"github.com/OffchainLabs/prysm/v6/config/features"
1414
"github.com/OffchainLabs/prysm/v6/config/params"
1515
"github.com/OffchainLabs/prysm/v6/consensus-types/blocks"
16+
"github.com/OffchainLabs/prysm/v6/consensus-types/interfaces"
1617
"github.com/OffchainLabs/prysm/v6/io/file"
17-
"github.com/dgraph-io/ristretto"
18+
ethpb "github.com/OffchainLabs/prysm/v6/proto/prysm/v1alpha1"
19+
"github.com/dgraph-io/ristretto/v2"
1820
"github.com/pkg/errors"
1921
"github.com/prometheus/client_golang/prometheus"
2022
"github.com/prometheus/client_golang/prometheus/promauto"
@@ -86,8 +88,8 @@ var blockedBuckets = [][]byte{
8688
type Store struct {
8789
db *bolt.DB
8890
databasePath string
89-
blockCache *ristretto.Cache
90-
validatorEntryCache *ristretto.Cache
91+
blockCache *ristretto.Cache[string, interfaces.ReadOnlySignedBeaconBlock]
92+
validatorEntryCache *ristretto.Cache[[]byte, *ethpb.Validator]
9193
stateSummaryCache *stateSummaryCache
9294
ctx context.Context
9395
}
@@ -156,7 +158,7 @@ func NewKVStore(ctx context.Context, dirPath string, opts ...KVStoreOption) (*St
156158
return nil, err
157159
}
158160
boltDB.AllocSize = boltAllocSize
159-
blockCache, err := ristretto.NewCache(&ristretto.Config{
161+
blockCache, err := ristretto.NewCache(&ristretto.Config[string, interfaces.ReadOnlySignedBeaconBlock]{
160162
NumCounters: 1000, // number of keys to track frequency of (1000).
161163
MaxCost: BlockCacheSize, // maximum cost of cache (1000 Blocks).
162164
BufferItems: 64, // number of keys per Get buffer.
@@ -165,7 +167,7 @@ func NewKVStore(ctx context.Context, dirPath string, opts ...KVStoreOption) (*St
165167
return nil, err
166168
}
167169

168-
validatorCache, err := ristretto.NewCache(&ristretto.Config{
170+
validatorCache, err := ristretto.NewCache(&ristretto.Config[[]byte, *ethpb.Validator]{
169171
NumCounters: NumOfValidatorEntries, // number of entries in cache (2 Million).
170172
MaxCost: ValidatorEntryMaxCost, // maximum size of the cache (64Mb)
171173
BufferItems: 64, // number of keys per Get buffer.

beacon-chain/db/kv/state.go

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -744,14 +744,9 @@ func (s *Store) validatorEntries(ctx context.Context, blockRoot [32]byte) ([]*et
744744
// get the entry bytes from the cache or from the DB.
745745
v, ok := s.validatorEntryCache.Get(key)
746746
if ok {
747-
valEntry, vType := v.(*ethpb.Validator)
748-
if vType {
749-
validatorEntries = append(validatorEntries, valEntry)
750-
validatorEntryCacheHit.Inc()
751-
} else {
752-
// this should never happen, but anyway it's good to bail out if one happens.
753-
return errors.New("validator cache does not have proper object type")
754-
}
747+
valEntry := v
748+
validatorEntries = append(validatorEntries, valEntry)
749+
validatorEntryCacheHit.Inc()
755750
} else {
756751
// not in cache, so get it from the DB, decode it and add to the entry list.
757752
valEntryBytes := valBkt.Get(key)

beacon-chain/db/kv/state_test.go

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -321,15 +321,11 @@ func TestState_CanSaveRetrieveValidatorEntriesFromCache(t *testing.T) {
321321
hash, hashErr := stateValidators[i].HashTreeRoot()
322322
assert.NoError(t, hashErr)
323323

324-
data, ok := db.validatorEntryCache.Get(string(hash[:]))
324+
data, ok := db.validatorEntryCache.Get(hash[:])
325325
assert.Equal(t, true, ok)
326326
require.NotNil(t, data)
327327

328-
valEntry, vType := data.(*ethpb.Validator)
329-
assert.Equal(t, true, vType)
330-
require.NotNil(t, valEntry)
331-
332-
require.DeepSSZEqual(t, stateValidators[i], valEntry, "validator entry is not matching")
328+
require.DeepSSZEqual(t, stateValidators[i], data, "validator entry is not matching")
333329
}
334330

335331
// check if all the validator entries are still intact in the validator entry bucket.
@@ -447,7 +443,7 @@ func TestState_DeleteState(t *testing.T) {
447443
assert.NoError(t, hashErr)
448444
v, found := db.validatorEntryCache.Get(hash[:])
449445
require.Equal(t, false, found)
450-
require.Equal(t, nil, v)
446+
require.IsNil(t, v)
451447
}
452448

453449
// check if the index of the first state is deleted.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
### Changed
2+
3+
- Upgraded ristretto to v2.2.0, for RISC-V support.

deps.bzl

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -639,8 +639,14 @@ def prysm_deps():
639639
go_repository(
640640
name = "com_github_dgraph_io_ristretto",
641641
importpath = "github.com/dgraph-io/ristretto",
642-
sum = "h1:cNcG4c2n5xanQzp2hMyxDxPYVQmZ91y4WN6fJFlndLo=",
643-
version = "v0.0.4-0.20210318174700-74754f61e018",
642+
sum = "h1:a5WaUrDa0qm0YrAAS1tUykT5El3kt62KNZZeMxQn3po=",
643+
version = "v0.0.2",
644+
)
645+
go_repository(
646+
name = "com_github_dgraph_io_ristretto_v2",
647+
importpath = "github.com/dgraph-io/ristretto/v2",
648+
sum = "h1:bkY3XzJcXoMuELV8F+vS8kzNgicwQFAaGINAEJdWGOM=",
649+
version = "v2.2.0",
644650
)
645651
go_repository(
646652
name = "com_github_dgrijalva_jwt_go",
@@ -651,8 +657,8 @@ def prysm_deps():
651657
go_repository(
652658
name = "com_github_dgryski_go_farm",
653659
importpath = "github.com/dgryski/go-farm",
654-
sum = "h1:tdlZCpZ/P9DhczCTSixgIKmwPv6+wP5DGjqLYw5SUiA=",
655-
version = "v0.0.0-20190423205320-6a90982ecee2",
660+
sum = "h1:aIftn67I1fkbMa512G+w+Pxci9hJPB8oMnkcP3iZF38=",
661+
version = "v0.0.0-20240924180020-3414d57e47da",
656662
)
657663
go_repository(
658664
name = "com_github_dlclark_regexp2",
@@ -687,8 +693,8 @@ def prysm_deps():
687693
go_repository(
688694
name = "com_github_dustin_go_humanize",
689695
importpath = "github.com/dustin/go-humanize",
690-
sum = "h1:VSnTsYCnlFHaM2/igO1h6X3HA71jcobQuxemgkq4zYo=",
691-
version = "v1.0.0",
696+
sum = "h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=",
697+
version = "v1.0.1",
692698
)
693699
go_repository(
694700
name = "com_github_eapache_go_resiliency",
@@ -2467,12 +2473,6 @@ def prysm_deps():
24672473
sum = "h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec=",
24682474
version = "v0.0.5",
24692475
)
2470-
go_repository(
2471-
name = "com_github_oneofone_xxhash",
2472-
importpath = "github.com/OneOfOne/xxhash",
2473-
sum = "h1:KMrpdQIwFcEqXDklaen+P1axHaj9BSKzvpUUfnHldSE=",
2474-
version = "v1.2.2",
2475-
)
24762476
go_repository(
24772477
name = "com_github_onsi_ginkgo",
24782478
importpath = "github.com/onsi/ginkgo",

go.mod

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ require (
1111
github.com/consensys/gnark-crypto v0.14.0
1212
github.com/crate-crypto/go-kzg-4844 v1.1.0
1313
github.com/d4l3k/messagediff v1.2.1
14-
github.com/dgraph-io/ristretto v0.0.4-0.20210318174700-74754f61e018
15-
github.com/dustin/go-humanize v1.0.0
14+
github.com/dgraph-io/ristretto/v2 v2.2.0
15+
github.com/dustin/go-humanize v1.0.1
1616
github.com/emicklei/dot v0.11.0
1717
github.com/ethereum/c-kzg-4844/v2 v2.1.1
1818
github.com/ethereum/go-ethereum v1.15.9
@@ -113,7 +113,6 @@ require (
113113
github.com/bits-and-blooms/bitset v1.17.0 // indirect
114114
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
115115
github.com/cespare/cp v1.1.1 // indirect
116-
github.com/cespare/xxhash v1.1.0 // indirect
117116
github.com/cespare/xxhash/v2 v2.3.0 // indirect
118117
github.com/chzyer/readline v1.5.1 // indirect
119118
github.com/cockroachdb/errors v1.11.3 // indirect

go.sum

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,6 @@ github.com/MariusVanDerWijden/tx-fuzz v1.4.0 h1:Tq4lXivsR8mtoP4RpasUDIUpDLHfN1Yh
5757
github.com/MariusVanDerWijden/tx-fuzz v1.4.0/go.mod h1:gmOVECg7o5FY5VU3DQ/fY0zTk/ExBdMkUGz0vA8qqms=
5858
github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERoyfY=
5959
github.com/Microsoft/go-winio v0.6.2/go.mod h1:yd8OoFMLzJbo9gZq8j5qaps8bJ9aShtEA8Ipt1oGCvU=
60-
github.com/OneOfOne/xxhash v1.2.2 h1:KMrpdQIwFcEqXDklaen+P1axHaj9BSKzvpUUfnHldSE=
61-
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
6260
github.com/Shopify/sarama v1.19.0/go.mod h1:FVkBWblsNy7DGZRfXLU0O9RCGt5g3g3yEuWXgklEdEo=
6361
github.com/Shopify/sarama v1.26.1/go.mod h1:NbSGBSSndYaIhRcBtY9V0U7AyH+x71bG668AuWys/yU=
6462
github.com/Shopify/toxiproxy v2.1.4+incompatible/go.mod h1:OXgGpZ6Cli1/URJOF1DMxUHB2q5Ap20/P/eIdh4G0pI=
@@ -114,8 +112,6 @@ github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyY
114112
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
115113
github.com/cespare/cp v1.1.1 h1:nCb6ZLdB7NRaqsm91JtQTAme2SKJzXVsdPIPkyJr1MU=
116114
github.com/cespare/cp v1.1.1/go.mod h1:SOGHArjBr4JWaSDEVpWpo/hNg6RoKrls6Oh40hiwW+s=
117-
github.com/cespare/xxhash v1.1.0 h1:a6HrQnmkObjyL+Gs60czilIUGqrzKutQD6XZog3p+ko=
118-
github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc=
119115
github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
120116
github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
121117
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
@@ -197,11 +193,11 @@ github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0/go.mod h1:v57UDF4pDQJcEfFUCRop3
197193
github.com/deepmap/oapi-codegen v1.6.0/go.mod h1:ryDa9AgbELGeB+YEXE1dR53yAjHwFvE9iAUlWl9Al3M=
198194
github.com/deepmap/oapi-codegen v1.8.2 h1:SegyeYGcdi0jLLrpbCMoJxnUUn8GBXHsvr4rbzjuhfU=
199195
github.com/deepmap/oapi-codegen v1.8.2/go.mod h1:YLgSKSDv/bZQB7N4ws6luhozi3cEdRktEqrX88CvjIw=
200-
github.com/dgraph-io/ristretto v0.0.4-0.20210318174700-74754f61e018 h1:cNcG4c2n5xanQzp2hMyxDxPYVQmZ91y4WN6fJFlndLo=
201-
github.com/dgraph-io/ristretto v0.0.4-0.20210318174700-74754f61e018/go.mod h1:MIonLggsKgZLUSt414ExgwNtlOL5MuEoAJP514mwGe8=
196+
github.com/dgraph-io/ristretto/v2 v2.2.0 h1:bkY3XzJcXoMuELV8F+vS8kzNgicwQFAaGINAEJdWGOM=
197+
github.com/dgraph-io/ristretto/v2 v2.2.0/go.mod h1:RZrm63UmcBAaYWC1DotLYBmTvgkrs0+XhBd7Npn7/zI=
202198
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
203-
github.com/dgryski/go-farm v0.0.0-20190423205320-6a90982ecee2 h1:tdlZCpZ/P9DhczCTSixgIKmwPv6+wP5DGjqLYw5SUiA=
204-
github.com/dgryski/go-farm v0.0.0-20190423205320-6a90982ecee2/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw=
199+
github.com/dgryski/go-farm v0.0.0-20240924180020-3414d57e47da h1:aIftn67I1fkbMa512G+w+Pxci9hJPB8oMnkcP3iZF38=
200+
github.com/dgryski/go-farm v0.0.0-20240924180020-3414d57e47da/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw=
205201
github.com/dlclark/regexp2 v1.4.1-0.20201116162257-a2a8dda75c91/go.mod h1:2pZnwuY/m+8K6iRw6wQdMtk+rH5tNGR1i55kozfMjCc=
206202
github.com/dlclark/regexp2 v1.7.0 h1:7lJfhqlPssTb1WQx4yvTHN0uElPEv52sbaECrAQxjAo=
207203
github.com/dlclark/regexp2 v1.7.0/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnmRbL6yW8=
@@ -214,8 +210,9 @@ github.com/dop251/goja v0.0.0-20230806174421-c933cf95e127/go.mod h1:QMWlm50DNe14
214210
github.com/dop251/goja_nodejs v0.0.0-20210225215109-d91c329300e7/go.mod h1:hn7BA7c8pLvoGndExHudxTDKZ84Pyvv+90pbBjbTz0Y=
215211
github.com/dop251/goja_nodejs v0.0.0-20211022123610-8dd9abb0616d/go.mod h1:DngW8aVqWbuLRMHItjPUyqdj+HWPvnQe8V8y1nDpIbM=
216212
github.com/dustin/go-humanize v0.0.0-20171111073723-bb3d318650d4/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
217-
github.com/dustin/go-humanize v1.0.0 h1:VSnTsYCnlFHaM2/igO1h6X3HA71jcobQuxemgkq4zYo=
218213
github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
214+
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
215+
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
219216
github.com/eapache/go-resiliency v1.1.0/go.mod h1:kFI+JgMyC7bLPUVY133qvEBtVayf5mFgVsvEsIPBvNs=
220217
github.com/eapache/go-resiliency v1.2.0/go.mod h1:kFI+JgMyC7bLPUVY133qvEBtVayf5mFgVsvEsIPBvNs=
221218
github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21/go.mod h1:+020luEh2TKB4/GOp8oxxtq0Daoen/Cii55CzbTV6DU=
@@ -980,7 +977,6 @@ github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4k
980977
github.com/sony/gobreaker v0.4.1/go.mod h1:ZKptC7FHNvhBz7dN2LGjPVBz2sZJmc0/PkyDJOjmxWY=
981978
github.com/sourcegraph/annotate v0.0.0-20160123013949-f4cad6c6324d/go.mod h1:UdhH50NIW0fCiwBSr0co2m7BnFLdv4fQTgdqdJTHFeE=
982979
github.com/sourcegraph/syntaxhighlight v0.0.0-20170531221838-bd320f5d308e/go.mod h1:HuIsMU8RRBOtsCgI77wP899iHVBQpCmg4ErYMZB+2IA=
983-
github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
984980
github.com/spaolacci/murmur3 v1.1.0 h1:7c1g84S4BPRrfL5Xrdp6fOJ206sU9y293DDHaoy0bLI=
985981
github.com/spaolacci/murmur3 v1.1.0/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
986982
github.com/spf13/afero v0.0.0-20170901052352-ee1bd8ee15a1/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ=

validator/client/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ go_library(
6969
"//validator/keymanager:go_default_library",
7070
"//validator/keymanager/local:go_default_library",
7171
"//validator/keymanager/remote-web3signer:go_default_library",
72-
"@com_github_dgraph_io_ristretto//:go_default_library",
72+
"@com_github_dgraph_io_ristretto_v2//:go_default_library",
7373
"@com_github_ethereum_go_ethereum//common:go_default_library",
7474
"@com_github_ethereum_go_ethereum//common/hexutil:go_default_library",
7575
"@com_github_golang_protobuf//ptypes/empty",

0 commit comments

Comments
 (0)