diff --git a/CHANGELOG_PENDING.md b/CHANGELOG_PENDING.md index 93f5cfe9cf..d8c9ca4836 100644 --- a/CHANGELOG_PENDING.md +++ b/CHANGELOG_PENDING.md @@ -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 diff --git a/eth/client.go b/eth/client.go index 034649942a..1e9ed240c4 100644 --- a/eth/client.go +++ b/eth/client.go @@ -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 @@ -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() } diff --git a/eth/stubclient.go b/eth/stubclient.go index af7d11a6c0..65f9c57e2a 100644 --- a/eth/stubclient.go +++ b/eth/stubclient.go @@ -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 diff --git a/server/handlers.go b/server/handlers.go index 9616b33c25..972f2052c4 100644 --- a/server/handlers.go +++ b/server/handlers.go @@ -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 { @@ -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 +} diff --git a/server/webserver.go b/server/webserver.go index d53c106193..4d4d53fa9f 100644 --- a/server/webserver.go +++ b/server/webserver.go @@ -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