Skip to content

Commit f52f52a

Browse files
authored
execution/tests: add bal-devnet-3 fixtures and move bals hash check after post block validation and before commitment validation (#19595)
DO NOT MERGE BEFORE #19528 - adds the new bal-devnet-3 test fixtures and applies the skips for failing eips - moves the bals hash check after post block validation and before commitment verification so that we can clearly see the real errors (e.g. gas mismatches/receipt mismatches/etc) instead of always seeing `block access list mismatch`
1 parent cdb5451 commit f52f52a

File tree

4 files changed

+521
-48
lines changed

4 files changed

+521
-48
lines changed

execution/stagedsync/bal_create.go

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ import (
66
"path/filepath"
77

88
"github.com/erigontech/erigon/common/log/v3"
9+
"github.com/erigontech/erigon/db/kv"
10+
"github.com/erigontech/erigon/db/rawdb"
11+
"github.com/erigontech/erigon/execution/protocol/rules"
912
"github.com/erigontech/erigon/execution/state"
1013
"github.com/erigontech/erigon/execution/types"
1114
)
@@ -105,3 +108,54 @@ func writeBALToFile(bal types.BlockAccessList, blockNum uint64, dataDir string)
105108

106109
//log.Info("BAL written to file", "blockNum", blockNum, "filename", filename, "accounts", len(bal))
107110
}
111+
112+
func ProcessBAL(tx kv.TemporalRwTx, h *types.Header, vio *state.VersionedIO, blockProduction bool, amsterdam bool, experimental bool, dataDir string) error {
113+
if !amsterdam && !experimental {
114+
return nil
115+
}
116+
blockNum := h.Number.Uint64()
117+
blockHash := h.Hash()
118+
bal := CreateBAL(blockNum, vio, dataDir)
119+
err := bal.Validate()
120+
if err != nil {
121+
return fmt.Errorf("block %d: invalid computed block access list: %w", blockNum, err)
122+
}
123+
log.Debug("bal", "blockNum", blockNum, "hash", bal.Hash())
124+
if !amsterdam {
125+
return nil
126+
}
127+
if h.BlockAccessListHash == nil {
128+
if blockProduction {
129+
hash := bal.Hash()
130+
h.BlockAccessListHash = &hash
131+
return nil
132+
}
133+
return fmt.Errorf("block %d: missing block access list hash", blockNum)
134+
}
135+
headerBALHash := *h.BlockAccessListHash
136+
dbBALBytes, err := rawdb.ReadBlockAccessListBytes(tx, blockHash, blockNum)
137+
if err != nil {
138+
return fmt.Errorf("block %d: read stored block access list: %w", blockNum, err)
139+
}
140+
// BAL data may not be stored for blocks downloaded via backward
141+
// block downloader (p2p sync) since it does not carry BAL sidecars.
142+
// Remove after eth/71 has been implemented.
143+
if dbBALBytes != nil {
144+
dbBAL, err := types.DecodeBlockAccessListBytes(dbBALBytes)
145+
if err != nil {
146+
return fmt.Errorf("block %d: read stored block access list: %w", blockNum, err)
147+
}
148+
if err = dbBAL.Validate(); err != nil {
149+
return fmt.Errorf("block %d: db block access list is invalid: %w", blockNum, err)
150+
}
151+
152+
if headerBALHash != dbBAL.Hash() {
153+
log.Info(fmt.Sprintf("bal from block: %s", dbBAL.DebugString()))
154+
return fmt.Errorf("block %d: invalid block access list, hash mismatch: got %s expected %s", blockNum, dbBAL.Hash(), headerBALHash)
155+
}
156+
}
157+
if headerBALHash != bal.Hash() {
158+
return fmt.Errorf("%w, block=%d: block access list mismatch: got %s expected %s", rules.ErrInvalidBlock, blockNum, bal.Hash(), headerBALHash)
159+
}
160+
return nil
161+
}

execution/stagedsync/exec3_parallel.go

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

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+
395356
if shouldGenerateChangesets {
396357
pe.domains().SavePastChangesetAccumulator(applyResult.BlockHash, applyResult.BlockNum, changeSet)
397358
}

0 commit comments

Comments
 (0)