Skip to content

Commit

Permalink
eth,server: Use global total supply instead of L2 supply to calculate…
Browse files Browse the repository at this point in the history
… participation rate on Arbitrum networks (livepeer#2276)
  • Loading branch information
leszko authored Feb 18, 2022
1 parent f8eda18 commit 6ba48a0
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 3 deletions.
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

0 comments on commit 6ba48a0

Please sign in to comment.