From 2347545708af6129126e04d21df75d1f15ac61f0 Mon Sep 17 00:00:00 2001 From: Dusan Brajovic Date: Thu, 11 Jan 2024 14:21:52 +0100 Subject: [PATCH 1/5] estimate gas limit when sending eth tx (relaying) --- .../ethereum/committer/eth_committer.go | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/orchestrator/ethereum/committer/eth_committer.go b/orchestrator/ethereum/committer/eth_committer.go index b231f1b8..7ab666b4 100644 --- a/orchestrator/ethereum/committer/eth_committer.go +++ b/orchestrator/ethereum/committer/eth_committer.go @@ -2,6 +2,7 @@ package committer import ( "context" + "github.com/ethereum/go-ethereum" "math/big" "strings" @@ -114,6 +115,34 @@ func (e *ethCommitter) SendTx( return common.Hash{}, errors.Errorf("Suggested gas price %v is greater than max gas price %v", opts.GasPrice.Int64(), maxGasPrice.Int64()) } + // estimate gas limit + peggyContract := recipient + + // Gas estimation cannot succeed without code for method invocations + code, err := e.evmProvider.PendingCodeAt(opts.Context, peggyContract) + if err != nil { + return common.Hash{}, errors.Wrap(err, "failed to get code") + } + + if len(code) == 0 { + return common.Hash{}, bind.ErrNoCode + } + + msg := ethereum.CallMsg{ + From: opts.From, + To: &peggyContract, + GasPrice: gasPrice, + Value: new(big.Int), + Data: txData, + } + + gasLimit, err := e.evmProvider.EstimateGas(opts.Context, msg) + if err != nil { + return common.Hash{}, errors.Wrap(err, "failed to estimate gas") + } + + opts.GasLimit = gasLimit + resyncNonces := func(from common.Address) { e.nonceCache.Sync(from, func() (uint64, error) { nonce, err := e.evmProvider.PendingNonceAt(context.TODO(), from) From 288496de0c2b8798d76274948f499cb6a9c53392 Mon Sep 17 00:00:00 2001 From: Dusan Brajovic Date: Thu, 11 Jan 2024 14:31:34 +0100 Subject: [PATCH 2/5] logs --- orchestrator/ethereum/peggy/submit_batch.go | 4 ++-- orchestrator/ethereum/peggy/valset_update.go | 2 +- orchestrator/relayer.go | 4 ++++ 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/orchestrator/ethereum/peggy/submit_batch.go b/orchestrator/ethereum/peggy/submit_batch.go index 427e09b9..bf61f7a7 100644 --- a/orchestrator/ethereum/peggy/submit_batch.go +++ b/orchestrator/ethereum/peggy/submit_batch.go @@ -25,9 +25,9 @@ func (s *peggyContract) SendTransactionBatch( log.WithFields(log.Fields{ "token_contract": batch.TokenContract, "batch_nonce": batch.BatchNonce, - "transactions": len(batch.Transactions), + "txs": len(batch.Transactions), "confirmations": len(confirms), - }).Debugln("checking signatures and submitting batch") + }).Infoln("checking signatures and submitting batch") validators, powers, sigV, sigR, sigS, err := checkBatchSigsAndRepack(currentValset, confirms) if err != nil { diff --git a/orchestrator/ethereum/peggy/valset_update.go b/orchestrator/ethereum/peggy/valset_update.go index 8fbbc7b6..18bd1a42 100644 --- a/orchestrator/ethereum/peggy/valset_update.go +++ b/orchestrator/ethereum/peggy/valset_update.go @@ -41,7 +41,7 @@ func (s *peggyContract) SendEthValsetUpdate( "valset_nonce": newValset.Nonce, "validators": len(newValset.Members), "confirmations": len(confirms), - }).Debugln("checking signatures and submitting valset update") + }).Infoln("checking signatures and submitting valset update") newValidators, newPowers := validatorsAndPowers(newValset) newValsetNonce := new(big.Int).SetUint64(newValset.Nonce) diff --git a/orchestrator/relayer.go b/orchestrator/relayer.go index 7eb61507..b38ed0ca 100644 --- a/orchestrator/relayer.go +++ b/orchestrator/relayer.go @@ -125,6 +125,7 @@ func (l *relayerLoop) relayValset(ctx context.Context) error { } if oldestConfirmedValset.Nonce <= currentEthValset.Nonce { + l.Logger().WithFields(log.Fields{"eth_valset_nonce": currentEthValset.Nonce, "inj_valset_nonce": currentEthValset.Nonce}).Debugln("valset already updated on Ethereum") return nil } @@ -135,6 +136,7 @@ func (l *relayerLoop) relayValset(ctx context.Context) error { // Check if other validators already updated the valset if oldestConfirmedValset.Nonce <= latestEthereumValsetNonce.Uint64() { + l.Logger().WithFields(log.Fields{"eth_valset_nonce": latestEthereumValsetNonce, "inj_valset_nonce": currentEthValset.Nonce}).Debugln("valset already updated on Ethereum") return nil } @@ -212,6 +214,7 @@ func (l *relayerLoop) relayBatch(ctx context.Context) error { } if oldestConfirmedBatch.BatchNonce <= latestEthereumBatch.Uint64() { + l.Logger().WithFields(log.Fields{"eth_batch_nonce": latestEthereumBatch.Uint64(), "inj_batch_nonce": oldestConfirmedBatch.BatchNonce}).Debugln("batch already updated on Ethereum") return nil } @@ -222,6 +225,7 @@ func (l *relayerLoop) relayBatch(ctx context.Context) error { // Check if ethereum batch was updated by other validators if oldestConfirmedBatch.BatchNonce <= latestEthereumBatch.Uint64() { + l.Logger().WithFields(log.Fields{"eth_batch_nonce": latestEthereumBatch.Uint64(), "inj_batch_nonce": oldestConfirmedBatch.BatchNonce}).Debugln("batch already updated on Ethereum") return nil } From 0097309b22b36a801f3ba98f2e558d6ad7de0f87 Mon Sep 17 00:00:00 2001 From: Dusan Brajovic Date: Thu, 11 Jan 2024 16:51:14 +0100 Subject: [PATCH 3/5] remove redundant check for contract code --- orchestrator/ethereum/committer/eth_committer.go | 14 +------------- orchestrator/ethereum/peggy/submit_batch.go | 2 +- 2 files changed, 2 insertions(+), 14 deletions(-) diff --git a/orchestrator/ethereum/committer/eth_committer.go b/orchestrator/ethereum/committer/eth_committer.go index 7ab666b4..19444bed 100644 --- a/orchestrator/ethereum/committer/eth_committer.go +++ b/orchestrator/ethereum/committer/eth_committer.go @@ -116,21 +116,9 @@ func (e *ethCommitter) SendTx( } // estimate gas limit - peggyContract := recipient - - // Gas estimation cannot succeed without code for method invocations - code, err := e.evmProvider.PendingCodeAt(opts.Context, peggyContract) - if err != nil { - return common.Hash{}, errors.Wrap(err, "failed to get code") - } - - if len(code) == 0 { - return common.Hash{}, bind.ErrNoCode - } - msg := ethereum.CallMsg{ From: opts.From, - To: &peggyContract, + To: &recipient, GasPrice: gasPrice, Value: new(big.Int), Data: txData, diff --git a/orchestrator/ethereum/peggy/submit_batch.go b/orchestrator/ethereum/peggy/submit_batch.go index bf61f7a7..4a15cfcf 100644 --- a/orchestrator/ethereum/peggy/submit_batch.go +++ b/orchestrator/ethereum/peggy/submit_batch.go @@ -93,7 +93,7 @@ func (s *peggyContract) SendTransactionBatch( txHash, err := s.SendTx(ctx, s.peggyAddress, txData) if err != nil { metrics.ReportFuncError(s.svcTags) - log.WithError(err).WithField("tx_hash", txHash.Hex()).Errorln("Failed to sign and submit (Peggy submitBatch) to EVM") + log.WithError(err).WithField("tx_hash", txHash.Hex()).Errorln("failed to sign and submit (Peggy submitBatch) to EVM") return nil, err } From bc825ba9cc6a82e9fcd78b7fd0106e27c7af8d88 Mon Sep 17 00:00:00 2001 From: Dusan Brajovic Date: Thu, 11 Jan 2024 16:56:22 +0100 Subject: [PATCH 4/5] logs --- orchestrator/relayer.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/orchestrator/relayer.go b/orchestrator/relayer.go index b38ed0ca..56c6cf46 100644 --- a/orchestrator/relayer.go +++ b/orchestrator/relayer.go @@ -125,7 +125,7 @@ func (l *relayerLoop) relayValset(ctx context.Context) error { } if oldestConfirmedValset.Nonce <= currentEthValset.Nonce { - l.Logger().WithFields(log.Fields{"eth_valset_nonce": currentEthValset.Nonce, "inj_valset_nonce": currentEthValset.Nonce}).Debugln("valset already updated on Ethereum") + l.Logger().WithFields(log.Fields{"eth_nonce": currentEthValset.Nonce, "inj_nonce": currentEthValset.Nonce}).Debugln("valset already updated on Ethereum") return nil } @@ -136,11 +136,11 @@ func (l *relayerLoop) relayValset(ctx context.Context) error { // Check if other validators already updated the valset if oldestConfirmedValset.Nonce <= latestEthereumValsetNonce.Uint64() { - l.Logger().WithFields(log.Fields{"eth_valset_nonce": latestEthereumValsetNonce, "inj_valset_nonce": currentEthValset.Nonce}).Debugln("valset already updated on Ethereum") + l.Logger().WithFields(log.Fields{"eth_nonce": latestEthereumValsetNonce, "inj_nonce": currentEthValset.Nonce}).Debugln("valset already updated on Ethereum") return nil } - l.Logger().WithFields(log.Fields{"inj_valset_nonce": oldestConfirmedValset.Nonce, "eth_valset_nonce": latestEthereumValsetNonce.Uint64()}).Debugln("latest valset updates") + l.Logger().WithFields(log.Fields{"inj_nonce": oldestConfirmedValset.Nonce, "eth_nonce": latestEthereumValsetNonce.Uint64()}).Debugln("latest valset updates") // Check custom time delay offset blockTime, err := l.inj.GetBlockCreationTime(ctx, int64(oldestConfirmedValset.Height)) @@ -164,7 +164,7 @@ func (l *relayerLoop) relayValset(ctx context.Context) error { return err } - l.Logger().WithField("tx_hash", txHash.Hex()).Infoln("sent valset update to Ethereum") + l.Logger().WithField("tx_hash", txHash.Hex()).Infoln("sent valset tx to Ethereum") return nil } @@ -214,7 +214,7 @@ func (l *relayerLoop) relayBatch(ctx context.Context) error { } if oldestConfirmedBatch.BatchNonce <= latestEthereumBatch.Uint64() { - l.Logger().WithFields(log.Fields{"eth_batch_nonce": latestEthereumBatch.Uint64(), "inj_batch_nonce": oldestConfirmedBatch.BatchNonce}).Debugln("batch already updated on Ethereum") + l.Logger().WithFields(log.Fields{"eth_nonce": latestEthereumBatch.Uint64(), "inj_nonce": oldestConfirmedBatch.BatchNonce}).Debugln("batch already updated on Ethereum") return nil } @@ -225,11 +225,11 @@ func (l *relayerLoop) relayBatch(ctx context.Context) error { // Check if ethereum batch was updated by other validators if oldestConfirmedBatch.BatchNonce <= latestEthereumBatch.Uint64() { - l.Logger().WithFields(log.Fields{"eth_batch_nonce": latestEthereumBatch.Uint64(), "inj_batch_nonce": oldestConfirmedBatch.BatchNonce}).Debugln("batch already updated on Ethereum") + l.Logger().WithFields(log.Fields{"eth_nonce": latestEthereumBatch.Uint64(), "inj_nonce": oldestConfirmedBatch.BatchNonce}).Debugln("batch already updated on Ethereum") return nil } - l.Logger().WithFields(log.Fields{"inj_batch_nonce": oldestConfirmedBatch.BatchNonce, "eth_batch_nonce": latestEthereumBatch.Uint64()}).Debugln("latest batch updates") + l.Logger().WithFields(log.Fields{"inj_nonce": oldestConfirmedBatch.BatchNonce, "eth_nonce": latestEthereumBatch.Uint64()}).Debugln("latest batch updates") // Check custom time delay offset blockTime, err := l.inj.GetBlockCreationTime(ctx, int64(oldestConfirmedBatch.Block)) @@ -249,7 +249,7 @@ func (l *relayerLoop) relayBatch(ctx context.Context) error { return err } - l.Logger().WithField("tx_hash", txHash.Hex()).Infoln("sent tx batch to Ethereum") + l.Logger().WithField("tx_hash", txHash.Hex()).Infoln("sent batch tx to Ethereum") return nil } From 6ea82718cc80beaa83f20d7040164d2fa19010e6 Mon Sep 17 00:00:00 2001 From: Dusan Brajovic Date: Thu, 11 Jan 2024 17:10:00 +0100 Subject: [PATCH 5/5] logs 2 --- orchestrator/batch_request.go | 2 +- orchestrator/relayer.go | 6 +++--- orchestrator/signer.go | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/orchestrator/batch_request.go b/orchestrator/batch_request.go index 72f628d4..7ee1e01d 100644 --- a/orchestrator/batch_request.go +++ b/orchestrator/batch_request.go @@ -47,7 +47,7 @@ func (l *batchRequestLoop) requestBatches(ctx context.Context) error { } if len(fees) == 0 { - l.Logger().Debugln("no outgoing withdrawals to batch") + l.Logger().Debugln("no withdrawals to batch") return nil } diff --git a/orchestrator/relayer.go b/orchestrator/relayer.go index 56c6cf46..17e5b9d2 100644 --- a/orchestrator/relayer.go +++ b/orchestrator/relayer.go @@ -150,7 +150,7 @@ func (l *relayerLoop) relayValset(ctx context.Context) error { if timeElapsed := time.Since(blockTime); timeElapsed <= l.relayValsetOffsetDur { timeRemaining := time.Duration(int64(l.relayValsetOffsetDur) - int64(timeElapsed)) - l.Logger().WithField("time_remaining", timeRemaining.String()).Debugln("valset relay offset duration not expired") + l.Logger().WithField("time_remaining", timeRemaining.String()).Debugln("valset relay offset not reached yet") return nil } @@ -197,7 +197,7 @@ func (l *relayerLoop) relayBatch(ctx context.Context) error { } if oldestConfirmedBatch == nil { - l.Logger().Debugln("no outgoing batch to relay") + l.Logger().Debugln("no batch to relay") return nil } @@ -239,7 +239,7 @@ func (l *relayerLoop) relayBatch(ctx context.Context) error { if timeElapsed := time.Since(blockTime); timeElapsed <= l.relayBatchOffsetDur { timeRemaining := time.Duration(int64(l.relayBatchOffsetDur) - int64(timeElapsed)) - l.Logger().WithField("time_remaining", timeRemaining.String()).Debugln("batch relay offset duration not expired") + l.Logger().WithField("time_remaining", timeRemaining.String()).Debugln("batch relay offset not reached yet") return nil } diff --git a/orchestrator/signer.go b/orchestrator/signer.go index cdb9b688..9b429f0d 100644 --- a/orchestrator/signer.go +++ b/orchestrator/signer.go @@ -110,7 +110,7 @@ func (l *ethSignerLoop) signNewBatch(ctx context.Context) error { } if oldestUnsignedTransactionBatch == nil { - l.Logger().Debugln("no outgoing batch to confirm") + l.Logger().Debugln("no batch to confirm") return nil }