Skip to content

Commit

Permalink
bump approach [goreleaser]
Browse files Browse the repository at this point in the history
  • Loading branch information
parodime committed Jan 28, 2025
1 parent 82b4f99 commit 5b02cca
Showing 1 changed file with 35 additions and 22 deletions.
57 changes: 35 additions & 22 deletions ethergo/submitter/submitter.go
Original file line number Diff line number Diff line change
Expand Up @@ -435,22 +435,28 @@ func (t *txSubmitterImpl) SubmitTransaction(parentCtx context.Context, chainID *
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")
// //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
}

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
}

//tmpdebug
Expand Down Expand Up @@ -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

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) {
Expand All @@ -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))))

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 @@ -755,27 +761,34 @@ 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)

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
if err != nil {

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

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)

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
}

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

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

return gasEstimate, nil
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

0 comments on commit 5b02cca

Please sign in to comment.