Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions cl/beacon/handler/blobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,6 @@ func (a *ApiHandler) GetEthV1BeaconBlobSidecars(w http.ResponseWriter, r *http.R
return nil, beaconhttp.NewEndpointError(http.StatusNotFound, errors.New("block not found"))
}

// reject after fulu fork
if a.beaconChainCfg.GetCurrentStateVersion(*slot/a.beaconChainCfg.SlotsPerEpoch) >= clparams.FuluVersion {
return nil, beaconhttp.NewEndpointError(http.StatusNotFound, errors.New("blobs are not supported after fulu fork"))
}

if a.caplinSnapshots != nil && *slot <= a.caplinSnapshots.FrozenBlobs() {
out, err := a.caplinSnapshots.ReadBlobSidecars(*slot)
if err != nil {
Expand Down
10 changes: 6 additions & 4 deletions cl/clparams/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -675,13 +675,14 @@ type BeaconChainConfig struct {

// GetBlobParameters returns the blob parameters at a given epoch
func (b *BeaconChainConfig) GetBlobParameters(epoch uint64) BlobParameters {
// Iterate through schedule in desceding order
for i := range b.BlobSchedule {
// Iterate through schedule in desc order
for i := len(b.BlobSchedule) - 1; i >= 0; i-- {
entry := b.BlobSchedule[i]
if epoch >= entry.Epoch {
return entry
}
}

// Default to Electra parameters if no matching schedule entry
return BlobParameters{
Epoch: b.ElectraForkEpoch,
Expand Down Expand Up @@ -729,9 +730,9 @@ func (b *BeaconChainConfig) GetCurrentStateVersion(epoch uint64) StateVersion {
// InitializeForkSchedule initializes the schedules forks baked into the config.
func (b *BeaconChainConfig) InitializeForkSchedule() {
b.ForkVersionSchedule = configForkSchedule(b)
// sort blob schedule by epoch in descending order
// sort blob schedule by epoch in ascending order
sort.Slice(b.BlobSchedule, func(i, j int) bool {
return b.BlobSchedule[i].Epoch > b.BlobSchedule[j].Epoch
return b.BlobSchedule[i].Epoch < b.BlobSchedule[j].Epoch
})
}

Expand Down Expand Up @@ -1197,6 +1198,7 @@ func gnosisConfig() BeaconChainConfig {
cfg.MaxPerEpochActivationChurnLimit = 2
cfg.MaxPerEpochActivationExitChurnLimit = 64_000_000_000
cfg.MaxRequestBlobSidecarsElectra = 256
cfg.MaxPendingPartialsPerWithdrawalsSweep = 6
cfg.InitializeForkSchedule()
return cfg
}
Expand Down
3 changes: 3 additions & 0 deletions cl/cltypes/justification_bits.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,12 @@ import (

"github.com/erigontech/erigon-lib/common/hexutil"
"github.com/erigontech/erigon-lib/types/clonable"
ssz2 "github.com/erigontech/erigon/cl/ssz"
"github.com/erigontech/erigon/cl/utils"
)

var _ ssz2.SizedObjectSSZ = (*JustificationBits)(nil)

const JustificationBitsLength = 4

type JustificationBits [JustificationBitsLength]bool // Bit vector of size 4
Expand Down
2 changes: 2 additions & 0 deletions cl/cltypes/solid/checkpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import (
ssz2 "github.com/erigontech/erigon/cl/ssz"
)

var _ ssz2.SizedObjectSSZ = (*Checkpoint)(nil)

const CheckpointSizeSSZ = 40

type Checkpoint struct {
Expand Down
2 changes: 1 addition & 1 deletion cl/persistence/state/epoch_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,6 @@ func (m *EpochData) getSchema() []interface{} {
&m.FinalizedCheckpoint,
&m.HistoricalSummariesLength,
&m.HistoricalRootsLength,
&m.ProposerLookahead,
m.ProposerLookahead,
}
}
7 changes: 7 additions & 0 deletions core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,13 @@ var alwaysSkipReceiptCheck = dbg.EnvBool("EXEC_SKIP_RECEIPT_CHECK", false)

func BlockPostValidation(gasUsed, blobGasUsed uint64, checkReceipts bool, receipts types.Receipts, h *types.Header, isMining bool, txns types.Transactions, chainConfig *chain.Config, logger log.Logger) error {
if gasUsed != h.GasUsed {
var txgas string
sep := ""
for _, receipt := range receipts {
txgas += fmt.Sprintf("%s%d=%d", sep, receipt.TransactionIndex, receipt.GasUsed)
sep = ", "
}
logger.Warn("gas used mismatch", "block", h.Number.Uint64(), "header", h.GasUsed, "execution", gasUsed, "txgas", txgas)
return fmt.Errorf("gas used by execution: %d, in header: %d, headerNum=%d, %x",
gasUsed, h.GasUsed, h.Number.Uint64(), h.Hash())
}
Expand Down
10 changes: 5 additions & 5 deletions core/state/cached_writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ func (cw *CachedWriter) UpdateAccountData(address common.Address, original, acco
}

func (cw *CachedWriter) UpdateAccountCode(address common.Address, incarnation uint64, codeHash common.Hash, code []byte) error {
if err := cw.w.UpdateAccountCode(address, incarnation, codeHash, code); err != nil {
if err := cw.w.UpdateAccountCode(address, 1, codeHash, code); err != nil {
return err
}
cw.cache.SetCodeWrite(address.Bytes(), incarnation, code)
cw.cache.SetCodeWrite(address.Bytes(), 1, code)
return nil
}

Expand All @@ -60,16 +60,16 @@ func (cw *CachedWriter) DeleteAccount(address common.Address, original *accounts
}

func (cw *CachedWriter) WriteAccountStorage(address common.Address, incarnation uint64, key common.Hash, original, value uint256.Int) error {
if err := cw.w.WriteAccountStorage(address, incarnation, key, original, value); err != nil {
if err := cw.w.WriteAccountStorage(address, 1, key, original, value); err != nil {
return err
}
if original == value {
return nil
}
if value.IsZero() {
cw.cache.SetStorageDelete(address.Bytes(), incarnation, key[:])
cw.cache.SetStorageDelete(address.Bytes(), 1, key[:])
} else {
cw.cache.SetStorageWrite(address.Bytes(), incarnation, key[:], value.Bytes())
cw.cache.SetStorageWrite(address.Bytes(), 1, key[:], value.Bytes())
}
return nil
}
Expand Down
40 changes: 35 additions & 5 deletions core/state/intra_block_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,12 @@ func (sdb *IntraBlockState) SubRefund(gas uint64) error {

// Exist reports whether the given account address exists in the state.
// Notably this also returns true for suicided accounts.
func (sdb *IntraBlockState) Exist(addr common.Address) (bool, error) {
func (sdb *IntraBlockState) Exist(addr common.Address) (exists bool, err error) {
if dbg.TraceTransactionIO && (sdb.trace || traceAccount(addr)) {
defer func() {
fmt.Printf("%d (%d.%d) Exists %x: %v (%s)\n", sdb.blockNum, sdb.txIndex, sdb.version, addr, exists, dbg.Stack())
}()
}
s, err := sdb.getStateObject(addr)
if err != nil {
return false, err
Expand All @@ -339,7 +344,12 @@ func (sdb *IntraBlockState) Exist(addr common.Address) (bool, error) {

// Empty returns whether the state object is either non-existent
// or empty according to the EIP161 specification (balance = nonce = code = 0)
func (sdb *IntraBlockState) Empty(addr common.Address) (bool, error) {
func (sdb *IntraBlockState) Empty(addr common.Address) (empty bool, err error) {
if dbg.TraceTransactionIO && (sdb.trace || traceAccount(addr)) {
defer func() {
fmt.Printf("%d (%d.%d) Empty %x: %v\n", sdb.blockNum, sdb.txIndex, sdb.version, addr, empty)
}()
}
so, err := sdb.getStateObject(addr)
if err != nil {
return false, err
Expand Down Expand Up @@ -1139,9 +1149,29 @@ func (sdb *IntraBlockState) createObject(addr common.Address, previous *stateObj
// 2. tx_create(sha(account ++ nonce)) (note that this gets the address of 1)
//
// Carrying over the balance ensures that Ether doesn't disappear.
func (sdb *IntraBlockState) CreateAccount(addr common.Address, contractCreation bool) error {
func (sdb *IntraBlockState) CreateAccount(addr common.Address, contractCreation bool) (err error) {
var prevInc uint64
previous, err := sdb.getStateObject(addr)
var previous *stateObject

if dbg.TraceTransactionIO && (sdb.trace || traceAccount(addr)) {
defer func() {
var creatingContract string
if contractCreation {
creatingContract = " (contract)"
}
if err != nil {
fmt.Printf("%d (%d.%d) Create Account%s: %x, err=%s\n", sdb.blockNum, sdb.txIndex, sdb.version, creatingContract, addr, err)
} else {
var bal uint256.Int
if previous != nil {
bal = previous.data.Balance
}
fmt.Printf("%d (%d.%d) Create Account%s: %x, balance=%d\n", sdb.blockNum, sdb.txIndex, sdb.version, creatingContract, addr, &bal)
}
}()
}

previous, err = sdb.getStateObject(addr)
if err != nil {
return err
}
Expand Down Expand Up @@ -1233,7 +1263,7 @@ func (sdb *IntraBlockState) RevertToSnapshot(revid int, err error) {
}
}

if traced && sdb.txIndex == 8 && sdb.version == 1 {
if traced {
fmt.Printf("%d (%d.%d) Reverted: %d:%d\n", sdb.blockNum, sdb.txIndex, sdb.version, revid, snapshot)
}
}
Expand Down
4 changes: 2 additions & 2 deletions core/state_transition.go
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,7 @@ func (st *StateTransition) TransitionDb(refunds bool, gasBailout bool) (result *
}
}

if st.state.Trace() || st.state.TraceAccount(st.msg.From()) {
if dbg.TraceGas || st.state.Trace() || st.state.TraceAccount(st.msg.From()) {
fmt.Printf("(%d.%d) Fees %x: tipped: %d, burnt: %d, price: %d, gas: %d\n", st.state.TxIndex(), st.state.Incarnation(), st.msg.From(), tipAmount, &burnAmount, st.gasPrice, st.gasUsed())
}

Expand Down Expand Up @@ -718,7 +718,7 @@ func (st *StateTransition) verifyAuthorities(auths []types.Authorization, contra
func (st *StateTransition) refundGas() {
// Return ETH for remaining gas, exchanged at the original rate.
remaining := new(uint256.Int).Mul(new(uint256.Int).SetUint64(st.gasRemaining), st.gasPrice)
if st.state.Trace() || st.state.TraceAccount(st.msg.From()) {
if dbg.TraceGas || st.state.Trace() || st.state.TraceAccount(st.msg.From()) {
fmt.Printf("(%d.%d) Refund %x: remaining: %d, price: %d val: %d\n", st.state.TxIndex(), st.state.Incarnation(), st.msg.From(), st.gasRemaining, st.gasPrice, remaining)
}

Expand Down
30 changes: 23 additions & 7 deletions core/vm/interpreter.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,12 +264,14 @@ func (in *EVMInterpreter) Run(contract *Contract, input []byte, readOnly bool) (
pc = &_pc // program counter
cost uint64
// copies used by tracer
pcCopy uint64 // needed for the deferred Tracer
gasCopy uint64 // for Tracer to log gas remaining before execution
logged bool // deferred Tracer should ignore already logged steps
res []byte // result of the opcode execution function
debug = in.cfg.Tracer != nil && (in.cfg.Tracer.OnOpcode != nil || in.cfg.Tracer.OnGasChange != nil || in.cfg.Tracer.OnFault != nil)
trace = dbg.TraceInstructions && in.evm.intraBlockState.Trace()
pcCopy uint64 // needed for the deferred Tracer
gasCopy uint64 // for Tracer to log gas remaining before execution
callGas uint64
logged bool // deferred Tracer should ignore already logged steps
res []byte // result of the opcode execution function
debug = in.cfg.Tracer != nil && (in.cfg.Tracer.OnOpcode != nil || in.cfg.Tracer.OnGasChange != nil || in.cfg.Tracer.OnFault != nil)
trace = dbg.TraceInstructions && in.evm.intraBlockState.Trace()
txIndex, txIncarnation int
)

contract.Input = input
Expand Down Expand Up @@ -307,14 +309,24 @@ func (in *EVMInterpreter) Run(contract *Contract, input []byte, readOnly bool) (
// parent context.
steps := 0

var traceGas = func(op OpCode, callGas, cost uint64) uint64 {
switch op {
case CALL, CALLCODE, DELEGATECALL, STATICCALL:
return callGas
default:
return cost
}
}

for {
steps++
if steps%5000 == 0 && in.evm.Cancelled() {
break
}
if debug {
if dbg.TraceDyanmicGas || debug || trace {
// Capture pre-execution values for tracing.
logged, pcCopy, gasCopy = false, _pc, contract.Gas
txIndex, txIncarnation = in.evm.intraBlockState.TxIndex(), in.evm.intraBlockState.Incarnation()
}
// Get the operation from the jump table and validate the stack to ensure there are
// enough stack items available to perform the operation.
Expand Down Expand Up @@ -354,9 +366,13 @@ func (in *EVMInterpreter) Run(contract *Contract, input []byte, readOnly bool) (
var dynamicCost uint64
dynamicCost, err = operation.dynamicGas(in.evm, contract, locStack, mem, memorySize)
cost += dynamicCost // for tracing
callGas = operation.constantGas + dynamicCost - in.evm.CallGasTemp()
if err != nil {
return nil, fmt.Errorf("%w: %v", ErrOutOfGas, err)
}
if dbg.TraceDyanmicGas && dynamicCost > 0 {
fmt.Printf("(%d.%d) Dynamic Gas: %d (%s)\n", txIndex, txIncarnation, traceGas(op, callGas, cost), op)
}
if !contract.UseGas(dynamicCost, in.cfg.Tracer, tracing.GasChangeIgnored) {
return nil, ErrOutOfGas
}
Expand Down
13 changes: 6 additions & 7 deletions db/snapshotsync/freezeblocks/block_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"encoding/binary"
"errors"
"fmt"
"math"
"sort"

lru "github.com/hashicorp/golang-lru/v2"
Expand Down Expand Up @@ -455,7 +454,6 @@ func (r *BlockReader) MinimumBlockAvailable(ctx context.Context, tx kv.Tx) (uint
return 0, errors.New("MinimumBlockAvailable: no snapshot or DB available")
}

var err error
dbMinBlock, err := r.findFirstCompleteBlock(tx)
if err != nil {
return 0, fmt.Errorf("failed to find first complete block in database: %w", err)
Expand All @@ -464,18 +462,19 @@ func (r *BlockReader) MinimumBlockAvailable(ctx context.Context, tx kv.Tx) (uint
return dbMinBlock, nil
}

// findFirstCompleteBlock finds the first block (after genesis) where block body is available, returns math.Uint64 if no block is found
// findFirstCompleteBlock finds the first block (after genesis) where block body is available.
// When no block bodies exist beyond genesis, it returns 0.
func (r *BlockReader) findFirstCompleteBlock(tx kv.Tx) (uint64, error) {
firstKey, err := rawdbv3.SecondKey(tx, kv.BlockBody)
secondKey, err := rawdbv3.SecondKey(tx, kv.BlockBody)
if err != nil {
return 0, fmt.Errorf("failed to get first BlockBody key after genesis: %w", err)
}

if len(firstKey) < 8 {
return math.MaxUint64, nil // no body data found
if len(secondKey) < 8 { // incomplete key, no block found
return 0, nil
}

result := binary.BigEndian.Uint64(firstKey[:8])
result := binary.BigEndian.Uint64(secondKey[:8])
return result, nil
}
func (r *BlockReader) FrozenBorBlocks(align bool) uint64 {
Expand Down
Loading
Loading