diff --git a/accounts/abi/bind/v2/base.go b/accounts/abi/bind/v2/base.go index 744e4b6fd9..840df59a3a 100644 --- a/accounts/abi/bind/v2/base.go +++ b/accounts/abi/bind/v2/base.go @@ -297,7 +297,7 @@ func (c *BoundContract) createDynamicTx(opts *TransactOpts, contract *common.Add if gasFeeCap == nil { gasFeeCap = new(big.Int).Add( gasTipCap, - new(big.Int).Mul(head.BaseFee, big.NewInt(basefeeWiggleMultiplier)), + new(big.Int).Mul(head.BaseFee(), big.NewInt(basefeeWiggleMultiplier)), ) } if gasFeeCap.Cmp(gasTipCap) < 0 { diff --git a/beacon/engine/types.go b/beacon/engine/types.go index b165686fcd..eb67127d66 100644 --- a/beacon/engine/types.go +++ b/beacon/engine/types.go @@ -330,7 +330,8 @@ func ExecutableDataToBlockNoHash(data ExecutableData, versionedHashes []common.H GasLimit: data.GasLimit, GasUsed: data.GasUsed, Time: data.Timestamp, - BaseFee: data.BaseFeePerGas, + EthBaseFee: data.BaseFeePerGas, + RskMinimumGasPrice: data.BaseFeePerGas, Extra: data.ExtraData, MixDigest: data.Random, WithdrawalsHash: withdrawalsRoot, diff --git a/consensus/misc/eip1559/eip1559.go b/consensus/misc/eip1559/eip1559.go index eb5dfed657..2f0a24c348 100644 --- a/consensus/misc/eip1559/eip1559.go +++ b/consensus/misc/eip1559/eip1559.go @@ -42,14 +42,14 @@ func VerifyEIP1559Header(config *params.ChainConfig, parent, header *types.Heade } } // Verify the header is not malformed - if header.BaseFee == nil { + if header.BaseFee() == nil { return errors.New("header is missing baseFee") } // Verify the baseFee is correct based on the parent header. expectedBaseFee := CalcBaseFee(config, parent, header.Time) - if header.BaseFee.Cmp(expectedBaseFee) != 0 { + if header.BaseFee().Cmp(expectedBaseFee) != 0 { return fmt.Errorf("invalid baseFee: have %s, want %s, parentBaseFee %s, parentGasUsed %d", - header.BaseFee, expectedBaseFee, parent.BaseFee, parent.GasUsed) + header.BaseFee(), expectedBaseFee, parent.BaseFee(), parent.GasUsed) } return nil } @@ -103,7 +103,7 @@ func calcBaseFeeInner(config *params.ChainConfig, parent *types.Header, elastici } // If the parent gasMetered is the same as the target, the baseFee remains unchanged. if parentGasMetered == parentGasTarget { - return new(big.Int).Set(parent.BaseFee) + return new(big.Int).Set(parent.BaseFee()) } var ( @@ -115,22 +115,22 @@ func calcBaseFeeInner(config *params.ChainConfig, parent *types.Header, elastici // If the parent block used more gas than its target, the baseFee should increase. // max(1, parentBaseFee * gasUsedDelta / parentGasTarget / baseFeeChangeDenominator) num.SetUint64(parentGasMetered - parentGasTarget) - num.Mul(num, parent.BaseFee) + num.Mul(num, parent.BaseFee()) num.Div(num, denom.SetUint64(parentGasTarget)) num.Div(num, denom.SetUint64(denominator)) if num.Cmp(common.Big1) < 0 { - return num.Add(parent.BaseFee, common.Big1) + return num.Add(parent.BaseFee(), common.Big1) } - return num.Add(parent.BaseFee, num) + return num.Add(parent.BaseFee(), num) } else { // Otherwise if the parent block used less gas than its target, the baseFee should decrease. // max(0, parentBaseFee * gasUsedDelta / parentGasTarget / baseFeeChangeDenominator) num.SetUint64(parentGasTarget - parentGasMetered) - num.Mul(num, parent.BaseFee) + num.Mul(num, parent.BaseFee()) num.Div(num, denom.SetUint64(parentGasTarget)) num.Div(num, denom.SetUint64(denominator)) - baseFee := num.Sub(parent.BaseFee, num) + baseFee := num.Sub(parent.BaseFee(), num) if baseFee.Cmp(common.Big0) < 0 { baseFee = common.Big0 } diff --git a/consensus/misc/eip4844/eip4844.go b/consensus/misc/eip4844/eip4844.go index a7df6f2cbc..f0328bf626 100644 --- a/consensus/misc/eip4844/eip4844.go +++ b/consensus/misc/eip4844/eip4844.go @@ -168,7 +168,7 @@ func calcExcessBlobGas(isOsaka bool, bcfg *BlobConfig, parent *types.Header) uin if isOsaka { var ( baseCost = big.NewInt(params.BlobBaseCost) - reservePrice = baseCost.Mul(baseCost, parent.BaseFee) + reservePrice = baseCost.Mul(baseCost, parent.BaseFee()) blobPrice = bcfg.blobPrice(parentExcessBlobGas) ) if reservePrice.Cmp(blobPrice) > 0 { diff --git a/core/blockchain_optimism.go b/core/blockchain_optimism.go index fa7ee47390..0ede1e7d16 100644 --- a/core/blockchain_optimism.go +++ b/core/blockchain_optimism.go @@ -16,7 +16,7 @@ var ( ) func updateOptimismBlockMetrics(header *types.Header) error { - headBaseFeeGauge.TryUpdate(header.BaseFee) + headBaseFeeGauge.TryUpdate(header.BaseFee()) headGasUsedGauge.Update(int64(header.GasUsed)) headBlobGasUsedGauge.TryUpdateUint64(header.BlobGasUsed) headGasUsedHist.Update(int64(header.GasUsed)) diff --git a/core/blockchain_reader.go b/core/blockchain_reader.go index d3bde18457..8c2cc07c30 100644 --- a/core/blockchain_reader.go +++ b/core/blockchain_reader.go @@ -247,7 +247,7 @@ func (bc *BlockChain) GetCanonicalReceipt(tx *types.Transaction, blockHash commo BlockHash: blockHash, BlockNumber: blockNumber, BlockTime: header.Time, - BaseFee: header.BaseFee, + BaseFee: header.BaseFee(), BlobGasPrice: blobGasPrice, GasUsed: ctx.GasUsed, LogIndex: ctx.LogIndex, diff --git a/core/chain_makers.go b/core/chain_makers.go index 4a64830ef8..0cd4e2ec82 100644 --- a/core/chain_makers.go +++ b/core/chain_makers.go @@ -191,7 +191,7 @@ func (b *BlockGen) Timestamp() uint64 { // BaseFee returns the EIP-1559 base fee of the block being generated. func (b *BlockGen) BaseFee() *big.Int { - return new(big.Int).Set(b.header.BaseFee) + return new(big.Int).Set(b.header.BaseFee()) } // Gas returns the amount of gas left in the current block. @@ -239,7 +239,7 @@ func (b *BlockGen) AddUncle(h *types.Header) { // The gas limit and price should be derived from the parent h.GasLimit = parent.GasLimit if b.cm.config.IsLondon(h.Number) { - h.BaseFee = eip1559.CalcBaseFee(b.cm.config, parent, h.Time) + h.EthBaseFee = eip1559.CalcBaseFee(b.cm.config, parent, h.Time) if !b.cm.config.IsLondon(parent.Number) { parentGasLimit := parent.GasLimit * b.cm.config.ElasticityMultiplier() h.GasLimit = CalcGasLimit(parentGasLimit, parentGasLimit) @@ -619,7 +619,7 @@ func (cm *chainMaker) makeHeader(parent *types.Block, state *state.StateDB, engi } if cm.config.IsLondon(header.Number) { - header.BaseFee = eip1559.CalcBaseFee(cm.config, parentHeader, header.Time) + header.EthBaseFee = eip1559.CalcBaseFee(cm.config, parentHeader, header.Time) if !cm.config.IsLondon(parent.Number()) { parentGasLimit := parent.GasLimit() * cm.config.ElasticityMultiplier() header.GasLimit = CalcGasLimit(parentGasLimit, parentGasLimit) diff --git a/core/evm.go b/core/evm.go index 17b62a7890..96009d1cc0 100644 --- a/core/evm.go +++ b/core/evm.go @@ -58,8 +58,8 @@ func NewEVMBlockContext(header *types.Header, chain ChainContext, author *common } else { beneficiary = *author } - if header.BaseFee != nil { - baseFee = new(big.Int).Set(header.BaseFee) + if header.BaseFee() != nil { + baseFee = new(big.Int).Set(header.BaseFee()) } if header.ExcessBlobGas != nil { blobBaseFee = eip4844.CalcBlobFee(chain.Config(), header) diff --git a/core/genesis.go b/core/genesis.go index 737e9ae1f4..33a17c1885 100644 --- a/core/genesis.go +++ b/core/genesis.go @@ -125,7 +125,7 @@ func ReadGenesis(db ethdb.Database) (*Genesis, error) { genesis.Difficulty = genesisHeader.Difficulty genesis.Mixhash = genesisHeader.MixDigest genesis.Coinbase = genesisHeader.Coinbase - genesis.BaseFee = genesisHeader.BaseFee + genesis.BaseFee = genesisHeader.BaseFee() genesis.ExcessBlobGas = genesisHeader.ExcessBlobGas genesis.BlobGasUsed = genesisHeader.BlobGasUsed // A nil or empty alloc, with a non-matching state-root in the block header, intents to override the state-root. @@ -619,7 +619,8 @@ func (g *Genesis) toBlockWithRoot(stateRoot, storageRootMessagePasser common.Has Extra: g.ExtraData, GasLimit: g.GasLimit, GasUsed: g.GasUsed, - BaseFee: g.BaseFee, + EthBaseFee: g.BaseFee, + RskMinimumGasPrice: g.BaseFee, Difficulty: g.Difficulty, MixDigest: g.Mixhash, Coinbase: g.Coinbase, @@ -637,9 +638,11 @@ func (g *Genesis) toBlockWithRoot(stateRoot, storageRootMessagePasser common.Has } if g.Config != nil && g.Config.IsLondon(common.Big0) { if g.BaseFee != nil { - head.BaseFee = g.BaseFee + head.EthBaseFee = g.BaseFee + head.RskMinimumGasPrice = g.BaseFee } else { - head.BaseFee = new(big.Int).SetUint64(params.InitialBaseFee) + head.EthBaseFee = new(big.Int).SetUint64(params.InitialBaseFee) + head.RskMinimumGasPrice = new(big.Int).SetUint64(params.InitialBaseFee) } } var withdrawals []*types.Withdrawal diff --git a/core/rawdb/accessors_chain.go b/core/rawdb/accessors_chain.go index 3bd394b4e1..d6b9745e07 100644 --- a/core/rawdb/accessors_chain.go +++ b/core/rawdb/accessors_chain.go @@ -617,7 +617,7 @@ func ReadReceipts(db ethdb.Reader, hash common.Hash, number uint64, time uint64, if header == nil { baseFee = big.NewInt(0) } else { - baseFee = header.BaseFee + baseFee = header.BaseFee() } // Compute effective blob gas price. var blobGasPrice *big.Int diff --git a/core/state/journal.go b/core/state/journal.go index f3f976f24f..0e8b1c2fe0 100644 --- a/core/state/journal.go +++ b/core/state/journal.go @@ -88,6 +88,7 @@ func (j *journal) revertToSnapshot(revid int, s *StateDB) { return j.validRevisions[i].id >= revid }) if idx == len(j.validRevisions) || j.validRevisions[idx].id != revid { + fmt.Printf("\n\n journal.go ~ revertToSnapshot ~ revision id %v cannot be reverted\n\n", revid) panic(fmt.Errorf("revision id %v cannot be reverted", revid)) } snapshot := j.validRevisions[idx].journalIndex diff --git a/core/state/state_object.go b/core/state/state_object.go index 767f469bfd..acffe79461 100644 --- a/core/state/state_object.go +++ b/core/state/state_object.go @@ -92,10 +92,13 @@ func (s *stateObject) empty() bool { // newObject creates a state object. func newObject(db *StateDB, address common.Address, acct *types.StateAccount) *stateObject { + fmt.Println("state_object.go ~ newObject ~ Creating state object", address, acct) origin := acct if acct == nil { acct = types.NewEmptyStateAccount() + fmt.Println("state_object.go ~ newObject ~ New empty state account", acct) } + fmt.Println("state_object.go ~ newObject ~ State account", acct) return &stateObject{ db: db, address: address, diff --git a/core/state/statedb.go b/core/state/statedb.go index b278e762aa..759895be23 100644 --- a/core/state/statedb.go +++ b/core/state/statedb.go @@ -639,6 +639,7 @@ func (s *StateDB) getStateObject(addr common.Address) *stateObject { start := time.Now() acct, err := s.reader.Account(addr) + fmt.Println("statedb.go ~ getStateObject ~ Account", acct, err) if err != nil { s.setError(fmt.Errorf("getStateObject (%x) error: %w", addr.Bytes(), err)) return nil @@ -647,17 +648,21 @@ func (s *StateDB) getStateObject(addr common.Address) *stateObject { // Short circuit if the account is not found if acct == nil { + fmt.Println("statedb.go ~ getStateObject ~ Account is nil") return nil } // Schedule the resolved account for prefetching if it's enabled. if s.prefetcher != nil { + fmt.Println("statedb.go ~ getStateObject ~ Prefetcher is not nil") if err = s.prefetcher.prefetch(common.Hash{}, s.originalRoot, common.Address{}, []common.Address{addr}, nil, true); err != nil { log.Error("Failed to prefetch account", "addr", addr, "err", err) } } // Insert into the live set obj := newObject(s, addr, acct) + fmt.Println("statedb.go ~ getStateObject ~ Setting state object", obj) s.setStateObject(obj) + fmt.Println("statedb.go ~ getStateObject ~ State object set", obj) return obj } diff --git a/core/state/trie_prefetcher.go b/core/state/trie_prefetcher.go index a9faddcdff..cac7aca96b 100644 --- a/core/state/trie_prefetcher.go +++ b/core/state/trie_prefetcher.go @@ -18,6 +18,7 @@ package state import ( "errors" + "fmt" "sync" "github.com/ethereum/go-ethereum/common" @@ -159,6 +160,7 @@ func (p *triePrefetcher) report() { // repeated. // 2. Finalize of the main account trie. This happens only once per block. func (p *triePrefetcher) prefetch(owner common.Hash, root common.Hash, addr common.Address, addrs []common.Address, slots []common.Hash, read bool) error { + fmt.Println("trie_prefetcher.go ~ prefetch ~ Prefetching", owner, root, addr, addrs, slots, read) // If the state item is only being read, but reads are disabled, return if read && p.noreads { return nil @@ -170,11 +172,16 @@ func (p *triePrefetcher) prefetch(owner common.Hash, root common.Hash, addr comm default: } id := p.trieID(owner, root) + fmt.Println("trie_prefetcher.go ~ prefetch ~ Trie ID", id) fetcher := p.fetchers[id] if fetcher == nil { + fmt.Println("trie_prefetcher.go ~ prefetch ~ New subfetcher") fetcher = newSubfetcher(p.db, p.root, owner, root, addr) p.fetchers[id] = fetcher + } else { + fmt.Println("trie_prefetcher.go ~ prefetch ~ Subfetcher already exists") } + fmt.Println("trie_prefetcher.go ~ prefetch ~ Scheduling", addrs, slots, read) return fetcher.schedule(addrs, slots, read) } diff --git a/core/state_prefetcher.go b/core/state_prefetcher.go index 2e55b89dfe..bd800758ba 100644 --- a/core/state_prefetcher.go +++ b/core/state_prefetcher.go @@ -95,7 +95,7 @@ func (p *statePrefetcher) Prefetch(block *types.Block, statedb *state.StateDB, c evm := vm.NewEVM(NewEVMBlockContext(header, p.chain, nil, p.config, stateCpy), stateCpy, p.config, cfg) // Convert the transaction into an executable message and pre-cache its sender - msg, err := TransactionToMessage(tx, signer, header.BaseFee) + msg, err := TransactionToMessage(tx, signer, header.EthBaseFee) if err != nil { fails.Add(1) return nil // Also invalid block, bail out diff --git a/core/state_processor.go b/core/state_processor.go index c29d0c24de..1fc72e964b 100644 --- a/core/state_processor.go +++ b/core/state_processor.go @@ -91,7 +91,7 @@ func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg // Iterate over and process the individual transactions for i, tx := range block.Transactions() { - msg, err := TransactionToMessage(tx, signer, header.BaseFee) + msg, err := TransactionToMessage(tx, signer, header.BaseFee()) if err != nil { return nil, fmt.Errorf("could not apply tx %d [%v]: %w", i, tx.Hash().Hex(), err) } @@ -228,7 +228,7 @@ func MakeReceipt(evm *vm.EVM, result *ExecutionResult, statedb *state.StateDB, b // for the transaction, gas used and an error if the transaction failed, // indicating the block was invalid. func ApplyTransaction(evm *vm.EVM, gp *GasPool, statedb *state.StateDB, header *types.Header, tx *types.Transaction, usedGas *uint64) (*types.Receipt, error) { - msg, err := TransactionToMessage(tx, types.MakeSigner(evm.ChainConfig(), header.Number, header.Time), header.BaseFee) + msg, err := TransactionToMessage(tx, types.MakeSigner(evm.ChainConfig(), header.Number, header.Time), header.BaseFee()) if err != nil { return nil, err } diff --git a/core/types/block.go b/core/types/block.go index 1a3f0f1773..97a869e82a 100644 --- a/core/types/block.go +++ b/core/types/block.go @@ -90,7 +90,10 @@ type Header struct { Nonce BlockNonce `json:"nonce"` // BaseFee was added by EIP-1559 and is ignored in legacy headers. - BaseFee *big.Int `json:"baseFeePerGas" rlp:"optional"` + EthBaseFee *big.Int `json:"baseFeePerGas" rlp:"optional"` + + // Rootstock specific + RskMinimumGasPrice *big.Int `json:"minimumGasPrice,omitempty" rlp:"-"` // WithdrawalsHash was added by EIP-4895 and is ignored in legacy headers. WithdrawalsHash *common.Hash `json:"withdrawalsRoot" rlp:"optional"` @@ -107,20 +110,24 @@ type Header struct { // RequestsHash was added by EIP-7685 and is ignored in legacy headers. RequestsHash *common.Hash `json:"requestsHash" rlp:"optional"` + + // Hash from the json object. + NodeHash common.Hash `json:"hash" rlp:"-"` } // field type overrides for gencodec type headerMarshaling struct { - Difficulty *hexutil.Big - Number *hexutil.Big - GasLimit hexutil.Uint64 - GasUsed hexutil.Uint64 - Time hexutil.Uint64 - Extra hexutil.Bytes - BaseFee *hexutil.Big - Hash common.Hash `json:"hash"` // adds call to Hash() in MarshalJSON - BlobGasUsed *hexutil.Uint64 - ExcessBlobGas *hexutil.Uint64 + Difficulty *hexutil.Big + Number *hexutil.Big + GasLimit hexutil.Uint64 + GasUsed hexutil.Uint64 + Time hexutil.Uint64 + Extra hexutil.Bytes + EthBaseFee *hexutil.Big + RskMinimumGasPrice *hexutil.Big + Hash common.Hash `json:"hash"` // adds call to Hash() in MarshalJSON + BlobGasUsed *hexutil.Uint64 + ExcessBlobGas *hexutil.Uint64 } // Hash returns the block hash of the header, which is simply the keccak256 hash of its @@ -129,14 +136,26 @@ func (h *Header) Hash() common.Hash { return rlpHash(h) } +func (h *Header) isL1Block() bool { + return h.RskMinimumGasPrice != nil +} + +func (h *Header) BaseFee() *big.Int { + if h.isL1Block() { + return (*big.Int)(h.RskMinimumGasPrice) + } else { + return h.EthBaseFee + } +} + var headerSize = common.StorageSize(reflect.TypeFor[Header]().Size()) // Size returns the approximate memory used by all internal contents. It is used // to approximate and limit the memory consumption of various caches. func (h *Header) Size() common.StorageSize { var baseFeeBits int - if h.BaseFee != nil { - baseFeeBits = h.BaseFee.BitLen() + if h.BaseFee() != nil { + baseFeeBits = h.BaseFee().BitLen() } return headerSize + common.StorageSize(len(h.Extra)+(h.Difficulty.BitLen()+h.Number.BitLen()+baseFeeBits)/8) } @@ -157,8 +176,8 @@ func (h *Header) SanityCheck() error { if eLen := len(h.Extra); eLen > 100*1024 { return fmt.Errorf("too large block extradata: size %d", eLen) } - if h.BaseFee != nil { - if bfLen := h.BaseFee.BitLen(); bfLen > 256 { + if h.BaseFee() != nil { + if bfLen := h.BaseFee().BitLen(); bfLen > 256 { return fmt.Errorf("too large base fee: bitlen %d", bfLen) } } @@ -332,8 +351,9 @@ func CopyHeader(h *Header) *Header { if cpy.Number = new(big.Int); h.Number != nil { cpy.Number.Set(h.Number) } - if h.BaseFee != nil { - cpy.BaseFee = new(big.Int).Set(h.BaseFee) + if h.BaseFee() != nil { + cpy.EthBaseFee = new(big.Int).Set(h.BaseFee()) + cpy.RskMinimumGasPrice = new(big.Int).Set(h.RskMinimumGasPrice) } if len(h.Extra) > 0 { cpy.Extra = make([]byte, len(h.Extra)) @@ -440,10 +460,10 @@ func (b *Block) WithdrawalsRoot() *common.Hash { } func (b *Block) BaseFee() *big.Int { - if b.header.BaseFee == nil { + if b.header.BaseFee() == nil { return nil } - return new(big.Int).Set(b.header.BaseFee) + return new(big.Int).Set(b.header.BaseFee()) } func (b *Block) BeaconRoot() *common.Hash { return b.header.ParentBeaconRoot } diff --git a/core/types/gen_header_json.go b/core/types/gen_header_json.go index 0af12500bd..d871500515 100644 --- a/core/types/gen_header_json.go +++ b/core/types/gen_header_json.go @@ -55,7 +55,7 @@ func (h Header) MarshalJSON() ([]byte, error) { enc.Extra = h.Extra enc.MixDigest = h.MixDigest enc.Nonce = h.Nonce - enc.BaseFee = (*hexutil.Big)(h.BaseFee) + enc.BaseFee = (*hexutil.Big)(h.BaseFee()) enc.WithdrawalsHash = h.WithdrawalsHash enc.BlobGasUsed = (*hexutil.Uint64)(h.BlobGasUsed) enc.ExcessBlobGas = (*hexutil.Uint64)(h.ExcessBlobGas) @@ -83,7 +83,8 @@ func (h *Header) UnmarshalJSON(input []byte) error { Extra *hexutil.Bytes `json:"extraData" gencodec:"required"` MixDigest *common.Hash `json:"mixHash"` Nonce *BlockNonce `json:"nonce"` - BaseFee *hexutil.Big `json:"baseFeePerGas" rlp:"optional"` + EthBaseFee *hexutil.Big `json:"baseFeePerGas" rlp:"optional"` + RskMinimumGasPrice *hexutil.Big `json:"minimumGasPrice,omitempty" rlp:"optional"` WithdrawalsHash *common.Hash `json:"withdrawalsRoot" rlp:"optional"` BlobGasUsed *hexutil.Uint64 `json:"blobGasUsed" rlp:"optional"` ExcessBlobGas *hexutil.Uint64 `json:"excessBlobGas" rlp:"optional"` @@ -151,8 +152,11 @@ func (h *Header) UnmarshalJSON(input []byte) error { if dec.Nonce != nil { h.Nonce = *dec.Nonce } - if dec.BaseFee != nil { - h.BaseFee = (*big.Int)(dec.BaseFee) + if dec.EthBaseFee != nil { + h.EthBaseFee = (*big.Int)(dec.EthBaseFee) + } + if dec.RskMinimumGasPrice != nil { + h.RskMinimumGasPrice = (*big.Int)(dec.RskMinimumGasPrice) } if dec.WithdrawalsHash != nil { h.WithdrawalsHash = dec.WithdrawalsHash diff --git a/core/types/gen_header_rlp.go b/core/types/gen_header_rlp.go index c79aa8a250..d500df1764 100644 --- a/core/types/gen_header_rlp.go +++ b/core/types/gen_header_rlp.go @@ -37,20 +37,20 @@ func (obj *Header) EncodeRLP(_w io.Writer) error { w.WriteBytes(obj.Extra) w.WriteBytes(obj.MixDigest[:]) w.WriteBytes(obj.Nonce[:]) - _tmp1 := obj.BaseFee != nil + _tmp1 := obj.BaseFee() != nil _tmp2 := obj.WithdrawalsHash != nil _tmp3 := obj.BlobGasUsed != nil _tmp4 := obj.ExcessBlobGas != nil _tmp5 := obj.ParentBeaconRoot != nil _tmp6 := obj.RequestsHash != nil if _tmp1 || _tmp2 || _tmp3 || _tmp4 || _tmp5 || _tmp6 { - if obj.BaseFee == nil { + if obj.BaseFee() == nil { w.Write(rlp.EmptyString) } else { - if obj.BaseFee.Sign() == -1 { + if obj.BaseFee().Sign() == -1 { return rlp.ErrNegativeBigInt } - w.WriteBigInt(obj.BaseFee) + w.WriteBigInt(obj.BaseFee()) } } if _tmp2 || _tmp3 || _tmp4 || _tmp5 || _tmp6 { diff --git a/core/vm/contracts.go b/core/vm/contracts.go index 18dfb9a9d2..08942dca0c 100644 --- a/core/vm/contracts.go +++ b/core/vm/contracts.go @@ -368,14 +368,19 @@ func ActivePrecompiles(rules params.Rules) []common.Address { // - any error that occurred func RunPrecompiledContract(p PrecompiledContract, input []byte, suppliedGas uint64, logger *tracing.Hooks) (ret []byte, remainingGas uint64, err error) { gasCost := p.RequiredGas(input) + fmt.Println("contracts.go ~ RunPrecompiledContract ~ gasCost", gasCost) if suppliedGas < gasCost { return nil, 0, ErrOutOfGas } + fmt.Println("contracts.go ~ RunPrecompiledContract ~ suppliedGas", suppliedGas) if logger != nil && logger.OnGasChange != nil { logger.OnGasChange(suppliedGas, suppliedGas-gasCost, tracing.GasChangeCallPrecompiledContract) } + fmt.Println("contracts.go ~ RunPrecompiledContract ~ suppliedGas after gas change", suppliedGas) suppliedGas -= gasCost output, err := p.Run(input) + fmt.Println("contracts.go ~ RunPrecompiledContract ~ output length", len(output)) + fmt.Println("contracts.go ~ RunPrecompiledContract ~ error", err) return output, suppliedGas, err } diff --git a/core/vm/evm.go b/core/vm/evm.go index 05ba870b96..ef37083213 100644 --- a/core/vm/evm.go +++ b/core/vm/evm.go @@ -18,6 +18,7 @@ package vm import ( "errors" + "fmt" "math/big" "sync/atomic" @@ -255,6 +256,7 @@ func isSystemCall(caller common.Address) bool { // the necessary steps to create accounts and reverses the state in case of an // execution error or failed value transfer. func (evm *EVM) Call(caller common.Address, addr common.Address, input []byte, gas uint64, value *uint256.Int) (ret []byte, leftOverGas uint64, err error) { + fmt.Println("evm.go ~ EVM ~ Call ~ Calling contract", caller, addr, string(input[:10]), gas, value) caller = evm.maybeOverrideCaller(caller) // Capture the tracer start/end events in debug mode if evm.Config.Tracer != nil { @@ -265,10 +267,12 @@ func (evm *EVM) Call(caller common.Address, addr common.Address, input []byte, g } // Fail if we're trying to execute above the call depth limit if evm.depth > int(params.CallCreateDepth) { + fmt.Println("evm.go ~ EVM ~ Call ~ Depth limit exceeded", evm.depth) return nil, gas, ErrDepth } // Fail if we're trying to transfer more than the available balance if !value.IsZero() && !evm.Context.CanTransfer(evm.StateDB, caller, value) { + fmt.Println("evm.go ~ EVM ~ Call ~ Insufficient balance", caller, value) return nil, gas, ErrInsufficientBalance } snapshot := evm.StateDB.Snapshot() @@ -298,19 +302,28 @@ func (evm *EVM) Call(caller common.Address, addr common.Address, input []byte, g evm.StateDB.CreateAccount(addr) } evm.Context.Transfer(evm.StateDB, caller, addr, value) - + fmt.Println("evm.go ~ EVM ~ Call ~ Transferred value", caller, addr, value) if isPrecompile { ret, gas, err = RunPrecompiledContract(p, input, gas, evm.Config.Tracer) + if len(ret) > 0 { + fmt.Println("evm.go ~ EVM ~ Call ~ RunPrecompiledContract", string(ret[:10])) + } else { + fmt.Println("evm.go ~ EVM ~ Call ~ RunPrecompiledContract no output", gas, err) + } } else { // Initialise a new contract and set the code that is to be used by the EVM. code := evm.resolveCode(addr) if len(code) == 0 { + fmt.Println("evm.go ~ EVM ~ Call ~ No code to run", addr) ret, err = nil, nil // gas is unchanged } else { + fmt.Println("evm.go ~ EVM ~ Call ~ Code to run", addr, string(code[:10])) // The contract is a scoped environment for this execution context only. contract := NewContract(caller, addr, value, gas, evm.jumpDests) + fmt.Println("evm.go ~ EVM ~ Call ~ New contract", contract) contract.IsSystemCall = isSystemCall(caller) contract.SetCallCode(evm.resolveCodeHash(addr), code) + fmt.Println("evm.go ~ EVM ~ Call ~ Running contract", contract.Address()) ret, err = evm.Run(contract, input, false) gas = contract.Gas } @@ -319,7 +332,9 @@ func (evm *EVM) Call(caller common.Address, addr common.Address, input []byte, g // above we revert to the snapshot and consume any gas remaining. Additionally, // when we're in homestead this also counts for code storage gas errors. if err != nil { + fmt.Println("evm.go ~ EVM ~ Call ~ Error", err.Error()) evm.StateDB.RevertToSnapshot(snapshot) + fmt.Println("evm.go ~ EVM ~ Call ~ Reverted to snapshot", snapshot) if err != ErrExecutionReverted { if evm.Config.Tracer != nil && evm.Config.Tracer.OnGasChange != nil { evm.Config.Tracer.OnGasChange(gas, 0, tracing.GasChangeCallFailedExecution) @@ -646,11 +661,14 @@ func (evm *EVM) Create2(caller common.Address, code []byte, gas uint64, endowmen // resolveCode returns the code associated with the provided account. After // Prague, it can also resolve code pointed to by a delegation designator. func (evm *EVM) resolveCode(addr common.Address) []byte { + fmt.Println("evm.go ~ EVM ~ resolveCode ~ Resolving code for", addr) code := evm.StateDB.GetCode(addr) if !evm.chainRules.IsPrague { + fmt.Println("evm.go ~ EVM ~ resolveCode ~ Not Prague") return code } if target, ok := types.ParseDelegation(code); ok { + fmt.Println("evm.go ~ EVM ~ resolveCode ~ Parsed delegation target", target) // Note we only follow one level of delegation. return evm.StateDB.GetCode(target) } diff --git a/rpc/client.go b/rpc/client.go index 04d1e0170f..10badc906e 100644 --- a/rpc/client.go +++ b/rpc/client.go @@ -340,11 +340,13 @@ func (c *Client) Call(result interface{}, method string, args ...interface{}) er // The result must be a pointer so that package json can unmarshal into it. You // can also pass nil, in which case the result is ignored. func (c *Client) CallContext(ctx context.Context, result interface{}, method string, args ...interface{}) error { + fmt.Println("client.go ~ Client ~ CallContext ~ Calling", method, args) if result != nil && reflect.TypeOf(result).Kind() != reflect.Ptr { return fmt.Errorf("call result parameter must be pointer or nil interface: %v", result) } msg, err := c.newMessage(method, args...) if err != nil { + fmt.Println("client.go ~ Client ~ CallContext ~ NewMessage error", err.Error()) return err } var recordDone RecordDone @@ -357,8 +359,10 @@ func (c *Client) CallContext(ctx context.Context, result interface{}, method str } if c.isHTTP { + fmt.Println("client.go ~ Client ~ CallContext ~ Sending HTTP", method, args) err = c.sendHTTP(ctx, op, msg) } else { + fmt.Println("client.go ~ Client ~ CallContext ~ Sending", method, args) err = c.send(ctx, op, msg) } if err != nil { @@ -368,9 +372,11 @@ func (c *Client) CallContext(ctx context.Context, result interface{}, method str // dispatch has accepted the request and will close the channel when it quits. batchresp, err := op.wait(ctx, c) if err != nil { + fmt.Println("client.go ~ Client ~ CallContext ~ Error", err) return err } resp := batchresp[0] + fmt.Println("client.go ~ Client ~ CallContext ~ Response", resp) if recordDone != nil { recordDone(ctx, msg, resp) }