Skip to content

Commit

Permalink
Merge pull request #327 from bandprotocol/yoda-remove-cache
Browse files Browse the repository at this point in the history
[Yoda] Remove cache of data source hash in Yoda
  • Loading branch information
RogerKSI authored Sep 14, 2023
2 parents 294da33 + 49ac23e commit e6548bb
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 11 deletions.
2 changes: 0 additions & 2 deletions yoda/context.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package yoda

import (
"sync"
"sync/atomic"
"time"

Expand Down Expand Up @@ -45,7 +44,6 @@ type Context struct {
freeKeys chan int64
keyRoundRobinIndex int64 // Must use in conjunction with sync/atomic

dataSourceCache *sync.Map
pendingRequests map[types.RequestID]bool

metricsEnabled bool
Expand Down
8 changes: 1 addition & 7 deletions yoda/execute.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,10 +222,6 @@ func GetExecutable(c *Context, l *Logger, hash string) ([]byte, error) {

// GetDataSourceHash fetches data source hash by id
func GetDataSourceHash(c *Context, l *Logger, id types.DataSourceID) (string, error) {
if hash, ok := c.dataSourceCache.Load(id); ok {
return hash.(string), nil
}

res, err := abciQuery(c, l, fmt.Sprintf("/store/%s/key", types.StoreKey), types.DataSourceStoreKey(id))
if err != nil {
l.Error(":skull: Failed to get data source with error: %s", c, err.Error())
Expand All @@ -235,9 +231,7 @@ func GetDataSourceHash(c *Context, l *Logger, id types.DataSourceID) (string, er
var d types.DataSource
cdc.MustUnmarshal(res.Response.Value, &d)

hash, _ := c.dataSourceCache.LoadOrStore(id, d.Filename)

return hash.(string), nil
return d.Filename, nil
}

// GetRequest fetches request by id
Expand Down
2 changes: 0 additions & 2 deletions yoda/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"errors"
"path/filepath"
"sync"
"time"

"github.com/cosmos/cosmos-sdk/client/flags"
Expand Down Expand Up @@ -157,7 +156,6 @@ func runCmd(c *Context) *cobra.Command {
c.pendingMsgs = make(chan ReportMsgWithKey)
c.freeKeys = make(chan int64, len(keys))
c.keyRoundRobinIndex = -1
c.dataSourceCache = new(sync.Map)
c.pendingRequests = make(map[types.RequestID]bool)
c.metricsEnabled = cfg.MetricsListenAddr != ""
return runImpl(c, l)
Expand Down

0 comments on commit e6548bb

Please sign in to comment.