Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

+dynamic_gas_unit_add_percentage flag #3494

Draft
wants to merge 33 commits into
base: feat/relayer-arb-call
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
dfbf6ba
+dynamic_gas_unit_add_percentage flag
parodime Jan 23, 2025
93459f1
test fix
parodime Jan 24, 2025
905a3a5
[goreleaser]
parodime Jan 24, 2025
09816fb
new simulate approach
parodime Jan 24, 2025
63f730c
[goreleaser]
parodime Jan 24, 2025
31ca3cf
fix tx.Hash empty [goreleaser]
parodime Jan 24, 2025
d8481f2
remove debug noise. nil deref fix... ?
parodime Jan 24, 2025
d7f1cad
[goreleaser]
parodime Jan 24, 2025
3d7eea2
check tx call b4 estgas [goreleaser]
parodime Jan 24, 2025
4c11d33
+tmp debuggers [goreleaser]
parodime Jan 27, 2025
145583d
more tmp debug [goreleaser]
parodime Jan 27, 2025
2005d91
tmp debug tx output [goreleaser]
parodime Jan 27, 2025
a8a48bb
tmp debug submit tweaks [goreleaser]
parodime Jan 27, 2025
75c9c44
submitTransaction refactor [goreleaser]
parodime Jan 27, 2025
96e16c3
clone transactor [goreleaser]
parodime Jan 27, 2025
dada2b0
deepcopy [goreleaser]
parodime Jan 27, 2025
7abfdb0
[goreleaser]
parodime Jan 27, 2025
0e7c236
test getGasEstimate skip
parodime Jan 27, 2025
220e0d4
[goreleaser]
parodime Jan 27, 2025
b995385
try gaslimit 0 [goreleaser]
parodime Jan 28, 2025
4782b44
gaslimit2 [goreleaser]
parodime Jan 28, 2025
d699cd0
gaslimit2 pre/post [goreleaser]
parodime Jan 28, 2025
04ccdc2
tx_forGasEst [goreleaser]
parodime Jan 28, 2025
c8f2dfe
diff nonces [goreleaser]
parodime Jan 28, 2025
d199850
Prove gas [goreleaser]
parodime Jan 28, 2025
e8fd10e
print nonce [goreleaser]
parodime Jan 28, 2025
ee9eb85
low gas test [goreleaser]
parodime Jan 28, 2025
f6bfa43
getGasEst bump approach [goreleaser]
parodime Jan 28, 2025
c79a81b
reproduce [goreleaser]
parodime Jan 28, 2025
82b4f99
repro err [goreleaser]
parodime Jan 28, 2025
5b02cca
bump approach [goreleaser]
parodime Jan 28, 2025
965802d
bump approach - arbi test focus [goreleaser]
parodime Jan 29, 2025
7b62df2
swap context [goreleaser]
parodime Jan 29, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs/bridge/docs/06-Services/04-Submitter.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
28 changes: 26 additions & 2 deletions ethergo/submitter/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@
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 (
Expand All @@ -64,6 +67,9 @@

// 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.
Expand Down Expand Up @@ -188,19 +194,37 @@
return gasBumpPercentage
}

// GetDynamicGasUnitAddPercentage returns the percentage to bump the gas limit by

Check failure on line 197 in ethergo/submitter/config/config.go

View workflow job for this annotation

GitHub Actions / Lint (ethergo)

Comment should end in a period (godot)
func (c *Config) GetDynamicGasUnitAddPercentage(chainID int) (dynamicGasUnitAddPercentage int) {
chainConfig, ok := c.Chains[chainID]
if ok {
dynamicGasUnitAddPercentage = chainConfig.DynamicGasUnitAddPercentage
}

Check warning on line 202 in ethergo/submitter/config/config.go

View check run for this annotation

Codecov / codecov/patch

ethergo/submitter/config/config.go#L198-L202

Added lines #L198 - L202 were not covered by tests
// if dynamicGasUnitAddPercentage is not set for the chain, use the global config
if dynamicGasUnitAddPercentage == 0 {
dynamicGasUnitAddPercentage = c.DynamicGasUnitAddPercentage
}

Check warning on line 206 in ethergo/submitter/config/config.go

View check run for this annotation

Codecov / codecov/patch

ethergo/submitter/config/config.go#L204-L206

Added lines #L204 - L206 were not covered by tests

// if the dynamicGasUnitAddPercentage isn't set at all, use the default
if dynamicGasUnitAddPercentage == 0 {
dynamicGasUnitAddPercentage = DefaultDynamicGasUnitAddPercentage
}
return dynamicGasUnitAddPercentage

Check warning on line 212 in ethergo/submitter/config/config.go

View check run for this annotation

Codecov / codecov/patch

ethergo/submitter/config/config.go#L209-L212

Added lines #L209 - L212 were not covered by tests
}

// GetGasEstimate returns the gas estimate to use for transactions
// TODO: test this method.
func (c *Config) GetGasEstimate(chainID int) (gasEstimate uint64) {
chainConfig, ok := c.Chains[chainID]
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
}
Expand Down
2 changes: 2 additions & 0 deletions ethergo/submitter/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,15 @@ 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)
assert.NoError(t, err)
assert.Equal(t, big.NewInt(250000000000), cfg.MaxGasPrice)
assert.Equal(t, 60, cfg.BumpIntervalSeconds)
assert.Equal(t, 10, cfg.GasBumpPercentage)
assert.Equal(t, 20, cfg.DynamicGasUnitAddPercentage)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Enhance test coverage for the new configuration parameter.

While the basic YAML parsing test is good, consider adding the following test cases:

  1. Add a test case in TestGetters for GetDynamicGasUnitAddPercentage
  2. Test the default value (5%)
  3. Add validation tests for edge cases (negative values, zero, etc.)

Here's a suggested implementation:

 func TestGetters(t *testing.T) {
     cfg := config.Config{
         ChainConfig: config.ChainConfig{
             MaxBatchSize: 5,
             DoNotBatch:   false,
             MaxGasPrice:  big.NewInt(250 * params.GWei),
+            DynamicGasUnitAddPercentage: 15,
         },
         Chains: map[int]config.ChainConfig{
                 MaxBatchSize: 8,
                 DoNotBatch:   true,
                 MaxGasPrice:  big.NewInt(300 * params.GWei),
+                DynamicGasUnitAddPercentage: 25,
             },
                 MaxBatchSize: 0, // Should use global config value
             },
         },
     }

     // ... existing test cases ...

+    t.Run("GetDynamicGasUnitAddPercentage", func(t *testing.T) {
+        // Test chain-specific value
+        assert.Equal(t, 25, cfg.GetDynamicGasUnitAddPercentage(1))
+        // Test fallback to global value
+        assert.Equal(t, 15, cfg.GetDynamicGasUnitAddPercentage(2))
+        // Test nonexistent chain
+        assert.Equal(t, 15, cfg.GetDynamicGasUnitAddPercentage(999))
+
+        // Test default value
+        emptyCfg := config.Config{}
+        assert.Equal(t, config.DefaultDynamicGasUnitAddPercentage, 
+            emptyCfg.GetDynamicGasUnitAddPercentage(1))
+
+        // Test validation (if implemented)
+        invalidCfg := config.Config{
+            ChainConfig: config.ChainConfig{
+                DynamicGasUnitAddPercentage: -1,
+            },
+        }
+        assert.Equal(t, config.DefaultDynamicGasUnitAddPercentage,
+            invalidCfg.GetDynamicGasUnitAddPercentage(1))
+    })
 }

Committable suggestion skipped: line range outside the PR's diff.

assert.Equal(t, uint64(1000), cfg.GasEstimate)
assert.Equal(t, true, cfg.DynamicGasEstimate)
assert.Equal(t, true, cfg.SupportsEIP1559(0))
Expand Down
2 changes: 2 additions & 0 deletions ethergo/submitter/config/iconfig_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

108 changes: 93 additions & 15 deletions ethergo/submitter/submitter.go
Original file line number Diff line number Diff line change
Expand Up @@ -388,13 +388,13 @@
// 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

Check failure on line 391 in ethergo/submitter/submitter.go

View workflow job for this annotation

GitHub Actions / Lint (ethergo)

commentFormatting: put a space between `//` and comment text (gocritic)
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())))
}
if !t.config.GetDynamicGasEstimate(int(chainID.Uint64())) {
transactor.GasLimit = t.config.GetGasEstimate(int(chainID.Uint64()))
}

transactor.Signer = func(address common.Address, transaction *types.Transaction) (_ *types.Transaction, err error) {
locker = t.nonceMux.Lock(chainID)
Expand All @@ -421,12 +421,60 @@
//nolint: wrapcheck
return parentTransactor.Signer(address, transaction)
}

//tmpdebug

Check failure on line 425 in ethergo/submitter/submitter.go

View workflow job for this annotation

GitHub Actions / Lint (ethergo)

commentFormatting: put a space between `//` and comment text (gocritic)
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())) {

Check failure on line 430 in ethergo/submitter/submitter.go

View workflow job for this annotation

GitHub Actions / Lint (ethergo)

G115: integer overflow conversion uint64 -> int (gosec)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Prevent potential integer overflow in chain ID conversion.

The conversion of chainID.Uint64() to int could overflow on 32-bit systems.

-	if !t.config.GetDynamicGasEstimate(int(chainID.Uint64())) {
+	chainIDInt := chainID.Int64()
+	if chainIDInt > math.MaxInt32 {
+		return 0, fmt.Errorf("chain ID %d exceeds maximum supported value", chainIDInt)
+	}
+	if !t.config.GetDynamicGasEstimate(int(chainIDInt)) {

Also applies to: 431-431, 443-443

🧰 Tools
🪛 golangci-lint (1.62.2)

[high] 426-426: G115: integer overflow conversion uint64 -> int

(gosec)

🪛 GitHub Check: Lint (ethergo)

[failure] 426-426:
G115: integer overflow conversion uint64 -> int (gosec)


//tmpdebug

Check failure on line 432 in ethergo/submitter/submitter.go

View workflow job for this annotation

GitHub Actions / Lint (ethergo)

commentFormatting: put a space between `//` and comment text (gocritic)
fmt.Printf("Using Default \n")

transactor.GasLimit = t.config.GetGasEstimate(int(chainID.Uint64()))

Check failure on line 435 in ethergo/submitter/submitter.go

View workflow job for this annotation

GitHub Actions / Lint (ethergo)

G115: integer overflow conversion uint64 -> int (gosec)
} else {

// //tmpdebug
// fmt.Printf("SubmitTransaction>forGasEst call \n")

// transactor_forGasEstimate := copyTransactOpts(transactor)

// 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)
// }

// fmt.Printf("tx_forGasEstimate: %v\n", tx_forGasEstimate.Gas())

//transactor.GasLimit = tx_forGasEstimate.Gas() + 555

// 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
}

Check warning on line 459 in ethergo/submitter/submitter.go

View check run for this annotation

Codecov / codecov/patch

ethergo/submitter/submitter.go#L437-L459

Added lines #L437 - L459 were not covered by tests
}
Comment on lines +454 to +460
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Remove hard-coded gas limits for specific chains.

Using hard-coded gas limits (0 for chain ID 10 and 200000 for chain ID 42161) is dangerous as it:

  1. Will cause transaction failures with zero gas limit
  2. May lead to out-of-gas errors with insufficient gas limit
  3. Wastes gas if the limit is too high

Remove the hard-coded values and use proper gas estimation:

-		// 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
-		}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// 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
}
}
}
🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 455-455: ethergo/submitter/submitter.go#L455
Added line #L455 was not covered by tests


[warning] 457-457: ethergo/submitter/submitter.go#L457
Added line #L457 was not covered by tests


[warning] 459-459: ethergo/submitter/submitter.go#L459
Added line #L459 was not covered by tests


//tmpdebug
fmt.Printf("transactor.GasLimit: %d\n", transactor.GasLimit)

tx, err := call(transactor)
if err != nil {
return 0, fmt.Errorf("could not call contract: %w", err)
return 0, fmt.Errorf("err contract call for tx: %w", err)

Check warning on line 467 in ethergo/submitter/submitter.go

View check run for this annotation

Codecov / codecov/patch

ethergo/submitter/submitter.go#L467

Added line #L467 was not covered by tests
}

//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 {
Expand All @@ -436,6 +484,9 @@
span.AddEvent("trigger reprocess")
t.triggerProcessQueue(ctx)

//tmpdebug
fmt.Printf("SubmitTransaction>tx.Nonce: %d\n", tx.Nonce())

return tx.Nonce(), nil
}

Expand Down Expand Up @@ -676,18 +727,31 @@

// 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) {

Comment on lines +735 to +736
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Follow Go naming conventions.

The variable name gasLimit_new should follow Go naming conventions.

Apply this diff:

-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) (gasLimitNew uint64, err error) {
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
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) (gasLimitNew uint64, err error) {
🧰 Tools
🪛 golangci-lint (1.62.2)

[warning] 735-735: var-naming: don't use underscores in Go names; method result gasLimit_new should be gasLimitNew

(revive)

🪛 GitHub Check: codecov/patch

[warning] 735-737: ethergo/submitter/submitter.go#L735-L737
Added lines #L735 - L737 were not covered by tests

// if dynamic gas estimation is not enabled, use cfg var gas_estimate as a default

Check warning on line 732 in ethergo/submitter/submitter.go

View check run for this annotation

Codecov / codecov/patch

ethergo/submitter/submitter.go#L730-L732

Added lines #L730 - L732 were not covered by tests
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)

Check warning on line 744 in ethergo/submitter/submitter.go

View check run for this annotation

Codecov / codecov/patch

ethergo/submitter/submitter.go#L738-L744

Added lines #L738 - L744 were not covered by tests
ctx, span := t.metrics.Tracer().Start(ctx, "submitter.getGasEstimate", trace.WithAttributes(
attribute.Int(metrics.ChainID, chainID),

Check warning on line 747 in ethergo/submitter/submitter.go

View check run for this annotation

Codecov / codecov/patch

ethergo/submitter/submitter.go#L747

Added line #L747 was not covered by tests
attribute.String(metrics.TxHash, tx.Hash().String()),

attribute.Int("gasUnitAddPercentage", gasUnitAddPercentage),

Check warning on line 750 in ethergo/submitter/submitter.go

View check run for this annotation

Codecov / codecov/patch

ethergo/submitter/submitter.go#L749-L750

Added lines #L749 - L750 were not covered by tests
))

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))))

Check warning on line 754 in ethergo/submitter/submitter.go

View check run for this annotation

Codecov / codecov/patch

ethergo/submitter/submitter.go#L754

Added line #L754 was not covered by tests
metrics.EndSpanWithErr(span, err)
}()

Expand All @@ -696,21 +760,35 @@
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)
// bump gas limit from prior by X%
gasLimit_fromPrior := tx.Gas()

gasLimit_fromEstimate, err := chainClient.EstimateGas(ctx, *call)

Check warning on line 768 in ethergo/submitter/submitter.go

View check run for this annotation

Codecov / codecov/patch

ethergo/submitter/submitter.go#L765-L768

Added lines #L765 - L768 were not covered by tests
Comment on lines +770 to +773
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Follow Go naming conventions for variables.

Variable names should follow Go naming conventions.

Apply this diff:

-	gasLimit_fromPrior := tx.Gas()
-	gasLimit_fromEstimate, err := chainClient.EstimateGas(ctx, *call)
+	gasLimitFromPrior := tx.Gas()
+	gasLimitFromEstimate, err := chainClient.EstimateGas(ctx, *call)
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
gasLimit_fromPrior := tx.Gas()
gasLimit_fromEstimate, err := chainClient.EstimateGas(ctx, *call)
gasLimitFromPrior := tx.Gas()
gasLimitFromEstimate, err := chainClient.EstimateGas(ctx, *call)
🧰 Tools
🪛 golangci-lint (1.62.2)

[warning] 770-770: var-naming: don't use underscores in Go names; var gasLimit_fromPrior should be gasLimitFromPrior

(revive)


[warning] 772-772: var-naming: don't use underscores in Go names; var gasLimit_fromEstimate should be gasLimitFromEstimate

(revive)

🪛 GitHub Check: codecov/patch

[warning] 770-773: ethergo/submitter/submitter.go#L770-L773
Added lines #L770 - L773 were not covered by tests

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))
//tmpdebug
fmt.Printf("getGasEstimate> Error estimating gas: %v\n", err)

Check warning on line 772 in ethergo/submitter/submitter.go

View check run for this annotation

Codecov / codecov/patch

ethergo/submitter/submitter.go#L771-L772

Added lines #L771 - L772 were not covered by tests

// fallback to default
return t.config.GetGasEstimate(chainID), nil
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)

Check warning on line 777 in ethergo/submitter/submitter.go

View check run for this annotation

Codecov / codecov/patch

ethergo/submitter/submitter.go#L774-L777

Added lines #L774 - L777 were not covered by tests
}

return gasEstimate, nil
// use whichever 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)

Check failure on line 784 in ethergo/submitter/submitter.go

View workflow job for this annotation

GitHub Actions / Lint (ethergo)

assignOp: replace `gasLimit_new = gasLimit_new + (gasLimit_new * uint64(gasUnitAddPercentage) / 100)` with `gasLimit_new += (gasLimit_new * uint64(gasUnitAddPercentage) / 100)` (gocritic)
Comment on lines +788 to +789
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Protect against integer overflow in gas limit calculation.

The gas limit calculation could overflow when multiplying by the percentage.

Apply this diff to use big.Int for safe calculation:

-	gasLimit_new = gasLimit_new + (gasLimit_new * uint64(gasUnitAddPercentage) / 100)
+	increase := new(big.Int).SetUint64(gasLimitNew)
+	increase.Mul(increase, big.NewInt(int64(gasUnitAddPercentage)))
+	increase.Div(increase, big.NewInt(100))
+	if !increase.IsUint64() {
+		return 0, fmt.Errorf("gas limit increase exceeds uint64 max value")
+	}
+	gasLimitNew += increase.Uint64()

Committable suggestion skipped: line range outside the PR's diff.

🧰 Tools
🪛 golangci-lint (1.62.2)

789-789: assignOp: replace gasLimit_new = gasLimit_new + (gasLimit_new * uint64(gasUnitAddPercentage) / 100) with gasLimit_new += (gasLimit_new * uint64(gasUnitAddPercentage) / 100)

(gocritic)

🪛 GitHub Check: Lint (ethergo)

[failure] 789-789:
assignOp: replace gasLimit_new = gasLimit_new + (gasLimit_new * uint64(gasUnitAddPercentage) / 100) with gasLimit_new += (gasLimit_new * uint64(gasUnitAddPercentage) / 100) (gocritic)

span.AddEvent("new gas limit", trace.WithAttributes(
attribute.Int64("gas_limit", int64(gasLimit_new)),

Check failure on line 786 in ethergo/submitter/submitter.go

View workflow job for this annotation

GitHub Actions / Lint (ethergo)

G115: integer overflow conversion uint64 -> int64 (gosec)
attribute.Int64("gas_limit_from_prior", int64(gasLimit_fromPrior)),

Check failure on line 787 in ethergo/submitter/submitter.go

View workflow job for this annotation

GitHub Actions / Lint (ethergo)

G115: integer overflow conversion uint64 -> int64 (gosec)
attribute.Int64("gas_limit_from_estimate", int64(gasLimit_fromEstimate)),

Check failure on line 788 in ethergo/submitter/submitter.go

View workflow job for this annotation

GitHub Actions / Lint (ethergo)

G115: integer overflow conversion uint64 -> int64 (gosec)
))
Comment on lines +790 to +794
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Protect against integer overflow in trace attributes.

The conversion from uint64 to int64 could overflow.

Apply this diff:

-		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)),
+		attribute.String("gas_limit", fmt.Sprintf("%d", gasLimitNew)),
+		attribute.String("gas_limit_from_prior", fmt.Sprintf("%d", gasLimitFromPrior)),
+		attribute.String("gas_limit_from_estimate", fmt.Sprintf("%d", gasLimitFromEstimate)),
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
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)),
))
span.AddEvent("new gas limit", trace.WithAttributes(
attribute.String("gas_limit", fmt.Sprintf("%d", gasLimitNew)),
attribute.String("gas_limit_from_prior", fmt.Sprintf("%d", gasLimitFromPrior)),
attribute.String("gas_limit_from_estimate", fmt.Sprintf("%d", gasLimitFromEstimate)),
))
🧰 Tools
🪛 golangci-lint (1.62.2)

[high] 791-791: G115: integer overflow conversion uint64 -> int64

(gosec)


[high] 792-792: G115: integer overflow conversion uint64 -> int64

(gosec)


[high] 793-793: G115: integer overflow conversion uint64 -> int64

(gosec)

🪛 GitHub Check: Lint (ethergo)

[failure] 791-791:
G115: integer overflow conversion uint64 -> int64 (gosec)


[failure] 792-792:
G115: integer overflow conversion uint64 -> int64 (gosec)


[failure] 793-793:
G115: integer overflow conversion uint64 -> int64 (gosec)


return gasLimit_new, nil

Check warning on line 791 in ethergo/submitter/submitter.go

View check run for this annotation

Codecov / codecov/patch

ethergo/submitter/submitter.go#L781-L791

Added lines #L781 - L791 were not covered by tests
}

func (t *txSubmitterImpl) Address() common.Address {
Expand Down
15 changes: 15 additions & 0 deletions ethergo/submitter/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
Comment on lines +209 to +214
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Enhance test with assertions.
TestBox prints the gas limit of the first mock transaction but includes no checks. For completeness, consider verifying that the gas limit is within expected bounds.


// Test for the outersection function.
func TestOutersection(t *testing.T) {
set := []*big.Int{
Expand Down
21 changes: 21 additions & 0 deletions services/rfq/relayer/chain/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@
gasAmount := big.NewInt(0)
var err error

//tmpdebug

Check failure on line 77 in services/rfq/relayer/chain/chain.go

View workflow job for this annotation

GitHub Actions / Lint (services/rfq)

commentFormatting: put a space between `//` and comment text (gocritic)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Fix comment formatting to follow Go standards.

The comments don't follow Go formatting standards. There should be a space between // and the comment text.

Apply this diff to fix the formatting:

-	//tmpdebug
+	// tmpdebug

Also applies to: 92-92, 98-98

🧰 Tools
🪛 golangci-lint (1.62.2)

77-77: commentFormatting: put a space between // and comment text

(gocritic)

🪛 GitHub Check: Lint (services/rfq)

[failure] 77-77:
commentFormatting: put a space between // and comment text (gocritic)

fmt.Println("SubmitRelay>start: ", request.OriginTxHash)
Comment on lines +77 to +78
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Replace debug print with structured logging.

Replace temporary debug print with proper logging using the existing logger instance.

Apply this diff to improve the code:

-	//tmpdebug
-	fmt.Println("SubmitRelay>start: ", request.OriginTxHash)
+	logger.Debugw("starting relay submission",
+		"origin_tx_hash", request.OriginTxHash)
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
//tmpdebug
fmt.Println("SubmitRelay>start: ", request.OriginTxHash)
logger.Debugw("starting relay submission",
"origin_tx_hash", request.OriginTxHash)
🧰 Tools
🪛 golangci-lint (1.62.2)

77-77: commentFormatting: put a space between // and comment text

(gocritic)

🪛 GitHub Check: Lint (services/rfq)

[failure] 77-77:
commentFormatting: put a space between // and comment text (gocritic)


// Check to see if ETH should be sent to destination
if util.IsGasToken(request.Transaction.DestToken) {
gasAmount = request.Transaction.DestAmount
Expand All @@ -86,19 +89,37 @@
}
}

//tmpdebug

Check failure on line 92 in services/rfq/relayer/chain/chain.go

View workflow job for this annotation

GitHub Actions / Lint (services/rfq)

commentFormatting: put a space between `//` and comment text (gocritic)
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

Check failure on line 98 in services/rfq/relayer/chain/chain.go

View workflow job for this annotation

GitHub Actions / Lint (services/rfq)

commentFormatting: put a space between `//` and comment text (gocritic)
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
}
9 changes: 0 additions & 9 deletions services/rfq/relayer/quoter/quoter.go
Original file line number Diff line number Diff line change
Expand Up @@ -693,28 +693,19 @@ 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 {
logger.Error("Error getting dest amount", "error", err)
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(),
Expand Down
Loading
Loading