Commit 6cca247a authored by Tei Im's avatar Tei Im

Apply suggestions from code reivews

Use duration flag type
Dedup long lines
parent 5c6d39b6
...@@ -44,10 +44,10 @@ func main() { ...@@ -44,10 +44,10 @@ func main() {
Usage: "L2 RPC URL", Usage: "L2 RPC URL",
EnvVars: []string{"L2_RPC_URL"}, EnvVars: []string{"L2_RPC_URL"},
}, },
&cli.IntFlag{ &cli.DurationFlag{
Name: "polling-interval", Name: "polling-interval",
Value: 500, Value: time.Millisecond * 500,
Usage: "Polling interval (ms)", Usage: "Polling interval",
}, },
}, },
Action: detectL2Reorg, Action: detectL2Reorg,
...@@ -62,10 +62,10 @@ func main() { ...@@ -62,10 +62,10 @@ func main() {
Usage: "L2 RPC URL", Usage: "L2 RPC URL",
EnvVars: []string{"L2_RPC_URL"}, EnvVars: []string{"L2_RPC_URL"},
}, },
&cli.IntFlag{ &cli.DurationFlag{
Name: "polling-interval", Name: "polling-interval",
Value: 1000, Value: time.Millisecond * 1000,
Usage: "Polling interval (ms)", Usage: "Polling interval",
}, },
&cli.StringFlag{ &cli.StringFlag{
Name: "private-key", Name: "private-key",
...@@ -157,7 +157,7 @@ func detectL2Reorg(cliCtx *cli.Context) error { ...@@ -157,7 +157,7 @@ func detectL2Reorg(cliCtx *cli.Context) error {
return err return err
} }
var pollingInterval = time.Duration(cliCtx.Int("polling-interval")) * time.Millisecond var pollingInterval = cliCtx.Duration("polling-interval")
// blockMap maps blockNumber to blockHash // blockMap maps blockNumber to blockHash
blockMap := make(map[uint64]common.Hash) blockMap := make(map[uint64]common.Hash)
var prevUnsafeHeadNum uint64 var prevUnsafeHeadNum uint64
...@@ -326,10 +326,7 @@ func checkConsolidation(cliCtx *cli.Context) error { ...@@ -326,10 +326,7 @@ func checkConsolidation(cliCtx *cli.Context) error {
if err != nil { if err != nil {
return err return err
} }
if err != nil { var pollingInterval = cliCtx.Duration("polling-interval")
return err
}
var pollingInterval = time.Duration(cliCtx.Int("polling-interval")) * time.Millisecond
privateKey, err := getPrivateKey(cliCtx) privateKey, err := getPrivateKey(cliCtx)
if err != nil { if err != nil {
return err return err
...@@ -355,17 +352,19 @@ func checkConsolidation(cliCtx *cli.Context) error { ...@@ -355,17 +352,19 @@ func checkConsolidation(cliCtx *cli.Context) error {
// txMap maps txHash to blockID // txMap maps txHash to blockID
txMap := make(map[common.Hash]eth.BlockID) txMap := make(map[common.Hash]eth.BlockID)
for i := 0; i < txCount; i++ { for i := 0; i < txCount; i++ {
var tx *types.Transaction txType := types.LegacyTxType
protected := true
switch i % 4 { switch i % 4 {
case 0: case 0:
tx, err = getRandomSignedTransaction(ctx, cl, rng, from, privateKey, l2ChainID, types.LegacyTxType, false) protected = false // legacy unprotected TX (Homestead)
case 1: case 1:
tx, err = getRandomSignedTransaction(ctx, cl, rng, from, privateKey, l2ChainID, types.LegacyTxType, true) // legacy protected TX
case 2: case 2:
tx, err = getRandomSignedTransaction(ctx, cl, rng, from, privateKey, l2ChainID, types.AccessListTxType, true) txType = types.AccessListTxType
case 3: case 3:
tx, err = getRandomSignedTransaction(ctx, cl, rng, from, privateKey, l2ChainID, types.DynamicFeeTxType, true) txType = types.DynamicFeeTxType
} }
tx, err := getRandomSignedTransaction(ctx, cl, rng, from, privateKey, l2ChainID, txType, protected)
if err != nil { if err != nil {
return err return err
} }
...@@ -373,6 +372,7 @@ func checkConsolidation(cliCtx *cli.Context) error { ...@@ -373,6 +372,7 @@ func checkConsolidation(cliCtx *cli.Context) error {
if err != nil { if err != nil {
return fmt.Errorf("failed to send transaction: %w", err) return fmt.Errorf("failed to send transaction: %w", err)
} }
log.Info("Sent transaction", "txType", txType, "protected", protected)
txHash := tx.Hash() txHash := tx.Hash()
blockId, err := confirmTransaction(ctx, cl, l2BlockTime, txHash) blockId, err := confirmTransaction(ctx, cl, l2BlockTime, txHash)
if err != nil { if err != nil {
......
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