Commit b7230930 authored by Mark Tyneway's avatar Mark Tyneway

op-chain-ops: cleanup rollover scripts

Adds some nice to have logging that makes it much
more obvious that the rollover scripts are working
as intended. Its very important to have good introspection
into what they are doing to be sure that we know
how to solve any problems that may arise.
parent f9946fd8
...@@ -9,21 +9,25 @@ import ( ...@@ -9,21 +9,25 @@ import (
"sync" "sync"
"time" "time"
"github.com/ethereum/go-ethereum/common/hexutil" "github.com/mattn/go-isatty"
"github.com/urfave/cli/v2"
"github.com/ethereum-optimism/optimism/op-chain-ops/util"
"github.com/ethereum-optimism/optimism/op-bindings/bindings" "github.com/ethereum-optimism/optimism/op-bindings/bindings"
legacy_bindings "github.com/ethereum-optimism/optimism/op-bindings/legacy-bindings" legacy_bindings "github.com/ethereum-optimism/optimism/op-bindings/legacy-bindings"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/ethereum-optimism/optimism/op-chain-ops/util"
"github.com/ethereum/go-ethereum/accounts/abi/bind" "github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/rpc" "github.com/ethereum/go-ethereum/rpc"
"github.com/urfave/cli/v2"
) )
func main() { func main() {
log.Root().SetHandler(log.StreamHandler(os.Stderr, log.TerminalFormat(isatty.IsTerminal(os.Stderr.Fd()))))
app := cli.NewApp() app := cli.NewApp()
app.Name = "rollover" app.Name = "rollover"
app.Usage = "Commands for assisting in the rollover of the system" app.Usage = "Commands for assisting in the rollover of the system"
...@@ -149,6 +153,9 @@ func main() { ...@@ -149,6 +153,9 @@ func main() {
return err return err
} }
log.Info("Remaining deposits that must be submitted", "count", finalPending) log.Info("Remaining deposits that must be submitted", "count", finalPending)
if finalPending.Cmp(common.Big0) == 0 {
log.Info("All deposits have been batch submitted")
}
return nil return nil
}, },
}, },
...@@ -183,11 +190,11 @@ func main() { ...@@ -183,11 +190,11 @@ func main() {
log.Info("Waiting for CanonicalTransactionChain") log.Info("Waiting for CanonicalTransactionChain")
wg.Add(1) wg.Add(1)
go waitForTotalElements(&wg, ctc, clients.L2Client) go waitForTotalElements(&wg, ctc, clients.L2Client, "CanonicalTransactionChain")
log.Info("Waiting for StateCommitmentChain") log.Info("Waiting for StateCommitmentChain")
wg.Add(1) wg.Add(1)
go waitForTotalElements(&wg, scc, clients.L2Client) go waitForTotalElements(&wg, scc, clients.L2Client, "StateCommitmentChain")
wg.Wait() wg.Wait()
log.Info("All batches have been submitted") log.Info("All batches have been submitted")
...@@ -210,7 +217,7 @@ type RollupContract interface { ...@@ -210,7 +217,7 @@ type RollupContract interface {
} }
// waitForTotalElements will poll to see // waitForTotalElements will poll to see
func waitForTotalElements(wg *sync.WaitGroup, contract RollupContract, client *ethclient.Client) { func waitForTotalElements(wg *sync.WaitGroup, contract RollupContract, client *ethclient.Client, name string) {
defer wg.Done() defer wg.Done()
for { for {
...@@ -228,9 +235,16 @@ func waitForTotalElements(wg *sync.WaitGroup, contract RollupContract, client *e ...@@ -228,9 +235,16 @@ func waitForTotalElements(wg *sync.WaitGroup, contract RollupContract, client *e
} }
if totalElements.Uint64() == bn { if totalElements.Uint64() == bn {
log.Info("Total elements matches block number", "name", name, "count", bn)
return return
} }
log.Info("Waiting for elements to be submitted", "count", totalElements.Uint64()-bn, "height", bn, "total-elements", totalElements.Uint64()) log.Info(
"Waiting for elements to be submitted",
"name", name,
"count", totalElements.Uint64()-bn,
"height", bn,
"total-elements", totalElements.Uint64(),
)
time.Sleep(3 * time.Second) time.Sleep(3 * time.Second)
} }
......
...@@ -39,21 +39,21 @@ func NewClients(ctx *cli.Context) (*Clients, error) { ...@@ -39,21 +39,21 @@ func NewClients(ctx *cli.Context) (*Clients, error) {
l1RpcURL := ctx.String("l1-rpc-url") l1RpcURL := ctx.String("l1-rpc-url")
l1Client, err := ethclient.Dial(l1RpcURL) l1Client, err := ethclient.Dial(l1RpcURL)
if err != nil { if err != nil {
return nil, err return nil, fmt.Errorf("cannot dial L1: %w", err)
} }
l1ChainID, err := l1Client.ChainID(context.Background()) l1ChainID, err := l1Client.ChainID(context.Background())
if err != nil { if err != nil {
return nil, err return nil, fmt.Errorf("cannot fetch L1 chainid: %w", err)
} }
l2RpcURL := ctx.String("l2-rpc-url") l2RpcURL := ctx.String("l2-rpc-url")
l2Client, err := ethclient.Dial(l2RpcURL) l2Client, err := ethclient.Dial(l2RpcURL)
if err != nil { if err != nil {
return nil, err return nil, fmt.Errorf("cannot dial L2: %w", err)
} }
l2ChainID, err := l2Client.ChainID(context.Background()) l2ChainID, err := l2Client.ChainID(context.Background())
if err != nil { if err != nil {
return nil, err return nil, fmt.Errorf("cannot fetch L2 chainid: %w", err)
} }
l1RpcClient, err := rpc.DialContext(context.Background(), l1RpcURL) l1RpcClient, err := rpc.DialContext(context.Background(), l1RpcURL)
......
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