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

[api] Fix wrong cache for api readState at tip height #4253

Merged
merged 3 commits into from
Apr 26, 2024
Merged
Changes from 2 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
9 changes: 7 additions & 2 deletions api/coreservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -910,16 +910,19 @@ func (core *coreService) readState(ctx context.Context, p protocol.Protocol, hei
Method: methodName,
Args: arguments,
}
tipHeight := core.bc.TipHeight()
if height == "" {
key.Height = strconv.FormatUint(tipHeight, 10)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch

if d, ok := core.readCache.Get(key.Hash()); ok {
var h uint64
h := tipHeight
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

before this change h = 0?

if height != "" {
h, _ = strconv.ParseUint(height, 0, 64)
}
return d, h, nil
}

// TODO: need to complete the context
tipHeight := core.bc.TipHeight()
ctx = protocol.WithBlockCtx(ctx, protocol.BlockCtx{
BlockHeight: tipHeight,
})
Expand All @@ -945,6 +948,7 @@ func (core *coreService) readState(ctx context.Context, p protocol.Protocol, hei
// old data, wrap to history state reader
d, h, err := p.ReadState(ctx, factory.NewHistoryStateReader(core.sf, rp.GetEpochHeight(inputEpochNum)), methodName, arguments...)
if err == nil {
key.Height = strconv.FormatUint(h, 10)
dustinxie marked this conversation as resolved.
Show resolved Hide resolved
core.readCache.Put(key.Hash(), d)
}
return d, h, err
Expand All @@ -954,6 +958,7 @@ func (core *coreService) readState(ctx context.Context, p protocol.Protocol, hei
// TODO: need to distinguish user error and system error
d, h, err := p.ReadState(ctx, core.sf, methodName, arguments...)
if err == nil {
key.Height = strconv.FormatUint(h, 10)
core.readCache.Put(key.Hash(), d)
}
return d, h, err
Expand Down
Loading