From dfbf6ba6efadee4f990f8c51bdbf309403b949dc Mon Sep 17 00:00:00 2001 From: parodime Date: Thu, 23 Jan 2025 16:22:05 -0500 Subject: [PATCH 01/42] +dynamic_gas_unit_add_percentage flag --- docs/bridge/docs/06-Services/04-Submitter.md | 3 ++ ethergo/submitter/config/config.go | 28 +++++++++++++++++-- ethergo/submitter/config/config_test.go | 2 ++ ethergo/submitter/config/iconfig_generated.go | 2 ++ ethergo/submitter/submitter.go | 15 ++++++++-- ethergo/submitter/util_test.go | 15 ++++++++++ 6 files changed, 60 insertions(+), 5 deletions(-) diff --git a/docs/bridge/docs/06-Services/04-Submitter.md b/docs/bridge/docs/06-Services/04-Submitter.md index ff2f045802..0800d16c1b 100644 --- a/docs/bridge/docs/06-Services/04-Submitter.md +++ b/docs/bridge/docs/06-Services/04-Submitter.md @@ -59,6 +59,9 @@ submitter_config: dynamic_gas_estimate: true # SupportsEIP1559 is whether or not this chain supports EIP1559. supports_eip_1559: true + # DynamicGasUnitAddPercentage - increase gas unit limit (ie: "gas" field on a typical tx) by X% from what dynamic gas estimate returns + # Has no effect if dynamic gas estimation is not also enabled. + dynamic_gas_unit_add_percentage: 5 43114: max_gas_price: 100000000000 # 100 Gwei 10: diff --git a/ethergo/submitter/config/config.go b/ethergo/submitter/config/config.go index af6cf120d7..591029b41e 100644 --- a/ethergo/submitter/config/config.go +++ b/ethergo/submitter/config/config.go @@ -49,6 +49,9 @@ type ChainConfig struct { DynamicGasEstimate bool `yaml:"dynamic_gas_estimate"` // SupportsEIP1559 is whether or not this chain supports EIP1559 SupportsEIP1559 bool `yaml:"supports_eip_1559"` + // DynamicGasUnitAddPercentage - increase gas unit limit (ie: "gas" field on a typical tx) by X% from what dynamic gas estimate returns + // Has no effect if dynamic gas estimation is not also enabled. + DynamicGasUnitAddPercentage int `yaml:"dynamic_gas_unit_add_percentage"` } const ( @@ -64,6 +67,9 @@ const ( // DefaultGasEstimate is the default gas estimate to use for transactions. DefaultGasEstimate = uint64(1200000) + + // DefaultDynamicGasUnitAddPercentage is the default percentage to bump the gas limit by. + DefaultDynamicGasUnitAddPercentage = 5 ) // DefaultMaxPrice is the default max price of a tx. @@ -188,6 +194,24 @@ func (c *Config) GetGasBumpPercentage(chainID int) (gasBumpPercentage int) { return gasBumpPercentage } +// GetDynamicGasUnitAddPercentage returns the percentage to bump the gas limit by +func (c *Config) GetDynamicGasUnitAddPercentage(chainID int) (dynamicGasUnitAddPercentage int) { + chainConfig, ok := c.Chains[chainID] + if ok { + dynamicGasUnitAddPercentage = chainConfig.DynamicGasUnitAddPercentage + } + // if dynamicGasUnitAddPercentage is not set for the chain, use the global config + if dynamicGasUnitAddPercentage == 0 { + dynamicGasUnitAddPercentage = c.DynamicGasUnitAddPercentage + } + + // if the dynamicGasUnitAddPercentage isn't set at all, use the default + if dynamicGasUnitAddPercentage == 0 { + dynamicGasUnitAddPercentage = DefaultDynamicGasUnitAddPercentage + } + return dynamicGasUnitAddPercentage +} + // GetGasEstimate returns the gas estimate to use for transactions // TODO: test this method. func (c *Config) GetGasEstimate(chainID int) (gasEstimate uint64) { @@ -195,12 +219,12 @@ func (c *Config) GetGasEstimate(chainID int) (gasEstimate uint64) { if ok { gasEstimate = chainConfig.GasEstimate } - // if gasBumpPercentage is not set for the chain, use the global config + // if gasEstimate is not set for the chain, use the global config if gasEstimate == 0 { gasEstimate = c.GasEstimate } - // if the gasBumpPercentage isn't set at all, use the default + // if the gasEstimate isn't set at all, use the default if gasEstimate == 0 { gasEstimate = DefaultGasEstimate } diff --git a/ethergo/submitter/config/config_test.go b/ethergo/submitter/config/config_test.go index 2d72049d65..4299620b9c 100644 --- a/ethergo/submitter/config/config_test.go +++ b/ethergo/submitter/config/config_test.go @@ -77,6 +77,7 @@ gas_bump_percentage: 10 gas_estimate: 1000 is_l2: true dynamic_gas_estimate: true +dynamic_gas_unit_add_percentage: 20 supports_eip_1559: true` var cfg config.Config err := yaml.Unmarshal([]byte(cfgStr), &cfg) @@ -84,6 +85,7 @@ supports_eip_1559: true` assert.Equal(t, big.NewInt(250000000000), cfg.MaxGasPrice) assert.Equal(t, 60, cfg.BumpIntervalSeconds) assert.Equal(t, 10, cfg.GasBumpPercentage) + assert.Equal(t, 5, cfg.DynamicGasUnitAddPercentage) assert.Equal(t, uint64(1000), cfg.GasEstimate) assert.Equal(t, true, cfg.DynamicGasEstimate) assert.Equal(t, true, cfg.SupportsEIP1559(0)) diff --git a/ethergo/submitter/config/iconfig_generated.go b/ethergo/submitter/config/iconfig_generated.go index 12716431c3..d17b995655 100644 --- a/ethergo/submitter/config/iconfig_generated.go +++ b/ethergo/submitter/config/iconfig_generated.go @@ -41,4 +41,6 @@ type IConfig interface { SetMinGasPrice(basePrice *big.Int) // SetGlobalEIP1559Support is a helper function that sets the global EIP1559 support. SetGlobalEIP1559Support(supportsEIP1559 bool) + // GetDynamicGasUnitAddPercentage returns the percentage to modify the gas unit limit by + GetDynamicGasUnitAddPercentage(chainID int) (dynamicGasUnitAddPercentage int) } diff --git a/ethergo/submitter/submitter.go b/ethergo/submitter/submitter.go index 67b590fe7e..3f67c1f90b 100644 --- a/ethergo/submitter/submitter.go +++ b/ethergo/submitter/submitter.go @@ -392,9 +392,10 @@ func (t *txSubmitterImpl) SubmitTransaction(parentCtx context.Context, chainID * if err != nil { span.AddEvent("could not set gas price", trace.WithAttributes(attribute.String("error", err.Error()))) } - if !t.config.GetDynamicGasEstimate(int(chainID.Uint64())) { - transactor.GasLimit = t.config.GetGasEstimate(int(chainID.Uint64())) - } + + gasEstimate, err := t.getGasEstimate(ctx, chainClient, int(chainID.Uint64()), nil) + + transactor.GasLimit = gasEstimate transactor.Signer = func(address common.Address, transaction *types.Transaction) (_ *types.Transaction, err error) { locker = t.nonceMux.Lock(chainID) @@ -677,13 +678,18 @@ func (t *txSubmitterImpl) getGasBlock(ctx context.Context, chainClient client.EV // getGasEstimate gets the gas estimate for the given transaction. // TODO: handle l2s w/ custom gas pricing through contracts. func (t *txSubmitterImpl) getGasEstimate(ctx context.Context, chainClient client.EVM, chainID int, tx *types.Transaction) (gasEstimate uint64, err error) { + + // if dynamic gas estimation is not enabled, use cfg var gas_estimate as a default if !t.config.GetDynamicGasEstimate(chainID) { return t.config.GetGasEstimate(chainID), nil } + gasUnitAddPercentage := t.config.GetDynamicGasUnitAddPercentage(chainID) + ctx, span := t.metrics.Tracer().Start(ctx, "submitter.getGasEstimate", trace.WithAttributes( attribute.Int(metrics.ChainID, chainID), attribute.String(metrics.TxHash, tx.Hash().String()), + attribute.Int("gasUnitAddPercentage", gasUnitAddPercentage), )) defer func() { @@ -710,6 +716,9 @@ func (t *txSubmitterImpl) getGasEstimate(ctx context.Context, chainClient client return t.config.GetGasEstimate(chainID), nil } + // Modify the gasEstimate by the configured percentage + gasEstimate = gasEstimate + (gasEstimate * uint64(gasUnitAddPercentage) / 100) + return gasEstimate, nil } diff --git a/ethergo/submitter/util_test.go b/ethergo/submitter/util_test.go index a5e057324e..ceedc3d1dc 100644 --- a/ethergo/submitter/util_test.go +++ b/ethergo/submitter/util_test.go @@ -198,6 +198,21 @@ func (s *SubmitterSuite) TestGroupTxesByNonce() { } } +func (s *SubmitterSuite) TestOpStackGas() { + + mockTx := mocks.GetMockTxes(s.GetTestContext(), s.T(), 1, types.LegacyTxType)[0] + + fmt.Printf("Original Transaction Gas Limit: %d\n", mockTx.Gas()) + +} + +func TestBox(t *testing.T) { + const testTxCount = 10 + mockTx := mocks.GetMockTxes(context.Background(), t, testTxCount, 0) + + fmt.Printf("Original Transaction Gas Limit: %d\n", mockTx[0].Gas()) +} + // Test for the outersection function. func TestOutersection(t *testing.T) { set := []*big.Int{ From 93459f1ced99a6c1c43a41ee2089d41d794800d1 Mon Sep 17 00:00:00 2001 From: parodime Date: Fri, 24 Jan 2025 11:52:54 -0500 Subject: [PATCH 02/42] test fix --- ethergo/submitter/config/config_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ethergo/submitter/config/config_test.go b/ethergo/submitter/config/config_test.go index 4299620b9c..52ed92c1bc 100644 --- a/ethergo/submitter/config/config_test.go +++ b/ethergo/submitter/config/config_test.go @@ -85,7 +85,7 @@ supports_eip_1559: true` assert.Equal(t, big.NewInt(250000000000), cfg.MaxGasPrice) assert.Equal(t, 60, cfg.BumpIntervalSeconds) assert.Equal(t, 10, cfg.GasBumpPercentage) - assert.Equal(t, 5, cfg.DynamicGasUnitAddPercentage) + assert.Equal(t, 20, cfg.DynamicGasUnitAddPercentage) assert.Equal(t, uint64(1000), cfg.GasEstimate) assert.Equal(t, true, cfg.DynamicGasEstimate) assert.Equal(t, true, cfg.SupportsEIP1559(0)) From 905a3a54d3ac31498022182636a4e0d265c7ae37 Mon Sep 17 00:00:00 2001 From: parodime Date: Fri, 24 Jan 2025 14:02:26 -0500 Subject: [PATCH 03/42] [goreleaser] From 09816fb0bd55de53db0e06ecb618b44250d2a6c0 Mon Sep 17 00:00:00 2001 From: parodime Date: Fri, 24 Jan 2025 16:03:55 -0500 Subject: [PATCH 04/42] new simulate approach --- ethergo/submitter/submitter.go | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/ethergo/submitter/submitter.go b/ethergo/submitter/submitter.go index 3f67c1f90b..832fb2f908 100644 --- a/ethergo/submitter/submitter.go +++ b/ethergo/submitter/submitter.go @@ -393,10 +393,6 @@ func (t *txSubmitterImpl) SubmitTransaction(parentCtx context.Context, chainID * span.AddEvent("could not set gas price", trace.WithAttributes(attribute.String("error", err.Error()))) } - gasEstimate, err := t.getGasEstimate(ctx, chainClient, int(chainID.Uint64()), nil) - - transactor.GasLimit = gasEstimate - transactor.Signer = func(address common.Address, transaction *types.Transaction) (_ *types.Transaction, err error) { locker = t.nonceMux.Lock(chainID) // it's important that we unlock the nonce if we fail to sign the transaction. @@ -422,7 +418,22 @@ func (t *txSubmitterImpl) SubmitTransaction(parentCtx context.Context, chainID * //nolint: wrapcheck return parentTransactor.Signer(address, transaction) } + + transactor.NoSend = true + + tx_forEstimate, err := call(transactor) + + gasEstimate, err := t.getGasEstimate(ctx, chainClient, int(chainID.Uint64()), tx_forEstimate) + if err != nil { + return 0, fmt.Errorf("err getGasEstimate: %w", err) + } + + transactor.GasLimit = gasEstimate + + transactor.NoSend = false + tx, err := call(transactor) + if err != nil { return 0, fmt.Errorf("could not call contract: %w", err) } From 63f730cff9adba4e50dbf6dcab42eb060d878121 Mon Sep 17 00:00:00 2001 From: parodime Date: Fri, 24 Jan 2025 16:04:08 -0500 Subject: [PATCH 05/42] [goreleaser] From 31ca3cfc393c80150c247a4bf50c6165cbe072ff Mon Sep 17 00:00:00 2001 From: parodime Date: Fri, 24 Jan 2025 16:12:45 -0500 Subject: [PATCH 06/42] fix tx.Hash empty [goreleaser] --- ethergo/submitter/submitter.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/ethergo/submitter/submitter.go b/ethergo/submitter/submitter.go index 832fb2f908..57deed0ea0 100644 --- a/ethergo/submitter/submitter.go +++ b/ethergo/submitter/submitter.go @@ -699,7 +699,14 @@ func (t *txSubmitterImpl) getGasEstimate(ctx context.Context, chainClient client ctx, span := t.metrics.Tracer().Start(ctx, "submitter.getGasEstimate", trace.WithAttributes( attribute.Int(metrics.ChainID, chainID), - attribute.String(metrics.TxHash, tx.Hash().String()), + + // note: tx hash can be null legitimately if we are pre-estimating gas rather than bumping it from a prior failure + attribute.String(metrics.TxHash, func() string { + if tx.Hash() == (common.Hash{}) { + return "not_known_yet" + } + return tx.Hash().String() + }()), attribute.Int("gasUnitAddPercentage", gasUnitAddPercentage), )) From d8481f2bab82b3c00549cf253ec650dc3e90dfb9 Mon Sep 17 00:00:00 2001 From: parodime Date: Fri, 24 Jan 2025 16:17:28 -0500 Subject: [PATCH 07/42] remove debug noise. nil deref fix... ? --- ethergo/submitter/submitter.go | 7 +------ services/rfq/relayer/quoter/quoter.go | 9 --------- 2 files changed, 1 insertion(+), 15 deletions(-) diff --git a/ethergo/submitter/submitter.go b/ethergo/submitter/submitter.go index 57deed0ea0..b2b047e9db 100644 --- a/ethergo/submitter/submitter.go +++ b/ethergo/submitter/submitter.go @@ -702,7 +702,7 @@ func (t *txSubmitterImpl) getGasEstimate(ctx context.Context, chainClient client // note: tx hash can be null legitimately if we are pre-estimating gas rather than bumping it from a prior failure attribute.String(metrics.TxHash, func() string { - if tx.Hash() == (common.Hash{}) { + if tx == nil || tx.Hash() == (common.Hash{}) { return "not_known_yet" } return tx.Hash().String() @@ -720,16 +720,11 @@ func (t *txSubmitterImpl) getGasEstimate(ctx context.Context, chainClient client if err != nil { return 0, fmt.Errorf("could not convert tx to call: %w", err) } - // tmpdebug - fmt.Printf("Debug Calling EstimateGas") gasEstimate, err = chainClient.EstimateGas(ctx, *call) if err != nil { span.AddEvent("could not estimate gas", trace.WithAttributes(attribute.String("error", err.Error()))) - // tmpdebug - fmt.Printf("Debug Default Gas Estimate: %d\n", t.config.GetGasEstimate(chainID)) - // fallback to default return t.config.GetGasEstimate(chainID), nil } diff --git a/services/rfq/relayer/quoter/quoter.go b/services/rfq/relayer/quoter/quoter.go index 6456f08154..9b96b7bee5 100644 --- a/services/rfq/relayer/quoter/quoter.go +++ b/services/rfq/relayer/quoter/quoter.go @@ -693,18 +693,12 @@ func (m *Manager) generateQuote(ctx context.Context, input QuoteInput) (quote *m return nil, fmt.Errorf("error getting total fee: %w", err) } - // tmpdebug - fmt.Printf("Debug Total Fee Amt: %s\n", fee.String()) - originRFQAddr, err := m.config.GetRFQAddress(input.OriginChainID) if err != nil { logger.Error("Error getting RFQ address", "error", err) return nil, fmt.Errorf("error getting RFQ address: %w", err) } - // tmpdebug - fmt.Printf("Debug originRFQAddr: %s\n", originRFQAddr.String()) - // Build the quote destAmount, err := m.getDestAmount(ctx, originAmount, destToken, input) if err != nil { @@ -712,9 +706,6 @@ func (m *Manager) generateQuote(ctx context.Context, input QuoteInput) (quote *m return nil, fmt.Errorf("error getting dest amount: %w", err) } - // tmpdebug - fmt.Printf("Debug destAmount: %s\n", destAmount.String()) - quote = &model.PutRelayerQuoteRequest{ OriginChainID: input.OriginChainID, OriginTokenAddr: input.OriginTokenAddr.Hex(), From d7f1cad17ceaaf42b0876a31f96a5f99a425d047 Mon Sep 17 00:00:00 2001 From: parodime Date: Fri, 24 Jan 2025 16:22:32 -0500 Subject: [PATCH 08/42] [goreleaser] From 3d7eea28752944ae0ff54b8a564f2bac40f3807c Mon Sep 17 00:00:00 2001 From: parodime Date: Fri, 24 Jan 2025 16:33:44 -0500 Subject: [PATCH 09/42] check tx call b4 estgas [goreleaser] --- ethergo/submitter/submitter.go | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/ethergo/submitter/submitter.go b/ethergo/submitter/submitter.go index b2b047e9db..4599314964 100644 --- a/ethergo/submitter/submitter.go +++ b/ethergo/submitter/submitter.go @@ -422,6 +422,9 @@ func (t *txSubmitterImpl) SubmitTransaction(parentCtx context.Context, chainID * transactor.NoSend = true tx_forEstimate, err := call(transactor) + if err != nil { + return 0, fmt.Errorf("err contract call sim: %w", err) + } gasEstimate, err := t.getGasEstimate(ctx, chainClient, int(chainID.Uint64()), tx_forEstimate) if err != nil { @@ -435,7 +438,7 @@ func (t *txSubmitterImpl) SubmitTransaction(parentCtx context.Context, chainID * tx, err := call(transactor) if err != nil { - return 0, fmt.Errorf("could not call contract: %w", err) + return 0, fmt.Errorf("err contract call exec: %w", err) } defer locker.Unlock() @@ -700,13 +703,8 @@ func (t *txSubmitterImpl) getGasEstimate(ctx context.Context, chainClient client ctx, span := t.metrics.Tracer().Start(ctx, "submitter.getGasEstimate", trace.WithAttributes( attribute.Int(metrics.ChainID, chainID), - // note: tx hash can be null legitimately if we are pre-estimating gas rather than bumping it from a prior failure - attribute.String(metrics.TxHash, func() string { - if tx == nil || tx.Hash() == (common.Hash{}) { - return "not_known_yet" - } - return tx.Hash().String() - }()), + attribute.String(metrics.TxHash, tx.Hash().String()), + attribute.Int("gasUnitAddPercentage", gasUnitAddPercentage), )) From 4c11d3376b7542034234cea63c22e3e9f41ab1bc Mon Sep 17 00:00:00 2001 From: parodime Date: Mon, 27 Jan 2025 11:14:47 -0500 Subject: [PATCH 10/42] +tmp debuggers [goreleaser] --- services/rfq/relayer/chain/chain.go | 9 +++++++++ services/rfq/relayer/service/handlers.go | 8 ++++++++ 2 files changed, 17 insertions(+) diff --git a/services/rfq/relayer/chain/chain.go b/services/rfq/relayer/chain/chain.go index 7fed1ff887..0719b3d6ee 100644 --- a/services/rfq/relayer/chain/chain.go +++ b/services/rfq/relayer/chain/chain.go @@ -74,6 +74,9 @@ func (c Chain) SubmitRelay(ctx context.Context, request reldb.QuoteRequest) (uin gasAmount := big.NewInt(0) var err error + //tmpdebug + fmt.Println("SubmitRelay>start: ", request.TransactionID) + // Check to see if ETH should be sent to destination if util.IsGasToken(request.Transaction.DestToken) { gasAmount = request.Transaction.DestAmount @@ -86,9 +89,15 @@ func (c Chain) SubmitRelay(ctx context.Context, request reldb.QuoteRequest) (uin } } + //tmpdebug + fmt.Println("SubmitRelay>SubmitTransaction: ", request.TransactionID) + nonce, err := c.SubmitTransaction(ctx, func(transactor *bind.TransactOpts) (tx *types.Transaction, err error) { transactor.Value = core.CopyBigInt(gasAmount) + //tmpdebug + fmt.Println("SubmitTransaction>RelayV2: ", request.TransactionID) + tx, err = c.Bridge.RelayV2(transactor, request.RawRequest, c.submitter.Address()) if err != nil { return nil, fmt.Errorf("could not relay: %w", err) diff --git a/services/rfq/relayer/service/handlers.go b/services/rfq/relayer/service/handlers.go index 5856861976..156264a6a2 100644 --- a/services/rfq/relayer/service/handlers.go +++ b/services/rfq/relayer/service/handlers.go @@ -376,6 +376,10 @@ func (q *QuoteRequestHandler) handleCommitPending(ctx context.Context, span trac // This is the fourth step in the bridge process. Here we submit the relay transaction to the destination chain. // TODO: just to be safe, we should probably check if another relayer has already relayed this. func (q *QuoteRequestHandler) handleCommitConfirmed(ctx context.Context, span trace.Span, request reldb.QuoteRequest) (err error) { + + //tmpdebug + fmt.Println("handleCommitConfirmed>SubmitRelay: ", request.TransactionID) + // TODO: store the dest txhash connected to the nonce nonce, _, err := q.Dest.SubmitRelay(ctx, request) if err != nil { @@ -384,11 +388,15 @@ func (q *QuoteRequestHandler) handleCommitConfirmed(ctx context.Context, span tr span.AddEvent("relay successfully submitted") span.SetAttributes(attribute.Int("relay_nonce", int(nonce))) + //tmpdebug + fmt.Println("handleCommitConfirmed>UpdateQuoteRequestStatus: ", request.TransactionID) err = q.db.UpdateQuoteRequestStatus(ctx, request.TransactionID, reldb.RelayStarted, &request.Status) if err != nil { return fmt.Errorf("could not update quote request status: %w", err) } + //tmpdebug + fmt.Println("handleCommitConfirmed>UpdateRelayNonce: ", request.TransactionID) err = q.db.UpdateRelayNonce(ctx, request.TransactionID, nonce) if err != nil { return fmt.Errorf("could not update relay nonce: %w", err) From 145583d028f97d1dab9d75a7a645a4326040b176 Mon Sep 17 00:00:00 2001 From: parodime Date: Mon, 27 Jan 2025 11:56:19 -0500 Subject: [PATCH 11/42] more tmp debug [goreleaser] --- services/rfq/relayer/chain/chain.go | 11 ++++++++--- services/rfq/relayer/service/handlers.go | 6 +++--- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/services/rfq/relayer/chain/chain.go b/services/rfq/relayer/chain/chain.go index 0719b3d6ee..a13edd62d2 100644 --- a/services/rfq/relayer/chain/chain.go +++ b/services/rfq/relayer/chain/chain.go @@ -75,7 +75,7 @@ func (c Chain) SubmitRelay(ctx context.Context, request reldb.QuoteRequest) (uin var err error //tmpdebug - fmt.Println("SubmitRelay>start: ", request.TransactionID) + fmt.Println("SubmitRelay>start: ", request.OriginTxHash) // Check to see if ETH should be sent to destination if util.IsGasToken(request.Transaction.DestToken) { @@ -90,24 +90,29 @@ func (c Chain) SubmitRelay(ctx context.Context, request reldb.QuoteRequest) (uin } //tmpdebug - fmt.Println("SubmitRelay>SubmitTransaction: ", request.TransactionID) + fmt.Println("SubmitRelay>SubmitTransaction: ", request.OriginTxHash) nonce, err := c.SubmitTransaction(ctx, func(transactor *bind.TransactOpts) (tx *types.Transaction, err error) { transactor.Value = core.CopyBigInt(gasAmount) //tmpdebug - fmt.Println("SubmitTransaction>RelayV2: ", request.TransactionID) + fmt.Println("SubmitTransaction>RelayV2: ", request.OriginTxHash) tx, err = c.Bridge.RelayV2(transactor, request.RawRequest, c.submitter.Address()) if err != nil { return nil, fmt.Errorf("could not relay: %w", err) } + //tmpdebug + fmt.Println("RelayV2 hash: ", tx.Hash()) + return tx, nil }) if err != nil { return 0, nil, fmt.Errorf("could not submit transaction: %w", err) } + //tmpdebug + fmt.Println("SubmitRelay nonce:", nonce, "gas amount:", gasAmount) return nonce, gasAmount, nil } diff --git a/services/rfq/relayer/service/handlers.go b/services/rfq/relayer/service/handlers.go index 156264a6a2..6f2ab5981e 100644 --- a/services/rfq/relayer/service/handlers.go +++ b/services/rfq/relayer/service/handlers.go @@ -378,7 +378,7 @@ func (q *QuoteRequestHandler) handleCommitPending(ctx context.Context, span trac func (q *QuoteRequestHandler) handleCommitConfirmed(ctx context.Context, span trace.Span, request reldb.QuoteRequest) (err error) { //tmpdebug - fmt.Println("handleCommitConfirmed>SubmitRelay: ", request.TransactionID) + fmt.Println("handleCommitConfirmed>SubmitRelay: ", request.OriginTxHash) // TODO: store the dest txhash connected to the nonce nonce, _, err := q.Dest.SubmitRelay(ctx, request) @@ -389,14 +389,14 @@ func (q *QuoteRequestHandler) handleCommitConfirmed(ctx context.Context, span tr span.SetAttributes(attribute.Int("relay_nonce", int(nonce))) //tmpdebug - fmt.Println("handleCommitConfirmed>UpdateQuoteRequestStatus: ", request.TransactionID) + fmt.Println("handleCommitConfirmed>UpdateQuoteRequestStatus: ", request.OriginTxHash) err = q.db.UpdateQuoteRequestStatus(ctx, request.TransactionID, reldb.RelayStarted, &request.Status) if err != nil { return fmt.Errorf("could not update quote request status: %w", err) } //tmpdebug - fmt.Println("handleCommitConfirmed>UpdateRelayNonce: ", request.TransactionID) + fmt.Println("handleCommitConfirmed>UpdateRelayNonce: ", request.OriginTxHash) err = q.db.UpdateRelayNonce(ctx, request.TransactionID, nonce) if err != nil { return fmt.Errorf("could not update relay nonce: %w", err) From 2005d9152236ac23cac7e0fa978e203f8014c599 Mon Sep 17 00:00:00 2001 From: parodime Date: Mon, 27 Jan 2025 13:18:26 -0500 Subject: [PATCH 12/42] tmp debug tx output [goreleaser] --- services/rfq/relayer/chain/chain.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/rfq/relayer/chain/chain.go b/services/rfq/relayer/chain/chain.go index a13edd62d2..ac787d481a 100644 --- a/services/rfq/relayer/chain/chain.go +++ b/services/rfq/relayer/chain/chain.go @@ -104,7 +104,7 @@ func (c Chain) SubmitRelay(ctx context.Context, request reldb.QuoteRequest) (uin } //tmpdebug - fmt.Println("RelayV2 hash: ", tx.Hash()) + fmt.Printf("RelayV2 transaction: %+v\n", tx) return tx, nil }) From a8a48bb0af6aa413f99f08cbe36f10169d3e271d Mon Sep 17 00:00:00 2001 From: parodime Date: Mon, 27 Jan 2025 13:30:27 -0500 Subject: [PATCH 13/42] tmp debug submit tweaks [goreleaser] --- ethergo/submitter/submitter.go | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/ethergo/submitter/submitter.go b/ethergo/submitter/submitter.go index 4599314964..54059adcad 100644 --- a/ethergo/submitter/submitter.go +++ b/ethergo/submitter/submitter.go @@ -388,6 +388,9 @@ func (t *txSubmitterImpl) SubmitTransaction(parentCtx context.Context, chainID * // this also prevents a bug in the caller from breaking our lock transactor.Nonce = new(big.Int).Add(new(big.Int).SetUint64(math.MaxUint64), big.NewInt(1)) + //tmpdebug + fmt.Printf("SubmitTransaction>setGasPrice") + err = t.setGasPrice(ctx, chainClient, transactor, chainID, nil) if err != nil { span.AddEvent("could not set gas price", trace.WithAttributes(attribute.String("error", err.Error()))) @@ -419,29 +422,29 @@ func (t *txSubmitterImpl) SubmitTransaction(parentCtx context.Context, chainID * return parentTransactor.Signer(address, transaction) } - transactor.NoSend = true + //tmpdebug + fmt.Printf("SubmitTransaction>call") - tx_forEstimate, err := call(transactor) - if err != nil { - return 0, fmt.Errorf("err contract call sim: %w", err) - } + tx, err := call(transactor) - gasEstimate, err := t.getGasEstimate(ctx, chainClient, int(chainID.Uint64()), tx_forEstimate) + gasEstimate, err := t.getGasEstimate(ctx, chainClient, int(chainID.Uint64()), tx) if err != nil { return 0, fmt.Errorf("err getGasEstimate: %w", err) } - transactor.GasLimit = gasEstimate + //tmpdebug + fmt.Printf("Gas estimate: %d\n", gasEstimate) - transactor.NoSend = false - - tx, err := call(transactor) + transactor.GasLimit = gasEstimate if err != nil { return 0, fmt.Errorf("err contract call exec: %w", err) } defer locker.Unlock() + //tmpdebug + fmt.Printf("SubmitTransaction>storeTX") + // now that we've stored the tx err = t.storeTX(ctx, tx, db.Stored, uuid.New().String()) if err != nil { @@ -451,6 +454,9 @@ func (t *txSubmitterImpl) SubmitTransaction(parentCtx context.Context, chainID * span.AddEvent("trigger reprocess") t.triggerProcessQueue(ctx) + //tmpdebug + fmt.Printf("SubmitTransaction>tx.Nonce: %d\n", tx.Nonce()) + return tx.Nonce(), nil } From 75c9c44ce24a75015fd3923cfd25602ae5f1e161 Mon Sep 17 00:00:00 2001 From: parodime Date: Mon, 27 Jan 2025 13:55:38 -0500 Subject: [PATCH 14/42] submitTransaction refactor [goreleaser] --- ethergo/submitter/submitter.go | 35 +++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/ethergo/submitter/submitter.go b/ethergo/submitter/submitter.go index 54059adcad..91df21077e 100644 --- a/ethergo/submitter/submitter.go +++ b/ethergo/submitter/submitter.go @@ -421,24 +421,41 @@ func (t *txSubmitterImpl) SubmitTransaction(parentCtx context.Context, chainID * //nolint: wrapcheck return parentTransactor.Signer(address, transaction) } + // if dynamic gas estimation is not enabled, use cfg var gas_estimate as a gas limit default and do not run a pre-flight simulation + // since we do not need it to determine proper gas units + if !t.config.GetDynamicGasEstimate(int(chainID.Uint64())) { - //tmpdebug - fmt.Printf("SubmitTransaction>call") + //tmpdebug + fmt.Printf("Using Default") - tx, err := call(transactor) + transactor.GasLimit = t.config.GetGasEstimate(int(chainID.Uint64())) + } else { + + //tmpdebug + fmt.Printf("SubmitTransaction>forGasEst call") + + tx_forGasEstimate, err := call(transactor) + + if err != nil { + return 0, fmt.Errorf("err contract call for gas est: %w", err) + } + + gasEstimate, err := t.getGasEstimate(ctx, chainClient, int(chainID.Uint64()), tx_forGasEstimate) + if err != nil { + return 0, fmt.Errorf("err getGasEstimate: %w", err) + } + + transactor.GasLimit = gasEstimate - gasEstimate, err := t.getGasEstimate(ctx, chainClient, int(chainID.Uint64()), tx) - if err != nil { - return 0, fmt.Errorf("err getGasEstimate: %w", err) } //tmpdebug - fmt.Printf("Gas estimate: %d\n", gasEstimate) + fmt.Printf("transactor.GasLimit: %d\n", transactor.GasLimit) - transactor.GasLimit = gasEstimate + tx, err := call(transactor) if err != nil { - return 0, fmt.Errorf("err contract call exec: %w", err) + return 0, fmt.Errorf("err contract call for tx: %w", err) } defer locker.Unlock() From 96e16c3fed5ab9a74c47358be5f237e97e688bf2 Mon Sep 17 00:00:00 2001 From: parodime Date: Mon, 27 Jan 2025 14:19:16 -0500 Subject: [PATCH 15/42] clone transactor [goreleaser] --- ethergo/submitter/submitter.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/ethergo/submitter/submitter.go b/ethergo/submitter/submitter.go index 91df21077e..7a513a5e3d 100644 --- a/ethergo/submitter/submitter.go +++ b/ethergo/submitter/submitter.go @@ -434,7 +434,10 @@ func (t *txSubmitterImpl) SubmitTransaction(parentCtx context.Context, chainID * //tmpdebug fmt.Printf("SubmitTransaction>forGasEst call") - tx_forGasEstimate, err := call(transactor) + transactor_forGasEstimate := new(bind.TransactOpts) + *transactor_forGasEstimate = *transactor + + tx_forGasEstimate, err := call(transactor_forGasEstimate) if err != nil { return 0, fmt.Errorf("err contract call for gas est: %w", err) From dada2b092f81917d80432c75e4679e61ce493e7a Mon Sep 17 00:00:00 2001 From: parodime Date: Mon, 27 Jan 2025 15:25:00 -0500 Subject: [PATCH 16/42] deepcopy [goreleaser] --- ethergo/submitter/submitter.go | 7 +++---- services/rfq/relayer/chain/chain.go | 1 + 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/ethergo/submitter/submitter.go b/ethergo/submitter/submitter.go index 7a513a5e3d..a88e8c3a43 100644 --- a/ethergo/submitter/submitter.go +++ b/ethergo/submitter/submitter.go @@ -426,16 +426,15 @@ func (t *txSubmitterImpl) SubmitTransaction(parentCtx context.Context, chainID * if !t.config.GetDynamicGasEstimate(int(chainID.Uint64())) { //tmpdebug - fmt.Printf("Using Default") + fmt.Printf("Using Default ") transactor.GasLimit = t.config.GetGasEstimate(int(chainID.Uint64())) } else { //tmpdebug - fmt.Printf("SubmitTransaction>forGasEst call") + fmt.Printf("SubmitTransaction>forGasEst call ") - transactor_forGasEstimate := new(bind.TransactOpts) - *transactor_forGasEstimate = *transactor + transactor_forGasEstimate := copyTransactOpts(transactor) tx_forGasEstimate, err := call(transactor_forGasEstimate) diff --git a/services/rfq/relayer/chain/chain.go b/services/rfq/relayer/chain/chain.go index ac787d481a..7ca26e84d5 100644 --- a/services/rfq/relayer/chain/chain.go +++ b/services/rfq/relayer/chain/chain.go @@ -104,6 +104,7 @@ func (c Chain) SubmitRelay(ctx context.Context, request reldb.QuoteRequest) (uin } //tmpdebug + fmt.Println("RelayV2 OriginTxHash:", request.OriginTxHash) fmt.Printf("RelayV2 transaction: %+v\n", tx) return tx, nil From 7abfdb04e3b985f875b6cf4f00682feb61c29e82 Mon Sep 17 00:00:00 2001 From: parodime Date: Mon, 27 Jan 2025 15:41:05 -0500 Subject: [PATCH 17/42] [goreleaser] From 0e7c236c7d206e3a9e21139b32cbf35f0be0df0e Mon Sep 17 00:00:00 2001 From: parodime Date: Mon, 27 Jan 2025 15:53:32 -0500 Subject: [PATCH 18/42] test getGasEstimate skip --- ethergo/submitter/submitter.go | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/ethergo/submitter/submitter.go b/ethergo/submitter/submitter.go index a88e8c3a43..579b244e48 100644 --- a/ethergo/submitter/submitter.go +++ b/ethergo/submitter/submitter.go @@ -389,7 +389,7 @@ func (t *txSubmitterImpl) SubmitTransaction(parentCtx context.Context, chainID * transactor.Nonce = new(big.Int).Add(new(big.Int).SetUint64(math.MaxUint64), big.NewInt(1)) //tmpdebug - fmt.Printf("SubmitTransaction>setGasPrice") + fmt.Printf("SubmitTransaction>setGasPrice\n") err = t.setGasPrice(ctx, chainClient, transactor, chainID, nil) if err != nil { @@ -421,33 +421,39 @@ func (t *txSubmitterImpl) SubmitTransaction(parentCtx context.Context, chainID * //nolint: wrapcheck return parentTransactor.Signer(address, transaction) } + + //tmpdebug + fmt.Printf("test ver 1\n") + // if dynamic gas estimation is not enabled, use cfg var gas_estimate as a gas limit default and do not run a pre-flight simulation // since we do not need it to determine proper gas units if !t.config.GetDynamicGasEstimate(int(chainID.Uint64())) { //tmpdebug - fmt.Printf("Using Default ") + fmt.Printf("Using Default \n") transactor.GasLimit = t.config.GetGasEstimate(int(chainID.Uint64())) } else { //tmpdebug - fmt.Printf("SubmitTransaction>forGasEst call ") + fmt.Printf("SubmitTransaction>forGasEst call \n") transactor_forGasEstimate := copyTransactOpts(transactor) tx_forGasEstimate, err := call(transactor_forGasEstimate) + fmt.Printf("tx_forGasEstimate: %v\n", tx_forGasEstimate) + if err != nil { return 0, fmt.Errorf("err contract call for gas est: %w", err) } - gasEstimate, err := t.getGasEstimate(ctx, chainClient, int(chainID.Uint64()), tx_forGasEstimate) - if err != nil { - return 0, fmt.Errorf("err getGasEstimate: %w", err) - } + // gasEstimate, err := t.getGasEstimate(ctx, chainClient, int(chainID.Uint64()), tx_forGasEstimate) + // if err != nil { + // return 0, fmt.Errorf("err getGasEstimate: %w", err) + // } - transactor.GasLimit = gasEstimate + transactor.GasLimit = 1405050 } @@ -462,7 +468,7 @@ func (t *txSubmitterImpl) SubmitTransaction(parentCtx context.Context, chainID * defer locker.Unlock() //tmpdebug - fmt.Printf("SubmitTransaction>storeTX") + fmt.Printf("SubmitTransaction>storeTX\n") // now that we've stored the tx err = t.storeTX(ctx, tx, db.Stored, uuid.New().String()) From 220e0d49bf7ced0ec178600381bd45da0d6b0927 Mon Sep 17 00:00:00 2001 From: parodime Date: Mon, 27 Jan 2025 15:53:50 -0500 Subject: [PATCH 19/42] [goreleaser] From b9953858ca700a143540fe92213aa3b73e32b4cd Mon Sep 17 00:00:00 2001 From: parodime Date: Tue, 28 Jan 2025 09:31:38 -0500 Subject: [PATCH 20/42] try gaslimit 0 [goreleaser] --- ethergo/submitter/submitter.go | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/ethergo/submitter/submitter.go b/ethergo/submitter/submitter.go index 579b244e48..228ac09aac 100644 --- a/ethergo/submitter/submitter.go +++ b/ethergo/submitter/submitter.go @@ -423,7 +423,7 @@ func (t *txSubmitterImpl) SubmitTransaction(parentCtx context.Context, chainID * } //tmpdebug - fmt.Printf("test ver 1\n") + fmt.Printf("test ver 2\n") // if dynamic gas estimation is not enabled, use cfg var gas_estimate as a gas limit default and do not run a pre-flight simulation // since we do not need it to determine proper gas units @@ -435,25 +435,25 @@ func (t *txSubmitterImpl) SubmitTransaction(parentCtx context.Context, chainID * transactor.GasLimit = t.config.GetGasEstimate(int(chainID.Uint64())) } else { - //tmpdebug - fmt.Printf("SubmitTransaction>forGasEst call \n") + // // //tmpdebug + // // fmt.Printf("SubmitTransaction>forGasEst call \n") - transactor_forGasEstimate := copyTransactOpts(transactor) + // // transactor_forGasEstimate := copyTransactOpts(transactor) - tx_forGasEstimate, err := call(transactor_forGasEstimate) + // // tx_forGasEstimate, err := call(transactor_forGasEstimate) - fmt.Printf("tx_forGasEstimate: %v\n", tx_forGasEstimate) + // // fmt.Printf("tx_forGasEstimate: %v\n", tx_forGasEstimate) - if err != nil { - return 0, fmt.Errorf("err contract call for gas est: %w", err) - } + // // if err != nil { + // // return 0, fmt.Errorf("err contract call for gas est: %w", err) + // // } // gasEstimate, err := t.getGasEstimate(ctx, chainClient, int(chainID.Uint64()), tx_forGasEstimate) // if err != nil { // return 0, fmt.Errorf("err getGasEstimate: %w", err) // } - transactor.GasLimit = 1405050 + transactor.GasLimit = 0 } @@ -462,6 +462,9 @@ func (t *txSubmitterImpl) SubmitTransaction(parentCtx context.Context, chainID * tx, err := call(transactor) + //tmpdebug + fmt.Printf("tx.Gas: %d\n", tx.Gas()) + if err != nil { return 0, fmt.Errorf("err contract call for tx: %w", err) } @@ -729,6 +732,9 @@ func (t *txSubmitterImpl) getGasEstimate(ctx context.Context, chainClient client return t.config.GetGasEstimate(chainID), nil } + //tmpdebug + fmt.Println("getGasEstimate>start") + gasUnitAddPercentage := t.config.GetDynamicGasUnitAddPercentage(chainID) ctx, span := t.metrics.Tracer().Start(ctx, "submitter.getGasEstimate", trace.WithAttributes( From 4782b4485e9214b5e1bd848dd19e55357a4d0bdc Mon Sep 17 00:00:00 2001 From: parodime Date: Tue, 28 Jan 2025 10:27:58 -0500 Subject: [PATCH 21/42] gaslimit2 [goreleaser] --- ethergo/submitter/submitter.go | 13 ++++++++++++- services/rfq/relayer/chain/chain.go | 11 ++++++++--- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/ethergo/submitter/submitter.go b/ethergo/submitter/submitter.go index 228ac09aac..6f80a0e4c0 100644 --- a/ethergo/submitter/submitter.go +++ b/ethergo/submitter/submitter.go @@ -423,7 +423,7 @@ func (t *txSubmitterImpl) SubmitTransaction(parentCtx context.Context, chainID * } //tmpdebug - fmt.Printf("test ver 2\n") + fmt.Printf("test ver 3\n") // if dynamic gas estimation is not enabled, use cfg var gas_estimate as a gas limit default and do not run a pre-flight simulation // since we do not need it to determine proper gas units @@ -462,6 +462,17 @@ func (t *txSubmitterImpl) SubmitTransaction(parentCtx context.Context, chainID * tx, err := call(transactor) + if t.config.GetDynamicGasEstimate(int(chainID.Uint64())) { + + transactor.GasLimit = 1450000 + + //tmpdebug + fmt.Printf("transactor.GasLimit2: %d\n", transactor.GasLimit) + + tx, err = call(transactor) + + } + //tmpdebug fmt.Printf("tx.Gas: %d\n", tx.Gas()) diff --git a/services/rfq/relayer/chain/chain.go b/services/rfq/relayer/chain/chain.go index 7ca26e84d5..45d836484b 100644 --- a/services/rfq/relayer/chain/chain.go +++ b/services/rfq/relayer/chain/chain.go @@ -95,17 +95,22 @@ func (c Chain) SubmitRelay(ctx context.Context, request reldb.QuoteRequest) (uin nonce, err := c.SubmitTransaction(ctx, func(transactor *bind.TransactOpts) (tx *types.Transaction, err error) { transactor.Value = core.CopyBigInt(gasAmount) + callType := "exec" + if transactor.GasLimit == 0 { + callType = "sim" + } //tmpdebug - fmt.Println("SubmitTransaction>RelayV2: ", request.OriginTxHash) + fmt.Println(callType, "SubmitTransaction>RelayV2: ", request.OriginTxHash) tx, err = c.Bridge.RelayV2(transactor, request.RawRequest, c.submitter.Address()) + if err != nil { return nil, fmt.Errorf("could not relay: %w", err) } //tmpdebug - fmt.Println("RelayV2 OriginTxHash:", request.OriginTxHash) - fmt.Printf("RelayV2 transaction: %+v\n", tx) + fmt.Println(callType, "RelayV2 OriginTxHash:", request.OriginTxHash) + fmt.Printf(callType+" RelayV2 transaction: %+v\n", tx) return tx, nil }) From d699cd0d4dd71a749c665f96f23a1240312d1466 Mon Sep 17 00:00:00 2001 From: parodime Date: Tue, 28 Jan 2025 10:42:24 -0500 Subject: [PATCH 22/42] gaslimit2 pre/post [goreleaser] --- ethergo/submitter/submitter.go | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/ethergo/submitter/submitter.go b/ethergo/submitter/submitter.go index 6f80a0e4c0..ceb9d6cec8 100644 --- a/ethergo/submitter/submitter.go +++ b/ethergo/submitter/submitter.go @@ -423,7 +423,7 @@ func (t *txSubmitterImpl) SubmitTransaction(parentCtx context.Context, chainID * } //tmpdebug - fmt.Printf("test ver 3\n") + fmt.Printf("test ver 4\n") // if dynamic gas estimation is not enabled, use cfg var gas_estimate as a gas limit default and do not run a pre-flight simulation // since we do not need it to determine proper gas units @@ -461,24 +461,31 @@ func (t *txSubmitterImpl) SubmitTransaction(parentCtx context.Context, chainID * fmt.Printf("transactor.GasLimit: %d\n", transactor.GasLimit) tx, err := call(transactor) + if err != nil { + return 0, fmt.Errorf("err contract call for tx: %w", err) + } if t.config.GetDynamicGasEstimate(int(chainID.Uint64())) { - transactor.GasLimit = 1450000 + //tmpdebug + fmt.Printf("tx.Gas (pre): %d\n", tx.Gas()) + transactor.GasLimit = tx.Gas() + 555 //tmpdebug fmt.Printf("transactor.GasLimit2: %d\n", transactor.GasLimit) tx, err = call(transactor) + if err != nil { + return 0, fmt.Errorf("err contract call 2 for tx: %w", err) + } + //tmpdebug + fmt.Printf("tx.Gas (post): %d\n", tx.Gas()) } //tmpdebug fmt.Printf("tx.Gas: %d\n", tx.Gas()) - if err != nil { - return 0, fmt.Errorf("err contract call for tx: %w", err) - } defer locker.Unlock() //tmpdebug From 04ccdc2110cf89dd740218c39b8b5c40a45c1079 Mon Sep 17 00:00:00 2001 From: parodime Date: Tue, 28 Jan 2025 10:56:12 -0500 Subject: [PATCH 23/42] tx_forGasEst [goreleaser] --- ethergo/submitter/submitter.go | 46 +++++++++++++++++----------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/ethergo/submitter/submitter.go b/ethergo/submitter/submitter.go index ceb9d6cec8..5440a4771a 100644 --- a/ethergo/submitter/submitter.go +++ b/ethergo/submitter/submitter.go @@ -423,7 +423,7 @@ func (t *txSubmitterImpl) SubmitTransaction(parentCtx context.Context, chainID * } //tmpdebug - fmt.Printf("test ver 4\n") + fmt.Printf("test ver 5\n") // if dynamic gas estimation is not enabled, use cfg var gas_estimate as a gas limit default and do not run a pre-flight simulation // since we do not need it to determine proper gas units @@ -435,25 +435,25 @@ func (t *txSubmitterImpl) SubmitTransaction(parentCtx context.Context, chainID * transactor.GasLimit = t.config.GetGasEstimate(int(chainID.Uint64())) } else { - // // //tmpdebug - // // fmt.Printf("SubmitTransaction>forGasEst call \n") + //tmpdebug + fmt.Printf("SubmitTransaction>forGasEst call \n") - // // transactor_forGasEstimate := copyTransactOpts(transactor) + transactor_forGasEstimate := copyTransactOpts(transactor) - // // tx_forGasEstimate, err := call(transactor_forGasEstimate) + tx_forGasEstimate, err := call(transactor_forGasEstimate) - // // fmt.Printf("tx_forGasEstimate: %v\n", tx_forGasEstimate) + fmt.Printf("tx_forGasEstimate: %v\n", tx_forGasEstimate) - // // if err != nil { - // // return 0, fmt.Errorf("err contract call for gas est: %w", err) - // // } + if err != nil { + return 0, fmt.Errorf("err contract call for gas est: %w", err) + } // gasEstimate, err := t.getGasEstimate(ctx, chainClient, int(chainID.Uint64()), tx_forGasEstimate) // if err != nil { // return 0, fmt.Errorf("err getGasEstimate: %w", err) // } - transactor.GasLimit = 0 + transactor.GasLimit = tx_forGasEstimate.Gas() } @@ -465,23 +465,23 @@ func (t *txSubmitterImpl) SubmitTransaction(parentCtx context.Context, chainID * return 0, fmt.Errorf("err contract call for tx: %w", err) } - if t.config.GetDynamicGasEstimate(int(chainID.Uint64())) { + // if t.config.GetDynamicGasEstimate(int(chainID.Uint64())) { - //tmpdebug - fmt.Printf("tx.Gas (pre): %d\n", tx.Gas()) - transactor.GasLimit = tx.Gas() + 555 + // //tmpdebug + // fmt.Printf("tx.Gas (pre): %d\n", tx.Gas()) + // transactor.GasLimit = tx.Gas() + 555 - //tmpdebug - fmt.Printf("transactor.GasLimit2: %d\n", transactor.GasLimit) + // //tmpdebug + // fmt.Printf("transactor.GasLimit2: %d\n", transactor.GasLimit) - tx, err = call(transactor) - if err != nil { - return 0, fmt.Errorf("err contract call 2 for tx: %w", err) - } + // tx, err = call(transactor) + // if err != nil { + // return 0, fmt.Errorf("err contract call 2 for tx: %w", err) + // } - //tmpdebug - fmt.Printf("tx.Gas (post): %d\n", tx.Gas()) - } + // //tmpdebug + // fmt.Printf("tx.Gas (post): %d\n", tx.Gas()) + // } //tmpdebug fmt.Printf("tx.Gas: %d\n", tx.Gas()) From c8f2dfe075afd9249da6a7261aa6ce2cb8b2c892 Mon Sep 17 00:00:00 2001 From: parodime Date: Tue, 28 Jan 2025 11:03:00 -0500 Subject: [PATCH 24/42] diff nonces [goreleaser] --- ethergo/submitter/submitter.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/ethergo/submitter/submitter.go b/ethergo/submitter/submitter.go index 5440a4771a..c3d61e3d92 100644 --- a/ethergo/submitter/submitter.go +++ b/ethergo/submitter/submitter.go @@ -440,9 +440,11 @@ func (t *txSubmitterImpl) SubmitTransaction(parentCtx context.Context, chainID * transactor_forGasEstimate := copyTransactOpts(transactor) + transactor_forGasEstimate.Nonce.Sub(transactor_forGasEstimate.Nonce, big.NewInt(1)) + tx_forGasEstimate, err := call(transactor_forGasEstimate) - fmt.Printf("tx_forGasEstimate: %v\n", tx_forGasEstimate) + fmt.Printf("tx_forGasEstimate: %v\n", tx_forGasEstimate.Gas()) if err != nil { return 0, fmt.Errorf("err contract call for gas est: %w", err) @@ -453,7 +455,7 @@ func (t *txSubmitterImpl) SubmitTransaction(parentCtx context.Context, chainID * // return 0, fmt.Errorf("err getGasEstimate: %w", err) // } - transactor.GasLimit = tx_forGasEstimate.Gas() + transactor.GasLimit = tx_forGasEstimate.Gas() + 555 } From d199850316d62df825fbe9e39f6cb42eb1a709ef Mon Sep 17 00:00:00 2001 From: parodime Date: Tue, 28 Jan 2025 11:11:29 -0500 Subject: [PATCH 25/42] Prove gas [goreleaser] --- services/rfq/relayer/service/handlers.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/services/rfq/relayer/service/handlers.go b/services/rfq/relayer/service/handlers.go index 6f2ab5981e..51eae62264 100644 --- a/services/rfq/relayer/service/handlers.go +++ b/services/rfq/relayer/service/handlers.go @@ -480,11 +480,14 @@ func (q *QuoteRequestHandler) handleRelayCompleted(ctx context.Context, span tra // relay has been finalized, it's time to go back to the origin chain and try to prove _, err = q.Origin.SubmitTransaction(ctx, func(transactor *bind.TransactOpts) (tx *types.Transaction, err error) { + + fmt.Println("SubmitTransaction>Prove ", request.OriginTxHash) tx, err = q.Origin.Bridge.Prove(transactor, request.RawRequest, request.DestTxHash) if err != nil { - return nil, fmt.Errorf("could not relay: %w", err) + return nil, fmt.Errorf("could not prove: %w", err) } + fmt.Println("SubmitTransaction>Prove return tx.gas ", tx.Gas()) return tx, nil }) if err != nil { From e8fd10eaf68b96e1df4d19cb5c59a827ebfcabd5 Mon Sep 17 00:00:00 2001 From: parodime Date: Tue, 28 Jan 2025 11:18:31 -0500 Subject: [PATCH 26/42] print nonce [goreleaser] --- services/rfq/relayer/service/handlers.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/rfq/relayer/service/handlers.go b/services/rfq/relayer/service/handlers.go index 51eae62264..d730b9b612 100644 --- a/services/rfq/relayer/service/handlers.go +++ b/services/rfq/relayer/service/handlers.go @@ -481,7 +481,7 @@ func (q *QuoteRequestHandler) handleRelayCompleted(ctx context.Context, span tra // relay has been finalized, it's time to go back to the origin chain and try to prove _, err = q.Origin.SubmitTransaction(ctx, func(transactor *bind.TransactOpts) (tx *types.Transaction, err error) { - fmt.Println("SubmitTransaction>Prove ", request.OriginTxHash) + fmt.Println("SubmitTransaction>Prove ", request.OriginTxHash, "Nonce:", transactor.Nonce) tx, err = q.Origin.Bridge.Prove(transactor, request.RawRequest, request.DestTxHash) if err != nil { return nil, fmt.Errorf("could not prove: %w", err) From ee9eb8519dd3c54fee05f524b8a11184bbb2ba04 Mon Sep 17 00:00:00 2001 From: parodime Date: Tue, 28 Jan 2025 11:34:50 -0500 Subject: [PATCH 27/42] low gas test [goreleaser] --- ethergo/submitter/submitter.go | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/ethergo/submitter/submitter.go b/ethergo/submitter/submitter.go index c3d61e3d92..cdb16d8f50 100644 --- a/ethergo/submitter/submitter.go +++ b/ethergo/submitter/submitter.go @@ -423,7 +423,7 @@ func (t *txSubmitterImpl) SubmitTransaction(parentCtx context.Context, chainID * } //tmpdebug - fmt.Printf("test ver 5\n") + fmt.Printf("test ver 6\n") // if dynamic gas estimation is not enabled, use cfg var gas_estimate as a gas limit default and do not run a pre-flight simulation // since we do not need it to determine proper gas units @@ -435,27 +435,29 @@ func (t *txSubmitterImpl) SubmitTransaction(parentCtx context.Context, chainID * transactor.GasLimit = t.config.GetGasEstimate(int(chainID.Uint64())) } else { - //tmpdebug - fmt.Printf("SubmitTransaction>forGasEst call \n") - - transactor_forGasEstimate := copyTransactOpts(transactor) + // //tmpdebug + // fmt.Printf("SubmitTransaction>forGasEst call \n") - transactor_forGasEstimate.Nonce.Sub(transactor_forGasEstimate.Nonce, big.NewInt(1)) + // transactor_forGasEstimate := copyTransactOpts(transactor) - tx_forGasEstimate, err := call(transactor_forGasEstimate) + // transactor_forGasEstimate.Nonce.Add(transactor_forGasEstimate.Nonce, big.NewInt(1)) - fmt.Printf("tx_forGasEstimate: %v\n", tx_forGasEstimate.Gas()) + // tx_forGasEstimate, err := call(transactor_forGasEstimate) - if err != nil { - return 0, fmt.Errorf("err contract call for gas est: %w", err) - } + // fmt.Printf("tx_forGasEstimate: %v\n", tx_forGasEstimate.Gas()) - // gasEstimate, err := t.getGasEstimate(ctx, chainClient, int(chainID.Uint64()), tx_forGasEstimate) // if err != nil { - // return 0, fmt.Errorf("err getGasEstimate: %w", err) + // return 0, fmt.Errorf("err contract call for gas est: %w", err) // } - transactor.GasLimit = tx_forGasEstimate.Gas() + 555 + // // gasEstimate, err := t.getGasEstimate(ctx, chainClient, int(chainID.Uint64()), tx_forGasEstimate) + // // if err != nil { + // // return 0, fmt.Errorf("err getGasEstimate: %w", err) + // // } + + // transactor.GasLimit = tx_forGasEstimate.Gas() + 555 + + transactor.GasLimit = 21555 // intentionally set too low } From f6bfa434800c117558b5807dd26309a3f03cd67c Mon Sep 17 00:00:00 2001 From: parodime Date: Tue, 28 Jan 2025 11:44:08 -0500 Subject: [PATCH 28/42] getGasEst bump approach [goreleaser] --- ethergo/submitter/submitter.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/ethergo/submitter/submitter.go b/ethergo/submitter/submitter.go index cdb16d8f50..b117221acb 100644 --- a/ethergo/submitter/submitter.go +++ b/ethergo/submitter/submitter.go @@ -759,6 +759,9 @@ func (t *txSubmitterImpl) getGasEstimate(ctx context.Context, chainClient client gasUnitAddPercentage := t.config.GetDynamicGasUnitAddPercentage(chainID) + //tmpdebug + fmt.Println("getGasEstimate>gasUnitAddPercentage", gasUnitAddPercentage) + ctx, span := t.metrics.Tracer().Start(ctx, "submitter.getGasEstimate", trace.WithAttributes( attribute.Int(metrics.ChainID, chainID), @@ -780,15 +783,25 @@ func (t *txSubmitterImpl) getGasEstimate(ctx context.Context, chainClient client gasEstimate, err = chainClient.EstimateGas(ctx, *call) if err != nil { + + //tmpdebug + fmt.Printf("getGasEstimate> Error estimating gas: %v\n", err) + span.AddEvent("could not estimate gas", trace.WithAttributes(attribute.String("error", err.Error()))) // fallback to default return t.config.GetGasEstimate(chainID), nil } + //tmpdebug + fmt.Println("getGasEstimate>gasEstimate pre", gasEstimate) + // Modify the gasEstimate by the configured percentage gasEstimate = gasEstimate + (gasEstimate * uint64(gasUnitAddPercentage) / 100) + //tmpdebug + fmt.Println("getGasEstimate>gasEstimate post", gasEstimate) + return gasEstimate, nil } From c79a81bcdf0a58214106a5582c587f4773140027 Mon Sep 17 00:00:00 2001 From: parodime Date: Tue, 28 Jan 2025 12:32:22 -0500 Subject: [PATCH 29/42] reproduce [goreleaser] --- ethergo/submitter/submitter.go | 48 +++++++---------------------- services/rfq/relayer/chain/chain.go | 2 ++ 2 files changed, 13 insertions(+), 37 deletions(-) diff --git a/ethergo/submitter/submitter.go b/ethergo/submitter/submitter.go index b117221acb..efeda8580b 100644 --- a/ethergo/submitter/submitter.go +++ b/ethergo/submitter/submitter.go @@ -423,7 +423,7 @@ func (t *txSubmitterImpl) SubmitTransaction(parentCtx context.Context, chainID * } //tmpdebug - fmt.Printf("test ver 6\n") + fmt.Printf("test ver 7\n") // if dynamic gas estimation is not enabled, use cfg var gas_estimate as a gas limit default and do not run a pre-flight simulation // since we do not need it to determine proper gas units @@ -435,29 +435,22 @@ func (t *txSubmitterImpl) SubmitTransaction(parentCtx context.Context, chainID * transactor.GasLimit = t.config.GetGasEstimate(int(chainID.Uint64())) } else { - // //tmpdebug - // fmt.Printf("SubmitTransaction>forGasEst call \n") - - // transactor_forGasEstimate := copyTransactOpts(transactor) - - // transactor_forGasEstimate.Nonce.Add(transactor_forGasEstimate.Nonce, big.NewInt(1)) + //tmpdebug + fmt.Printf("SubmitTransaction>forGasEst call \n") - // tx_forGasEstimate, err := call(transactor_forGasEstimate) + transactor_forGasEstimate := copyTransactOpts(transactor) - // fmt.Printf("tx_forGasEstimate: %v\n", tx_forGasEstimate.Gas()) + transactor_forGasEstimate.Nonce.Add(transactor_forGasEstimate.Nonce, big.NewInt(1)) - // if err != nil { - // return 0, fmt.Errorf("err contract call for gas est: %w", err) - // } + tx_forGasEstimate, err := call(transactor_forGasEstimate) - // // gasEstimate, err := t.getGasEstimate(ctx, chainClient, int(chainID.Uint64()), tx_forGasEstimate) - // // if err != nil { - // // return 0, fmt.Errorf("err getGasEstimate: %w", err) - // // } + fmt.Printf("tx_forGasEstimate: %v\n", tx_forGasEstimate.Gas()) - // transactor.GasLimit = tx_forGasEstimate.Gas() + 555 + if err != nil { + return 0, fmt.Errorf("err contract call for gas est: %w", err) + } - transactor.GasLimit = 21555 // intentionally set too low + transactor.GasLimit = tx_forGasEstimate.Gas() + 555 } @@ -469,24 +462,6 @@ func (t *txSubmitterImpl) SubmitTransaction(parentCtx context.Context, chainID * return 0, fmt.Errorf("err contract call for tx: %w", err) } - // if t.config.GetDynamicGasEstimate(int(chainID.Uint64())) { - - // //tmpdebug - // fmt.Printf("tx.Gas (pre): %d\n", tx.Gas()) - // transactor.GasLimit = tx.Gas() + 555 - - // //tmpdebug - // fmt.Printf("transactor.GasLimit2: %d\n", transactor.GasLimit) - - // tx, err = call(transactor) - // if err != nil { - // return 0, fmt.Errorf("err contract call 2 for tx: %w", err) - // } - - // //tmpdebug - // fmt.Printf("tx.Gas (post): %d\n", tx.Gas()) - // } - //tmpdebug fmt.Printf("tx.Gas: %d\n", tx.Gas()) @@ -789,7 +764,6 @@ func (t *txSubmitterImpl) getGasEstimate(ctx context.Context, chainClient client span.AddEvent("could not estimate gas", trace.WithAttributes(attribute.String("error", err.Error()))) - // fallback to default return t.config.GetGasEstimate(chainID), nil } diff --git a/services/rfq/relayer/chain/chain.go b/services/rfq/relayer/chain/chain.go index 45d836484b..e2b06da07b 100644 --- a/services/rfq/relayer/chain/chain.go +++ b/services/rfq/relayer/chain/chain.go @@ -95,10 +95,12 @@ func (c Chain) SubmitRelay(ctx context.Context, request reldb.QuoteRequest) (uin nonce, err := c.SubmitTransaction(ctx, func(transactor *bind.TransactOpts) (tx *types.Transaction, err error) { transactor.Value = core.CopyBigInt(gasAmount) + //tmpdebug callType := "exec" if transactor.GasLimit == 0 { callType = "sim" } + //tmpdebug fmt.Println(callType, "SubmitTransaction>RelayV2: ", request.OriginTxHash) From 82b4f9926b042afb57c377fdd0bef367ed97af3c Mon Sep 17 00:00:00 2001 From: parodime Date: Tue, 28 Jan 2025 12:45:59 -0500 Subject: [PATCH 30/42] repro err [goreleaser] --- ethergo/submitter/submitter.go | 5 ++--- services/rfq/relayer/chain/chain.go | 3 +-- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/ethergo/submitter/submitter.go b/ethergo/submitter/submitter.go index efeda8580b..8a8cd45ba2 100644 --- a/ethergo/submitter/submitter.go +++ b/ethergo/submitter/submitter.go @@ -443,13 +443,12 @@ func (t *txSubmitterImpl) SubmitTransaction(parentCtx context.Context, chainID * transactor_forGasEstimate.Nonce.Add(transactor_forGasEstimate.Nonce, big.NewInt(1)) tx_forGasEstimate, err := call(transactor_forGasEstimate) - - fmt.Printf("tx_forGasEstimate: %v\n", tx_forGasEstimate.Gas()) - if err != nil { return 0, fmt.Errorf("err contract call for gas est: %w", err) } + fmt.Printf("tx_forGasEstimate: %v\n", tx_forGasEstimate.Gas()) + transactor.GasLimit = tx_forGasEstimate.Gas() + 555 } diff --git a/services/rfq/relayer/chain/chain.go b/services/rfq/relayer/chain/chain.go index e2b06da07b..08f38035eb 100644 --- a/services/rfq/relayer/chain/chain.go +++ b/services/rfq/relayer/chain/chain.go @@ -111,8 +111,7 @@ func (c Chain) SubmitRelay(ctx context.Context, request reldb.QuoteRequest) (uin } //tmpdebug - fmt.Println(callType, "RelayV2 OriginTxHash:", request.OriginTxHash) - fmt.Printf(callType+" RelayV2 transaction: %+v\n", tx) + fmt.Println(callType, "RelayV2 Return tx hash:", request.OriginTxHash, tx.Hash()) return tx, nil }) From 5b02ccaf6adfae4a340dd28c78caa6f5432a23ad Mon Sep 17 00:00:00 2001 From: parodime Date: Tue, 28 Jan 2025 15:57:25 -0500 Subject: [PATCH 31/42] bump approach [goreleaser] --- ethergo/submitter/submitter.go | 57 +++++++++++++++++++++------------- 1 file changed, 35 insertions(+), 22 deletions(-) diff --git a/ethergo/submitter/submitter.go b/ethergo/submitter/submitter.go index 8a8cd45ba2..57d328a8b5 100644 --- a/ethergo/submitter/submitter.go +++ b/ethergo/submitter/submitter.go @@ -435,22 +435,28 @@ func (t *txSubmitterImpl) SubmitTransaction(parentCtx context.Context, chainID * transactor.GasLimit = t.config.GetGasEstimate(int(chainID.Uint64())) } else { - //tmpdebug - fmt.Printf("SubmitTransaction>forGasEst call \n") + // //tmpdebug + // fmt.Printf("SubmitTransaction>forGasEst call \n") - transactor_forGasEstimate := copyTransactOpts(transactor) + // transactor_forGasEstimate := copyTransactOpts(transactor) - transactor_forGasEstimate.Nonce.Add(transactor_forGasEstimate.Nonce, big.NewInt(1)) + // transactor_forGasEstimate.Nonce.Add(transactor_forGasEstimate.Nonce, big.NewInt(1)) - tx_forGasEstimate, err := call(transactor_forGasEstimate) - if err != nil { - return 0, fmt.Errorf("err contract call for gas est: %w", err) - } + // tx_forGasEstimate, err := call(transactor_forGasEstimate) + // if err != nil { + // return 0, fmt.Errorf("err contract call for gas est: %w", err) + // } - fmt.Printf("tx_forGasEstimate: %v\n", tx_forGasEstimate.Gas()) + // fmt.Printf("tx_forGasEstimate: %v\n", tx_forGasEstimate.Gas()) - transactor.GasLimit = tx_forGasEstimate.Gas() + 555 + //transactor.GasLimit = tx_forGasEstimate.Gas() + 555 + // spoof some low gas units to induce bump tests + if chainID.Uint64() == 10 { + transactor.GasLimit = 25000 + } else if chainID.Uint64() == 42161 { + transactor.GasLimit = 150000 + } } //tmpdebug @@ -721,7 +727,7 @@ func (t *txSubmitterImpl) getGasBlock(ctx context.Context, chainClient client.EV // getGasEstimate gets the gas estimate for the given transaction. // TODO: handle l2s w/ custom gas pricing through contracts. -func (t *txSubmitterImpl) getGasEstimate(ctx context.Context, chainClient client.EVM, chainID int, tx *types.Transaction) (gasEstimate uint64, err error) { +func (t *txSubmitterImpl) getGasEstimate(ctx context.Context, chainClient client.EVM, chainID int, tx *types.Transaction) (gasLimit_new uint64, err error) { // if dynamic gas estimation is not enabled, use cfg var gas_estimate as a default if !t.config.GetDynamicGasEstimate(chainID) { @@ -745,7 +751,7 @@ func (t *txSubmitterImpl) getGasEstimate(ctx context.Context, chainClient client )) defer func() { - span.AddEvent("estimated_gas", trace.WithAttributes(attribute.Int64("gas", int64(gasEstimate)))) + span.AddEvent("estimated_gas", trace.WithAttributes(attribute.Int64("gas", int64(gasLimit_new)))) metrics.EndSpanWithErr(span, err) }() @@ -755,7 +761,11 @@ func (t *txSubmitterImpl) getGasEstimate(ctx context.Context, chainClient client return 0, fmt.Errorf("could not convert tx to call: %w", err) } - gasEstimate, err = chainClient.EstimateGas(ctx, *call) + // bump gas limit from prior by X% + gasLimit_fromPrior := tx.Gas() + + gasLimit_fromEstimate, err := chainClient.EstimateGas(ctx, *call) + if err != nil { //tmpdebug @@ -763,19 +773,22 @@ func (t *txSubmitterImpl) getGasEstimate(ctx context.Context, chainClient client span.AddEvent("could not estimate gas", trace.WithAttributes(attribute.String("error", err.Error()))) - return t.config.GetGasEstimate(chainID), nil + // if we failed to est gas for any reason, use *at least* the default flat gas on the next bump + gasLimit_fromEstimate = max(t.config.GetGasEstimate(chainID), gasLimit_fromEstimate) } - //tmpdebug - fmt.Println("getGasEstimate>gasEstimate pre", gasEstimate) - - // Modify the gasEstimate by the configured percentage - gasEstimate = gasEstimate + (gasEstimate * uint64(gasUnitAddPercentage) / 100) + // use whichever is higher, gas from the prior attempt, or gas from our latest simulation estimate + gasLimit_new = max(gasLimit_fromPrior, gasLimit_fromEstimate) - //tmpdebug - fmt.Println("getGasEstimate>gasEstimate post", gasEstimate) + // whichever source is used as the base, multiply it by the configured gas unit add percentage + gasLimit_new = gasLimit_new + (gasLimit_new * uint64(gasUnitAddPercentage) / 100) + span.AddEvent("new gas limit", trace.WithAttributes( + attribute.Int64("gas_limit", int64(gasLimit_new)), + attribute.Int64("gas_limit_from_prior", int64(gasLimit_fromPrior)), + attribute.Int64("gas_limit_from_estimate", int64(gasLimit_fromEstimate)), + )) - return gasEstimate, nil + return gasLimit_new, nil } func (t *txSubmitterImpl) Address() common.Address { From 965802de69b618eba8449415386803093e5a8405 Mon Sep 17 00:00:00 2001 From: parodime Date: Wed, 29 Jan 2025 12:35:46 -0500 Subject: [PATCH 32/42] bump approach - arbi test focus [goreleaser] --- ethergo/submitter/submitter.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ethergo/submitter/submitter.go b/ethergo/submitter/submitter.go index 57d328a8b5..7b6da9ead7 100644 --- a/ethergo/submitter/submitter.go +++ b/ethergo/submitter/submitter.go @@ -451,11 +451,11 @@ func (t *txSubmitterImpl) SubmitTransaction(parentCtx context.Context, chainID * //transactor.GasLimit = tx_forGasEstimate.Gas() + 555 - // spoof some low gas units to induce bump tests + // if arbitrum, spoof some low gas units to induce bump tests if chainID.Uint64() == 10 { - transactor.GasLimit = 25000 + transactor.GasLimit = 0 } else if chainID.Uint64() == 42161 { - transactor.GasLimit = 150000 + transactor.GasLimit = 200000 } } From 7b62df2ee6752135f7d9ca1fdb894172488824d5 Mon Sep 17 00:00:00 2001 From: parodime Date: Wed, 29 Jan 2025 15:52:48 -0500 Subject: [PATCH 33/42] swap context [goreleaser] --- .gitignore | 3 +++ ethergo/submitter/submitter.go | 7 ++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index f458e67ba8..abf987290d 100644 --- a/.gitignore +++ b/.gitignore @@ -133,3 +133,6 @@ main # golang-ci-lint binary contrib/golang-ci-lint/golang-ci-lint + +*signer*.txt +config-stage.yaml \ No newline at end of file diff --git a/ethergo/submitter/submitter.go b/ethergo/submitter/submitter.go index 7b6da9ead7..3e7d9443f4 100644 --- a/ethergo/submitter/submitter.go +++ b/ethergo/submitter/submitter.go @@ -462,6 +462,11 @@ func (t *txSubmitterImpl) SubmitTransaction(parentCtx context.Context, chainID * //tmpdebug fmt.Printf("transactor.GasLimit: %d\n", transactor.GasLimit) + var cancel context.CancelFunc + transactor.Context, cancel = context.WithTimeout(ctx, time.Second*5) + defer func() { + cancel() + }() tx, err := call(transactor) if err != nil { return 0, fmt.Errorf("err contract call for tx: %w", err) @@ -777,7 +782,7 @@ func (t *txSubmitterImpl) getGasEstimate(ctx context.Context, chainClient client gasLimit_fromEstimate = max(t.config.GetGasEstimate(chainID), gasLimit_fromEstimate) } - // use whichever is higher, gas from the prior attempt, or gas from our latest simulation estimate + // start with whichever value is higher gas from the prior attempt, or gas from our latest simulation estimate gasLimit_new = max(gasLimit_fromPrior, gasLimit_fromEstimate) // whichever source is used as the base, multiply it by the configured gas unit add percentage From 73442fa38662c38280b31ff4f0a1fe3cf7840c78 Mon Sep 17 00:00:00 2001 From: parodime Date: Fri, 31 Jan 2025 10:12:06 -0500 Subject: [PATCH 34/42] fix transactor_forGasEstimate lock. +QuoteDetails event --- ethergo/submitter/submitter.go | 114 +++++++----------- services/rfq/contracts/fastbridgev2/events.go | 3 + .../fastbridgev2/eventtype_string.go | 5 +- services/rfq/contracts/fastbridgev2/parser.go | 8 ++ services/rfq/relayer/chain/chain.go | 20 --- services/rfq/relayer/pricer/fee_pricer.go | 10 +- services/rfq/relayer/service/handlers.go | 11 +- 7 files changed, 65 insertions(+), 106 deletions(-) diff --git a/ethergo/submitter/submitter.go b/ethergo/submitter/submitter.go index 3e7d9443f4..735b1db129 100644 --- a/ethergo/submitter/submitter.go +++ b/ethergo/submitter/submitter.go @@ -8,6 +8,7 @@ import ( "math/big" "reflect" "runtime" + "strings" "sync" "time" @@ -388,9 +389,6 @@ func (t *txSubmitterImpl) SubmitTransaction(parentCtx context.Context, chainID * // this also prevents a bug in the caller from breaking our lock transactor.Nonce = new(big.Int).Add(new(big.Int).SetUint64(math.MaxUint64), big.NewInt(1)) - //tmpdebug - fmt.Printf("SubmitTransaction>setGasPrice\n") - err = t.setGasPrice(ctx, chainClient, transactor, chainID, nil) if err != nil { span.AddEvent("could not set gas price", trace.WithAttributes(attribute.String("error", err.Error()))) @@ -422,64 +420,59 @@ func (t *txSubmitterImpl) SubmitTransaction(parentCtx context.Context, chainID * return parentTransactor.Signer(address, transaction) } - //tmpdebug - fmt.Printf("test ver 7\n") - // if dynamic gas estimation is not enabled, use cfg var gas_estimate as a gas limit default and do not run a pre-flight simulation // since we do not need it to determine proper gas units if !t.config.GetDynamicGasEstimate(int(chainID.Uint64())) { - - //tmpdebug - fmt.Printf("Using Default \n") - transactor.GasLimit = t.config.GetGasEstimate(int(chainID.Uint64())) } else { - // //tmpdebug - // fmt.Printf("SubmitTransaction>forGasEst call \n") + // deepcopy the real transactor so we can use it for simulation + transactor_forGasEstimate := copyTransactOpts(transactor) - // transactor_forGasEstimate := copyTransactOpts(transactor) + // override the signer func for our simulation/estimation with a version that does not lock the nonce, + // which would othewrise cause a deadlock with the following *actual* transactor + transactor_forGasEstimate.Signer = func(address common.Address, transaction *types.Transaction) (_ *types.Transaction, err error) { - // transactor_forGasEstimate.Nonce.Add(transactor_forGasEstimate.Nonce, big.NewInt(1)) + newNonce, err := t.getNonce(ctx, chainID, address) + if err != nil { + return nil, fmt.Errorf("could not sign tx: %w", err) + } - // tx_forGasEstimate, err := call(transactor_forGasEstimate) - // if err != nil { - // return 0, fmt.Errorf("err contract call for gas est: %w", err) - // } + txType := t.txTypeForChain(chainID) - // fmt.Printf("tx_forGasEstimate: %v\n", tx_forGasEstimate.Gas()) + transaction, err = util.CopyTX(transaction, util.WithNonce(newNonce), util.WithTxType(txType)) + if err != nil { + return nil, fmt.Errorf("could not copy tx: %w", err) + } - //transactor.GasLimit = tx_forGasEstimate.Gas() + 555 + //nolint: wrapcheck + return parentTransactor.Signer(address, transaction) + } + + tx_forGasEstimate, err := call(transactor_forGasEstimate) + if err != nil { + // at the moment, omniRPC gives a massive HTML doc w/ many sim errors.. reduce the noise. + errMsg := err.Error() + if strings.Contains(errMsg, "") { + errMsg = strings.Split(errMsg, "")[0] + "" + } - // if arbitrum, spoof some low gas units to induce bump tests - if chainID.Uint64() == 10 { - transactor.GasLimit = 0 - } else if chainID.Uint64() == 42161 { - transactor.GasLimit = 200000 + return 0, fmt.Errorf("err contract call for gas est: %s", errMsg) } - } - //tmpdebug - fmt.Printf("transactor.GasLimit: %d\n", transactor.GasLimit) + // with our gas limit now obtained from the simulation, apply this limit (plus any configured % modifier) to the + // gas limit of the actual transactor that is about to prepare the real transaction + gasLimitAddPercentage := t.config.GetDynamicGasUnitAddPercentage(int(chainID.Uint64())) + transactor.GasLimit = tx_forGasEstimate.Gas() + (tx_forGasEstimate.Gas() * uint64(gasLimitAddPercentage) / 100) + } - var cancel context.CancelFunc - transactor.Context, cancel = context.WithTimeout(ctx, time.Second*5) - defer func() { - cancel() - }() tx, err := call(transactor) if err != nil { return 0, fmt.Errorf("err contract call for tx: %w", err) } - //tmpdebug - fmt.Printf("tx.Gas: %d\n", tx.Gas()) - defer locker.Unlock() - //tmpdebug - fmt.Printf("SubmitTransaction>storeTX\n") - // now that we've stored the tx err = t.storeTX(ctx, tx, db.Stored, uuid.New().String()) if err != nil { @@ -489,9 +482,6 @@ func (t *txSubmitterImpl) SubmitTransaction(parentCtx context.Context, chainID * span.AddEvent("trigger reprocess") t.triggerProcessQueue(ctx) - //tmpdebug - fmt.Printf("SubmitTransaction>tx.Nonce: %d\n", tx.Nonce()) - return tx.Nonce(), nil } @@ -732,31 +722,23 @@ func (t *txSubmitterImpl) getGasBlock(ctx context.Context, chainClient client.EV // getGasEstimate gets the gas estimate for the given transaction. // TODO: handle l2s w/ custom gas pricing through contracts. -func (t *txSubmitterImpl) getGasEstimate(ctx context.Context, chainClient client.EVM, chainID int, tx *types.Transaction) (gasLimit_new uint64, err error) { +func (t *txSubmitterImpl) getGasEstimate(ctx context.Context, chainClient client.EVM, chainID int, tx *types.Transaction) (gasLimit uint64, err error) { // if dynamic gas estimation is not enabled, use cfg var gas_estimate as a default if !t.config.GetDynamicGasEstimate(chainID) { return t.config.GetGasEstimate(chainID), nil } - //tmpdebug - fmt.Println("getGasEstimate>start") - gasUnitAddPercentage := t.config.GetDynamicGasUnitAddPercentage(chainID) - //tmpdebug - fmt.Println("getGasEstimate>gasUnitAddPercentage", gasUnitAddPercentage) - ctx, span := t.metrics.Tracer().Start(ctx, "submitter.getGasEstimate", trace.WithAttributes( attribute.Int(metrics.ChainID, chainID), - attribute.String(metrics.TxHash, tx.Hash().String()), - attribute.Int("gasUnitAddPercentage", gasUnitAddPercentage), )) defer func() { - span.AddEvent("estimated_gas", trace.WithAttributes(attribute.Int64("gas", int64(gasLimit_new)))) + span.AddEvent("estimated_gas", trace.WithAttributes(attribute.Int64("gas", int64(gasLimit)))) metrics.EndSpanWithErr(span, err) }() @@ -766,34 +748,20 @@ func (t *txSubmitterImpl) getGasEstimate(ctx context.Context, chainClient client return 0, fmt.Errorf("could not convert tx to call: %w", err) } - // bump gas limit from prior by X% - gasLimit_fromPrior := tx.Gas() - gasLimit_fromEstimate, err := chainClient.EstimateGas(ctx, *call) if err != nil { - - //tmpdebug - fmt.Printf("getGasEstimate> Error estimating gas: %v\n", err) - span.AddEvent("could not estimate gas", trace.WithAttributes(attribute.String("error", err.Error()))) - // if we failed to est gas for any reason, use *at least* the default flat gas on the next bump - gasLimit_fromEstimate = max(t.config.GetGasEstimate(chainID), gasLimit_fromEstimate) + // if we failed to est gas for any reason, use the default flat gas from config + gasLimit = t.config.GetGasEstimate(chainID) + } else { + // multiply the freshly simulated gasLimit by the configured gas unit add percentage + gasLimit_fromEstimate += (gasLimit_fromEstimate * uint64(gasUnitAddPercentage) / 100) + gasLimit = gasLimit_fromEstimate } - // start with whichever value is higher gas from the prior attempt, or gas from our latest simulation estimate - gasLimit_new = max(gasLimit_fromPrior, gasLimit_fromEstimate) - - // whichever source is used as the base, multiply it by the configured gas unit add percentage - gasLimit_new = gasLimit_new + (gasLimit_new * uint64(gasUnitAddPercentage) / 100) - span.AddEvent("new gas limit", trace.WithAttributes( - attribute.Int64("gas_limit", int64(gasLimit_new)), - attribute.Int64("gas_limit_from_prior", int64(gasLimit_fromPrior)), - attribute.Int64("gas_limit_from_estimate", int64(gasLimit_fromEstimate)), - )) - - return gasLimit_new, nil + return gasLimit, nil } func (t *txSubmitterImpl) Address() common.Address { diff --git a/services/rfq/contracts/fastbridgev2/events.go b/services/rfq/contracts/fastbridgev2/events.go index 2547ebad28..aeff1ee0eb 100644 --- a/services/rfq/contracts/fastbridgev2/events.go +++ b/services/rfq/contracts/fastbridgev2/events.go @@ -20,6 +20,8 @@ var ( BridgeDepositClaimedTopic common.Hash // BridgeProofDisputedTopic is the topic emitted by a bridge dispute. BridgeProofDisputedTopic common.Hash + // BridgeProofDisputedTopic is a secondary topic emitted by a bridge request. + BridgeQuoteDetailsTopic common.Hash ) // static checks to make sure topics actually exist. @@ -67,6 +69,7 @@ func topicMap() map[EventType]common.Hash { BridgeProofProvidedEvent: BridgeProofProvidedTopic, BridgeDepositClaimedEvent: BridgeDepositClaimedTopic, BridgeDisputeEvent: BridgeProofDisputedTopic, + BridgeQuoteDetailsEvent: BridgeQuoteDetailsTopic, } } diff --git a/services/rfq/contracts/fastbridgev2/eventtype_string.go b/services/rfq/contracts/fastbridgev2/eventtype_string.go index b7c65ba096..9fd676f18d 100644 --- a/services/rfq/contracts/fastbridgev2/eventtype_string.go +++ b/services/rfq/contracts/fastbridgev2/eventtype_string.go @@ -13,11 +13,12 @@ func _() { _ = x[BridgeProofProvidedEvent-3] _ = x[BridgeDepositClaimedEvent-4] _ = x[BridgeDisputeEvent-5] + _ = x[BridgeQuoteDetailsEvent-6] } -const _EventType_name = "BridgeRequestedEventBridgeRelayedEventBridgeProofProvidedEventBridgeDepositClaimedEventBridgeDisputeEvent" +const _EventType_name = "BridgeRequestedEventBridgeRelayedEventBridgeProofProvidedEventBridgeDepositClaimedEventBridgeDisputeEventBridgeQuoteDetailsEvent" -var _EventType_index = [...]uint8{0, 20, 38, 62, 87, 105} +var _EventType_index = [...]uint8{0, 20, 38, 62, 87, 105, 127} func (i EventType) String() string { i -= 1 diff --git a/services/rfq/contracts/fastbridgev2/parser.go b/services/rfq/contracts/fastbridgev2/parser.go index 5fe9d66570..4cc4870e31 100644 --- a/services/rfq/contracts/fastbridgev2/parser.go +++ b/services/rfq/contracts/fastbridgev2/parser.go @@ -23,6 +23,8 @@ const ( BridgeDepositClaimedEvent // BridgeDisputeEvent is the event type for the BridgeDispute event. BridgeDisputeEvent + // BridgeQuoteDetailsEvent is emitted along w/ BridgeRequestedEvent as supplemental data + BridgeQuoteDetailsEvent ) // Parser parses events from the fastbridge contracat. @@ -91,6 +93,12 @@ func (p parserImpl) ParseEvent(log ethTypes.Log) (_ EventType, event interface{} return noOpEvent, nil, false } return eventType, disputed, true + case BridgeQuoteDetailsEvent: + quoteDetails, err := p.filterer.ParseBridgeQuoteDetails(log) + if err != nil { + return noOpEvent, nil, false + } + return eventType, quoteDetails, true } return eventType, nil, true diff --git a/services/rfq/relayer/chain/chain.go b/services/rfq/relayer/chain/chain.go index 08f38035eb..7fab137186 100644 --- a/services/rfq/relayer/chain/chain.go +++ b/services/rfq/relayer/chain/chain.go @@ -74,9 +74,6 @@ func (c Chain) SubmitRelay(ctx context.Context, request reldb.QuoteRequest) (uin gasAmount := big.NewInt(0) var err error - //tmpdebug - fmt.Println("SubmitRelay>start: ", request.OriginTxHash) - // Check to see if ETH should be sent to destination if util.IsGasToken(request.Transaction.DestToken) { gasAmount = request.Transaction.DestAmount @@ -89,37 +86,20 @@ func (c Chain) SubmitRelay(ctx context.Context, request reldb.QuoteRequest) (uin } } - //tmpdebug - fmt.Println("SubmitRelay>SubmitTransaction: ", request.OriginTxHash) - nonce, err := c.SubmitTransaction(ctx, func(transactor *bind.TransactOpts) (tx *types.Transaction, err error) { transactor.Value = core.CopyBigInt(gasAmount) - //tmpdebug - callType := "exec" - if transactor.GasLimit == 0 { - callType = "sim" - } - - //tmpdebug - fmt.Println(callType, "SubmitTransaction>RelayV2: ", request.OriginTxHash) - tx, err = c.Bridge.RelayV2(transactor, request.RawRequest, c.submitter.Address()) if err != nil { return nil, fmt.Errorf("could not relay: %w", err) } - //tmpdebug - fmt.Println(callType, "RelayV2 Return tx hash:", request.OriginTxHash, tx.Hash()) - return tx, nil }) if err != nil { return 0, nil, fmt.Errorf("could not submit transaction: %w", err) } - //tmpdebug - fmt.Println("SubmitRelay nonce:", nonce, "gas amount:", gasAmount) return nonce, gasAmount, nil } diff --git a/services/rfq/relayer/pricer/fee_pricer.go b/services/rfq/relayer/pricer/fee_pricer.go index b259497b01..8871b458dc 100644 --- a/services/rfq/relayer/pricer/fee_pricer.go +++ b/services/rfq/relayer/pricer/fee_pricer.go @@ -261,9 +261,17 @@ func (f *feePricer) getZapGasEstimate(ctx context.Context, destination uint32, q callMsg.Value = quoteRequest.Transaction.ZapNative } + // note: this gas amount is intentionally not modified gasEstimate, err = client.EstimateGas(ctx, callMsg) if err != nil { - return 0, fmt.Errorf("could not estimate gas: %w", err) + + // at the moment, omniRPC gives a massive HTML doc w/ many sim errors.. reduce the noise. + errMsg := err.Error() + if strings.Contains(errMsg, "") { + errMsg = strings.Split(errMsg, "")[0] + "" + } + + return 0, fmt.Errorf("could not estimate gas: %s", errMsg) } return gasEstimate, nil diff --git a/services/rfq/relayer/service/handlers.go b/services/rfq/relayer/service/handlers.go index d730b9b612..124cd13527 100644 --- a/services/rfq/relayer/service/handlers.go +++ b/services/rfq/relayer/service/handlers.go @@ -377,9 +377,6 @@ func (q *QuoteRequestHandler) handleCommitPending(ctx context.Context, span trac // TODO: just to be safe, we should probably check if another relayer has already relayed this. func (q *QuoteRequestHandler) handleCommitConfirmed(ctx context.Context, span trace.Span, request reldb.QuoteRequest) (err error) { - //tmpdebug - fmt.Println("handleCommitConfirmed>SubmitRelay: ", request.OriginTxHash) - // TODO: store the dest txhash connected to the nonce nonce, _, err := q.Dest.SubmitRelay(ctx, request) if err != nil { @@ -388,15 +385,11 @@ func (q *QuoteRequestHandler) handleCommitConfirmed(ctx context.Context, span tr span.AddEvent("relay successfully submitted") span.SetAttributes(attribute.Int("relay_nonce", int(nonce))) - //tmpdebug - fmt.Println("handleCommitConfirmed>UpdateQuoteRequestStatus: ", request.OriginTxHash) err = q.db.UpdateQuoteRequestStatus(ctx, request.TransactionID, reldb.RelayStarted, &request.Status) if err != nil { return fmt.Errorf("could not update quote request status: %w", err) } - //tmpdebug - fmt.Println("handleCommitConfirmed>UpdateRelayNonce: ", request.OriginTxHash) err = q.db.UpdateRelayNonce(ctx, request.TransactionID, nonce) if err != nil { return fmt.Errorf("could not update relay nonce: %w", err) @@ -420,7 +413,7 @@ func (r *Relayer) handleRelayLog(parentCtx context.Context, req *fastbridgev2.Fa reqID, err := r.db.GetQuoteRequestByID(ctx, req.TransactionId) if err != nil { - return fmt.Errorf("could not get quote request: %w", err) + return fmt.Errorf("could not get quote request for tx ID %s: %w", hexutil.Encode(req.TransactionId[:]), err) } // we might've accidentally gotten this later, if so we'll just ignore it // note that in the edge case where we pessimistically marked as DeadlineExceeded @@ -481,13 +474,11 @@ func (q *QuoteRequestHandler) handleRelayCompleted(ctx context.Context, span tra // relay has been finalized, it's time to go back to the origin chain and try to prove _, err = q.Origin.SubmitTransaction(ctx, func(transactor *bind.TransactOpts) (tx *types.Transaction, err error) { - fmt.Println("SubmitTransaction>Prove ", request.OriginTxHash, "Nonce:", transactor.Nonce) tx, err = q.Origin.Bridge.Prove(transactor, request.RawRequest, request.DestTxHash) if err != nil { return nil, fmt.Errorf("could not prove: %w", err) } - fmt.Println("SubmitTransaction>Prove return tx.gas ", tx.Gas()) return tx, nil }) if err != nil { From ab18ea99e9c17613df10fd528635e357733039bb Mon Sep 17 00:00:00 2001 From: parodime Date: Fri, 31 Jan 2025 12:06:24 -0500 Subject: [PATCH 35/42] quotedetails event fix. +basic print logs --- services/rfq/contracts/fastbridgev2/events.go | 11 +++++++++++ services/rfq/relayer/chain/chain.go | 1 + services/rfq/relayer/service/handlers.go | 2 ++ 3 files changed, 14 insertions(+) diff --git a/services/rfq/contracts/fastbridgev2/events.go b/services/rfq/contracts/fastbridgev2/events.go index aeff1ee0eb..499b726ae1 100644 --- a/services/rfq/contracts/fastbridgev2/events.go +++ b/services/rfq/contracts/fastbridgev2/events.go @@ -38,6 +38,7 @@ func init() { BridgeProofProvidedTopic = parsedABI.Events["BridgeProofProvided"].ID BridgeDepositClaimedTopic = parsedABI.Events["BridgeDepositClaimed"].ID BridgeProofDisputedTopic = parsedABI.Events["BridgeProofDisputed"].ID + BridgeQuoteDetailsTopic = parsedABI.Events["BridgeQuoteDetails"].ID _, err = parsedABI.EventByID(BridgeRequestedTopic) if err != nil { @@ -58,6 +59,16 @@ func init() { if err != nil { panic(err) } + + _, err = parsedABI.EventByID(BridgeDepositClaimedTopic) + if err != nil { + panic(err) + } + + _, err = parsedABI.EventByID(BridgeQuoteDetailsTopic) + if err != nil { + panic(err) + } } // topicMap maps events to topics. diff --git a/services/rfq/relayer/chain/chain.go b/services/rfq/relayer/chain/chain.go index 7fab137186..8c1971cd49 100644 --- a/services/rfq/relayer/chain/chain.go +++ b/services/rfq/relayer/chain/chain.go @@ -89,6 +89,7 @@ func (c Chain) SubmitRelay(ctx context.Context, request reldb.QuoteRequest) (uin nonce, err := c.SubmitTransaction(ctx, func(transactor *bind.TransactOpts) (tx *types.Transaction, err error) { transactor.Value = core.CopyBigInt(gasAmount) + fmt.Printf("RFQ: %s - Submitting Relay\n", request.TransactionID) tx, err = c.Bridge.RelayV2(transactor, request.RawRequest, c.submitter.Address()) if err != nil { diff --git a/services/rfq/relayer/service/handlers.go b/services/rfq/relayer/service/handlers.go index 124cd13527..6bdad6f719 100644 --- a/services/rfq/relayer/service/handlers.go +++ b/services/rfq/relayer/service/handlers.go @@ -474,6 +474,7 @@ func (q *QuoteRequestHandler) handleRelayCompleted(ctx context.Context, span tra // relay has been finalized, it's time to go back to the origin chain and try to prove _, err = q.Origin.SubmitTransaction(ctx, func(transactor *bind.TransactOpts) (tx *types.Transaction, err error) { + fmt.Printf("RFQ: %s - Submitting Proof\n", request.TransactionID) tx, err = q.Origin.Bridge.Prove(transactor, request.RawRequest, request.DestTxHash) if err != nil { return nil, fmt.Errorf("could not prove: %w", err) @@ -619,6 +620,7 @@ func (q *QuoteRequestHandler) handleProofPosted(ctx context.Context, span trace. return nil } _, err = q.Origin.SubmitTransaction(ctx, func(transactor *bind.TransactOpts) (tx *types.Transaction, err error) { + fmt.Printf("RFQ: %s - Submitting Claim\n", request.TransactionID) tx, err = q.Origin.Bridge.Claim(transactor, request.RawRequest, transactor.From) if err != nil { return nil, fmt.Errorf("could not relay: %w", err) From cf43fdcf61b568bdbb48ce655dc8b51642e22f69 Mon Sep 17 00:00:00 2001 From: parodime Date: Fri, 31 Jan 2025 13:45:21 -0500 Subject: [PATCH 36/42] print log impvs [goreleaser] --- services/rfq/relayer/chain/chain.go | 9 ++++++++- services/rfq/relayer/service/handlers.go | 21 ++++++++++++++++++--- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/services/rfq/relayer/chain/chain.go b/services/rfq/relayer/chain/chain.go index 8c1971cd49..3ec2da5960 100644 --- a/services/rfq/relayer/chain/chain.go +++ b/services/rfq/relayer/chain/chain.go @@ -86,10 +86,17 @@ func (c Chain) SubmitRelay(ctx context.Context, request reldb.QuoteRequest) (uin } } + fmt.Printf( + "TxID 0x%x %7d.%s > %7d.%s : Submitting \033[32mRelay\033[0m\n", + request.TransactionID, + request.Transaction.OriginChainId, + request.Transaction.OriginToken.Hex()[:6], + request.Transaction.DestChainId, + request.Transaction.DestToken.Hex()[:6]) + nonce, err := c.SubmitTransaction(ctx, func(transactor *bind.TransactOpts) (tx *types.Transaction, err error) { transactor.Value = core.CopyBigInt(gasAmount) - fmt.Printf("RFQ: %s - Submitting Relay\n", request.TransactionID) tx, err = c.Bridge.RelayV2(transactor, request.RawRequest, c.submitter.Address()) if err != nil { diff --git a/services/rfq/relayer/service/handlers.go b/services/rfq/relayer/service/handlers.go index 6bdad6f719..1016af4a70 100644 --- a/services/rfq/relayer/service/handlers.go +++ b/services/rfq/relayer/service/handlers.go @@ -471,10 +471,16 @@ func (q *QuoteRequestHandler) handleRelayCompleted(ctx context.Context, span tra return nil } + fmt.Printf( + "TxID 0x%x %7d.%s > %7d.%s : Submitting \033[33mProof\033[0m\n", + request.TransactionID, + request.Transaction.OriginChainId, + request.Transaction.OriginToken.Hex()[:6], + request.Transaction.DestChainId, + request.Transaction.DestToken.Hex()[:6]) + // relay has been finalized, it's time to go back to the origin chain and try to prove _, err = q.Origin.SubmitTransaction(ctx, func(transactor *bind.TransactOpts) (tx *types.Transaction, err error) { - - fmt.Printf("RFQ: %s - Submitting Proof\n", request.TransactionID) tx, err = q.Origin.Bridge.Prove(transactor, request.RawRequest, request.DestTxHash) if err != nil { return nil, fmt.Errorf("could not prove: %w", err) @@ -619,8 +625,17 @@ func (q *QuoteRequestHandler) handleProofPosted(ctx context.Context, span trace. if !canClaim { return nil } + + fmt.Printf( + "TxID 0x%x %7d.%s > %7d.%s : Submitting \033[35mClaim\033[0m\n", + request.TransactionID, + request.Transaction.OriginChainId, + request.Transaction.OriginToken.Hex()[:6], + request.Transaction.DestChainId, + request.Transaction.DestToken.Hex()[:6]) + _, err = q.Origin.SubmitTransaction(ctx, func(transactor *bind.TransactOpts) (tx *types.Transaction, err error) { - fmt.Printf("RFQ: %s - Submitting Claim\n", request.TransactionID) + tx, err = q.Origin.Bridge.Claim(transactor, request.RawRequest, transactor.From) if err != nil { return nil, fmt.Errorf("could not relay: %w", err) From c24c5687ad0748a28d5be47c07b9f3b837f7ccf1 Mon Sep 17 00:00:00 2001 From: parodime Date: Fri, 31 Jan 2025 14:03:21 -0500 Subject: [PATCH 37/42] typo fix --- services/rfq/contracts/fastbridgev2/events.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/rfq/contracts/fastbridgev2/events.go b/services/rfq/contracts/fastbridgev2/events.go index 499b726ae1..d33812112e 100644 --- a/services/rfq/contracts/fastbridgev2/events.go +++ b/services/rfq/contracts/fastbridgev2/events.go @@ -20,7 +20,7 @@ var ( BridgeDepositClaimedTopic common.Hash // BridgeProofDisputedTopic is the topic emitted by a bridge dispute. BridgeProofDisputedTopic common.Hash - // BridgeProofDisputedTopic is a secondary topic emitted by a bridge request. + // BridgeQuoteDetailsTopic is a secondary topic emitted by a bridge request. BridgeQuoteDetailsTopic common.Hash ) From 0e35f40333ea5cc08f1cf8095beb53026e027a71 Mon Sep 17 00:00:00 2001 From: parodime Date: Fri, 31 Jan 2025 14:08:00 -0500 Subject: [PATCH 38/42] gitignore edit --- .gitignore | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index abf987290d..b67a8ab7bb 100644 --- a/.gitignore +++ b/.gitignore @@ -135,4 +135,8 @@ main contrib/golang-ci-lint/golang-ci-lint *signer*.txt -config-stage.yaml \ No newline at end of file + +# ignore any rfq config files that are not the template +services/rfq/**/config*.yaml +services/rfq/**/config*.yml +!services/rfq/**/config.yml \ No newline at end of file From 8adb27872a0bc9320219874f2d78e2e705c0f8ed Mon Sep 17 00:00:00 2001 From: parodime Date: Fri, 31 Jan 2025 14:12:27 -0500 Subject: [PATCH 39/42] getGasEstimate code simplify --- ethergo/submitter/submitter.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/ethergo/submitter/submitter.go b/ethergo/submitter/submitter.go index 735b1db129..1917956b19 100644 --- a/ethergo/submitter/submitter.go +++ b/ethergo/submitter/submitter.go @@ -754,13 +754,13 @@ func (t *txSubmitterImpl) getGasEstimate(ctx context.Context, chainClient client span.AddEvent("could not estimate gas", trace.WithAttributes(attribute.String("error", err.Error()))) // if we failed to est gas for any reason, use the default flat gas from config - gasLimit = t.config.GetGasEstimate(chainID) - } else { - // multiply the freshly simulated gasLimit by the configured gas unit add percentage - gasLimit_fromEstimate += (gasLimit_fromEstimate * uint64(gasUnitAddPercentage) / 100) - gasLimit = gasLimit_fromEstimate + return t.config.GetGasEstimate(chainID), nil } + // multiply the freshly simulated gasLimit by the configured gas unit add percentage + gasLimit_fromEstimate += (gasLimit_fromEstimate * uint64(gasUnitAddPercentage) / 100) + gasLimit = gasLimit_fromEstimate + return gasLimit, nil } From 961fbfcbc031cbd2cff3b7bafebdc2cf6332fa88 Mon Sep 17 00:00:00 2001 From: parodime Date: Fri, 31 Jan 2025 14:13:11 -0500 Subject: [PATCH 40/42] remove temp tests --- ethergo/submitter/util_test.go | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/ethergo/submitter/util_test.go b/ethergo/submitter/util_test.go index ceedc3d1dc..a5e057324e 100644 --- a/ethergo/submitter/util_test.go +++ b/ethergo/submitter/util_test.go @@ -198,21 +198,6 @@ func (s *SubmitterSuite) TestGroupTxesByNonce() { } } -func (s *SubmitterSuite) TestOpStackGas() { - - mockTx := mocks.GetMockTxes(s.GetTestContext(), s.T(), 1, types.LegacyTxType)[0] - - fmt.Printf("Original Transaction Gas Limit: %d\n", mockTx.Gas()) - -} - -func TestBox(t *testing.T) { - const testTxCount = 10 - mockTx := mocks.GetMockTxes(context.Background(), t, testTxCount, 0) - - fmt.Printf("Original Transaction Gas Limit: %d\n", mockTx[0].Gas()) -} - // Test for the outersection function. func TestOutersection(t *testing.T) { set := []*big.Int{ From 6586d73d6a2d668a7f52f46457aff008b130b580 Mon Sep 17 00:00:00 2001 From: parodime Date: Fri, 31 Jan 2025 15:07:42 -0500 Subject: [PATCH 41/42] remove underscores, FormatError util func, --- ethergo/submitter/submitter.go | 21 ++++++++------------- ethergo/util/util.go | 17 +++++++++++++++++ services/rfq/relayer/pricer/fee_pricer.go | 11 ++++------- 3 files changed, 29 insertions(+), 20 deletions(-) create mode 100644 ethergo/util/util.go diff --git a/ethergo/submitter/submitter.go b/ethergo/submitter/submitter.go index 1917956b19..c69a0b80cf 100644 --- a/ethergo/submitter/submitter.go +++ b/ethergo/submitter/submitter.go @@ -8,7 +8,6 @@ import ( "math/big" "reflect" "runtime" - "strings" "sync" "time" @@ -427,11 +426,11 @@ func (t *txSubmitterImpl) SubmitTransaction(parentCtx context.Context, chainID * } else { // deepcopy the real transactor so we can use it for simulation - transactor_forGasEstimate := copyTransactOpts(transactor) + transactorForGasEstimate := copyTransactOpts(transactor) // override the signer func for our simulation/estimation with a version that does not lock the nonce, // which would othewrise cause a deadlock with the following *actual* transactor - transactor_forGasEstimate.Signer = func(address common.Address, transaction *types.Transaction) (_ *types.Transaction, err error) { + transactorForGasEstimate.Signer = func(address common.Address, transaction *types.Transaction) (_ *types.Transaction, err error) { newNonce, err := t.getNonce(ctx, chainID, address) if err != nil { @@ -449,13 +448,9 @@ func (t *txSubmitterImpl) SubmitTransaction(parentCtx context.Context, chainID * return parentTransactor.Signer(address, transaction) } - tx_forGasEstimate, err := call(transactor_forGasEstimate) + txForGasEstimate, err := call(transactorForGasEstimate) if err != nil { - // at the moment, omniRPC gives a massive HTML doc w/ many sim errors.. reduce the noise. - errMsg := err.Error() - if strings.Contains(errMsg, "") { - errMsg = strings.Split(errMsg, "")[0] + "" - } + errMsg := util.FormatError(err) return 0, fmt.Errorf("err contract call for gas est: %s", errMsg) } @@ -463,7 +458,7 @@ func (t *txSubmitterImpl) SubmitTransaction(parentCtx context.Context, chainID * // with our gas limit now obtained from the simulation, apply this limit (plus any configured % modifier) to the // gas limit of the actual transactor that is about to prepare the real transaction gasLimitAddPercentage := t.config.GetDynamicGasUnitAddPercentage(int(chainID.Uint64())) - transactor.GasLimit = tx_forGasEstimate.Gas() + (tx_forGasEstimate.Gas() * uint64(gasLimitAddPercentage) / 100) + transactor.GasLimit = txForGasEstimate.Gas() + (txForGasEstimate.Gas() * uint64(gasLimitAddPercentage) / 100) } tx, err := call(transactor) @@ -748,7 +743,7 @@ func (t *txSubmitterImpl) getGasEstimate(ctx context.Context, chainClient client return 0, fmt.Errorf("could not convert tx to call: %w", err) } - gasLimit_fromEstimate, err := chainClient.EstimateGas(ctx, *call) + gasLimitFromEstimate, err := chainClient.EstimateGas(ctx, *call) if err != nil { span.AddEvent("could not estimate gas", trace.WithAttributes(attribute.String("error", err.Error()))) @@ -758,8 +753,8 @@ func (t *txSubmitterImpl) getGasEstimate(ctx context.Context, chainClient client } // multiply the freshly simulated gasLimit by the configured gas unit add percentage - gasLimit_fromEstimate += (gasLimit_fromEstimate * uint64(gasUnitAddPercentage) / 100) - gasLimit = gasLimit_fromEstimate + gasLimitFromEstimate += (gasLimitFromEstimate * uint64(gasUnitAddPercentage) / 100) + gasLimit = gasLimitFromEstimate return gasLimit, nil } diff --git a/ethergo/util/util.go b/ethergo/util/util.go new file mode 100644 index 0000000000..5df4ad2104 --- /dev/null +++ b/ethergo/util/util.go @@ -0,0 +1,17 @@ +package util + +import "strings" + +// FormatError applies custom formatting & noise reduction to error messages. Add more as needed. +func FormatError(err error) string { + if err == nil { + return "" + } + errMsg := err.Error() + + //if an error message contains embedded HTML (eg: many RPC errors), strip it out to reduce noise. + if strings.Contains(errMsg, "") { + errMsg = strings.Split(errMsg, "")[0] + "" + } + return errMsg +} diff --git a/services/rfq/relayer/pricer/fee_pricer.go b/services/rfq/relayer/pricer/fee_pricer.go index 8871b458dc..5d06ac3829 100644 --- a/services/rfq/relayer/pricer/fee_pricer.go +++ b/services/rfq/relayer/pricer/fee_pricer.go @@ -14,11 +14,12 @@ import ( "github.com/jellydator/ttlcache/v3" "github.com/synapsecns/sanguine/core/metrics" "github.com/synapsecns/sanguine/ethergo/submitter" + ethergoUtil "github.com/synapsecns/sanguine/ethergo/util" "github.com/synapsecns/sanguine/services/rfq/contracts/fastbridgev2" "github.com/synapsecns/sanguine/services/rfq/relayer/chain" "github.com/synapsecns/sanguine/services/rfq/relayer/relconfig" "github.com/synapsecns/sanguine/services/rfq/relayer/reldb" - "github.com/synapsecns/sanguine/services/rfq/util" + rfqUtil "github.com/synapsecns/sanguine/services/rfq/util" "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/trace" ) @@ -255,7 +256,7 @@ func (f *feePricer) getZapGasEstimate(ctx context.Context, destination uint32, q Data: encodedData, } // Tx.value needs to match `DestAmount` for native gas token, or `ZapNative` for ERC20s. - if util.IsGasToken(quoteRequest.Transaction.DestToken) { + if rfqUtil.IsGasToken(quoteRequest.Transaction.DestToken) { callMsg.Value = quoteRequest.Transaction.DestAmount } else { callMsg.Value = quoteRequest.Transaction.ZapNative @@ -265,11 +266,7 @@ func (f *feePricer) getZapGasEstimate(ctx context.Context, destination uint32, q gasEstimate, err = client.EstimateGas(ctx, callMsg) if err != nil { - // at the moment, omniRPC gives a massive HTML doc w/ many sim errors.. reduce the noise. - errMsg := err.Error() - if strings.Contains(errMsg, "") { - errMsg = strings.Split(errMsg, "")[0] + "" - } + errMsg := ethergoUtil.FormatError(err) return 0, fmt.Errorf("could not estimate gas: %s", errMsg) } From 528839f40833b2d817a8f7f328ecbc963bb8ab39 Mon Sep 17 00:00:00 2001 From: parodime Date: Fri, 31 Jan 2025 15:15:30 -0500 Subject: [PATCH 42/42] submitTransaction use common performSignature func for sim & actual --- ethergo/submitter/submitter.go | 39 +++++++++++++--------------------- 1 file changed, 15 insertions(+), 24 deletions(-) diff --git a/ethergo/submitter/submitter.go b/ethergo/submitter/submitter.go index c69a0b80cf..70cfa6cb7b 100644 --- a/ethergo/submitter/submitter.go +++ b/ethergo/submitter/submitter.go @@ -393,15 +393,7 @@ func (t *txSubmitterImpl) SubmitTransaction(parentCtx context.Context, chainID * span.AddEvent("could not set gas price", trace.WithAttributes(attribute.String("error", err.Error()))) } - transactor.Signer = func(address common.Address, transaction *types.Transaction) (_ *types.Transaction, err error) { - locker = t.nonceMux.Lock(chainID) - // it's important that we unlock the nonce if we fail to sign the transaction. - // this is why we use a defer here. The second defer should only be called if the first defer is not called. - defer func() { - if err != nil { - locker.Unlock() - } - }() + performSignature := func(address common.Address, transaction *types.Transaction) (_ *types.Transaction, err error) { newNonce, err := t.getNonce(ctx, chainID, address) if err != nil { @@ -419,6 +411,19 @@ func (t *txSubmitterImpl) SubmitTransaction(parentCtx context.Context, chainID * return parentTransactor.Signer(address, transaction) } + transactor.Signer = func(address common.Address, transaction *types.Transaction) (_ *types.Transaction, err error) { + locker = t.nonceMux.Lock(chainID) + // it's important that we unlock the nonce if we fail to sign the transaction. + // this is why we use a defer here. The second defer should only be called if the first defer is not called. + defer func() { + if err != nil { + locker.Unlock() + } + }() + + return performSignature(address, transaction) + } + // if dynamic gas estimation is not enabled, use cfg var gas_estimate as a gas limit default and do not run a pre-flight simulation // since we do not need it to determine proper gas units if !t.config.GetDynamicGasEstimate(int(chainID.Uint64())) { @@ -431,21 +436,7 @@ func (t *txSubmitterImpl) SubmitTransaction(parentCtx context.Context, chainID * // override the signer func for our simulation/estimation with a version that does not lock the nonce, // which would othewrise cause a deadlock with the following *actual* transactor transactorForGasEstimate.Signer = func(address common.Address, transaction *types.Transaction) (_ *types.Transaction, err error) { - - newNonce, err := t.getNonce(ctx, chainID, address) - if err != nil { - return nil, fmt.Errorf("could not sign tx: %w", err) - } - - txType := t.txTypeForChain(chainID) - - transaction, err = util.CopyTX(transaction, util.WithNonce(newNonce), util.WithTxType(txType)) - if err != nil { - return nil, fmt.Errorf("could not copy tx: %w", err) - } - - //nolint: wrapcheck - return parentTransactor.Signer(address, transaction) + return performSignature(address, transaction) } txForGasEstimate, err := call(transactorForGasEstimate)