Commit cfe82c63 authored by Adrian Sutton's avatar Adrian Sutton Committed by GitHub

op-challenger: Include bonds when listing claims (#10625)

* op-challenger: Include bonds when listing claims

* fix: docker build missing bigint - reuse op-service wei conversion

---------
Co-authored-by: default avatarrefcell <abigger87@gmail.com>
parent 46a9f00c
...@@ -13,6 +13,7 @@ import ( ...@@ -13,6 +13,7 @@ import (
"github.com/ethereum-optimism/optimism/op-challenger/game/fault/types" "github.com/ethereum-optimism/optimism/op-challenger/game/fault/types"
opservice "github.com/ethereum-optimism/optimism/op-service" opservice "github.com/ethereum-optimism/optimism/op-service"
"github.com/ethereum-optimism/optimism/op-service/dial" "github.com/ethereum-optimism/optimism/op-service/dial"
"github.com/ethereum-optimism/optimism/op-service/eth"
oplog "github.com/ethereum-optimism/optimism/op-service/log" oplog "github.com/ethereum-optimism/optimism/op-service/log"
"github.com/ethereum-optimism/optimism/op-service/sources/batching" "github.com/ethereum-optimism/optimism/op-service/sources/batching"
"github.com/ethereum-optimism/optimism/op-service/sources/batching/rpcblock" "github.com/ethereum-optimism/optimism/op-service/sources/batching/rpcblock"
...@@ -105,8 +106,8 @@ func listClaims(ctx context.Context, game contracts.FaultDisputeGameContract, ve ...@@ -105,8 +106,8 @@ func listClaims(ctx context.Context, game contracts.FaultDisputeGameContract, ve
valueFormat = "%-66v" valueFormat = "%-66v"
} }
now := time.Now() now := time.Now()
lineFormat := "%3v %-7v %6v %5v %14v " + valueFormat + " %-42v %-19v %10v %v\n" lineFormat := "%3v %-7v %6v %5v %14v " + valueFormat + " %-42v %12v %-19v %10v %v\n"
info := fmt.Sprintf(lineFormat, "Idx", "Move", "Parent", "Depth", "Index", "Value", "Claimant", "Time", "Clock Used", "Resolution") info := fmt.Sprintf(lineFormat, "Idx", "Move", "Parent", "Depth", "Index", "Value", "Claimant", "Bond (ETH)", "Time", "Clock Used", "Resolution")
for i, claim := range claims { for i, claim := range claims {
pos := claim.Position pos := claim.Position
parent := strconv.Itoa(claim.ParentContractIndex) parent := strconv.Itoa(claim.ParentContractIndex)
...@@ -154,8 +155,12 @@ func listClaims(ctx context.Context, game contracts.FaultDisputeGameContract, ve ...@@ -154,8 +155,12 @@ func listClaims(ctx context.Context, game contracts.FaultDisputeGameContract, ve
value = claim.Value.Hex() value = claim.Value.Hex()
} }
timestamp := claim.Clock.Timestamp.Format(time.DateTime) timestamp := claim.Clock.Timestamp.Format(time.DateTime)
bond := fmt.Sprintf("%12.8f", eth.WeiToEther(claim.Bond))
if verbose {
bond = fmt.Sprintf("%f", eth.WeiToEther(claim.Bond))
}
info = info + fmt.Sprintf(lineFormat, info = info + fmt.Sprintf(lineFormat,
i, move, parent, pos.Depth(), traceIdx, value, claim.Claimant, timestamp, elapsed, countered) i, move, parent, pos.Depth(), traceIdx, value, claim.Claimant, bond, timestamp, elapsed, countered)
} }
blockNumChallenger := "L2 Block: Unchallenged" blockNumChallenger := "L2 Block: Unchallenged"
if metadata.L2BlockNumberChallenged { if metadata.L2BlockNumberChallenged {
......
...@@ -94,4 +94,4 @@ func NewHTTP(t mockConstructorTestingTNewHTTP) *HTTP { ...@@ -94,4 +94,4 @@ func NewHTTP(t mockConstructorTestingTNewHTTP) *HTTP {
t.Cleanup(func() { mock.AssertExpectations(t) }) t.Cleanup(func() { mock.AssertExpectations(t) })
return mock return mock
} }
\ No newline at end of file
package eth
import (
"math/big"
"github.com/ethereum/go-ethereum/params"
)
// WeiToEther divides the wei value by 10^18 to get a number in ether as a float64
func WeiToEther(wei *big.Int) float64 {
num := new(big.Rat).SetInt(wei)
denom := big.NewRat(params.Ether, 1)
num = num.Quo(num, denom)
f, _ := num.Float64()
return f
}
package metrics package eth
import ( import (
"math/big" "math/big"
...@@ -31,10 +31,9 @@ func TestWeiToEther(t *testing.T) { ...@@ -31,10 +31,9 @@ func TestWeiToEther(t *testing.T) {
} }
for i, tc := range tests { for i, tc := range tests {
out := weiToEther(tc.input) out := WeiToEther(tc.input)
if out != tc.output { if out != tc.output {
t.Fatalf("test %v: expected %v but got %v", i, tc.output, out) t.Fatalf("test %v: expected %v but got %v", i, tc.output, out)
} }
} }
} }
...@@ -2,7 +2,6 @@ package metrics ...@@ -2,7 +2,6 @@ package metrics
import ( import (
"context" "context"
"math/big"
"time" "time"
"github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus"
...@@ -11,20 +10,11 @@ import ( ...@@ -11,20 +10,11 @@ import (
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/ethclient" "github.com/ethereum/go-ethereum/ethclient"
"github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum-optimism/optimism/op-service/clock" "github.com/ethereum-optimism/optimism/op-service/clock"
"github.com/ethereum-optimism/optimism/op-service/eth"
) )
// weiToEther divides the wei value by 10^18 to get a number in ether as a float64
func weiToEther(wei *big.Int) float64 {
num := new(big.Rat).SetInt(wei)
denom := big.NewRat(params.Ether, 1)
num = num.Quo(num, denom)
f, _ := num.Float64()
return f
}
// LaunchBalanceMetrics starts a periodic query of the balance of the supplied account and records it // LaunchBalanceMetrics starts a periodic query of the balance of the supplied account and records it
// to the "balance" metric of the namespace. The balance of the account is recorded in Ether (not Wei). // to the "balance" metric of the namespace. The balance of the account is recorded in Ether (not Wei).
// Cancel the supplied context to shut down the go routine // Cancel the supplied context to shut down the go routine
...@@ -42,7 +32,7 @@ func LaunchBalanceMetrics(log log.Logger, r *prometheus.Registry, ns string, cli ...@@ -42,7 +32,7 @@ func LaunchBalanceMetrics(log log.Logger, r *prometheus.Registry, ns string, cli
log.Warn("failed to get balance of account", "err", err, "address", account) log.Warn("failed to get balance of account", "err", err, "address", account)
return return
} }
bal := weiToEther(bigBal) bal := eth.WeiToEther(bigBal)
balanceGuage.Set(bal) balanceGuage.Set(bal)
}, func() error { }, func() error {
log.Info("balance metrics shutting down") log.Info("balance metrics shutting down")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment