Skip to content

Commit

Permalink
rm defer
Browse files Browse the repository at this point in the history
  • Loading branch information
mmsqe committed Aug 1, 2024
1 parent d568439 commit 5e6c8ea
Showing 1 changed file with 14 additions and 15 deletions.
29 changes: 14 additions & 15 deletions baseapp/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -1238,17 +1238,18 @@ func (app *BaseApp) CreateQueryContextWithCheckHeader(height int64, prove, check
}

var header *cmtproto.Header
isLatest := height == 0
for _, state := range []*state{
app.checkState,
app.finalizeBlockState,
} {
if state != nil {
// branch the commit multi-store for safety
h := state.Context().BlockHeader()
if height == 0 {
if isLatest {
lastBlockHeight = qms.LatestVersion()
}
if !checkHeader || height != 0 || height == 0 && h.Height == lastBlockHeight {
if !checkHeader || !isLatest || isLatest && h.Height == lastBlockHeight {
header = &h
break
}
Expand All @@ -1264,20 +1265,8 @@ func (app *BaseApp) CreateQueryContextWithCheckHeader(height int64, prove, check
}

// when a client did not provide a query height, manually inject the latest
if height == 0 {
if isLatest {
height = lastBlockHeight
} else {
defer func() {
if err == nil {
rms, ok := app.cms.(*rootmulti.Store)
if ok {
cInfo, err := rms.GetCommitInfo(height)
if cInfo != nil && err == nil {
ctx = ctx.WithHeaderInfo(coreheader.Info{Height: height, Time: cInfo.Timestamp})
}
}
}
}()
}

cacheMS, err := qms.CacheMultiStoreWithVersion(height)
Expand All @@ -1298,6 +1287,16 @@ func (app *BaseApp) CreateQueryContextWithCheckHeader(height int64, prove, check
}).
WithBlockHeader(*header).
WithBlockHeight(height)

if !isLatest {
rms, ok := app.cms.(*rootmulti.Store)
if ok {
cInfo, err := rms.GetCommitInfo(height)
if cInfo != nil && err == nil {
ctx = ctx.WithHeaderInfo(coreheader.Info{Height: height, Time: cInfo.Timestamp})
}
}
}
return ctx, nil
}

Expand Down

0 comments on commit 5e6c8ea

Please sign in to comment.