cmd: core: apply review comments, fix t8n tool

This commit is contained in:
Marius van der Wijden 2023-09-20 14:26:59 +02:00
parent 44d6276f37
commit a09c7f1f06
8 changed files with 22 additions and 9 deletions

View file

@ -166,6 +166,7 @@ func (pre *Prestate) Apply(vmConfig vm.Config, chainConfig *params.ChainConfig,
// If excessBlobGas is defined, add it to the vmContext.
if pre.Env.ExcessBlobGas != nil {
vmContext.ExcessBlobGas = pre.Env.ExcessBlobGas
vmContext.BlobFee = eip4844.CalcBlobFee(*pre.Env.ExcessBlobGas)
} else {
// If it is not explicitly defined, but we have the parent values, we try
// to calculate it ourselves.
@ -174,6 +175,7 @@ func (pre *Prestate) Apply(vmConfig vm.Config, chainConfig *params.ChainConfig,
if parentExcessBlobGas != nil && parentBlobGasUsed != nil {
excessBlobGas := eip4844.CalcExcessBlobGas(*parentExcessBlobGas, *parentBlobGasUsed)
vmContext.ExcessBlobGas = &excessBlobGas
vmContext.BlobFee = eip4844.CalcBlobFee(excessBlobGas)
}
}
// If DAO is supported/enabled, we need to handle it here. In geth 'proper', it's

View file

@ -123,7 +123,8 @@ func runCmd(ctx *cli.Context) error {
sender = common.BytesToAddress([]byte("sender"))
receiver = common.BytesToAddress([]byte("receiver"))
preimages = ctx.Bool(DumpFlag.Name)
blobHashes []common.Hash // TODO (MariusVanDerWijden) implement blob hashes in state tests
blobHashes []common.Hash // TODO (MariusVanDerWijden) implement blob hashes in state tests
blobFee = new(big.Int) // TODO (MariusVanDerWijden) implement blob fee in state tests
)
if ctx.Bool(MachineFlag.Name) {
tracer = logger.NewJSONLogger(logconfig, os.Stdout)
@ -221,6 +222,7 @@ func runCmd(ctx *cli.Context) error {
Coinbase: genesisConfig.Coinbase,
BlockNumber: new(big.Int).SetUint64(genesisConfig.Number),
BlobHashes: blobHashes,
BlobFee: blobFee,
EVMConfig: vm.Config{
Tracer: tracer,
},

View file

@ -282,8 +282,8 @@ func opBlobHash(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([
return nil, nil
}
// opBlobfee implements BLOBFEE opcode
func opBlobfee(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
// opBlobFee implements BLOBBASEFEE opcode
func opBlobFee(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
blobFee, _ := uint256.FromBig(interpreter.evm.Context.BlobFee)
scope.Stack.push(blobFee)
return nil, nil
@ -298,8 +298,8 @@ func enable4844(jt *JumpTable) {
minStack: minStack(1, 1),
maxStack: maxStack(1, 1),
}
jt[BLOBFEE] = &operation{
execute: opBlobfee,
jt[BLOBBASEFEE] = &operation{
execute: opBlobFee,
constantGas: GasQuickStep,
minStack: minStack(0, 1),
maxStack: maxStack(0, 1),

View file

@ -73,7 +73,7 @@ type BlockContext struct {
Time uint64 // Provides information for TIME
Difficulty *big.Int // Provides information for DIFFICULTY
BaseFee *big.Int // Provides information for BASEFEE
BlobFee *big.Int // Provides information for BLOBFEE
BlobFee *big.Int // Provides information for BLOBBASEFEE
Random *common.Hash // Provides information for PREVRANDAO
ExcessBlobGas *uint64 // ExcessBlobGas field in the header, needed to compute the data
}

View file

@ -101,7 +101,7 @@ const (
SELFBALANCE OpCode = 0x47
BASEFEE OpCode = 0x48
BLOBHASH OpCode = 0x49
BLOBFEE OpCode = 0x4a
BLOBBASEFEE OpCode = 0x4a
)
// 0x50 range - 'storage' and execution.
@ -288,7 +288,7 @@ var opCodeToString = map[OpCode]string{
SELFBALANCE: "SELFBALANCE",
BASEFEE: "BASEFEE",
BLOBHASH: "BLOBHASH",
BLOBFEE: "BLOBFEE",
BLOBBASEFEE: "BLOBBASEFEE",
// 0x50 range - 'storage' and execution.
POP: "POP",
@ -446,7 +446,7 @@ var stringToOp = map[string]OpCode{
"CHAINID": CHAINID,
"BASEFEE": BASEFEE,
"BLOBHASH": BLOBHASH,
"BLOBFEE": BLOBFEE,
"BLOBBASEFEE": BLOBBASEFEE,
"DELEGATECALL": DELEGATECALL,
"STATICCALL": STATICCALL,
"CODESIZE": CODESIZE,

View file

@ -37,6 +37,7 @@ func NewEnv(cfg *Config) *vm.EVM {
Difficulty: cfg.Difficulty,
GasLimit: cfg.GasLimit,
BaseFee: cfg.BaseFee,
BlobFee: cfg.BlobFee,
Random: cfg.Random,
}

View file

@ -44,6 +44,7 @@ type Config struct {
Debug bool
EVMConfig vm.Config
BaseFee *big.Int
BlobFee *big.Int
BlobHashes []common.Hash
Random *common.Hash
@ -95,6 +96,9 @@ func setDefaults(cfg *Config) {
if cfg.BaseFee == nil {
cfg.BaseFee = big.NewInt(params.InitialBaseFee)
}
if cfg.BlobFee == nil {
cfg.BlobFee = new(big.Int)
}
}
// Execute executes the code using the input as call data during the execution.

View file

@ -998,6 +998,7 @@ type BlockOverrides struct {
Coinbase *common.Address
Random *common.Hash
BaseFee *hexutil.Big
BlobFee *hexutil.Big
}
// Apply overrides the given header fields into the given block context.
@ -1026,6 +1027,9 @@ func (diff *BlockOverrides) Apply(blockCtx *vm.BlockContext) {
if diff.BaseFee != nil {
blockCtx.BaseFee = diff.BaseFee.ToInt()
}
if diff.BlobFee != nil {
blockCtx.BlobFee = diff.BlobFee.ToInt()
}
}
// ChainContextBackend provides methods required to implement ChainContext.