Skip to content

Commit

Permalink
[auto 2.5.1] Fix automation - mercury v0.3 response decoding (#10806)
Browse files Browse the repository at this point in the history
* Fix mercury v0.3 decoding

* update fix

* add warn log

* add test
  • Loading branch information
infiloop2 authored Sep 27, 2023
1 parent eef6160 commit e1bb7ab
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 18 deletions.
15 changes: 12 additions & 3 deletions core/services/ocr2/plugins/ocr2keeper/evm21/streams_lookup.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ type MercuryV03Response struct {
}

type MercuryV03Report struct {
FeedID []byte `json:"feedID"` // feed id in hex
FeedID string `json:"feedID"` // feed id in hex encoded
ValidFromTimestamp uint32 `json:"validFromTimestamp"`
ObservationsTimestamp uint32 `json:"observationsTimestamp"`
FullReport []byte `json:"fullReport"` // the actual mercury report of this feed, can be sent to verifier
FullReport string `json:"fullReport"` // the actual hex encoded mercury report of this feed, can be sent to verifier
}

type MercuryData struct {
Expand Down Expand Up @@ -506,6 +506,7 @@ func (r *EvmRegistry) multiFeedsRequest(ctx context.Context, ch chan<- MercuryDa
} else if resp.StatusCode == 420 {
// in 0.3, this will happen when missing/malformed query args, missing or bad required headers, non-existent feeds, or no permissions for feeds
retryable = false
state = encoding.InvalidMercuryRequest
return fmt.Errorf("at timestamp %s upkeep %s received status code %d from mercury v0.3, most likely this is caused by missing/malformed query args, missing or bad required headers, non-existent feeds, or no permissions for feeds", sl.time.String(), sl.upkeepId.String(), resp.StatusCode)
} else if resp.StatusCode != http.StatusOK {
retryable = false
Expand All @@ -527,13 +528,21 @@ func (r *EvmRegistry) multiFeedsRequest(ctx context.Context, ch chan<- MercuryDa
// hence, retry in this case. retry will help when we send a very new timestamp and reports are not yet generated
if len(response.Reports) != len(sl.feeds) {
// TODO: AUTO-5044: calculate what reports are missing and log a warning
lggr.Warnf("at timestamp %s upkeep %s mercury v0.3 server retruned 200 status with %d reports while we requested %d feeds, treating as 404 (not found) and retrying", sl.time.String(), sl.upkeepId.String(), len(response.Reports), len(sl.feeds))
retryable = true
state = encoding.MercuryFlakyFailure
return fmt.Errorf("%d", http.StatusNotFound)
}
var reportBytes [][]byte
for _, rsp := range response.Reports {
reportBytes = append(reportBytes, rsp.FullReport)
b, err := hexutil.Decode(rsp.FullReport)
if err != nil {
lggr.Warnf("at timestamp %s upkeep %s failed to decode reportBlob %s: %v", sl.time.String(), sl.upkeepId.String(), rsp.FullReport, err)
retryable = false
state = encoding.InvalidMercuryResponse
return err
}
reportBytes = append(reportBytes, b)
}
ch <- MercuryData{
Index: 0,
Expand Down
60 changes: 45 additions & 15 deletions core/services/ocr2/plugins/ocr2keeper/evm21/streams_lookup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -681,16 +681,16 @@ func TestEvmRegistry_MultiFeedRequest(t *testing.T) {
response: &MercuryV03Response{
Reports: []MercuryV03Report{
{
FeedID: hexutil.MustDecode("0x4554482d5553442d415242495452554d2d544553544e45540000000000000000"),
FeedID: "0x4554482d5553442d415242495452554d2d544553544e45540000000000000000",
ValidFromTimestamp: 123456,
ObservationsTimestamp: 123456,
FullReport: hexutil.MustDecode("0xab2123dc00000012"),
FullReport: "0xab2123dc00000012",
},
{
FeedID: hexutil.MustDecode("0x4254432d5553442d415242495452554d2d544553544e45540000000000000000"),
FeedID: "0x4254432d5553442d415242495452554d2d544553544e45540000000000000000",
ValidFromTimestamp: 123458,
ObservationsTimestamp: 123458,
FullReport: hexutil.MustDecode("0xab2123dc00000016"),
FullReport: "0xab2123dc00000016",
},
},
},
Expand All @@ -711,20 +711,49 @@ func TestEvmRegistry_MultiFeedRequest(t *testing.T) {
response: &MercuryV03Response{
Reports: []MercuryV03Report{
{
FeedID: hexutil.MustDecode("0x4554482d5553442d415242495452554d2d544553544e45540000000000000000"),
FeedID: "0x4554482d5553442d415242495452554d2d544553544e45540000000000000000",
ValidFromTimestamp: 123456,
ObservationsTimestamp: 123456,
FullReport: hexutil.MustDecode("0xab2123dc00000012"),
FullReport: "0xab2123dc00000012",
},
{
FeedID: hexutil.MustDecode("0x4254432d5553442d415242495452554d2d544553544e45540000000000000000"),
FeedID: "0x4254432d5553442d415242495452554d2d544553544e45540000000000000000",
ValidFromTimestamp: 123458,
ObservationsTimestamp: 123458,
FullReport: hexutil.MustDecode("0xab2123dc00000019"),
FullReport: "0xab2123dc00000019",
},
},
},
},
{
name: "failure - fail to decode reportBlob",
lookup: &StreamsLookup{
feedParamKey: feedIDs,
feeds: []string{"0x4554482d5553442d415242495452554d2d544553544e45540000000000000000", "0x4254432d5553442d415242495452554d2d544553544e45540000000000000000"},
timeParamKey: timestamp,
time: big.NewInt(123456),
upkeepId: upkeepId,
},
response: &MercuryV03Response{
Reports: []MercuryV03Report{
{
FeedID: "0x4554482d5553442d415242495452554d2d544553544e45540000000000000000",
ValidFromTimestamp: 123456,
ObservationsTimestamp: 123456,
FullReport: "qerwiu", // invalid hex blob
},
{
FeedID: "0x4254432d5553442d415242495452554d2d544553544e45540000000000000000",
ValidFromTimestamp: 123458,
ObservationsTimestamp: 123458,
FullReport: "0xab2123dc00000016",
},
},
},
statusCode: http.StatusOK,
retryable: false,
errorMessage: "All attempts fail:\n#1: hex string without 0x prefix",
},
{
name: "failure - returns retryable",
lookup: &StreamsLookup{
Expand Down Expand Up @@ -789,26 +818,26 @@ func TestEvmRegistry_MultiFeedRequest(t *testing.T) {
firstResponse: &MercuryV03Response{
Reports: []MercuryV03Report{
{
FeedID: hexutil.MustDecode("0x4554482d5553442d415242495452554d2d544553544e45540000000000000000"),
FeedID: "0x4554482d5553442d415242495452554d2d544553544e45540000000000000000",
ValidFromTimestamp: 123456,
ObservationsTimestamp: 123456,
FullReport: hexutil.MustDecode("0xab2123dc00000012"),
FullReport: "0xab2123dc00000012",
},
},
},
response: &MercuryV03Response{
Reports: []MercuryV03Report{
{
FeedID: hexutil.MustDecode("0x4554482d5553442d415242495452554d2d544553544e45540000000000000000"),
FeedID: "0x4554482d5553442d415242495452554d2d544553544e45540000000000000000",
ValidFromTimestamp: 123456,
ObservationsTimestamp: 123456,
FullReport: hexutil.MustDecode("0xab2123dc00000012"),
FullReport: "0xab2123dc00000012",
},
{
FeedID: hexutil.MustDecode("0x4254432d5553442d415242495452554d2d544553544e45540000000000000000"),
FeedID: "0x4254432d5553442d415242495452554d2d544553544e45540000000000000000",
ValidFromTimestamp: 123458,
ObservationsTimestamp: 123458,
FullReport: hexutil.MustDecode("0xab2123dc00000019"),
FullReport: "0xab2123dc00000019",
},
},
},
Expand Down Expand Up @@ -880,7 +909,8 @@ func TestEvmRegistry_MultiFeedRequest(t *testing.T) {
assert.Nil(t, m.Error)
var reports [][]byte
for _, rsp := range tt.response.Reports {
reports = append(reports, rsp.FullReport)
b, _ := hexutil.Decode(rsp.FullReport)
reports = append(reports, b)
}
assert.Equal(t, reports, m.Bytes)
}
Expand Down

0 comments on commit e1bb7ab

Please sign in to comment.