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 excessBlobGas is defined, add it to the vmContext.
if pre.Env.ExcessBlobGas != nil { if pre.Env.ExcessBlobGas != nil {
vmContext.ExcessBlobGas = pre.Env.ExcessBlobGas vmContext.ExcessBlobGas = pre.Env.ExcessBlobGas
vmContext.BlobFee = eip4844.CalcBlobFee(*pre.Env.ExcessBlobGas)
} else { } else {
// If it is not explicitly defined, but we have the parent values, we try // If it is not explicitly defined, but we have the parent values, we try
// to calculate it ourselves. // to calculate it ourselves.
@ -174,6 +175,7 @@ func (pre *Prestate) Apply(vmConfig vm.Config, chainConfig *params.ChainConfig,
if parentExcessBlobGas != nil && parentBlobGasUsed != nil { if parentExcessBlobGas != nil && parentBlobGasUsed != nil {
excessBlobGas := eip4844.CalcExcessBlobGas(*parentExcessBlobGas, *parentBlobGasUsed) excessBlobGas := eip4844.CalcExcessBlobGas(*parentExcessBlobGas, *parentBlobGasUsed)
vmContext.ExcessBlobGas = &excessBlobGas vmContext.ExcessBlobGas = &excessBlobGas
vmContext.BlobFee = eip4844.CalcBlobFee(excessBlobGas)
} }
} }
// If DAO is supported/enabled, we need to handle it here. In geth 'proper', it's // 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")) sender = common.BytesToAddress([]byte("sender"))
receiver = common.BytesToAddress([]byte("receiver")) receiver = common.BytesToAddress([]byte("receiver"))
preimages = ctx.Bool(DumpFlag.Name) 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) { if ctx.Bool(MachineFlag.Name) {
tracer = logger.NewJSONLogger(logconfig, os.Stdout) tracer = logger.NewJSONLogger(logconfig, os.Stdout)
@ -221,6 +222,7 @@ func runCmd(ctx *cli.Context) error {
Coinbase: genesisConfig.Coinbase, Coinbase: genesisConfig.Coinbase,
BlockNumber: new(big.Int).SetUint64(genesisConfig.Number), BlockNumber: new(big.Int).SetUint64(genesisConfig.Number),
BlobHashes: blobHashes, BlobHashes: blobHashes,
BlobFee: blobFee,
EVMConfig: vm.Config{ EVMConfig: vm.Config{
Tracer: tracer, Tracer: tracer,
}, },

View file

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

View file

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

View file

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

View file

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

View file

@ -44,6 +44,7 @@ type Config struct {
Debug bool Debug bool
EVMConfig vm.Config EVMConfig vm.Config
BaseFee *big.Int BaseFee *big.Int
BlobFee *big.Int
BlobHashes []common.Hash BlobHashes []common.Hash
Random *common.Hash Random *common.Hash
@ -95,6 +96,9 @@ func setDefaults(cfg *Config) {
if cfg.BaseFee == nil { if cfg.BaseFee == nil {
cfg.BaseFee = big.NewInt(params.InitialBaseFee) 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. // 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 Coinbase *common.Address
Random *common.Hash Random *common.Hash
BaseFee *hexutil.Big BaseFee *hexutil.Big
BlobFee *hexutil.Big
} }
// Apply overrides the given header fields into the given block context. // 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 { if diff.BaseFee != nil {
blockCtx.BaseFee = diff.BaseFee.ToInt() blockCtx.BaseFee = diff.BaseFee.ToInt()
} }
if diff.BlobFee != nil {
blockCtx.BlobFee = diff.BlobFee.ToInt()
}
} }
// ChainContextBackend provides methods required to implement ChainContext. // ChainContextBackend provides methods required to implement ChainContext.