Skip to content

Commit 2a0f9d2

Browse files
committed
storage/client: Remove consensus block cache
1 parent 28d8773 commit 2a0f9d2

File tree

5 files changed

+6
-41
lines changed

5 files changed

+6
-41
lines changed

.changelog/1107.internal.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
storage/client: Remove consensus block cache
2+
3+
The API currently uses an in-memory cache for a single endpoint,
4+
while no caching is applied to other cases. This somewhat arbitrary
5+
choice stems from historical decisions without clear justification.

.golangci.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ linters:
3232
- github.com/oasisprotocol/metadata-registry-tools
3333
- github.com/akrylysov/pogreb
3434
- github.com/cockroachdb/apd
35-
- github.com/dgraph-io/ristretto
3635
- github.com/ethereum/go-ethereum
3736
- github.com/go-chi/chi/v5
3837
- github.com/go-kit/log

go.mod

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,6 @@ require (
176176
github.com/akrylysov/pogreb v0.10.2
177177
github.com/cockroachdb/apd v1.1.0
178178
github.com/cometbft/cometbft v0.37.15
179-
github.com/dgraph-io/ristretto v1.0.0
180179
github.com/oapi-codegen/oapi-codegen/v2 v2.4.1
181180
github.com/oapi-codegen/runtime v1.1.1
182181
github.com/oasisprotocol/curve25519-voi v0.0.0-20230904125328-1f23a7beb09a

go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,6 @@ github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 h1:rpfIENRNNilwHwZeG5+P150SMrnN
158158
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0/go.mod h1:v57UDF4pDQJcEfFUCRop3lJL149eHGSe9Jvczhzjo/0=
159159
github.com/dgraph-io/badger/v4 v4.5.1 h1:7DCIXrQjo1LKmM96YD+hLVJ2EEsyyoWxJfpdd56HLps=
160160
github.com/dgraph-io/badger/v4 v4.5.1/go.mod h1:qn3Be0j3TfV4kPbVoK0arXCD1/nr1ftth6sbL5jxdoA=
161-
github.com/dgraph-io/ristretto v1.0.0 h1:SYG07bONKMlFDUYu5pEu3DGAh8c2OFNzKm6G9J4Si84=
162-
github.com/dgraph-io/ristretto v1.0.0/go.mod h1:jTi2FiYEhQ1NsMmA7DeBykizjOuY88NhKBkepyu1jPc=
163161
github.com/dgraph-io/ristretto/v2 v2.1.0 h1:59LjpOJLNDULHh8MC4UaegN52lC4JnO2dITsie/Pa8I=
164162
github.com/dgraph-io/ristretto/v2 v2.1.0/go.mod h1:uejeqfYXpUomfse0+lO+13ATz4TypQYLJZzBSAemuB4=
165163
github.com/dgryski/go-farm v0.0.0-20200201041132-a6ae2369ad13 h1:fAjc9m62+UWV/WAFKLNi6ZS0675eEUC9y3AlwSbQu1Y=

storage/client/client.go

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import (
1414
"strings"
1515
"time"
1616

17-
"github.com/dgraph-io/ristretto"
1817
"github.com/ethereum/go-ethereum/accounts/abi"
1918
ethCommon "github.com/ethereum/go-ethereum/common"
2019
"github.com/jackc/pgx/v5"
@@ -42,8 +41,6 @@ import (
4241
)
4342

4443
const (
45-
blockCost = 1
46-
4744
defaultMaxTotalCount = 1000
4845

4946
// The maximum number of items that can be provided for name filters.
@@ -66,8 +63,6 @@ type StorageClient struct {
6663
disableCirculatingSupply bool
6764
circulatingSupplyExclusions []apiTypes.Address
6865

69-
blockCache *ristretto.Cache[int64, *Block]
70-
7166
logger *log.Logger
7267
}
7368

@@ -118,21 +113,6 @@ func NewStorageClient(
118113
networkConfig *oasisConfig.Network,
119114
l *log.Logger,
120115
) (*StorageClient, error) {
121-
// The API currently uses an in-memory block cache for a specific endpoint and no other cases.
122-
// This somewhat arbitrary choice seems to have been made historically.
123-
// Instead, we should review common queries and responses to implement a more consistent and general caching strategy.
124-
// https://github.com/oasisprotocol/nexus/issues/887
125-
blockCache, err := ristretto.NewCache(&ristretto.Config[int64, *Block]{
126-
NumCounters: 1024 * 10,
127-
MaxCost: 1024,
128-
BufferItems: 64,
129-
IgnoreInternalCost: true,
130-
})
131-
if err != nil {
132-
l.Error("api client: failed to create block cache: %w", err)
133-
return nil, err
134-
}
135-
136116
// Parse the provided custom EVM token ordering config into a suitable format for the EVM token query.
137117
// Per runtime list of token addresses.
138118
evmTokensCustomOrderAddresses := make(map[common.Runtime][]*apiTypes.StakingAddress)
@@ -179,7 +159,6 @@ func NewStorageClient(
179159
evmTokensCustomOrderGroups,
180160
cfg.DisableCirculatingSupplyEndpoint,
181161
circulatingSupplyExclusions,
182-
blockCache,
183162
l,
184163
}, nil
185164
}
@@ -426,17 +405,7 @@ func entityInfoFromRow(r entityInfoRow) apiTypes.EntityInfo {
426405
// Blocks returns a list of consensus blocks.
427406
func (c *StorageClient) Blocks(ctx context.Context, r apiTypes.GetConsensusBlocksParams, height *int64) (*BlockList, error) {
428407
if height != nil {
429-
// Querying a single block by height, check cache.
430-
// XXX: This cache is somewhat arbitrary and likely not very useful in practice.
431-
// It has been kept for now to avoid regressions: https://github.com/oasisprotocol/nexus/issues/887
432-
block, ok := c.blockCache.Get(*height)
433-
if ok {
434-
return &BlockList{
435-
Blocks: []Block{*block},
436-
}, nil
437-
}
438-
439-
// Otherwise continue with the query below.
408+
// Querying a single block by height, configure query parameters.
440409
r.From = height
441410
r.To = height
442411
r.Limit = common.Ptr(uint64(1))
@@ -500,11 +469,6 @@ func (c *StorageClient) Blocks(ctx context.Context, r apiTypes.GetConsensusBlock
500469
bs.Blocks = append(bs.Blocks, b)
501470
}
502471

503-
// Cache the block if we queried a single block.
504-
if height != nil && len(bs.Blocks) > 0 {
505-
c.blockCache.Set(*height, &bs.Blocks[0], blockCost)
506-
}
507-
508472
return &bs, nil
509473
}
510474

0 commit comments

Comments
 (0)