Skip to content

Commit c4e675c

Browse files
committed
Merge branch 'enable_devnet_3_tests' of github.com:erigontech/erigon into bal-devnet-3
2 parents 970c8da + 1d0b0f9 commit c4e675c

File tree

4 files changed

+522
-53
lines changed

4 files changed

+522
-53
lines changed

execution/stagedsync/bal_create.go

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ import (
1111
"github.com/holiman/uint256"
1212

1313
"github.com/erigontech/erigon/common/log/v3"
14+
"github.com/erigontech/erigon/db/kv"
15+
"github.com/erigontech/erigon/db/rawdb"
1416
"github.com/erigontech/erigon/execution/protocol/params"
17+
"github.com/erigontech/erigon/execution/protocol/rules"
1518
"github.com/erigontech/erigon/execution/state"
1619
"github.com/erigontech/erigon/execution/types"
1720
"github.com/erigontech/erigon/execution/types/accounts"
@@ -559,3 +562,55 @@ func writeBALToFile(bal types.BlockAccessList, blockNum uint64, dataDir string)
559562

560563
//log.Info("BAL written to file", "blockNum", blockNum, "filename", filename, "accounts", len(bal))
561564
}
565+
566+
func ProcessBAL(tx kv.TemporalRwTx, h *types.Header, vio *state.VersionedIO, blockProduction bool, amsterdam bool, experimental bool, dataDir string) error {
567+
if !amsterdam && !experimental {
568+
return nil
569+
}
570+
blockNum := h.Number.Uint64()
571+
blockHash := h.Hash()
572+
bal := CreateBAL(blockNum, vio, dataDir)
573+
err := bal.Validate()
574+
if err != nil {
575+
return fmt.Errorf("block %d: invalid computed block access list: %w", blockNum, err)
576+
}
577+
log.Debug("bal", "blockNum", blockNum, "hash", bal.Hash())
578+
if !amsterdam {
579+
return nil
580+
}
581+
if h.BlockAccessListHash == nil {
582+
if blockProduction {
583+
hash := bal.Hash()
584+
h.BlockAccessListHash = &hash
585+
return nil
586+
}
587+
return fmt.Errorf("block %d: missing block access list hash", blockNum)
588+
}
589+
headerBALHash := *h.BlockAccessListHash
590+
dbBALBytes, err := rawdb.ReadBlockAccessListBytes(tx, blockHash, blockNum)
591+
if err != nil {
592+
return fmt.Errorf("block %d: read stored block access list: %w", blockNum, err)
593+
}
594+
// BAL data may not be stored for blocks downloaded via backward
595+
// block downloader (p2p sync) since it does not carry BAL sidecars.
596+
// Remove after eth/71 has been implemented.
597+
if dbBALBytes != nil {
598+
dbBAL, err := types.DecodeBlockAccessListBytes(dbBALBytes)
599+
if err != nil {
600+
return fmt.Errorf("block %d: read stored block access list: %w", blockNum, err)
601+
}
602+
if err = dbBAL.Validate(); err != nil {
603+
return fmt.Errorf("block %d: db block access list is invalid: %w", blockNum, err)
604+
}
605+
606+
if headerBALHash != dbBAL.Hash() {
607+
log.Info(fmt.Sprintf("bal from block: %s", dbBAL.DebugString()))
608+
return fmt.Errorf("block %d: invalid block access list, hash mismatch: got %s expected %s", blockNum, dbBAL.Hash(), headerBALHash)
609+
}
610+
}
611+
if headerBALHash != bal.Hash() {
612+
log.Info(fmt.Sprintf("computed bal: %s", bal.DebugString()))
613+
return fmt.Errorf("%w, block=%d: block access list mismatch: got %s expected %s", rules.ErrInvalidBlock, blockNum, bal.Hash(), headerBALHash)
614+
}
615+
return nil
616+
}

execution/stagedsync/exec3_parallel.go

Lines changed: 7 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import (
2222
"github.com/erigontech/erigon/db/kv"
2323
"github.com/erigontech/erigon/db/kv/mdbx"
2424
"github.com/erigontech/erigon/db/kv/temporal"
25-
"github.com/erigontech/erigon/db/rawdb"
2625
"github.com/erigontech/erigon/db/state/changeset"
2726
"github.com/erigontech/erigon/diagnostics/metrics"
2827
"github.com/erigontech/erigon/execution/chain"
@@ -221,54 +220,6 @@ func (pe *parallelExecutor) exec(ctx context.Context, execStage *StageState, u U
221220
return fmt.Errorf("block %d: applyCount mismatch: got: %d expected %d", applyResult.BlockNum, blockUpdateCount, applyResult.ApplyCount)
222221
}
223222

224-
// pe.cfg.chainConfig.AmsterdamTime != nil && pe.cfg.chainConfig.AmsterdamTime.Uint64() > 0 is
225-
// temporary to allow for initial non bals amsterdam testing before parallel exec is live by default
226-
if (pe.cfg.chainConfig.AmsterdamTime != nil && pe.cfg.chainConfig.AmsterdamTime.Uint64() > 0 && pe.cfg.chainConfig.IsAmsterdam(applyResult.BlockTime)) || pe.cfg.experimentalBAL {
227-
bal := CreateBAL(applyResult.BlockNum, applyResult.TxIO, pe.cfg.dirs.DataDir)
228-
if err := bal.Validate(); err != nil {
229-
return fmt.Errorf("block %d: invalid computed block access list: %w", applyResult.BlockNum, err)
230-
}
231-
log.Debug("bal", "blockNum", applyResult.BlockNum, "hash", bal.Hash())
232-
if pe.cfg.chainConfig.IsAmsterdam(applyResult.BlockTime) {
233-
if lastHeader.BlockAccessListHash == nil {
234-
if pe.isBlockProduction {
235-
hash := bal.Hash()
236-
lastHeader.BlockAccessListHash = &hash
237-
} else {
238-
return fmt.Errorf("block %d: missing block access list hash", applyResult.BlockNum)
239-
}
240-
}
241-
headerBALHash := *lastHeader.BlockAccessListHash
242-
if !pe.isBlockProduction {
243-
dbBALBytes, err := rawdb.ReadBlockAccessListBytes(rwTx, applyResult.BlockHash, applyResult.BlockNum)
244-
if err != nil {
245-
return fmt.Errorf("block %d: read stored block access list: %w", applyResult.BlockNum, err)
246-
}
247-
// BAL data may not be stored for blocks downloaded via backward
248-
// block downloader (p2p sync) since it does not carry BAL sidecars.
249-
// Remove after eth/71 has been implemented.
250-
if dbBALBytes != nil {
251-
dbBAL, err := types.DecodeBlockAccessListBytes(dbBALBytes)
252-
if err != nil {
253-
return fmt.Errorf("block %d: read stored block access list: %w", applyResult.BlockNum, err)
254-
}
255-
if err = dbBAL.Validate(); err != nil {
256-
return fmt.Errorf("block %d: db block access list is invalid: %w", applyResult.BlockNum, err)
257-
}
258-
259-
if headerBALHash != dbBAL.Hash() {
260-
log.Info(fmt.Sprintf("bal from block: %s", dbBAL.DebugString()))
261-
return fmt.Errorf("block %d: invalid block access list, hash mismatch: got %s expected %s", applyResult.BlockNum, dbBAL.Hash(), headerBALHash)
262-
}
263-
}
264-
if headerBALHash != bal.Hash() {
265-
log.Info(fmt.Sprintf("computed bal: %s", bal.DebugString()))
266-
return fmt.Errorf("%w, block=%d: block access list mismatch: got %s expected %s", rules.ErrInvalidBlock, applyResult.BlockNum, bal.Hash(), headerBALHash)
267-
}
268-
}
269-
}
270-
}
271-
272223
if err := pe.getPostValidator().Process(applyResult.BlockGasUsed, applyResult.BlobGasUsed, checkReceipts, applyResult.Receipts,
273224
lastHeader, pe.isBlockProduction, b.Transactions(), pe.cfg.chainConfig, pe.logger); err != nil {
274225
dumpTxIODebug(applyResult.BlockNum, applyResult.TxIO)
@@ -395,6 +346,13 @@ func (pe *parallelExecutor) exec(ctx context.Context, execStage *StageState, u U
395346
return err
396347
}
397348

349+
if pe.cfg.chainConfig.IsAmsterdam(applyResult.BlockTime) || pe.cfg.experimentalBAL {
350+
err = ProcessBAL(rwTx, lastHeader, applyResult.TxIO, pe.isBlockProduction, pe.cfg.chainConfig.IsAmsterdam(applyResult.BlockTime), pe.cfg.experimentalBAL, pe.cfg.dirs.DataDir)
351+
if err != nil {
352+
return err
353+
}
354+
}
355+
398356
if shouldGenerateChangesets {
399357
pe.domains().SavePastChangesetAccumulator(applyResult.BlockHash, applyResult.BlockNum, changeSet)
400358
}

0 commit comments

Comments
 (0)