Skip to content

Commit

Permalink
fix: validatorupdateblock update every block cause messy of upgrade (#57
Browse files Browse the repository at this point in the history
)
  • Loading branch information
leonz789 authored May 24, 2024
1 parent d58d5a2 commit 67eafc8
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
4 changes: 3 additions & 1 deletion x/oracle/keeper/cache/caches.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,11 +177,13 @@ func (c *Cache) GetCache(i any) bool {
for addr, power := range c.validators.validators {
item[addr] = power
}
return c.validators.update
case ItemP:
if item == nil {
return false
}
*item = *(c.params.params)
return c.params.update
case *[]*ItemM:
if item == nil {
return false
Expand All @@ -191,10 +193,10 @@ func (c *Cache) GetCache(i any) bool {
tmp = append(tmp, msgs...)
}
*item = tmp
return len(c.msg) > 0
default:
return false
}
return true
}

// SkipCommit skip real commit by setting the updage flag to false
Expand Down
19 changes: 17 additions & 2 deletions x/oracle/keeper/single.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,24 @@ func recacheAggregatorContext(ctx sdk.Context, agc *aggregator.AggregatorContext
agc.SealRound(ctx, false)
}

// fill params cache
c.AddCache(cache.ItemP(&pTmp))
if from >= to {
// backwards compatible for that the validatorUpdateBlock updated every block
prev := int64(0)
for b, p := range recentParamsMap {
if b > prev {
// pTmp be set at least once, since len(recentParamsMap)>0
pTmp = common.Params(*p)
prev = b
}
}
agc.SetParams(&pTmp)
}

var pRet common.Params
if updated := c.GetCache(cache.ItemP(&pRet)); !updated {
c.AddCache(cache.ItemP(&pTmp))
}
// fill params cache
agc.PrepareRound(ctx, uint64(to))

return true
Expand Down
1 change: 1 addition & 0 deletions x/oracle/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ func (am AppModule) EndBlock(ctx sdk.Context, _ abci.RequestEndBlock) []abci.Val
logger.Info("prepare for next oracle round of each tokenFeeder")
agc.PrepareRound(ctx, 0)

// TODO: update params happened during this block for cache, for the case: agc is recached from history and cache'params is set with the latest params by recache, but parmas changed during this block as well. or force agc to be GET first before cache be GET(later approch is better)
cs.CommitCache(ctx, false, am.keeper)
return []abci.ValidatorUpdate{}
}

0 comments on commit 67eafc8

Please sign in to comment.