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,server: Use global total supply instead of L2 supply to calculate participation rate on Arbitrum networks #2276

Merged
merged 2 commits into from
Feb 18, 2022
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
1 change: 1 addition & 0 deletions CHANGELOG_PENDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

### Bug Fixes 🐞
- \#2267 Fix nil pointer in the block header logs (@leszko)
- \#2276 Use global total supply instead of L2 supply to calculate participation rate on Arbitrum networks (@leszko)

#### General

Expand Down
5 changes: 5 additions & 0 deletions eth/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ type LivepeerEthClient interface {
Inflation() (*big.Int, error)
InflationChange() (*big.Int, error)
TargetBondingRate() (*big.Int, error)
GetGlobalTotalSupply() (*big.Int, error)
Paused() (bool, error)

// Governance
Expand Down Expand Up @@ -471,6 +472,10 @@ func (c *client) TargetBondingRate() (*big.Int, error) {
return c.minterSess.TargetBondingRate()
}

func (c *client) GetGlobalTotalSupply() (*big.Int, error) {
return c.minterSess.GetGlobalTotalSupply()
}

func (c *client) CurrentMintableTokens() (*big.Int, error) {
return c.minterSess.CurrentMintableTokens()
}
Expand Down
1 change: 1 addition & 0 deletions eth/stubclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,7 @@ func (c *StubClient) UnbondingPeriod() (uint64, error) { return 0, ni
func (c *StubClient) Inflation() (*big.Int, error) { return big.NewInt(0), nil }
func (c *StubClient) InflationChange() (*big.Int, error) { return big.NewInt(0), nil }
func (c *StubClient) TargetBondingRate() (*big.Int, error) { return big.NewInt(0), nil }
func (c *StubClient) GetGlobalTotalSupply() (*big.Int, error) { return big.NewInt(0), nil }

// Helpers

Expand Down
13 changes: 11 additions & 2 deletions server/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -374,12 +374,12 @@ func withdrawFeesHandler(client eth.LivepeerEthClient, getChainId func() (int64,
return mustHaveClient(client, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// for L1 contracts backwards-compatibility
var tx *ethtypes.Transaction
chainId, err := getChainId()
isL1Network, err := isL1Network(getChainId)
if err != nil {
respondWith500(w, err.Error())
return
}
if chainId == MainnetChainId || chainId == RinkebyChainId {
if isL1Network {
// L1 contracts
tx, err = client.L1WithdrawFees()
if err != nil {
Expand Down Expand Up @@ -437,3 +437,12 @@ func setMinGasPriceHandler(client eth.LivepeerEthClient) http.Handler {
}),
)
}

func isL1Network(getChainId func() (int64, error)) (bool, error) {
chainId, err := getChainId()
if err != nil {
return false, err
}
isL1Network := chainId == MainnetChainId || chainId == RinkebyChainId
return isL1Network, err
}
12 changes: 11 additions & 1 deletion server/webserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -895,7 +895,17 @@ func (s *LivepeerServer) cliWebServerHandlers(bindAddr string) *http.ServeMux {
return
}

totalSupply, err := lp.TotalSupply()
isL1Network, err := isL1Network(getChainId)
if err != nil {
glog.Error(err)
return
}
var totalSupply *big.Int
if isL1Network {
totalSupply, err = lp.TotalSupply()
} else {
totalSupply, err = lp.GetGlobalTotalSupply()
}
if err != nil {
glog.Error(err)
return
Expand Down