Skip to content

Commit

Permalink
fix: return exact result when send bundle (#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
irrun authored Jul 11, 2024
1 parent 5d89879 commit b6cf5b6
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 5 deletions.
2 changes: 2 additions & 0 deletions core/types/bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ type SimulatedBundle struct {
BundleGasPrice *big.Int
BundleGasUsed uint64
EthSentToSystem *big.Int

Err error
}

func (bundle *Bundle) Size() uint64 {
Expand Down
2 changes: 1 addition & 1 deletion miner/bundle_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func (c *BundleCacheEntry) UpdateSimulatedBundles(result map[common.Hash]*types.

bundleHash := bundle.Hash()

if result[bundleHash] != nil {
if result[bundleHash] != nil && result[bundleHash].Err == nil {
c.successfulBundles[bundleHash] = result[bundleHash]
} else {
c.failedBundles[bundleHash] = struct{}{}
Expand Down
4 changes: 4 additions & 0 deletions miner/miner.go
Original file line number Diff line number Diff line change
Expand Up @@ -377,5 +377,9 @@ func (miner *Miner) SimulateBundle(bundle *types.Bundle) (*big.Int, error) {
return nil, errors.New("no valid sim result")
}

if s[0].Err != nil {
return nil, s[0].Err
}

return s[0].BundleGasPrice, nil
}
15 changes: 11 additions & 4 deletions miner/worker_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,15 +265,22 @@ func (w *worker) generateOrderedBundles(
return nil, nil, err
}

noErrBundles := make([]*types.SimulatedBundle, 0)
for _, v := range simulatedBundles {
if v.Err == nil {
noErrBundles = append(noErrBundles, v)
}
}

// sort bundles according to fresh gas price
sort.SliceStable(simulatedBundles, func(i, j int) bool {
priceI, priceJ := simulatedBundles[i].BundleGasPrice, simulatedBundles[j].BundleGasPrice
sort.SliceStable(noErrBundles, func(i, j int) bool {
priceI, priceJ := noErrBundles[i].BundleGasPrice, noErrBundles[j].BundleGasPrice

return priceI.Cmp(priceJ) >= 0
})

// merge bundles based on iterative state
includedTxs, mergedBundle, err := w.mergeBundles(env, simulatedBundles)
includedTxs, mergedBundle, err := w.mergeBundles(env, noErrBundles)
if err != nil {
log.Error("fail to merge bundles", "err", err)
return nil, nil, err
Expand Down Expand Up @@ -304,8 +311,8 @@ func (w *worker) simulateBundles(env *environment, bundles []*types.Bundle) ([]*
gasPool := prepareGasPool(env.header.GasLimit)
simmed, err := w.simulateBundle(env, bundle, state, gasPool, 0, true, true)
if err != nil {
simmed = &types.SimulatedBundle{Err: err}
log.Trace("Error computing gas for a simulateBundle", "error", err)
return
}

mu.Lock()
Expand Down

0 comments on commit b6cf5b6

Please sign in to comment.