Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[auto 2.5.1] Fix automation - mercury v0.3 response decoding #10806

Merged
merged 4 commits into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Contributor Author

@infiloop2 infiloop2 Sep 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is unrelated to the bug but was missing before (different bug)

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
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
Loading