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

Sim backend returns 1 for SuggestGasPrice not Basefee #23752

Closed
MariusVanDerWijden opened this issue Oct 16, 2021 · 4 comments
Closed

Sim backend returns 1 for SuggestGasPrice not Basefee #23752

MariusVanDerWijden opened this issue Oct 16, 2021 · 4 comments
Labels

Comments

@MariusVanDerWijden
Copy link
Member

// SuggestGasPrice implements ContractTransactor.SuggestGasPrice. Since the simulated
// chain doesn't have miners, we just return a gas price of 1 for any call.
func (b *SimulatedBackend) SuggestGasPrice(ctx context.Context) (*big.Int, error) {
	return big.NewInt(1), nil
}

-> Does not work post 1559, just return pendingBlock.Header.Basefee or something

@Sparty
Copy link
Contributor

Sparty commented Oct 17, 2021

Can I work on this?

@MariusVanDerWijden
Copy link
Member Author

Sure!

@MariusVanDerWijden
Copy link
Member Author

fixed

@deitch
Copy link

deitch commented Feb 21, 2022

I just stumbled across this. Given that this is a simulated backend, how is the original base fee set? I am doing a simple chain creation and getting a base fee of some absurdly high number, something like 875000000.

What particularly threw me off was the function description:

SuggestGasPrice implements ContractTransactor.SuggestGasPrice. Since the simulated chain doesn't have miners, we just return a gas price of 1 for any call.

That definitely is not 1.

I am not doing anything fancy, as simple as:

	privateKey, err := crypto.GenerateKey()
	if err != nil {
		return nil, err
	}

	auth, err := bind.NewKeyedTransactorWithChainID(privateKey, big.NewInt(1337))
	if err != nil {
		return nil, err
	}

	balance := new(big.Int)
	balance.SetString("10000000000000000000", 10) // 10 eth in wei

	address := auth.From
	genesisAlloc := map[common.Address]core.GenesisAccount{
		address: {
			Balance: balance,
		},
	}

	blockGasLimit := uint64(4712388)
	client := backends.NewSimulatedBackend(genesisAlloc, blockGasLimit)

Stepping through, it looks like it creates it here as part of NewSimulatedBackendWithDatabase, specifically as part of the core.Genesis, which has an option to set the BaseFee (but is unused here), which then is inherited in core.NewBlockChain(). I think.

func NewSimulatedBackendWithDatabase(database ethdb.Database, alloc core.GenesisAlloc, gasLimit uint64) *SimulatedBackend {
	genesis := core.Genesis{Config: params.AllEthashProtocolChanges, GasLimit: gasLimit, Alloc: alloc}
	genesis.MustCommit(database)
	blockchain, _ := core.NewBlockChain(database, nil, genesis.Config, ethash.NewFaker(), vm.Config{}, nil, nil)

	backend := &SimulatedBackend{
		database:   database,
		blockchain: blockchain,
		config:     genesis.Config,
		events:     filters.NewEventSystem(&filterBackend{database, blockchain}, false),
	}
	backend.rollback(blockchain.CurrentBlock())
	return backend
}

Is this a bug in how SuggestGasPrice() works? Am I setting up the chain incorrectly? Or is it that it needs some option that is missing?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants