Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge old but still relevant PRs #143

Merged
merged 3 commits into from
Dec 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
@@ -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
63 changes: 37 additions & 26 deletions internal/ethapi/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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)

Expand Down Expand Up @@ -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
Expand All @@ -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()

Expand All @@ -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
Expand Down
5 changes: 5 additions & 0 deletions internal/web3ext/web3ext.go
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down