diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml new file mode 100644 index 000000000000..1cdac54530e5 --- /dev/null +++ b/.github/workflows/go.yml @@ -0,0 +1,31 @@ +name: Go + +on: + push: + pull_request: + branches: [ master ] + +jobs: + + build: + name: Build + runs-on: ubuntu-latest + steps: + + - name: Set up Go 1.x + uses: actions/setup-go@v2 + with: + go-version: ^1.13 + id: go + + - name: Check out code into the Go module directory + uses: actions/checkout@v2 + + - name: Build + run: make geth + + - name: Test + run: go test ./core/... ./miner ./eth/... ./rpc ./internal/ethapi/... ./les/... + + - name: Lint + run: make lint diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index f69d49fd7dd4..59a9b586dd17 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -2088,6 +2088,19 @@ func (s *BundleAPI) CallBundle(ctx context.Context, args CallBundleArgs) (map[st timeoutMilliSeconds = *args.Timeout } timeout := time.Millisecond * time.Duration(timeoutMilliSeconds) + + // Setup context so it may be cancelled the call has completed + // or, in case of unmetered gas, setup a context with a timeout. + var cancel context.CancelFunc + if timeout > 0 { + ctx, cancel = context.WithTimeout(ctx, timeout) + } else { + ctx, cancel = context.WithCancel(ctx) + } + // Make sure the context is cancelled when the call has completed + // this makes sure resources are cleaned up. + defer cancel() + state, parent, err := s.b.StateAndHeaderByNumberOrHash(ctx, args.StateBlockNumberOrHash) if state == nil || err != nil { return nil, err @@ -2126,18 +2139,6 @@ func (s *BundleAPI) CallBundle(ctx context.Context, args CallBundleArgs) (map[st BaseFee: baseFee, } - // Setup context so it may be cancelled the call has completed - // or, in case of unmetered gas, setup a context with a timeout. - var cancel context.CancelFunc - if timeout > 0 { - ctx, cancel = context.WithTimeout(ctx, timeout) - } else { - ctx, cancel = context.WithCancel(ctx) - } - // Make sure the context is cancelled when the call has completed - // this makes sure resources are cleaned up. - defer cancel() - vmconfig := vm.Config{} // Setup the gas pool (also for unmetered requests) @@ -2152,6 +2153,11 @@ func (s *BundleAPI) CallBundle(ctx context.Context, args CallBundleArgs) (map[st var totalGasUsed uint64 gasFees := new(big.Int) for i, tx := range txs { + // Check if the context was cancelled (eg. timed-out) + if err := ctx.Err(); err != nil { + return nil, err + } + coinbaseBalanceBeforeTx := state.GetBalance(coinbase) state.Prepare(tx.Hash(), i) @@ -2241,6 +2247,20 @@ func (s *BundleAPI) EstimateGasBundle(ctx context.Context, args EstimateGasBundl } timeout := time.Millisecond * time.Duration(timeoutMS) + // Setup context so it may be cancelled when the call + // has completed or, in case of unmetered gas, setup + // a context with a timeout + var cancel context.CancelFunc + if timeout > 0 { + ctx, cancel = context.WithTimeout(ctx, timeout) + } else { + ctx, cancel = context.WithCancel(ctx) + } + + // Make sure the context is cancelled when the call has completed + // This makes sure resources are cleaned up + defer cancel() + state, parent, err := s.b.StateAndHeaderByNumberOrHash(ctx, args.StateBlockNumberOrHash) if state == nil || err != nil { return nil, err @@ -2265,20 +2285,6 @@ func (s *BundleAPI) EstimateGasBundle(ctx context.Context, args EstimateGasBundl BaseFee: parent.BaseFee, } - // Setup context so it may be cancelled when the call - // has completed or, in case of unmetered gas, setup - // a context with a timeout - var cancel context.CancelFunc - if timeout > 0 { - ctx, cancel = context.WithTimeout(ctx, timeout) - } else { - ctx, cancel = context.WithCancel(ctx) - } - - // Make sure the context is cancelled when the call has completed - // This makes sure resources are cleaned up - defer cancel() - // RPC Call gas cap globalGasCap := s.b.RPCGasCap() @@ -2297,6 +2303,11 @@ func (s *BundleAPI) EstimateGasBundle(ctx context.Context, args EstimateGasBundl // Feed each of the transactions into the VM ctx // And try and estimate the gas used for i, txArgs := range args.Txs { + // Check if the context was cancelled (eg. timed-out) + if err := ctx.Err(); err != nil { + return nil, err + } + // Since its a txCall we'll just prepare the // state with a random hash var randomHash common.Hash diff --git a/internal/web3ext/web3ext.go b/internal/web3ext/web3ext.go index f93b6f2af818..8e3ae0542b5e 100644 --- a/internal/web3ext/web3ext.go +++ b/internal/web3ext/web3ext.go @@ -605,6 +605,11 @@ web3._extend({ call: 'eth_estimateGasBundle', params: 1, }), + new web3._extend.Method({ + name: 'callBundle', + call: 'eth_callBundle', + params: 6 + }), ], properties: [ new web3._extend.Property({