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

feat(x/accounts): Add schema caching feature and corresponding test case #20055

Merged
merged 55 commits into from
May 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
0070d42
feat(x/accounts): Add schema caching feature and corresponding test case
meetrick Apr 16, 2024
389c2f1
fix(x/accounts): Avoid copying queryServer in its methods
meetrick Apr 16, 2024
4a20c00
Initialize mu as a pointer
meetrick Apr 16, 2024
9169303
Merge branch 'main' into 20240416_2
meetrick Apr 17, 2024
33fc9f8
Merge branch 'main' into 20240416_2
meetrick Apr 17, 2024
fcb45ce
chore(accounts): Ensure queryServer methods use pointer receivers
meetrick Apr 22, 2024
718cd59
Merge branch 'main' into 20240416_2
meetrick Apr 22, 2024
5ff10e3
chore: remove grpc-web (#20140)
tac0turtle Apr 23, 2024
8ea9ff5
docs: add authz reference info in the circuit antehandler (#20146)
Reecepbcups Apr 23, 2024
1cbe3f3
build(deps): Bump github.com/prometheus/common from 0.52.2 to 0.53.0 …
dependabot[bot] Apr 23, 2024
0b4e783
chore: reduce codeql time (#20158)
tac0turtle Apr 23, 2024
30f9375
fix(client/v2): close json file (#20120)
testwill Apr 23, 2024
d8ec18f
fix: Fix data race test coverage. (#20156)
tnv1 Apr 23, 2024
793c594
build(deps): Bump cosmossdk.io/x/tx from 0.13.2 to 0.13.3 (#20149)
dependabot[bot] Apr 23, 2024
2d90252
fix(simapp): store key override accounts (#20163)
julienrbrt Apr 24, 2024
2d614a1
refactor(lockup account): Add tests for lockup account (#19772)
sontrinh16 Apr 24, 2024
ff88c22
build(deps): Bump bufbuild/buf-setup-action from 1.30.1 to 1.31.0 (#2…
dependabot[bot] Apr 24, 2024
21a2269
build(deps): Bump amannn/action-semantic-pull-request from 5.4.0 to 5…
dependabot[bot] Apr 24, 2024
c604ffd
docs(x/authz): Update Staking Module Broken Link (#20157)
Erlangshen219 Apr 24, 2024
fd02ae0
chore: fix function names (#20170)
cuithon Apr 24, 2024
f58c610
chore: fix some quoting (#20166)
ChengenH Apr 24, 2024
5b61fce
chore: fix malformed struct tag (#20142)
ipangpang Apr 24, 2024
fc9cbe4
fix(docs): fix broken links (#20169)
goofylfg Apr 24, 2024
062433f
chore: remove unused testing framework (#20175)
tac0turtle Apr 24, 2024
c7ad722
tests(sims): Use temp dir for sims (#20143)
alpe Apr 24, 2024
964c562
build(deps): Bump github.com/cosmos/cosmos-sdk from 0.50.6-0.20240403…
dependabot[bot] Apr 25, 2024
e868c06
chore: remove repetitive words (#20180)
goofylfg Apr 25, 2024
8767a78
build(deps): Bump amannn/action-semantic-pull-request from 5.5.0 to 5…
dependabot[bot] Apr 25, 2024
1a203d1
fix(testsuite/sims): set all signatures (#20151)
leonz789 Apr 25, 2024
024003f
refactor: migrate to query Consensus Params (#19600)
tac0turtle Apr 25, 2024
12c7dee
chore: fix spelling errors (#20187)
github-prbot Apr 25, 2024
6a5ef16
feat(x/authz): Add `MsgRevokeAll` (#20161)
kien6034 Apr 26, 2024
41cd7b3
tests(types/tx): Add unit tests for types/tx (#20153)
EmilGeorgiev Apr 26, 2024
426c697
docs(x/auth/tx): fix typo in decodeMultisignatures function comment (…
meetrick Apr 26, 2024
12ab4ca
docs(x/authz): fix broken link (#20194)
hoanguyenkh Apr 26, 2024
ff0cbc7
build(deps): Bump cosmossdk.io/x/upgrade from 0.1.2-0.20240403102038-…
dependabot[bot] Apr 26, 2024
2449560
build(deps): Bump cosmossdk.io/store from 1.0.2 to 1.1.0 (#20191)
dependabot[bot] Apr 26, 2024
05c820a
chore: fix all typos (#20196)
hoangdv2429 Apr 26, 2024
422dc8a
refactor(proto): add denote version annotation (#20098)
minhngoc274 Apr 26, 2024
688163c
chore(docs/learn): fix broken links (#20193)
goofylfg Apr 26, 2024
8e929f7
test(store/snapshot): fix flaky test (#20078)
EmilGeorgiev Apr 26, 2024
a92ccce
docs(lockup): add documentation (#19898)
tac0turtle Apr 26, 2024
b79de2f
refactor(x/accounts): add sender assertions to SendModuleMessageUntyp…
sontrinh16 Apr 26, 2024
10fc2b8
refactor(baseapp): when the capacity is determined, avoid memory copy…
0x2d3c Apr 28, 2024
1ddeb8d
docs(x/circuit): fix broken link (#20201)
hoank101 Apr 28, 2024
fc07c2f
perf: Make recheck not re-run validate basic (#20208)
ValarDragon Apr 29, 2024
b1c0693
refactor(x/accounts/defaults/lockup): Clean up some logic (#20037)
sontrinh16 Apr 29, 2024
fafc385
Removed mutex in each function
meetrick Apr 29, 2024
90e1bc8
Merge branch 'main' into 20240416_2
meetrick Apr 29, 2024
e15cae8
Removed cache operation in Schema()
meetrick Apr 29, 2024
28f3431
Update x/accounts/query_server.go
meetrick Apr 29, 2024
ecb8d3f
Removoed SchemaCache field
meetrick May 14, 2024
b943f6f
Merge branch 'main' into 20240416_2
meetrick May 14, 2024
f6d2846
Removed unnecessary field from queryServer struct
meetrick May 14, 2024
848540c
Merge branch 'main' into 20240416_2
sontrinh16 May 17, 2024
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
31 changes: 20 additions & 11 deletions x/accounts/query_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,25 @@ import (
v1 "cosmossdk.io/x/accounts/v1"
)

var _ v1.QueryServer = queryServer{}
var _ v1.QueryServer = &queryServer{}

// NewQueryServer initializes a new instance of QueryServer.
// It precalculates and stores schemas for efficient schema retrieval.
func NewQueryServer(k Keeper) v1.QueryServer {
return &queryServer{k}
// Pre-calculate schemas for efficient retrieval.
schemas := v1.MakeAccountsSchemas(k.accounts)
meetrick marked this conversation as resolved.
Show resolved Hide resolved
return &queryServer{
k: k,
schemas: schemas, // Store precalculated schemas.
}
}

type queryServer struct {
k Keeper
k Keeper
schemas map[string]*v1.SchemaResponse // Stores precalculated schemas.
}

func (q queryServer) AccountQuery(ctx context.Context, request *v1.AccountQueryRequest) (*v1.AccountQueryResponse, error) {
func (q *queryServer) AccountQuery(ctx context.Context, request *v1.AccountQueryRequest) (*v1.AccountQueryResponse, error) {
// get target addr
targetAddr, err := q.k.addressCodec.StringToBytes(request.Target)
if err != nil {
Expand Down Expand Up @@ -47,18 +55,19 @@ func (q queryServer) AccountQuery(ctx context.Context, request *v1.AccountQueryR
}, nil
}

func (q queryServer) Schema(_ context.Context, request *v1.SchemaRequest) (*v1.SchemaResponse, error) {
// TODO: maybe we should cache this, considering accounts types are not
// added on the fly as the chain is running.
schemas := v1.MakeAccountsSchemas(q.k.accounts)
schema, ok := schemas[request.AccountType]
// Schema retrieves the schema for a given account type.
// It checks the precalculated schemas and returns an error if the schema is not found.
func (q *queryServer) Schema(_ context.Context, request *v1.SchemaRequest) (*v1.SchemaResponse, error) {
// Fetch schema from precalculated schemas.
schema, ok := q.schemas[request.AccountType]
if !ok {
return nil, fmt.Errorf("%w: %s", errAccountTypeNotFound, request.AccountType)
}

return schema, nil
}

func (q queryServer) AccountType(ctx context.Context, request *v1.AccountTypeRequest) (*v1.AccountTypeResponse, error) {
func (q *queryServer) AccountType(ctx context.Context, request *v1.AccountTypeRequest) (*v1.AccountTypeResponse, error) {
addr, err := q.k.addressCodec.StringToBytes(request.Address)
if err != nil {
return nil, err
Expand All @@ -72,7 +81,7 @@ func (q queryServer) AccountType(ctx context.Context, request *v1.AccountTypeReq
}, nil
}

func (q queryServer) AccountNumber(ctx context.Context, request *v1.AccountNumberRequest) (*v1.AccountNumberResponse, error) {
func (q *queryServer) AccountNumber(ctx context.Context, request *v1.AccountNumberRequest) (*v1.AccountNumberResponse, error) {
addr, err := q.k.addressCodec.StringToBytes(request.Address)
if err != nil {
return nil, err
Expand Down
16 changes: 16 additions & 0 deletions x/accounts/query_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,20 @@ func TestQueryServer(t *testing.T) {
require.NoError(t, err)
require.Equal(t, "test", typ.AccountType)
})

t.Run("schema caching", func(t *testing.T) {
// Request schema once
schemaReq := &v1.SchemaRequest{AccountType: "test"}
schemaResp1, err := qs.Schema(ctx, schemaReq)
require.NoError(t, err)
require.NotNil(t, schemaResp1)

// Request schema again
schemaResp2, err := qs.Schema(ctx, schemaReq)
require.NoError(t, err)
require.NotNil(t, schemaResp2)

// Check if both responses are the same (cached)
require.Equal(t, schemaResp1, schemaResp2)
})
}
Loading