Skip to content

Commit 55ad3db

Browse files
authored
Merge pull request #48 from 0xPolygon/mardizzone/upstream-erigon-v3.2.1
Fetch upstream erigon v3.2.1
2 parents b4fc478 + e815101 commit 55ad3db

File tree

25 files changed

+366
-55
lines changed

25 files changed

+366
-55
lines changed

cl/beacon/handler/blobs.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,6 @@ func (a *ApiHandler) GetEthV1BeaconBlobSidecars(w http.ResponseWriter, r *http.R
5757
return nil, beaconhttp.NewEndpointError(http.StatusNotFound, errors.New("block not found"))
5858
}
5959

60-
// reject after fulu fork
61-
if a.beaconChainCfg.GetCurrentStateVersion(*slot/a.beaconChainCfg.SlotsPerEpoch) >= clparams.FuluVersion {
62-
return nil, beaconhttp.NewEndpointError(http.StatusNotFound, errors.New("blobs are not supported after fulu fork"))
63-
}
64-
6560
if a.caplinSnapshots != nil && *slot <= a.caplinSnapshots.FrozenBlobs() {
6661
out, err := a.caplinSnapshots.ReadBlobSidecars(*slot)
6762
if err != nil {

cl/clparams/config.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -675,13 +675,14 @@ type BeaconChainConfig struct {
675675

676676
// GetBlobParameters returns the blob parameters at a given epoch
677677
func (b *BeaconChainConfig) GetBlobParameters(epoch uint64) BlobParameters {
678-
// Iterate through schedule in desceding order
679-
for i := range b.BlobSchedule {
678+
// Iterate through schedule in desc order
679+
for i := len(b.BlobSchedule) - 1; i >= 0; i-- {
680680
entry := b.BlobSchedule[i]
681681
if epoch >= entry.Epoch {
682682
return entry
683683
}
684684
}
685+
685686
// Default to Electra parameters if no matching schedule entry
686687
return BlobParameters{
687688
Epoch: b.ElectraForkEpoch,
@@ -729,9 +730,9 @@ func (b *BeaconChainConfig) GetCurrentStateVersion(epoch uint64) StateVersion {
729730
// InitializeForkSchedule initializes the schedules forks baked into the config.
730731
func (b *BeaconChainConfig) InitializeForkSchedule() {
731732
b.ForkVersionSchedule = configForkSchedule(b)
732-
// sort blob schedule by epoch in descending order
733+
// sort blob schedule by epoch in ascending order
733734
sort.Slice(b.BlobSchedule, func(i, j int) bool {
734-
return b.BlobSchedule[i].Epoch > b.BlobSchedule[j].Epoch
735+
return b.BlobSchedule[i].Epoch < b.BlobSchedule[j].Epoch
735736
})
736737
}
737738

@@ -1197,6 +1198,7 @@ func gnosisConfig() BeaconChainConfig {
11971198
cfg.MaxPerEpochActivationChurnLimit = 2
11981199
cfg.MaxPerEpochActivationExitChurnLimit = 64_000_000_000
11991200
cfg.MaxRequestBlobSidecarsElectra = 256
1201+
cfg.MaxPendingPartialsPerWithdrawalsSweep = 6
12001202
cfg.InitializeForkSchedule()
12011203
return cfg
12021204
}

cl/cltypes/justification_bits.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,12 @@ import (
2121

2222
"github.com/erigontech/erigon-lib/common/hexutil"
2323
"github.com/erigontech/erigon-lib/types/clonable"
24+
ssz2 "github.com/erigontech/erigon/cl/ssz"
2425
"github.com/erigontech/erigon/cl/utils"
2526
)
2627

28+
var _ ssz2.SizedObjectSSZ = (*JustificationBits)(nil)
29+
2730
const JustificationBitsLength = 4
2831

2932
type JustificationBits [JustificationBitsLength]bool // Bit vector of size 4

cl/cltypes/solid/checkpoint.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ import (
2525
ssz2 "github.com/erigontech/erigon/cl/ssz"
2626
)
2727

28+
var _ ssz2.SizedObjectSSZ = (*Checkpoint)(nil)
29+
2830
const CheckpointSizeSSZ = 40
2931

3032
type Checkpoint struct {

cl/persistence/state/epoch_data.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,6 @@ func (m *EpochData) getSchema() []interface{} {
111111
&m.FinalizedCheckpoint,
112112
&m.HistoricalSummariesLength,
113113
&m.HistoricalRootsLength,
114-
&m.ProposerLookahead,
114+
m.ProposerLookahead,
115115
}
116116
}

core/blockchain.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,13 @@ var alwaysSkipReceiptCheck = dbg.EnvBool("EXEC_SKIP_RECEIPT_CHECK", false)
402402

403403
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 {
404404
if gasUsed != h.GasUsed {
405+
var txgas string
406+
sep := ""
407+
for _, receipt := range receipts {
408+
txgas += fmt.Sprintf("%s%d=%d", sep, receipt.TransactionIndex, receipt.GasUsed)
409+
sep = ", "
410+
}
411+
logger.Warn("gas used mismatch", "block", h.Number.Uint64(), "header", h.GasUsed, "execution", gasUsed, "txgas", txgas)
405412
return fmt.Errorf("gas used by execution: %d, in header: %d, headerNum=%d, %x",
406413
gasUsed, h.GasUsed, h.Number.Uint64(), h.Hash())
407414
}

core/state/cached_writer.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,10 @@ func (cw *CachedWriter) UpdateAccountData(address common.Address, original, acco
4444
}
4545

4646
func (cw *CachedWriter) UpdateAccountCode(address common.Address, incarnation uint64, codeHash common.Hash, code []byte) error {
47-
if err := cw.w.UpdateAccountCode(address, incarnation, codeHash, code); err != nil {
47+
if err := cw.w.UpdateAccountCode(address, 1, codeHash, code); err != nil {
4848
return err
4949
}
50-
cw.cache.SetCodeWrite(address.Bytes(), incarnation, code)
50+
cw.cache.SetCodeWrite(address.Bytes(), 1, code)
5151
return nil
5252
}
5353

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

6262
func (cw *CachedWriter) WriteAccountStorage(address common.Address, incarnation uint64, key common.Hash, original, value uint256.Int) error {
63-
if err := cw.w.WriteAccountStorage(address, incarnation, key, original, value); err != nil {
63+
if err := cw.w.WriteAccountStorage(address, 1, key, original, value); err != nil {
6464
return err
6565
}
6666
if original == value {
6767
return nil
6868
}
6969
if value.IsZero() {
70-
cw.cache.SetStorageDelete(address.Bytes(), incarnation, key[:])
70+
cw.cache.SetStorageDelete(address.Bytes(), 1, key[:])
7171
} else {
72-
cw.cache.SetStorageWrite(address.Bytes(), incarnation, key[:], value.Bytes())
72+
cw.cache.SetStorageWrite(address.Bytes(), 1, key[:], value.Bytes())
7373
}
7474
return nil
7575
}

core/state/intra_block_state.go

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,12 @@ func (sdb *IntraBlockState) SubRefund(gas uint64) error {
329329

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

340345
// Empty returns whether the state object is either non-existent
341346
// or empty according to the EIP161 specification (balance = nonce = code = 0)
342-
func (sdb *IntraBlockState) Empty(addr common.Address) (bool, error) {
347+
func (sdb *IntraBlockState) Empty(addr common.Address) (empty bool, err error) {
348+
if dbg.TraceTransactionIO && (sdb.trace || traceAccount(addr)) {
349+
defer func() {
350+
fmt.Printf("%d (%d.%d) Empty %x: %v\n", sdb.blockNum, sdb.txIndex, sdb.version, addr, empty)
351+
}()
352+
}
343353
so, err := sdb.getStateObject(addr)
344354
if err != nil {
345355
return false, err
@@ -1139,9 +1149,29 @@ func (sdb *IntraBlockState) createObject(addr common.Address, previous *stateObj
11391149
// 2. tx_create(sha(account ++ nonce)) (note that this gets the address of 1)
11401150
//
11411151
// Carrying over the balance ensures that Ether doesn't disappear.
1142-
func (sdb *IntraBlockState) CreateAccount(addr common.Address, contractCreation bool) error {
1152+
func (sdb *IntraBlockState) CreateAccount(addr common.Address, contractCreation bool) (err error) {
11431153
var prevInc uint64
1144-
previous, err := sdb.getStateObject(addr)
1154+
var previous *stateObject
1155+
1156+
if dbg.TraceTransactionIO && (sdb.trace || traceAccount(addr)) {
1157+
defer func() {
1158+
var creatingContract string
1159+
if contractCreation {
1160+
creatingContract = " (contract)"
1161+
}
1162+
if err != nil {
1163+
fmt.Printf("%d (%d.%d) Create Account%s: %x, err=%s\n", sdb.blockNum, sdb.txIndex, sdb.version, creatingContract, addr, err)
1164+
} else {
1165+
var bal uint256.Int
1166+
if previous != nil {
1167+
bal = previous.data.Balance
1168+
}
1169+
fmt.Printf("%d (%d.%d) Create Account%s: %x, balance=%d\n", sdb.blockNum, sdb.txIndex, sdb.version, creatingContract, addr, &bal)
1170+
}
1171+
}()
1172+
}
1173+
1174+
previous, err = sdb.getStateObject(addr)
11451175
if err != nil {
11461176
return err
11471177
}
@@ -1233,7 +1263,7 @@ func (sdb *IntraBlockState) RevertToSnapshot(revid int, err error) {
12331263
}
12341264
}
12351265

1236-
if traced && sdb.txIndex == 8 && sdb.version == 1 {
1266+
if traced {
12371267
fmt.Printf("%d (%d.%d) Reverted: %d:%d\n", sdb.blockNum, sdb.txIndex, sdb.version, revid, snapshot)
12381268
}
12391269
}

core/state_transition.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -601,7 +601,7 @@ func (st *StateTransition) TransitionDb(refunds bool, gasBailout bool) (result *
601601
}
602602
}
603603

604-
if st.state.Trace() || st.state.TraceAccount(st.msg.From()) {
604+
if dbg.TraceGas || st.state.Trace() || st.state.TraceAccount(st.msg.From()) {
605605
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())
606606
}
607607

@@ -718,7 +718,7 @@ func (st *StateTransition) verifyAuthorities(auths []types.Authorization, contra
718718
func (st *StateTransition) refundGas() {
719719
// Return ETH for remaining gas, exchanged at the original rate.
720720
remaining := new(uint256.Int).Mul(new(uint256.Int).SetUint64(st.gasRemaining), st.gasPrice)
721-
if st.state.Trace() || st.state.TraceAccount(st.msg.From()) {
721+
if dbg.TraceGas || st.state.Trace() || st.state.TraceAccount(st.msg.From()) {
722722
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)
723723
}
724724

core/vm/interpreter.go

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -264,12 +264,14 @@ func (in *EVMInterpreter) Run(contract *Contract, input []byte, readOnly bool) (
264264
pc = &_pc // program counter
265265
cost uint64
266266
// copies used by tracer
267-
pcCopy uint64 // needed for the deferred Tracer
268-
gasCopy uint64 // for Tracer to log gas remaining before execution
269-
logged bool // deferred Tracer should ignore already logged steps
270-
res []byte // result of the opcode execution function
271-
debug = in.cfg.Tracer != nil && (in.cfg.Tracer.OnOpcode != nil || in.cfg.Tracer.OnGasChange != nil || in.cfg.Tracer.OnFault != nil)
272-
trace = dbg.TraceInstructions && in.evm.intraBlockState.Trace()
267+
pcCopy uint64 // needed for the deferred Tracer
268+
gasCopy uint64 // for Tracer to log gas remaining before execution
269+
callGas uint64
270+
logged bool // deferred Tracer should ignore already logged steps
271+
res []byte // result of the opcode execution function
272+
debug = in.cfg.Tracer != nil && (in.cfg.Tracer.OnOpcode != nil || in.cfg.Tracer.OnGasChange != nil || in.cfg.Tracer.OnFault != nil)
273+
trace = dbg.TraceInstructions && in.evm.intraBlockState.Trace()
274+
txIndex, txIncarnation int
273275
)
274276

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

312+
var traceGas = func(op OpCode, callGas, cost uint64) uint64 {
313+
switch op {
314+
case CALL, CALLCODE, DELEGATECALL, STATICCALL:
315+
return callGas
316+
default:
317+
return cost
318+
}
319+
}
320+
310321
for {
311322
steps++
312323
if steps%5000 == 0 && in.evm.Cancelled() {
313324
break
314325
}
315-
if debug {
326+
if dbg.TraceDyanmicGas || debug || trace {
316327
// Capture pre-execution values for tracing.
317328
logged, pcCopy, gasCopy = false, _pc, contract.Gas
329+
txIndex, txIncarnation = in.evm.intraBlockState.TxIndex(), in.evm.intraBlockState.Incarnation()
318330
}
319331
// Get the operation from the jump table and validate the stack to ensure there are
320332
// enough stack items available to perform the operation.
@@ -354,9 +366,13 @@ func (in *EVMInterpreter) Run(contract *Contract, input []byte, readOnly bool) (
354366
var dynamicCost uint64
355367
dynamicCost, err = operation.dynamicGas(in.evm, contract, locStack, mem, memorySize)
356368
cost += dynamicCost // for tracing
369+
callGas = operation.constantGas + dynamicCost - in.evm.CallGasTemp()
357370
if err != nil {
358371
return nil, fmt.Errorf("%w: %v", ErrOutOfGas, err)
359372
}
373+
if dbg.TraceDyanmicGas && dynamicCost > 0 {
374+
fmt.Printf("(%d.%d) Dynamic Gas: %d (%s)\n", txIndex, txIncarnation, traceGas(op, callGas, cost), op)
375+
}
360376
if !contract.UseGas(dynamicCost, in.cfg.Tracer, tracing.GasChangeIgnored) {
361377
return nil, ErrOutOfGas
362378
}

0 commit comments

Comments
 (0)