Skip to content

Commit 53405db

Browse files
committed
eth: internal: add eth_maxEnvelopeGas API
1 parent 756eb95 commit 53405db

File tree

7 files changed

+52
-0
lines changed

7 files changed

+52
-0
lines changed

eth/api_backend.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030
"github.com/ethereum/go-ethereum/core/bloombits"
3131
"github.com/ethereum/go-ethereum/core/rawdb"
3232
"github.com/ethereum/go-ethereum/core/state"
33+
"github.com/ethereum/go-ethereum/core/systemcontracts"
3334
"github.com/ethereum/go-ethereum/core/txpool"
3435
"github.com/ethereum/go-ethereum/core/types"
3536
"github.com/ethereum/go-ethereum/core/vm"
@@ -381,6 +382,14 @@ func (b *EthAPIBackend) EnvelopeFee(ctx context.Context) (*big.Int, error) {
381382
return b.gpo.EnvelopeFee(ctx)
382383
}
383384

385+
func (b *EthAPIBackend) MaxEnvelopeGas(ctx context.Context) (*big.Int, error) {
386+
stateDb, err := b.eth.blockchain.State()
387+
if err != nil {
388+
return nil, err
389+
}
390+
return stateDb.GetState(systemcontracts.PolicyProxyHash, systemcontracts.GetMaxEnvelopeGasLimitStateHash()).Big(), nil
391+
}
392+
384393
func (b *EthAPIBackend) FeeHistory(ctx context.Context, blockCount uint64, lastBlock rpc.BlockNumber, rewardPercentiles []float64) (firstBlock *big.Int, reward [][]*big.Int, baseFee []*big.Int, gasUsedRatio []float64, err error) {
385394
return b.gpo.FeeHistory(ctx, blockCount, lastBlock, rewardPercentiles)
386395
}

ethclient/ethclient.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,15 @@ func (ec *Client) EnvelopeFee(ctx context.Context) (*big.Int, error) {
577577
return (*big.Int)(&hex), nil
578578
}
579579

580+
// MaxEnvelopeGas retrieves the currently maximum envelope gas limit policy.
581+
func (ec *Client) MaxEnvelopeGas(ctx context.Context) (*big.Int, error) {
582+
var hex hexutil.Big
583+
if err := ec.c.CallContext(ctx, &hex, "eth_maxEnvelopeGas"); err != nil {
584+
return nil, err
585+
}
586+
return (*big.Int)(&hex), nil
587+
}
588+
580589
type feeHistoryResultMarshaling struct {
581590
OldestBlock *hexutil.Big `json:"oldestBlock"`
582591
Reward [][]*hexutil.Big `json:"reward,omitempty"`

ethclient/ethclient_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,24 @@ func testStatusFunctions(t *testing.T, client *rpc.Client) {
515515
t.Fatalf("unexpected gas tip cap: %v", gasTipCap)
516516
}
517517

518+
// EnvelopeFee
519+
envelopeFee, err := ec.EnvelopeFee(context.Background())
520+
if err != nil {
521+
t.Fatalf("unexpected error: %v", err)
522+
}
523+
if envelopeFee.Cmp(big.NewInt(0)) != 0 {
524+
t.Fatalf("unexpected envelope fee: %v", envelopeFee)
525+
}
526+
527+
// MaxEnvelopeGas
528+
maxEnvelopeGas, err := ec.MaxEnvelopeGas(context.Background())
529+
if err != nil {
530+
t.Fatalf("unexpected error: %v", err)
531+
}
532+
if maxEnvelopeGas.Cmp(big.NewInt(0)) != 0 {
533+
t.Fatalf("unexpected max envelope gas: %v", maxEnvelopeGas)
534+
}
535+
518536
// FeeHistory
519537
history, err := ec.FeeHistory(context.Background(), 1, big.NewInt(2), []float64{95, 99})
520538
if err != nil {

internal/ethapi/api.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,15 @@ func (s *EthereumAPI) EnvelopeFee(ctx context.Context) (*hexutil.Big, error) {
104104
return (*hexutil.Big)(fee), err
105105
}
106106

107+
// MaxEnvelopeGas returns the maximum envelope gas limit allowed by policy
108+
func (s *EthereumAPI) MaxEnvelopeGas(ctx context.Context) (*hexutil.Big, error) {
109+
maxGas, err := s.b.MaxEnvelopeGas(ctx)
110+
if err != nil {
111+
return nil, err
112+
}
113+
return (*hexutil.Big)(maxGas), err
114+
}
115+
107116
type feeHistoryResult struct {
108117
OldestBlock *hexutil.Big `json:"oldestBlock"`
109118
Reward [][]*hexutil.Big `json:"reward,omitempty"`

internal/ethapi/api_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,9 @@ func (b testBackend) SuggestGasTipCap(ctx context.Context) (*big.Int, error) {
471471
func (b testBackend) EnvelopeFee(ctx context.Context) (*big.Int, error) {
472472
return big.NewInt(0), nil
473473
}
474+
func (b testBackend) MaxEnvelopeGas(ctx context.Context) (*big.Int, error) {
475+
return big.NewInt(0), nil
476+
}
474477
func (b testBackend) FeeHistory(ctx context.Context, blockCount uint64, lastBlock rpc.BlockNumber, rewardPercentiles []float64) (*big.Int, [][]*big.Int, []*big.Int, []float64, error) {
475478
return nil, nil, nil, nil, nil
476479
}

internal/ethapi/backend.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ type Backend interface {
4545

4646
SuggestGasTipCap(ctx context.Context) (*big.Int, error)
4747
EnvelopeFee(ctx context.Context) (*big.Int, error)
48+
MaxEnvelopeGas(ctx context.Context) (*big.Int, error)
4849
FeeHistory(ctx context.Context, blockCount uint64, lastBlock rpc.BlockNumber, rewardPercentiles []float64) (*big.Int, [][]*big.Int, []*big.Int, []float64, error)
4950
ChainDb() ethdb.Database
5051
AccountManager() *accounts.Manager

internal/ethapi/transaction_args_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,9 @@ func (b *backendMock) SuggestGasTipCap(ctx context.Context) (*big.Int, error) {
317317
func (b *backendMock) EnvelopeFee(ctx context.Context) (*big.Int, error) {
318318
return big.NewInt(42), nil
319319
}
320+
func (b *backendMock) MaxEnvelopeGas(ctx context.Context) (*big.Int, error) {
321+
return big.NewInt(42), nil
322+
}
320323
func (b *backendMock) CurrentHeader() *types.Header { return b.current }
321324
func (b *backendMock) ChainConfig() *params.ChainConfig { return b.config }
322325

0 commit comments

Comments
 (0)