Commit b3efd63c authored by Mark Tyneway's avatar Mark Tyneway

op-chain-ops: migrate error handling

The migration script entrypoint failed due to the
L1StartingBlockTag in the `DeployConfig` being set to `nil`.
This adds a `nil` check as well as some better logging.
The lower level methods for the usage of block tags are
also used instead of manually accessing the values internal
to the struct, this is what geth does internally.
parent 6edd9903
...@@ -3,6 +3,7 @@ package main ...@@ -3,6 +3,7 @@ package main
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"errors"
"fmt" "fmt"
"math/big" "math/big"
"os" "os"
...@@ -168,10 +169,14 @@ func main() { ...@@ -168,10 +169,14 @@ func main() {
var block *types.Block var block *types.Block
tag := config.L1StartingBlockTag tag := config.L1StartingBlockTag
if tag.BlockNumber != nil { if tag == nil {
block, err = l1Client.BlockByNumber(context.Background(), big.NewInt(tag.BlockNumber.Int64())) return errors.New("l1StartingBlockTag cannot be nil")
} else if tag.BlockHash != nil { }
block, err = l1Client.BlockByHash(context.Background(), *tag.BlockHash) log.Info("Using L1 Starting Block Tag", "tag", tag.String())
if number, isNumber := tag.Number(); isNumber {
block, err = l1Client.BlockByNumber(context.Background(), big.NewInt(number.Int64()))
} else if hash, isHash := tag.Hash(); isHash {
block, err = l1Client.BlockByHash(context.Background(), hash)
} else { } else {
return fmt.Errorf("invalid l1StartingBlockTag in deploy config: %v", tag) return fmt.Errorf("invalid l1StartingBlockTag in deploy config: %v", tag)
} }
......
...@@ -493,3 +493,18 @@ func (m *MarshalableRPCBlockNumberOrHash) UnmarshalJSON(b []byte) error { ...@@ -493,3 +493,18 @@ func (m *MarshalableRPCBlockNumberOrHash) UnmarshalJSON(b []byte) error {
*m = asMarshalable *m = asMarshalable
return nil return nil
} }
// Number wraps the rpc.BlockNumberOrHash Number method.
func (m *MarshalableRPCBlockNumberOrHash) Number() (rpc.BlockNumber, bool) {
return (*rpc.BlockNumberOrHash)(m).Number()
}
// Hash wraps the rpc.BlockNumberOrHash Hash method.
func (m *MarshalableRPCBlockNumberOrHash) Hash() (common.Hash, bool) {
return (*rpc.BlockNumberOrHash)(m).Hash()
}
// String wraps the rpc.BlockNumberOrHash String method.
func (m *MarshalableRPCBlockNumberOrHash) String() string {
return (*rpc.BlockNumberOrHash)(m).String()
}
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