round trip receipt

This commit is contained in:
Felipe Andrade 2023-07-12 10:28:32 -07:00
parent 1e3eae57ce
commit 660539b3bf
2 changed files with 57 additions and 11 deletions

@ -38,10 +38,9 @@ type HealthzConfig struct {
} }
type WalletConfig struct { type WalletConfig struct {
// default: 420 (Optimism Goerli)
ChainID big.Int `toml:"chain_id"` ChainID big.Int `toml:"chain_id"`
// signer | static, default: signer // signer | static
SignerMethod string `toml:"signer_method"` SignerMethod string `toml:"signer_method"`
Address string `toml:"address"` Address string `toml:"address"`
// private key is used for static signing // private key is used for static signing
@ -57,10 +56,12 @@ type WalletConfig struct {
type ProviderConfig struct { type ProviderConfig struct {
Disabled bool `toml:"disabled"` Disabled bool `toml:"disabled"`
URL string `toml:"url"` URL string `toml:"url"`
Wallet string `toml:"wallet"`
ReadOnly bool `toml:"read_only"` ReadOnly bool `toml:"read_only"`
ReadInterval TOMLDuration `toml:"read_interval"` ReadInterval TOMLDuration `toml:"read_interval"`
SendInterval TOMLDuration `toml:"send_interval"` SendInterval TOMLDuration `toml:"send_interval"`
Wallet string `toml:"wallet"`
ReceiptRetrievalInterval TOMLDuration `toml:"receipt_retrieval_interval"`
ReceiptRetrievalTimeout TOMLDuration `toml:"receipt_retrieval_timeout"`
} }
func New(file string) (*Config, error) { func New(file string) (*Config, error) {
@ -120,6 +121,15 @@ func (c *Config) Validate() error {
if wallet.Address == "" { if wallet.Address == "" {
return errors.Errorf("wallet [%s] address is missing", name) return errors.Errorf("wallet [%s] address is missing", name)
} }
if wallet.TxValue.BitLen() == 0 {
return errors.Errorf("wallet [%s] tx_value is missing", name)
}
if wallet.GasLimit == 0 {
return errors.Errorf("wallet [%s] gas_limit is missing", name)
}
if wallet.GasFeeCap.BitLen() == 0 {
return errors.Errorf("wallet [%s] gas_fee_cap is missing", name)
}
} }
for name, provider := range c.Providers { for name, provider := range c.Providers {
@ -127,14 +137,20 @@ func (c *Config) Validate() error {
return errors.Errorf("provider [%s] url is missing", name) return errors.Errorf("provider [%s] url is missing", name)
} }
if provider.ReadInterval == 0 { if provider.ReadInterval == 0 {
return errors.Errorf("provider [%s] read interval is missing", name) return errors.Errorf("provider [%s] read_interval is missing", name)
} }
if provider.SendInterval == 0 { if provider.SendInterval == 0 {
return errors.Errorf("provider [%s] send interval is missing", name) return errors.Errorf("provider [%s] send_interval is missing", name)
} }
if provider.Wallet == "" { if provider.Wallet == "" {
return errors.Errorf("provider [%s] wallet is missing", name) return errors.Errorf("provider [%s] wallet is missing", name)
} }
if provider.SendInterval == 0 {
return errors.Errorf("provider [%s] receipt_retrieval_interval is missing", name)
}
if provider.SendInterval == 0 {
return errors.Errorf("provider [%s] receipt_retrieval_timeout is missing", name)
}
if _, ok := c.Wallets[provider.Wallet]; !ok { if _, ok := c.Wallets[provider.Wallet]; !ok {
return errors.Errorf("provider [%s] has an invalid wallet [%s]", name, provider.Wallet) return errors.Errorf("provider [%s] has an invalid wallet [%s]", name, provider.Wallet)
} }

@ -2,9 +2,11 @@ package provider
import ( import (
"context" "context"
"time"
"github.com/ethereum-optimism/optimism/op-service/tls" "github.com/ethereum-optimism/optimism/op-service/tls"
signer "github.com/ethereum-optimism/optimism/op-signer/client" signer "github.com/ethereum-optimism/optimism/op-signer/client"
"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/ethclient" "github.com/ethereum/go-ethereum/ethclient"
@ -39,7 +41,35 @@ func (p *Provider) Heartbeat(ctx context.Context) {
if err != nil { if err != nil {
log.Error("cant send transaction", "provider", p.name, "err", err) log.Error("cant send transaction", "provider", p.name, "err", err)
} }
log.Info("transaction sent", "hash", signedTx.Hash().Hex()) txHash := signedTx.Hash()
log.Info("transaction sent", "hash", txHash.Hex())
sentAt := time.Now()
var receipt *types.Receipt
attempt := 0
for receipt == nil {
if time.Since(sentAt) >= time.Duration(p.config.ReceiptRetrievalTimeout) {
log.Error("receipt retrieval timedout", "provider", p.name, "hash", "ellapsed", time.Since(sentAt))
break
}
time.Sleep(time.Duration(p.config.ReceiptRetrievalInterval))
if attempt%10 == 0 {
log.Debug("checking for receipt...", "attempt", attempt, "ellapsed", time.Since(sentAt))
}
receipt, err = ethClient.TransactionReceipt(ctx, txHash)
if err != nil && !errors.Is(err, ethereum.NotFound) {
log.Error("cant get receipt for transaction", "provider", p.name, "hash", txHash.Hex(), "err", err)
break
}
attempt++
}
roundtrip := time.Since(sentAt)
log.Info("got transaction receipt", "hash", txHash.Hex(),
"roundtrip", roundtrip,
"blockNumber", receipt.BlockNumber,
"blockHash", receipt.BlockHash,
"gasUsed", receipt.GasUsed)
} }
func (p *Provider) dial(ctx context.Context) (*ethclient.Client, error) { func (p *Provider) dial(ctx context.Context) (*ethclient.Client, error) {