eth_call 模拟交易 实现抢跑 无法达到0区块

透过eth_call 不断模拟买入 直到模拟成功 才去买入, 为什么gasPrice多高还是会慢1个区块。

然后我又改了geth源码,让他模拟的时候把txpool的交易也算进去了。他就直接比开盘的函数快2个区块。如何让我的交易紧跟着开盘的交易走。是要比开盘的交易的gasprice低一点点吗

bsc的geth 修改过的DoCall的源码在这里

func DoCall(ctx context.Context, b Backend, args TransactionArgs, blockNrOrHash rpc.BlockNumberOrHash, overrides *StateOverride, blockOverrides *BlockOverrides, timeout time.Duration, globalGasCap uint64) (*core.ExecutionResult, error) {
    defer func(start time.Time) { log.Debug("Executing EVM call finished", "runtime", time.Since(start)) }(time.Now())

    state, header, err := b.StateAndHeaderByNumberOrHash(ctx, blockNrOrHash)
    if state == nil || err != nil {
        return nil, err
    }

    pendingTxs, err := b.GetPoolTransactions()
    if err != nil {
        return nil, err
    }

    tmpStatedb := state.Copy()
    for _, tx := range pendingTxs {
        if tx.To() == args.To {
            msg, err := core.TransactionToMessage(tx, types.LatestSigner(b.ChainConfig()), header.BaseFee)
            if err != nil {
                return nil, err
            }

            txCtx := core.NewEVMTxContext(msg)
            context := core.NewEVMBlockContext(header, NewChainContext(ctx, b), nil)
            evm := vm.NewEVM(context, txCtx, tmpStatedb, b.ChainConfig(), vm.Config{NoBaseFee: true})

            _, err = core.ApplyMessage(evm, msg, new(core.GasPool))
            if err != nil {
                return nil, err
            }
        } else {
            continue
        }

    }
    return doCall(ctx, b, args, tmpStatedb, header, overrides, blockOverrides, timeout, globalGasCap)
}

python中大概的实现就是:

def simulate():
    eth_call(xxxx)

def main():
    while 1:
        if simulate == True:
            买入
请先 登录 后评论
  • 0 关注
  • 0 收藏,1580 浏览
  • 用户_20687 提出于 2024-06-01 01:47