Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
Geth-Modification
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
张蕾
Geth-Modification
Commits
eeebb07c
Unverified
Commit
eeebb07c
authored
Aug 07, 2023
by
Amin Talebi
Committed by
GitHub
Aug 07, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
internal/ethapi: add state override to estimateGas (#27845)
parent
d14c07d9
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
39 additions
and
9 deletions
+39
-9
graphql.go
graphql/graphql.go
+2
-2
api.go
internal/ethapi/api.go
+11
-3
api_test.go
internal/ethapi/api_test.go
+23
-1
transaction_args.go
internal/ethapi/transaction_args.go
+1
-1
web3ext.go
internal/web3ext/web3ext.go
+2
-2
No files found.
graphql/graphql.go
View file @
eeebb07c
...
...
@@ -1130,7 +1130,7 @@ func (b *Block) Call(ctx context.Context, args struct {
func
(
b
*
Block
)
EstimateGas
(
ctx
context
.
Context
,
args
struct
{
Data
ethapi
.
TransactionArgs
})
(
hexutil
.
Uint64
,
error
)
{
return
ethapi
.
DoEstimateGas
(
ctx
,
b
.
r
.
backend
,
args
.
Data
,
*
b
.
numberOrHash
,
b
.
r
.
backend
.
RPCGasCap
())
return
ethapi
.
DoEstimateGas
(
ctx
,
b
.
r
.
backend
,
args
.
Data
,
*
b
.
numberOrHash
,
nil
,
b
.
r
.
backend
.
RPCGasCap
())
}
type
Pending
struct
{
...
...
@@ -1194,7 +1194,7 @@ func (p *Pending) EstimateGas(ctx context.Context, args struct {
Data
ethapi
.
TransactionArgs
})
(
hexutil
.
Uint64
,
error
)
{
latestBlockNr
:=
rpc
.
BlockNumberOrHashWithNumber
(
rpc
.
LatestBlockNumber
)
return
ethapi
.
DoEstimateGas
(
ctx
,
p
.
r
.
backend
,
args
.
Data
,
latestBlockNr
,
p
.
r
.
backend
.
RPCGasCap
())
return
ethapi
.
DoEstimateGas
(
ctx
,
p
.
r
.
backend
,
args
.
Data
,
latestBlockNr
,
nil
,
p
.
r
.
backend
.
RPCGasCap
())
}
// Resolver is the top-level object in the GraphQL hierarchy.
...
...
internal/ethapi/api.go
View file @
eeebb07c
...
...
@@ -1134,7 +1134,7 @@ func (s *BlockChainAPI) Call(ctx context.Context, args TransactionArgs, blockNrO
return
result
.
Return
(),
result
.
Err
}
func
DoEstimateGas
(
ctx
context
.
Context
,
b
Backend
,
args
TransactionArgs
,
blockNrOrHash
rpc
.
BlockNumberOrHash
,
gasCap
uint64
)
(
hexutil
.
Uint64
,
error
)
{
func
DoEstimateGas
(
ctx
context
.
Context
,
b
Backend
,
args
TransactionArgs
,
blockNrOrHash
rpc
.
BlockNumberOrHash
,
overrides
*
StateOverride
,
gasCap
uint64
)
(
hexutil
.
Uint64
,
error
)
{
// Binary search the gas requirement, as it may be higher than the amount used
var
(
lo
uint64
=
params
.
TxGas
-
1
...
...
@@ -1176,6 +1176,10 @@ func DoEstimateGas(ctx context.Context, b Backend, args TransactionArgs, blockNr
if
err
!=
nil
{
return
0
,
err
}
err
=
overrides
.
Apply
(
state
)
if
err
!=
nil
{
return
0
,
err
}
balance
:=
state
.
GetBalance
(
*
args
.
From
)
// from can't be nil
available
:=
new
(
big
.
Int
)
.
Set
(
balance
)
if
args
.
Value
!=
nil
{
...
...
@@ -1221,6 +1225,10 @@ func DoEstimateGas(ctx context.Context, b Backend, args TransactionArgs, blockNr
if
state
==
nil
||
err
!=
nil
{
return
0
,
err
}
err
=
overrides
.
Apply
(
state
)
if
err
!=
nil
{
return
0
,
err
}
// Execute the binary search and hone in on an executable gas limit
for
lo
+
1
<
hi
{
s
:=
state
.
Copy
()
...
...
@@ -1261,12 +1269,12 @@ func DoEstimateGas(ctx context.Context, b Backend, args TransactionArgs, blockNr
// EstimateGas returns an estimate of the amount of gas needed to execute the
// given transaction against the current pending block.
func
(
s
*
BlockChainAPI
)
EstimateGas
(
ctx
context
.
Context
,
args
TransactionArgs
,
blockNrOrHash
*
rpc
.
BlockNumberOrHash
)
(
hexutil
.
Uint64
,
error
)
{
func
(
s
*
BlockChainAPI
)
EstimateGas
(
ctx
context
.
Context
,
args
TransactionArgs
,
blockNrOrHash
*
rpc
.
BlockNumberOrHash
,
overrides
*
StateOverride
)
(
hexutil
.
Uint64
,
error
)
{
bNrOrHash
:=
rpc
.
BlockNumberOrHashWithNumber
(
rpc
.
LatestBlockNumber
)
if
blockNrOrHash
!=
nil
{
bNrOrHash
=
*
blockNrOrHash
}
return
DoEstimateGas
(
ctx
,
s
.
b
,
args
,
bNrOrHash
,
s
.
b
.
RPCGasCap
())
return
DoEstimateGas
(
ctx
,
s
.
b
,
args
,
bNrOrHash
,
overrides
,
s
.
b
.
RPCGasCap
())
}
// RPCMarshalHeader converts the given header to the RPC output .
...
...
internal/ethapi/api_test.go
View file @
eeebb07c
...
...
@@ -560,6 +560,7 @@ func TestEstimateGas(t *testing.T) {
var
testSuite
=
[]
struct
{
blockNumber
rpc
.
BlockNumber
call
TransactionArgs
overrides
StateOverride
expectErr
error
want
uint64
}{
...
...
@@ -592,9 +593,30 @@ func TestEstimateGas(t *testing.T) {
expectErr
:
nil
,
want
:
53000
,
},
{
blockNumber
:
rpc
.
LatestBlockNumber
,
call
:
TransactionArgs
{},
overrides
:
StateOverride
{
randomAccounts
[
0
]
.
addr
:
OverrideAccount
{
Balance
:
newRPCBalance
(
new
(
big
.
Int
)
.
Mul
(
big
.
NewInt
(
1
),
big
.
NewInt
(
params
.
Ether
)))},
},
expectErr
:
nil
,
want
:
53000
,
},
{
blockNumber
:
rpc
.
LatestBlockNumber
,
call
:
TransactionArgs
{
From
:
&
randomAccounts
[
0
]
.
addr
,
To
:
&
randomAccounts
[
1
]
.
addr
,
Value
:
(
*
hexutil
.
Big
)(
big
.
NewInt
(
1000
)),
},
overrides
:
StateOverride
{
randomAccounts
[
0
]
.
addr
:
OverrideAccount
{
Balance
:
newRPCBalance
(
big
.
NewInt
(
0
))},
},
expectErr
:
core
.
ErrInsufficientFunds
,
},
}
for
i
,
tc
:=
range
testSuite
{
result
,
err
:=
api
.
EstimateGas
(
context
.
Background
(),
tc
.
call
,
&
rpc
.
BlockNumberOrHash
{
BlockNumber
:
&
tc
.
blockNumber
})
result
,
err
:=
api
.
EstimateGas
(
context
.
Background
(),
tc
.
call
,
&
rpc
.
BlockNumberOrHash
{
BlockNumber
:
&
tc
.
blockNumber
}
,
&
tc
.
overrides
)
if
tc
.
expectErr
!=
nil
{
if
err
==
nil
{
t
.
Errorf
(
"test %d: want error %v, have nothing"
,
i
,
tc
.
expectErr
)
...
...
internal/ethapi/transaction_args.go
View file @
eeebb07c
...
...
@@ -111,7 +111,7 @@ func (args *TransactionArgs) setDefaults(ctx context.Context, b Backend) error {
AccessList
:
args
.
AccessList
,
}
pendingBlockNr
:=
rpc
.
BlockNumberOrHashWithNumber
(
rpc
.
PendingBlockNumber
)
estimated
,
err
:=
DoEstimateGas
(
ctx
,
b
,
callArgs
,
pendingBlockNr
,
b
.
RPCGasCap
())
estimated
,
err
:=
DoEstimateGas
(
ctx
,
b
,
callArgs
,
pendingBlockNr
,
nil
,
b
.
RPCGasCap
())
if
err
!=
nil
{
return
err
}
...
...
internal/web3ext/web3ext.go
View file @
eeebb07c
...
...
@@ -536,8 +536,8 @@ web3._extend({
new web3._extend.Method({
name: 'estimateGas',
call: 'eth_estimateGas',
params:
2
,
inputFormatter: [web3._extend.formatters.inputCallFormatter, web3._extend.formatters.inputBlockNumberFormatter],
params:
3
,
inputFormatter: [web3._extend.formatters.inputCallFormatter, web3._extend.formatters.inputBlockNumberFormatter
, null
],
outputFormatter: web3._extend.utils.toDecimal
}),
new web3._extend.Method({
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment