|
1 | 1 | package espressotee
|
2 | 2 |
|
3 | 3 | import (
|
| 4 | + "context" |
4 | 5 | "fmt"
|
5 | 6 | "math/big"
|
6 | 7 | "strings"
|
7 | 8 | "time"
|
8 | 9 |
|
9 | 10 | "github.com/spf13/pflag"
|
10 | 11 |
|
| 12 | + "github.com/ethereum/go-ethereum/ethclient" |
11 | 13 | "github.com/ethereum/go-ethereum/log"
|
| 14 | + |
| 15 | + "github.com/offchainlabs/nitro/arbnode/dataposter" |
12 | 16 | )
|
13 | 17 |
|
14 | 18 | type TEE uint8
|
@@ -99,6 +103,30 @@ func BaseFeeCheck(
|
99 | 103 | return nil
|
100 | 104 | }
|
101 | 105 |
|
| 106 | +/** |
| 107 | + * This functions checks the dataposter nonce and the parent chains nonce |
| 108 | + * If these two differ, dont send a transaction as registering the signer is costly and we dont want to send multiple transactions. |
| 109 | + * This will constantly be called when we try and post a batch which will allow time for the two to eventually sync up. |
| 110 | + */ |
| 111 | +func NonceValidation(context context.Context, l1Client *ethclient.Client, dataPoster *dataposter.DataPoster) error { |
| 112 | + nonce, err := l1Client.NonceAt(context, dataPoster.Sender(), nil) |
| 113 | + if err != nil { |
| 114 | + log.Warn("could not retrieve on-chain nonce", "err", err) |
| 115 | + return err |
| 116 | + } |
| 117 | + dataPosterNonce, _, err := dataPoster.GetNextNonceAndMeta(context) |
| 118 | + if err != nil { |
| 119 | + log.Warn("error getting dataposter nonce", "err", err) |
| 120 | + return err |
| 121 | + } |
| 122 | + log.Info("successfully got datapaster next nonce and on-chain nonce", "dataposter nonce", dataPosterNonce, "on-chain nonce", nonce) |
| 123 | + if dataPosterNonce != nonce { |
| 124 | + log.Warn("dataposter and on-chain nonce have mismatch, not sending txn", "dataposter nonce", dataPosterNonce, "on-chain nonce", nonce) |
| 125 | + return err |
| 126 | + } |
| 127 | + return nil |
| 128 | +} |
| 129 | + |
102 | 130 | type EspressoRegisterSignerConfig struct {
|
103 | 131 | MaxTxnWaitTime time.Duration `koanf:"max-txn-wait-time"`
|
104 | 132 | RetryBaseFeeDelay time.Duration `koanf:"retry-base-fee-delay"`
|
|
0 commit comments