Skip to content

Commit

Permalink
Get gas price suggestion from the correct block (#817)
Browse files Browse the repository at this point in the history
# Conflicts:
#	internal/ethapi/api.go
  • Loading branch information
mrsmkl authored and Mariano Cortesi committed Jan 31, 2020
1 parent 8c1e533 commit 8807079
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 10 deletions.
9 changes: 6 additions & 3 deletions contract_comm/gasprice_minimum/gasprice_minimum.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
"github.com/ethereum/go-ethereum/contract_comm/errors"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/params"
)

Expand Down Expand Up @@ -101,11 +100,9 @@ func GetGasPriceMinimum(currency *common.Address, header *types.Header, state vm
return FallbackGasPriceMinimum, nil
}
if err == errors.ErrNoInternalEvmHandlerSingleton {
log.Error(err.Error())
return FallbackGasPriceMinimum, nil
}
if err != nil {
log.Error(err.Error())
return FallbackGasPriceMinimum, err
}
} else {
Expand All @@ -124,6 +121,12 @@ func GetGasPriceMinimum(currency *common.Address, header *types.Header, state vm
state,
)

if err == errors.ErrSmartContractNotDeployed || err == errors.ErrRegistryContractNotDeployed {
return FallbackGasPriceMinimum, nil
}
if err == errors.ErrNoInternalEvmHandlerSingleton {
return FallbackGasPriceMinimum, nil
}
if err != nil {
return FallbackGasPriceMinimum, err
}
Expand Down
4 changes: 2 additions & 2 deletions eth/api_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,8 +270,8 @@ func (b *EthAPIBackend) SuggestPrice(ctx context.Context) (*big.Int, error) {
return gpm.GetGasPriceSuggestion(nil, nil, nil)
}

func (b *EthAPIBackend) SuggestPriceInCurrency(ctx context.Context, currencyAddress *common.Address) (*big.Int, error) {
return gpm.GetGasPriceSuggestion(currencyAddress, nil, nil)
func (b *EthAPIBackend) SuggestPriceInCurrency(ctx context.Context, currencyAddress *common.Address, header *types.Header, state *state.StateDB) (*big.Int, error) {
return gpm.GetGasPriceSuggestion(currencyAddress, header, state)
}

func (b *EthAPIBackend) ChainDb() ethdb.Database {
Expand Down
12 changes: 10 additions & 2 deletions internal/ethapi/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -824,7 +824,11 @@ func DoCall(ctx context.Context, b Backend, args CallArgs, blockNrOrHash rpc.Blo
// TODO(asa): Remove this once this is handled in the Provider.
if gasPrice.Sign() == 0 || gasPrice.Cmp(big.NewInt(0)) == 0 {
// TODO(mcortesi): change SuggestGastPriceInCurrent so it doesn't return an error
gasPrice, _ = b.SuggestPriceInCurrency(ctx, args.FeeCurrency)
gasPrice, err = b.SuggestPriceInCurrency(ctx, args.FeeCurrency, header, state)
if err != nil {
log.Error("Error suggesting gas price", "block", blockNrOrHash, "err", err)
return nil, 0, false, err
}
}

value := new(big.Int)
Expand Down Expand Up @@ -1421,7 +1425,11 @@ func (args *SendTxArgs) setDefaults(ctx context.Context, b Backend) error {
// which will always be in Gold. This allows the default price to be set for the proper currency.
// TODO(asa): Remove this once this is handled in the Provider.
if args.GasPrice == nil || args.GasPrice.ToInt().Cmp(big.NewInt(0)) == 0 {
price, err := b.SuggestPriceInCurrency(ctx, args.FeeCurrency)
state, header, err := b.StateAndHeaderByNumber(ctx, rpc.LatestBlockNumber)
if err != nil {
return err
}
price, err := b.SuggestPriceInCurrency(ctx, args.FeeCurrency, header, state)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion internal/ethapi/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ type Backend interface {
Downloader() *downloader.Downloader
ProtocolVersion() int
SuggestPrice(ctx context.Context) (*big.Int, error)
SuggestPriceInCurrency(ctx context.Context, currencyAddress *common.Address) (*big.Int, error)
SuggestPriceInCurrency(ctx context.Context, currencyAddress *common.Address, header *types.Header, state *state.StateDB) (*big.Int, error)
ChainDb() ethdb.Database
EventMux() *event.TypeMux
AccountManager() *accounts.Manager
Expand Down
4 changes: 2 additions & 2 deletions les/api_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,8 @@ func (b *LesApiBackend) SuggestPrice(ctx context.Context) (*big.Int, error) {
return gpm.GetGasPriceSuggestion(nil, nil, nil)
}

func (b *LesApiBackend) SuggestPriceInCurrency(ctx context.Context, currencyAddress *common.Address) (*big.Int, error) {
return gpm.GetGasPriceSuggestion(currencyAddress, nil, nil)
func (b *LesApiBackend) SuggestPriceInCurrency(ctx context.Context, currencyAddress *common.Address, header *types.Header, state *state.StateDB) (*big.Int, error) {
return gpm.GetGasPriceSuggestion(currencyAddress, header, state)
}

func (b *LesApiBackend) GetGasPriceMinimum(ctx context.Context, currencyAddress *common.Address) (*big.Int, error) {
Expand Down

0 comments on commit 8807079

Please sign in to comment.