From bdb6d17aaa75f6b62c2e957aed2458d8cf7786ee Mon Sep 17 00:00:00 2001 From: badgersrus <43809877+badgersrus@users.noreply.github.com> Date: Tue, 5 Nov 2024 11:08:55 +0100 Subject: [PATCH] Sim flakiness (#2123) * reorder sim test shutdown and more efficient hash lookup on rollup verification --- go/enclave/components/rollup_consumer.go | 18 +++++++++++++++--- integration/simulation/simulation_tester.go | 9 ++++----- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/go/enclave/components/rollup_consumer.go b/go/enclave/components/rollup_consumer.go index aff7b3ec63..169c9fe929 100644 --- a/go/enclave/components/rollup_consumer.go +++ b/go/enclave/components/rollup_consumer.go @@ -159,10 +159,22 @@ func (rc *rollupConsumerImpl) extractAndVerifyRollups(br *common.BlockAndReceipt return rollups, nil } +// there may be many rollups in one block so the blobHashes array, so it is possible that the rollupHashes array is a +// subset of the blobHashes array func verifyBlobHashes(rollupHashes *ethadapter.L1RollupHashes, blobHashes []gethcommon.Hash) error { - for i, hash := range rollupHashes.BlobHashes { - if hash != blobHashes[i] { - return fmt.Errorf("hash mismatch at index %d: rollupHash (%s) != blobHash (%s)", i, hash.Hex(), blobHashes[i].Hex()) + // more efficient lookup + blobHashSet := make(map[gethcommon.Hash]struct{}, len(blobHashes)) + for _, h := range blobHashes { + blobHashSet[h] = struct{}{} + } + + for i, rollupHash := range rollupHashes.BlobHashes { + if _, exists := blobHashSet[rollupHash]; !exists { + return fmt.Errorf( + "rollupHash at index %d (%s) not found in blobHashes", + i, + rollupHash.Hex(), + ) } } return nil diff --git a/integration/simulation/simulation_tester.go b/integration/simulation/simulation_tester.go index 83b068f33e..f53bc60df8 100644 --- a/integration/simulation/simulation_tester.go +++ b/integration/simulation/simulation_tester.go @@ -73,14 +73,13 @@ func testSimulation(t *testing.T, netw network.Network, params *params.SimParams // run tests fmt.Printf("Validating simulation results\n") testlog.Logger().Info("Validating simulation results") - checkNetworkValidity(t, &simulation) - fmt.Printf("Stopping simulation\n") - testlog.Logger().Info("Stopping simulation") - simulation.Stop() - // generate and print the final stats t.Logf("Simulation results:%+v", NewOutputStats(&simulation)) testlog.Logger().Info(fmt.Sprintf("Simulation results:%+v", NewOutputStats(&simulation))) + + fmt.Printf("Stopping simulation\n") + testlog.Logger().Info("Stopping simulation") + simulation.Stop() }