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

eth,eth/watcher: Create Chainlink price feed watcher #2972

Merged
merged 10 commits into from
Mar 27, 2024

Conversation

victorges
Copy link
Member

@victorges victorges commented Mar 6, 2024

What does this pull request do? Explain your changes. (required)
This creates a new client in the eth package to fetch and watch a Chainlink PriceFeed.

This will be used by go-livepeer to be able to peg the transcoding price in an alternate currency,
mostly the American dollar, for a more predictable cost and revenue for node operators.

The logic for using this pricefeed info into tuning the price dynamically will be done in a separate PR.

Specific updates (required)

  • Create a pricefeed client in eth pkg, for basic fetching of price from a price feed
  • Create a pricefeed watcher in eth/watchers pkg, to keep up to date on pricing changes
  • Add a couple tests to those

How did you test each of these updates (required)

  • go test
  • Also ran it manually on top of the ETH/USD pricefeed

Does this pull request close any open issues?
Implements ENG-1725

Checklist:

@leszko
Copy link
Contributor

leszko commented Mar 7, 2024

@victorges would it maybe be possible to use Chainlink library instead of creating go bindings on our own?

https://pkg.go.dev/github.com/smartcontractkit/[email protected]/core/gethwrappers/generated/aggregator_v3_interface

@victorges victorges changed the title Vg/feat/usd price per unit broadcast,eth: Use Chainlink to peg transcode price in alternate currency Mar 9, 2024
@victorges victorges changed the title broadcast,eth: Use Chainlink to peg transcode price in alternate currency broadcast,eth: Use Chainlink to peg pricePerPixel in alternate currency Mar 9, 2024
@victorges victorges changed the title broadcast,eth: Use Chainlink to peg pricePerPixel in alternate currency broadcast,eth: Use Chainlink to peg pricePerPixel in USD Mar 9, 2024
@victorges victorges force-pushed the vg/feat/usd-price-per-unit branch 2 times, most recently from 67be5cb to 67286d8 Compare March 13, 2024 22:18
Makefile: Use mockgen binary from tool dependencies

eth/contracts: Add chainlink interfaces source

Makefile: Generate Chainlink contracts ABI

tools: Add abigen tool to repo

eth/contracts: Generate chainlink bindings

Makefile: Fix abigen bindings generation

Revert everything abigen

Turns out there's already bindings exported from the Chainlink lib.

go.mod: Add chainlink library

eth/watchers: Add pricefeed watcher

eth/watchers: Clean-up event watching code

eth/watchers: Improve price tracking

Revert "go.mod: Add chainlink library"

This reverts commit ac415bd.

Revert "Revert everything abigen"

This reverts commit b7c40b1.

eth/contracts: Gen bindings for proxy iface

eth/watchers: Use local bindings for contracts

eth/watchers: Simplify event subs logic

eth/watchers: Simplify&optimize truncated ticker

eth/watchers: Update decimals on fetch

eth/watchers: Improve handling of decimals

eth/watchers: Fix price rat creation

eth/watchers: Make sure we use UTC on truncated timer

eth/contracts/chainlink: Generate only V3 contract bindings

eth/watchers: Watch PriceFeed only with polling

eth/watchers: Add a retry logic on price update

eth/watchers: Use clog instead of fmt.Printf
This will make the code more testable.
Copy link

codecov bot commented Mar 14, 2024

Codecov Report

Attention: Patch coverage is 38.73874% with 68 lines in your changes are missing coverage. Please review.

Project coverage is 57.24231%. Comparing base (cad6713) to head (32087b4).
Report is 1 commits behind head on master.

Additional details and impacted files

Impacted file tree graph

@@                 Coverage Diff                 @@
##              master       #2972         +/-   ##
===================================================
- Coverage   57.37567%   57.24231%   -0.13336%     
===================================================
  Files             89          91          +2     
  Lines          15402       15513        +111     
===================================================
+ Hits            8837        8880         +43     
- Misses          5973        6040         +67     
- Partials         592         593          +1     
Files Coverage Δ
eth/pricefeed.go 32.14286% <32.14286%> (ø)
eth/watchers/pricefeedwatcher.go 40.96386% <40.96386%> (ø)

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update cad6713...32087b4. Read the comment docs.

Files Coverage Δ
eth/pricefeed.go 32.14286% <32.14286%> (ø)
eth/watchers/pricefeedwatcher.go 40.96386% <40.96386%> (ø)

@victorges victorges changed the title broadcast,eth: Use Chainlink to peg pricePerPixel in USD broadcast,eth: Create Chainlink price feed watcher Mar 21, 2024
@victorges victorges changed the title broadcast,eth: Create Chainlink price feed watcher eth,eth/watcher: Create Chainlink price feed watcher Mar 21, 2024
@victorges victorges requested a review from leszko March 21, 2024 03:02
@victorges victorges marked this pull request as ready for review March 21, 2024 03:02
Copy link
Contributor

@leszko leszko left a comment

Choose a reason for hiding this comment

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

Thanks for the PR @victorges . Added some comments. Other than that it looks good.

eth/pricefeed.go Outdated Show resolved Hide resolved
eth/pricefeed.go Outdated Show resolved Hide resolved
eth/pricefeed.go Outdated Show resolved Hide resolved
eth/watchers/pricefeedwatcher.go Show resolved Hide resolved
eth/watchers/pricefeedwatcher.go Outdated Show resolved Hide resolved
eth/watchers/pricefeedwatcher.go Outdated Show resolved Hide resolved
eth/watchers/pricefeedwatcher.go Outdated Show resolved Hide resolved
eth/watchers/pricefeedwatcher.go Outdated Show resolved Hide resolved
eth/watchers/pricefeedwatcher_test.go Show resolved Hide resolved
Copy link
Contributor

@leszko leszko left a comment

Choose a reason for hiding this comment

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

Added one more comment. Other than that LGTM.

@victorges victorges merged commit ef5d789 into master Mar 27, 2024
18 checks passed
@victorges victorges deleted the vg/feat/usd-price-per-unit branch March 27, 2024 18:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants