Skip to content

Commit

Permalink
bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ranlavanet committed Mar 17, 2024
1 parent 3f51fa9 commit 1f236c2
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions ecosystem/cache/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,14 @@ type CacheValue struct {
Response pairingtypes.RelayReply
Hash []byte
OptionalMetadata []pairingtypes.Metadata
SeenBlock int64
}

func (cv *CacheValue) ToCacheReply() *pairingtypes.CacheRelayReply {
return &pairingtypes.CacheRelayReply{
Reply: &cv.Response,
OptionalMetadata: cv.OptionalMetadata,
SeenBlock: cv.SeenBlock,
}
}

Expand Down Expand Up @@ -289,7 +291,7 @@ func (s *RelayerCacheServer) SetRelay(ctx context.Context, relayCacheSet *pairin
return nil, utils.LavaFormatError("invalid relay cache set data, request block is negative", nil, utils.Attribute{Key: "requestBlock", Value: relayCacheSet.RequestedBlock})
}
cacheKey := s.formatHashKey(relayCacheSet.RequestHash, relayCacheSet.RequestedBlock, relayCacheSet.SeenBlock)
cacheValue := formatCacheValue(relayCacheSet.Response, relayCacheSet.BlockHash, relayCacheSet.Finalized, relayCacheSet.OptionalMetadata)
cacheValue := formatCacheValue(relayCacheSet.Response, relayCacheSet.BlockHash, relayCacheSet.Finalized, relayCacheSet.OptionalMetadata, relayCacheSet.SeenBlock)
utils.LavaFormatDebug("Got Cache Set", utils.Attribute{Key: "cacheKey", Value: string(cacheKey)},
utils.Attribute{Key: "finalized", Value: fmt.Sprintf("%t", relayCacheSet.Finalized)},
utils.Attribute{Key: "requested_block", Value: relayCacheSet.RequestedBlock},
Expand Down Expand Up @@ -431,21 +433,23 @@ func (s *RelayerCacheServer) findInAllCaches(finalized bool, cacheKey []byte) (r
return CacheValue{}, "", false
}

func formatCacheValue(response *pairingtypes.RelayReply, hash []byte, finalized bool, optionalMetadata []pairingtypes.Metadata) CacheValue {
func formatCacheValue(response *pairingtypes.RelayReply, hash []byte, finalized bool, optionalMetadata []pairingtypes.Metadata, seenBlock int64) CacheValue {
response.Sig = []byte{} // make sure we return a signed value, as the output was modified by our outputParser
if !finalized {
// hash value is only used on non finalized entries to check for forks
return CacheValue{
Response: *response,
Hash: hash,
OptionalMetadata: optionalMetadata,
SeenBlock: seenBlock,
}
}
// no need to store the hash value for finalized entries
return CacheValue{
Response: *response,
Hash: nil,
OptionalMetadata: optionalMetadata,
SeenBlock: seenBlock,
}
}

Expand Down

0 comments on commit 1f236c2

Please sign in to comment.