-
Notifications
You must be signed in to change notification settings - Fork 19
[por] minor updates for m7 integration #2466
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -12,14 +12,17 @@ import ( | |||||||||||||||||||
| "sync" | ||||||||||||||||||||
| "time" | ||||||||||||||||||||
|
|
||||||||||||||||||||
| "github.com/rs/zerolog/log" | ||||||||||||||||||||
|
|
||||||||||||||||||||
| "bisonai.com/miko/node/pkg/chain/helper" | ||||||||||||||||||||
| chainUtils "bisonai.com/miko/node/pkg/chain/utils" | ||||||||||||||||||||
| "bisonai.com/miko/node/pkg/common/types" | ||||||||||||||||||||
| "bisonai.com/miko/node/pkg/db" | ||||||||||||||||||||
| errorSentinel "bisonai.com/miko/node/pkg/error" | ||||||||||||||||||||
| "bisonai.com/miko/node/pkg/fetcher" | ||||||||||||||||||||
| "bisonai.com/miko/node/pkg/secrets" | ||||||||||||||||||||
| "bisonai.com/miko/node/pkg/utils/request" | ||||||||||||||||||||
| "bisonai.com/miko/node/pkg/utils/retrier" | ||||||||||||||||||||
| "github.com/rs/zerolog/log" | ||||||||||||||||||||
| ) | ||||||||||||||||||||
|
|
||||||||||||||||||||
| const ( | ||||||||||||||||||||
|
|
@@ -34,10 +37,47 @@ var urls = map[string]urlEntry{ | |||||||||||||||||||
| "peg-por": { | ||||||||||||||||||||
| "/{CHAIN}/peg-{CHAIN}.por.json", | ||||||||||||||||||||
| "/{CHAIN}/peg.por.json", | ||||||||||||||||||||
| false, | ||||||||||||||||||||
| }, | ||||||||||||||||||||
| "gp": { | ||||||||||||||||||||
| "/{CHAIN}/gp-{CHAIN}.json", | ||||||||||||||||||||
| "/{CHAIN}/gp.json", | ||||||||||||||||||||
| false, | ||||||||||||||||||||
| }, | ||||||||||||||||||||
| "aapl": { | ||||||||||||||||||||
| "/{CHAIN}/aapl-{CHAIN}.json", | ||||||||||||||||||||
| "/{CHAIN}/aapl.json", | ||||||||||||||||||||
| true, | ||||||||||||||||||||
| }, | ||||||||||||||||||||
| "amzn": { | ||||||||||||||||||||
| "/{CHAIN}/amzn-{CHAIN}.json", | ||||||||||||||||||||
| "/{CHAIN}/amzn.json", | ||||||||||||||||||||
| true, | ||||||||||||||||||||
| }, | ||||||||||||||||||||
| "googl": { | ||||||||||||||||||||
| "/{CHAIN}/googl-{CHAIN}.json", | ||||||||||||||||||||
| "/{CHAIN}/googl.json", | ||||||||||||||||||||
| true, | ||||||||||||||||||||
| }, | ||||||||||||||||||||
| "meta": { | ||||||||||||||||||||
| "/{CHAIN}/meta-{CHAIN}.json", | ||||||||||||||||||||
| "/{CHAIN}/meta.json", | ||||||||||||||||||||
| true, | ||||||||||||||||||||
| }, | ||||||||||||||||||||
| "msft": { | ||||||||||||||||||||
| "/{CHAIN}/msft-{CHAIN}.json", | ||||||||||||||||||||
| "/{CHAIN}/msft.json", | ||||||||||||||||||||
| true, | ||||||||||||||||||||
| }, | ||||||||||||||||||||
| "nvda": { | ||||||||||||||||||||
| "/{CHAIN}/nvda-{CHAIN}.json", | ||||||||||||||||||||
| "/{CHAIN}/nvda.json", | ||||||||||||||||||||
| true, | ||||||||||||||||||||
| }, | ||||||||||||||||||||
| "tsla": { | ||||||||||||||||||||
| "/{CHAIN}/tsla-{CHAIN}.json", | ||||||||||||||||||||
| "/{CHAIN}/tsla.json", | ||||||||||||||||||||
| true, | ||||||||||||||||||||
| }, | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
|
|
@@ -84,6 +124,7 @@ func New(ctx context.Context) (*app, error) { | |||||||||||||||||||
| definition: d, | ||||||||||||||||||||
| adapter: ad, | ||||||||||||||||||||
| aggregator: ag, | ||||||||||||||||||||
| useProxy: u.useProxy, | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| entries[n] = e | ||||||||||||||||||||
|
|
@@ -104,9 +145,15 @@ func New(ctx context.Context) (*app, error) { | |||||||||||||||||||
| return nil, err | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| proxies, err := db.QueryRows[types.Proxy](ctx, "SELECT * FROM proxies", nil) | ||||||||||||||||||||
| if err != nil { | ||||||||||||||||||||
| return nil, err | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
Comment on lines
+148
to
+151
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Don’t hard-fail on proxy DB errors; degrade gracefully. - proxies, err := db.QueryRows[types.Proxy](ctx, "SELECT * FROM proxies", nil)
- if err != nil {
- return nil, err
- }
+ proxies, err := db.QueryRows[types.Proxy](ctx, "SELECT * FROM proxies", nil)
+ if err != nil {
+ log.Warn().Err(err).Msg("failed to load proxies; continuing without proxies")
+ proxies = nil
+ }📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||
|
|
||||||||||||||||||||
| return &app{ | ||||||||||||||||||||
| entries: entries, | ||||||||||||||||||||
| kaiaHelper: chainHelper, | ||||||||||||||||||||
| proxies: proxies, | ||||||||||||||||||||
| }, nil | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
|
|
@@ -183,7 +230,7 @@ func (a *app) startJob(ctx context.Context, entry entry) { | |||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| func (a *app) execute(ctx context.Context, e entry) error { | ||||||||||||||||||||
| v, err := fetcher.FetchSingle(ctx, e.definition) | ||||||||||||||||||||
| v, err := fetcher.FetchSingle(ctx, e.definition, a.buildRequestOpts(e)...) | ||||||||||||||||||||
| if err != nil { | ||||||||||||||||||||
| return err | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
@@ -319,3 +366,26 @@ func (a *app) getRoundId(ctx context.Context, e entry) (uint32, error) { | |||||||||||||||||||
|
|
||||||||||||||||||||
| return RoundID, nil | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| func (a *app) getNextProxy() *string { | ||||||||||||||||||||
| a.Lock() | ||||||||||||||||||||
| defer a.Unlock() | ||||||||||||||||||||
|
|
||||||||||||||||||||
| if len(a.proxies) == 0 { | ||||||||||||||||||||
| return nil | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| proxy := a.proxies[a.proxyIdx%len(a.proxies)].GetProxyUrl() | ||||||||||||||||||||
| a.proxyIdx++ | ||||||||||||||||||||
| return &proxy | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| func (a *app) buildRequestOpts(e entry) []request.RequestOption { | ||||||||||||||||||||
| opts := []request.RequestOption{} | ||||||||||||||||||||
| if e.useProxy { | ||||||||||||||||||||
| if p := a.getNextProxy(); p != nil && *p != "" { | ||||||||||||||||||||
| opts = append(opts, request.WithProxy(*p)) | ||||||||||||||||||||
| } | ||||||||||||||||||||
| } | ||||||||||||||||||||
| return opts | ||||||||||||||||||||
| } | ||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Verification agent
🧩 Analysis chain
Guard against nil URL to prevent panic.
*definition.Urlwill panic ifUrlis nil (e.g., malformed config). Confirm upstream guarantees or add a defensive check returning an error.Run to spot any definitions missing
url:🏁 Script executed:
Length of output: 148
🏁 Script executed:
Length of output: 1528
🏁 Script executed:
Length of output: 3793
🏁 Script executed:
Length of output: 31334
Guard against nil definition.Url (avoid panic).
Definition.Url is a *string (node/pkg/fetcher/types.go:97) but is dereferenced without a nil-check. Fix by validating/enforcing url on input or adding defensive checks that return an error instead of panicking. Relevant call sites to update: node/pkg/fetcher/utils.go:18, node/pkg/fetcher/fetcher.go:170,174, node/script/test_single_fetch/main.go:28.
🤖 Prompt for AI Agents