Skip to content

Commit

Permalink
Merge d8481f2 into 60f0e4c
Browse files Browse the repository at this point in the history
  • Loading branch information
parodime authored Jan 24, 2025
2 parents 60f0e4c + d8481f2 commit fda62d9
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 20 deletions.
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 @@ 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 (
Expand All @@ -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.
Expand Down Expand Up @@ -188,19 +194,37 @@ 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) {
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)
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.

40 changes: 31 additions & 9 deletions ethergo/submitter/submitter.go
Original file line number Diff line number Diff line change
Expand Up @@ -392,9 +392,6 @@ 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()))
}

transactor.Signer = func(address common.Address, transaction *types.Transaction) (_ *types.Transaction, err error) {
locker = t.nonceMux.Lock(chainID)
Expand All @@ -421,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)
}
Expand Down Expand Up @@ -677,13 +689,25 @@ 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()),

// 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.Int("gasUnitAddPercentage", gasUnitAddPercentage),
))

defer func() {
Expand All @@ -696,20 +720,18 @@ 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
}

// Modify the gasEstimate by the configured percentage
gasEstimate = gasEstimate + (gasEstimate * uint64(gasUnitAddPercentage) / 100)

return gasEstimate, nil
}

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

// Test for the outersection function.
func TestOutersection(t *testing.T) {
set := []*big.Int{
Expand Down
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

0 comments on commit fda62d9

Please sign in to comment.