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-6622-Enable-Mercury-v0.3-StreamsLookup-to-also-use-blockNumber #11012

Closed
wants to merge 12 commits into from
39 changes: 22 additions & 17 deletions core/services/ocr2/plugins/ocr2keeper/evm21/streams_lookup.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,21 @@ import (
)

const (
applicationJson = "application/json"
blockNumber = "blockNumber" // valid for v0.2
feedIDs = "feedIDs" // valid for v0.3
feedIdHex = "feedIdHex" // valid for v0.2
headerAuthorization = "Authorization"
headerContentType = "Content-Type"
headerTimestamp = "X-Authorization-Timestamp"
headerSignature = "X-Authorization-Signature-SHA256"
headerUpkeepId = "X-Authorization-Upkeep-Id"
mercuryPathV02 = "/client?" // only used to access mercury v0.2 server
mercuryBatchPathV03 = "/api/v1/reports/bulk?" // only used to access mercury v0.3 server
retryDelay = 500 * time.Millisecond
timestamp = "timestamp" // valid for v0.3
totalAttempt = 3
applicationJson = "application/json"
blockNumber = "blockNumber" // valid for v0.2
feedIDs = "feedIDs" // valid for v0.3
feedIdHex = "feedIdHex" // valid for v0.2
headerAuthorization = "Authorization"
headerContentType = "Content-Type"
headerTimestamp = "X-Authorization-Timestamp"
headerSignature = "X-Authorization-Signature-SHA256"
headerUpkeepId = "X-Authorization-Upkeep-Id"
mercuryPathV02 = "/client?" // only used to access mercury v0.2 server
mercuryBatchPathV03 = "/api/v1/reports/bulk?" // only used to access mercury v0.3 server
mercuryBatchPathV03BlockNumber = "/api/v1gmx/reports/bulk?" // only used to access mercury v0.3 server with blockNumber
retryDelay = 500 * time.Millisecond
timestamp = "timestamp" // valid for v0.3
totalAttempt = 3
)

type StreamsLookup struct {
Expand Down Expand Up @@ -442,7 +443,11 @@ func (r *EvmRegistry) multiFeedsRequest(ctx context.Context, ch chan<- MercuryDa
// timestamp: {sl.Time.String()},
//}
params := fmt.Sprintf("%s=%s&%s=%s", feedIDs, strings.Join(sl.Feeds, ","), sl.TimeParamKey, sl.Time.String())
reqUrl := fmt.Sprintf("%s%s%s", r.mercury.cred.URL, mercuryBatchPathV03, params)
batchPathV03 := mercuryBatchPathV03
if sl.TimeParamKey == blockNumber {
batchPathV03 = mercuryBatchPathV03BlockNumber
}
reqUrl := fmt.Sprintf("%s%s%s", r.mercury.cred.URL, batchPathV03, params)
lggr.Debugf("request URL for upkeep %s userId %s: %s", sl.upkeepId.String(), r.mercury.cred.Username, reqUrl)

req, err := http.NewRequestWithContext(ctx, http.MethodGet, reqUrl, nil)
Expand All @@ -452,7 +457,7 @@ func (r *EvmRegistry) multiFeedsRequest(ctx context.Context, ch chan<- MercuryDa
}

ts := time.Now().UTC().UnixMilli()
signature := r.generateHMAC(http.MethodGet, mercuryBatchPathV03+params, []byte{}, r.mercury.cred.Username, r.mercury.cred.Password, ts)
signature := r.generateHMAC(http.MethodGet, batchPathV03+params, []byte{}, r.mercury.cred.Username, r.mercury.cred.Password, ts)
req.Header.Set(headerContentType, applicationJson)
// username here is often referred to as user id
req.Header.Set(headerAuthorization, r.mercury.cred.Username)
Expand Down Expand Up @@ -498,7 +503,7 @@ func (r *EvmRegistry) multiFeedsRequest(ctx context.Context, ch chan<- MercuryDa
} else if resp.StatusCode == http.StatusBadRequest {
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 invalid format of timestamp", sl.Time.String(), sl.upkeepId.String(), resp.StatusCode)
return fmt.Errorf("at timestamp %s upkeep %s received status code %d from mercury v0.3 with message: %s", sl.Time.String(), sl.upkeepId.String(), resp.StatusCode, string(body))
} else if resp.StatusCode == http.StatusInternalServerError {
retryable = true
state = encoding.MercuryFlakyFailure
Expand Down
6 changes: 3 additions & 3 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ These will eventually replace `TelemetryIngress.URL` and `TelemetryIngress.Serve

- Removed the ability to set a next nonce value for an address through CLI

## 2.6.0 - UNRELEASED
<!-- unreleasedstop -->

## 2.6.0 - 2023-10-18

### Added

Expand Down Expand Up @@ -62,8 +64,6 @@ All nodes will have to remove the following configuration field: `ExplorerURL`
- Fixed health checker to include more services in the prometheus `health` metric and HTTP `/health` endpoint
- Fixed a bug where prices would not be parsed correctly in telemetry data

<!-- unreleasedstop -->

## 2.5.0 - 2023-09-13

### Added
Expand Down
Loading