Skip to content
This repository has been archived by the owner on May 13, 2024. It is now read-only.

Commit

Permalink
Merge pull request #5 from zeta-chain/backport-1782-revert-non-upgrad…
Browse files Browse the repository at this point in the history
…e-commits

Backport 1782 revert non upgrade commits
  • Loading branch information
skosito authored Apr 23, 2024
2 parents f99cf16 + 952b055 commit 20ee767
Show file tree
Hide file tree
Showing 31 changed files with 222 additions and 976 deletions.
1 change: 0 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ jobs:

integration_tests:
runs-on: ubuntu-latest
timeout-minutes: 60
steps:
- uses: actions/checkout@v3
- uses: cachix/install-nix-action@v20
Expand Down
9 changes: 0 additions & 9 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,6 @@ Ref: https://keepachangelog.com/en/1.0.0/

## Unreleased

### Features

* (rpc) [#1682](https://github.com/evmos/ethermint/pull/1682) Add config for maximum number of bytes returned from eth_call.

### State Machine Breaking

- (deps) [#1168](https://github.com/evmos/ethermint/pull/1716) Bump Cosmos-SDK to v0.46.11, Tendermint to v0.34.27, IAVL v0.19.5 and btcd to v0.23.4
Expand All @@ -53,15 +49,10 @@ Ref: https://keepachangelog.com/en/1.0.0/
### Bug Fixes

- (rpc) [#1688](https://github.com/evmos/ethermint/pull/1688) Align filter rule for `debug_traceBlockByNumber`
- (rpc) [#1722](https://github.com/evmos/ethermint/pull/1722) Align revert response for `eth_estimateGas` and `eth_call` as Ethereum.
- (rpc) [#1720](https://github.com/evmos/ethermint/pull/1720) Fix next block fee for historical block and calculate base fee by params.
- (rpc) [#1685](https://github.com/evmos/ethermint/pull/1685) Fix parse for websocket connID.
- (rpc) [#1773](https://github.com/evmos/ethermint/pull/1773) Avoid channel get changed when concurrent subscribe happens.

### Improvements

- (ante) [#1717](https://github.com/evmos/ethermint/pull/1717) Reuse sender recovery result.
- (cli) [#242](https://github.com/crypto-org-chain/ethermint/pull/242) Integrate tendermint bootstrap cmd.
- (cli) [#246](https://github.com/crypto-org-chain/ethermint/pull/246) Call app.Close to cleanup resource on graceful shutdown.


Expand Down
2 changes: 0 additions & 2 deletions docs/api/proto-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -547,8 +547,6 @@ EstimateGasResponse defines EstimateGas response
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `gas` | [uint64](#uint64) | | the estimated gas |
| `ret` | [bytes](#bytes) | | ret is the returned data from evm function (result or data supplied with revert opcode) |
| `vm_error` | [string](#string) | | vm_error is the error returned by vm execution |



Expand Down
2 changes: 1 addition & 1 deletion gomod2nix.toml
Original file line number Diff line number Diff line change
Expand Up @@ -624,4 +624,4 @@ schema = 3
hash = "sha256-VUgKDG+AcSVdsqKk5H4doz2rvehsWgt8rdZPDMKFDtE="
[mod."sigs.k8s.io/yaml"]
version = "v1.3.0"
hash = "sha256-RVp8vca2wxg8pcBDYospG7Z1dujoH7zXNu2rgZ1kky0="
hash = "sha256-RVp8vca2wxg8pcBDYospG7Z1dujoH7zXNu2rgZ1kky0="
5 changes: 0 additions & 5 deletions proto/ethermint/evm/v1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -231,11 +231,6 @@ message EthCallRequest {
message EstimateGasResponse {
// gas returns the estimated gas
uint64 gas = 1;
// ret is the returned data from evm function (result or data supplied with revert
// opcode)
bytes ret = 2;
// vm_error is the error returned by vm execution
string vm_error = 3;
}

// QueryTraceTxRequest defines TraceTx request
Expand Down
29 changes: 6 additions & 23 deletions rpc/backend/call_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,20 +304,6 @@ func (b *Backend) SetTxDefaults(args evmtypes.TransactionArgs) (evmtypes.Transac
return args, nil
}

// handleRevertError returns revert related error.
func (b *Backend) handleRevertError(vmError string, ret []byte) error {
if len(vmError) > 0 {
if vmError != vm.ErrExecutionReverted.Error() {
return status.Error(codes.Internal, vmError)
}
if len(ret) == 0 {
return errors.New(vmError)
}
return evmtypes.NewExecErrorWithReason(ret)
}
return nil
}

// EstimateGas returns an estimate of gas usage for the given smart contract call.
func (b *Backend) EstimateGas(args evmtypes.TransactionArgs, blockNrOptional *rpctypes.BlockNumber) (hexutil.Uint64, error) {
blockNr := rpctypes.EthPendingBlockNumber
Expand Down Expand Up @@ -350,9 +336,6 @@ func (b *Backend) EstimateGas(args evmtypes.TransactionArgs, blockNrOptional *rp
if err != nil {
return 0, err
}
if err = b.handleRevertError(res.VmError, res.Ret); err != nil {
return 0, err
}
return hexutil.Uint64(res.Gas), nil
}

Expand Down Expand Up @@ -401,14 +384,14 @@ func (b *Backend) DoCall(
if err != nil {
return nil, err
}
length := len(res.Ret)
if length > int(b.cfg.JSONRPC.ReturnDataLimit) && b.cfg.JSONRPC.ReturnDataLimit != 0 {
return nil, fmt.Errorf("call retuned result on length %d exceeding limit %d", length, b.cfg.JSONRPC.ReturnDataLimit)
}

if err = b.handleRevertError(res.VmError, res.Ret); err != nil {
return nil, err
if res.Failed() {
if res.VmError != vm.ErrExecutionReverted.Error() {
return nil, status.Error(codes.Internal, res.VmError)
}
return nil, evmtypes.NewExecErrorWithReason(res.Ret)
}

return res, nil
}

Expand Down
124 changes: 42 additions & 82 deletions rpc/backend/chain_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@ package backend

import (
"fmt"
"math"
"math/big"
"strconv"
"sync"

tmrpcclient "github.com/cometbft/cometbft/rpc/client"
tmrpctypes "github.com/cometbft/cometbft/rpc/core/types"
Expand Down Expand Up @@ -161,42 +159,29 @@ func (b *Backend) GetCoinbase() (sdk.AccAddress, error) {
return address, nil
}

var (
errInvalidPercentile = fmt.Errorf("invalid reward percentile")
errRequestBeyondHead = fmt.Errorf("request beyond head block")
)

// FeeHistory returns data relevant for fee estimation based on the specified range of blocks.
func (b *Backend) FeeHistory(
userBlockCount rpc.DecimalOrHex, // number blocks to fetch, maximum is 100
lastBlock rpc.BlockNumber, // the block to start search , to oldest
rewardPercentiles []float64, // percentiles to fetch reward
) (*rpctypes.FeeHistoryResult, error) {
for i, p := range rewardPercentiles {
if p < 0 || p > 100 {
return nil, fmt.Errorf("%w: %f", errInvalidPercentile, p)
}
if i > 0 && p < rewardPercentiles[i-1] {
return nil, fmt.Errorf("%w: #%d:%f > #%d:%f", errInvalidPercentile, i-1, rewardPercentiles[i-1], i, p)
}
}
blockNumber, err := b.BlockNumber()
if err != nil {
return nil, err
}
blockEnd := int64(lastBlock)

if blockEnd < 0 {
blockNumber, err := b.BlockNumber()
if err != nil {
return nil, err
}
blockEnd = int64(blockNumber)
} else if int64(blockNumber) < blockEnd {
return nil, fmt.Errorf("%w: requested %d, head %d", errRequestBeyondHead, blockEnd, int64(blockNumber))
}

blocks := int64(userBlockCount)
maxBlockCount := int64(b.cfg.JSONRPC.FeeHistoryCap)
if blocks > maxBlockCount {
return nil, fmt.Errorf("FeeHistory user block count %d higher than %d", blocks, maxBlockCount)
}
if blockEnd < math.MaxInt64 && blockEnd+1 < blocks {

if blockEnd+1 < blocks {
blocks = blockEnd + 1
}
// Ensure not trying to retrieve before genesis.
Expand All @@ -215,72 +200,47 @@ func (b *Backend) FeeHistory(

// rewards should only be calculated if reward percentiles were included
calculateRewards := rewardCount != 0
const maxBlockFetchers = 4
for blockID := blockStart; blockID <= blockEnd; blockID += maxBlockFetchers {
wg := sync.WaitGroup{}
wgDone := make(chan bool)
chanErr := make(chan error)
for i := 0; i < maxBlockFetchers; i++ {
if blockID+int64(i) >= blockEnd+1 {
break
}
wg.Add(1)
go func(index int32) {
defer wg.Done()
// fetch block
// tendermint block
blockNum := rpctypes.BlockNumber(blockStart + int64(index))
tendermintblock, err := b.TendermintBlockByNumber(blockNum)
if tendermintblock == nil {
chanErr <- err
return
}

// eth block
ethBlock, err := b.GetBlockByNumber(blockNum, true)
if ethBlock == nil {
chanErr <- err
return
}

// tendermint block result
tendermintBlockResult, err := b.TendermintBlockResultByNumber(&tendermintblock.Block.Height)
if tendermintBlockResult == nil {
b.logger.Debug("block result not found", "height", tendermintblock.Block.Height, "error", err.Error())
chanErr <- err
return
}
// fetch block
for blockID := blockStart; blockID <= blockEnd; blockID++ {
index := int32(blockID - blockStart)
// tendermint block
tendermintblock, err := b.TendermintBlockByNumber(rpctypes.BlockNumber(blockID))
if tendermintblock == nil {
return nil, err
}

oneFeeHistory := rpctypes.OneFeeHistory{}
err = b.processBlock(tendermintblock, &ethBlock, rewardPercentiles, tendermintBlockResult, &oneFeeHistory)
if err != nil {
chanErr <- err
return
}
// eth block
ethBlock, err := b.GetBlockByNumber(rpctypes.BlockNumber(blockID), true)
if ethBlock == nil {
return nil, err
}

// copy
thisBaseFee[index] = (*hexutil.Big)(oneFeeHistory.BaseFee)
thisBaseFee[index+1] = (*hexutil.Big)(oneFeeHistory.NextBaseFee)
thisGasUsedRatio[index] = oneFeeHistory.GasUsedRatio
if calculateRewards {
for j := 0; j < rewardCount; j++ {
reward[index][j] = (*hexutil.Big)(oneFeeHistory.Reward[j])
if reward[index][j] == nil {
reward[index][j] = (*hexutil.Big)(big.NewInt(0))
}
}
}
}(int32(blockID - blockStart + int64(i)))
// tendermint block result
tendermintBlockResult, err := b.TendermintBlockResultByNumber(&tendermintblock.Block.Height)
if tendermintBlockResult == nil {
b.logger.Debug("block result not found", "height", tendermintblock.Block.Height, "error", err.Error())
return nil, err
}
go func() {
wg.Wait()
close(wgDone)
}()
select {
case <-wgDone:
case err := <-chanErr:

oneFeeHistory := rpctypes.OneFeeHistory{}
err = b.processBlock(tendermintblock, &ethBlock, rewardPercentiles, tendermintBlockResult, &oneFeeHistory)
if err != nil {
return nil, err
}

// copy
thisBaseFee[index] = (*hexutil.Big)(oneFeeHistory.BaseFee)
thisBaseFee[index+1] = (*hexutil.Big)(oneFeeHistory.NextBaseFee)
thisGasUsedRatio[index] = oneFeeHistory.GasUsedRatio
if calculateRewards {
for j := 0; j < rewardCount; j++ {
reward[index][j] = (*hexutil.Big)(oneFeeHistory.Reward[j])
if reward[index][j] == nil {
reward[index][j] = (*hexutil.Big)(big.NewInt(0))
}
}
}
}

feeHistory := rpctypes.FeeHistoryResult{
Expand Down
10 changes: 0 additions & 10 deletions rpc/backend/chain_info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -361,9 +361,6 @@ func (suite *BackendTestSuite) TestFeeHistory() {
func(validator sdk.AccAddress) {
client := suite.backend.clientCtx.Client.(*mocks.Client)
suite.backend.cfg.JSONRPC.FeeHistoryCap = 2
var header metadata.MD
queryClient := suite.backend.queryClient.QueryClient.(*mocks.EVMQueryClient)
RegisterParams(queryClient, &header, 1)
RegisterBlockError(client, ethrpc.BlockNumber(1).Int64())
},
1,
Expand All @@ -377,9 +374,6 @@ func (suite *BackendTestSuite) TestFeeHistory() {
func(validator sdk.AccAddress) {
client := suite.backend.clientCtx.Client.(*mocks.Client)
suite.backend.cfg.JSONRPC.FeeHistoryCap = 2
var header metadata.MD
queryClient := suite.backend.queryClient.QueryClient.(*mocks.EVMQueryClient)
RegisterParams(queryClient, &header, 1)
RegisterBlock(client, ethrpc.BlockNumber(1).Int64(), nil)
RegisterBlockResultsError(client, 1)
},
Expand All @@ -396,8 +390,6 @@ func (suite *BackendTestSuite) TestFeeHistory() {
queryClient := suite.backend.queryClient.QueryClient.(*mocks.EVMQueryClient)
client := suite.backend.clientCtx.Client.(*mocks.Client)
suite.backend.cfg.JSONRPC.FeeHistoryCap = 2
var header metadata.MD
RegisterParams(queryClient, &header, 1)
RegisterBlock(client, ethrpc.BlockNumber(1).Int64(), nil)
RegisterBlockResults(client, 1)
RegisterBaseFeeError(queryClient)
Expand All @@ -416,7 +408,6 @@ func (suite *BackendTestSuite) TestFeeHistory() {
var header metadata.MD
baseFee := sdk.NewInt(1)
queryClient := suite.backend.queryClient.QueryClient.(*mocks.EVMQueryClient)
fQueryClient := suite.backend.queryClient.FeeMarket.(*mocks.FeeMarketQueryClient)
client := suite.backend.clientCtx.Client.(*mocks.Client)
suite.backend.cfg.JSONRPC.FeeHistoryCap = 2
RegisterBlock(client, ethrpc.BlockNumber(1).Int64(), nil)
Expand All @@ -426,7 +417,6 @@ func (suite *BackendTestSuite) TestFeeHistory() {
RegisterConsensusParams(client, 1)
RegisterParams(queryClient, &header, 1)
RegisterParamsWithoutHeader(queryClient, 1)
RegisterFeeMarketParams(fQueryClient, 1)
},
1,
1,
Expand Down
Loading

0 comments on commit 20ee767

Please sign in to comment.