Panic: max fee per gas less than block base fee: address 0xbc8153EE0b1E9B1f1E8153945400dc38EDbD8638, maxFeePerGas: 1 baseFee: 875000000

huangapple go评论86阅读模式
英文:

Panic: max fee per gas less than block base fee: address 0xbc8153EE0b1E9B1f1E8153945400dc38EDbD8638, maxFeePerGas: 1 baseFee: 875000000

问题

我找到了一个使用SimulatedBackend的示例。最近这段代码一直运行良好,但现在却导致了一个恐慌错误(panic: max fee per gas less than block base fee: address 0xbc8153EE0b1E9B1f1E8153945400dc38EDbD8638, maxFeePerGas: 1 baseFee: 875000000)。我怀疑这与伦敦升级有关。

即使我添加了auth.GasFeeCap = big.NewInt(875000000),我仍然遇到相同的恐慌错误。我不知道还应该在哪里设置这个值。

有没有人有一个可用的示例,或者能够解释我做错了什么?

英文:

I found the following example for working with the SimulatedBackend. Until recently that worked fine, however this code now results in a panic (panic: max fee per gas less than block base fee: address 0xbc8153EE0b1E9B1f1E8153945400dc38EDbD8638, maxFeePerGas: 1 baseFee: 875000000). I suspect it's related to the London update.

package eth

import (
	"context"
	"math/big"
	"testing"

	"github.com/ethereum/go-ethereum/accounts/abi/bind"
	"github.com/ethereum/go-ethereum/accounts/abi/bind/backends"
	"github.com/ethereum/go-ethereum/common"
	"github.com/ethereum/go-ethereum/core"
	"github.com/ethereum/go-ethereum/core/types"
	"github.com/ethereum/go-ethereum/crypto"
)

func TestSimulatedBackend(t *testing.T) {
	privateKey, err := crypto.GenerateKey()
	if err != nil {
		t.Fatalf("failed to generate key: %v", err)
	}

	auth, err := bind.NewKeyedTransactorWithChainID(privateKey, big.NewInt(1337))
	if err != nil {
		t.Fatalf("failed to generate transaction: %v", 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)

	fromAddress := auth.From
	nonce, err := client.PendingNonceAt(context.Background(), fromAddress)
	if err != nil {
		t.Fatalf("failed to generate nonce: %v", err)
	}

	value := big.NewInt(1000000000000000000) // in wei (1 eth)
	gasLimit := uint64(21000)                // in units
	gasPrice, err := client.SuggestGasPrice(context.Background())
	if err != nil {
		t.Fatalf("failed to generate suggested gas price: %v", err)
	}

	toAddress := common.HexToAddress("0x4592d8f8d7b001e72cb26a73e4fa1806a51ac79d")
	var data []byte
	tx := types.NewTransaction(nonce, toAddress, value, gasLimit, gasPrice, data)

	chainID := big.NewInt(1337)
	signedTx, err := types.SignTx(tx, types.NewEIP155Signer(chainID), privateKey)
	if err != nil {
		t.Fatalf("failed to sign transaction: %v", err)
	}

	err = client.SendTransaction(context.Background(), signedTx)
	if err != nil {
		t.Fatalf("failed to send transaction: %v", err)
	}

	t.Logf("tx sent: %s\n", signedTx.Hash().Hex()) // tx sent: 0xec3ceb05642c61d33fa6c951b54080d1953ac8227be81e7b5e4e2cfed69eeb51

	client.Commit()

	receipt, err := client.TransactionReceipt(context.Background(), signedTx.Hash())
	if err != nil {
		t.Fatalf("failed to create transaction receipt: %v", err)
	}
	if receipt == nil {
		t.Fatal("receipient is empty")
	}

	t.Logf("status: %v\n", receipt.Status) // status: 1
}

Even if I add auth.GasFeeCap = big.NewInt(875000000) I still get the same panic. I have no idea where else I'm supposed to to set this.

Does anyone have a working example or anyone able to explain me what I'm doing wrong?

答案1

得分: 1

模拟后端返回的是1,这是它设置的初始基础费用的gwei数量,但实际上基础费用和燃气价格需要使用wei单位。因此,在使用模拟后端时,将燃气价格设置为1000000000。

英文:

The simulated backend is returning 1 which is the number of gwei it sets the initial base fee to, but the base fee and gas price actually expects units of wei. So just set the gas price to 1000000000 when using the simulated backend.

答案2

得分: -1

打印出有效载荷,并检查参数是否正确。

在我的情况下,from 地址是 0x0000...,而 gas price 实际上非常低。因此,网络对此错误消息进行了投诉。

只需增加 gas,问题就解决了。

英文:

print out the payload , and check is the parameter is correct.

in my case, the from address is 0x0000... and the gas price is actually very low. so the network compliants for this error message.

just increate the gas , and problem solved.

huangapple
  • 本文由 发表于 2021年9月16日 12:25:44
  • 转载请务必保留本文链接:https://go.coder-hub.com/69202325.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定