Skip to content

Commit a01cd36

Browse files
committed
fix failover with local-da change
1 parent 1f6526a commit a01cd36

1 file changed

Lines changed: 23 additions & 29 deletions

File tree

test/e2e/failover_e2e_test.go

Lines changed: 23 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,7 @@ func TestLeaseFailoverE2E(t *testing.T) {
140140
t.Logf("+++ Killing current leader (%s)\n", oldLeader)
141141
_ = clusterNodes.Details(oldLeader).Kill()
142142

143-
const daStartHeight = 1
144-
lastDABlockOldLeader := queryLastDAHeight(t, daStartHeight, env.SequencerJWT, env.Endpoints.GetDAAddress())
143+
lastDABlockOldLeader := queryLastDAHeight(t, env.SequencerJWT, env.Endpoints.GetDAAddress())
145144
t.Log("+++ Last DA block by old leader: ", lastDABlockOldLeader)
146145
leaderElectionStart := time.Now()
147146

@@ -160,7 +159,7 @@ func TestLeaseFailoverE2E(t *testing.T) {
160159
// Verify DA progress
161160
var lastDABlockNewLeader uint64
162161
require.Eventually(t, func() bool {
163-
lastDABlockNewLeader = queryLastDAHeight(t, lastDABlockOldLeader, env.SequencerJWT, env.Endpoints.GetDAAddress())
162+
lastDABlockNewLeader = queryLastDAHeight(t, env.SequencerJWT, env.Endpoints.GetDAAddress())
164163
return lastDABlockNewLeader > lastDABlockOldLeader
165164
}, 2*must(time.ParseDuration(DefaultDABlockTime)), 100*time.Millisecond)
166165
t.Logf("+++ Last DA block by new leader: %d\n", lastDABlockNewLeader)
@@ -220,20 +219,20 @@ func TestLeaseFailoverE2E(t *testing.T) {
220219
return err == nil
221220
}, time.Second, 100*time.Millisecond)
222221

223-
lastDABlockNewLeader = queryLastDAHeight(t, lastDABlockNewLeader, env.SequencerJWT, env.Endpoints.GetDAAddress())
222+
lastDABlockNewLeader = queryLastDAHeight(t, env.SequencerJWT, env.Endpoints.GetDAAddress())
224223

225224
genesisHeight := state.InitialHeight
226225
verifyNoDoubleSigning(t, clusterNodes, genesisHeight, state.LastBlockHeight)
227226

228227
// wait for the next DA block to ensure all blocks are propagated
229228
require.Eventually(t, func() bool {
230229
before := lastDABlockNewLeader
231-
lastDABlockNewLeader = queryLastDAHeight(t, lastDABlockNewLeader, env.SequencerJWT, env.Endpoints.GetDAAddress())
230+
lastDABlockNewLeader = queryLastDAHeight(t, env.SequencerJWT, env.Endpoints.GetDAAddress())
232231
return before < lastDABlockNewLeader
233232
}, 2*must(time.ParseDuration(DefaultDABlockTime)), 100*time.Millisecond)
234233

235234
t.Log("+++ Verifying no DA gaps...")
236-
verifyDABlocks(t, daStartHeight, lastDABlockNewLeader, env.SequencerJWT, env.Endpoints.GetDAAddress(), genesisHeight, state.LastBlockHeight)
235+
verifyDABlocks(t, 1, lastDABlockNewLeader, env.SequencerJWT, env.Endpoints.GetDAAddress(), genesisHeight, state.LastBlockHeight)
237236

238237
// Cleanup processes
239238
clusterNodes.killAll()
@@ -326,8 +325,7 @@ func TestHASequencerRollingRestartE2E(t *testing.T) {
326325
// Wait for at least 5 blocks to be produced before starting shutdown sequence
327326
sut.AwaitNBlocks(t, 5, clusterNodes.Details(leaderNode).rpcAddr, 10*time.Second)
328327

329-
const daStartHeight = 1
330-
initialDAHeight := queryLastDAHeight(t, daStartHeight, env.SequencerJWT, env.Endpoints.GetDAAddress())
328+
initialDAHeight := queryLastDAHeight(t, env.SequencerJWT, env.Endpoints.GetDAAddress())
331329
t.Logf("+++ Initial DA height: %d", initialDAHeight)
332330

333331
// Calculate downtime per node
@@ -510,7 +508,7 @@ func TestHASequencerRollingRestartE2E(t *testing.T) {
510508
return err == nil
511509
}, time.Second, 100*time.Millisecond)
512510

513-
lastDABlock := queryLastDAHeight(t, initialDAHeight, env.SequencerJWT, env.Endpoints.GetDAAddress())
511+
lastDABlock := queryLastDAHeight(t, env.SequencerJWT, env.Endpoints.GetDAAddress())
514512

515513
genesisHeight := state.InitialHeight
516514
verifyNoDoubleSigning(t, clusterNodes, genesisHeight, state.LastBlockHeight)
@@ -519,13 +517,13 @@ func TestHASequencerRollingRestartE2E(t *testing.T) {
519517
// Wait for the next DA block to ensure all blocks are propagated
520518
require.Eventually(t, func() bool {
521519
before := lastDABlock
522-
lastDABlock = queryLastDAHeight(t, lastDABlock, env.SequencerJWT, env.Endpoints.GetDAAddress())
520+
lastDABlock = queryLastDAHeight(t, env.SequencerJWT, env.Endpoints.GetDAAddress())
523521
return before < lastDABlock
524522
}, 2*must(time.ParseDuration(DefaultDABlockTime)), 100*time.Millisecond)
525523

526524
// Verify no DA gaps
527525
t.Log("+++ Verifying no DA gaps...")
528-
verifyDABlocks(t, daStartHeight, lastDABlock, env.SequencerJWT, env.Endpoints.GetDAAddress(), genesisHeight, state.LastBlockHeight)
526+
verifyDABlocks(t, 1, lastDABlock, env.SequencerJWT, env.Endpoints.GetDAAddress(), genesisHeight, state.LastBlockHeight)
529527
t.Log("+++ No DA gaps detected ✓")
530528

531529
// Cleanup processes
@@ -579,10 +577,18 @@ func verifyDABlocks(t *testing.T, daStartHeight, lastDABlock uint64, jwtSecret s
579577
deduplicationCache := make(map[string]uint64) // mixed header and data hashes
580578

581579
// Verify each block is present exactly once
580+
// Note: local-da produces empty blocks on a ticker, so some DA heights may have no blobs — skip them.
582581
for daHeight := daStartHeight; daHeight <= lastDABlock; daHeight++ {
583582
blobs, err := blobClient.Blob.GetAll(t.Context(), daHeight, []libshare.Namespace{ns})
584-
require.NoError(t, err, "height %d/%d", daHeight, lastDABlock)
585-
require.NotEmpty(t, blobs)
583+
if err != nil {
584+
if strings.Contains(err.Error(), "blob: not found") {
585+
continue
586+
}
587+
require.NoError(t, err, "height %d/%d", daHeight, lastDABlock)
588+
}
589+
if len(blobs) == 0 {
590+
continue
591+
}
586592

587593
for _, blob := range blobs {
588594
if evHeight, hash, blobType := extractBlockHeight(t, blob.Data()); evHeight != 0 {
@@ -752,27 +758,15 @@ func submitTxToURL(t *testing.T, client *ethclient.Client) (common.Hash, uint64)
752758

753759
const defaultMaxBlobSize = 2 * 1024 * 1024 // 2MB
754760

755-
func queryLastDAHeight(t *testing.T, startHeight uint64, jwtSecret string, daAddress string) uint64 {
761+
func queryLastDAHeight(t *testing.T, jwtSecret string, daAddress string) uint64 {
756762
t.Helper()
757763
blobClient, err := blobrpc.NewClient(t.Context(), daAddress, jwtSecret, "")
758764
require.NoError(t, err)
759765
defer blobClient.Close()
760-
ns, err := libshare.NewNamespaceFromBytes(coreda.NamespaceFromString(DefaultDANamespace).Bytes())
766+
header, err := blobClient.Header.NetworkHead(t.Context())
761767
require.NoError(t, err)
762-
var lastDABlock = startHeight
763-
for {
764-
blobs, err := blobClient.Blob.GetAll(t.Context(), lastDABlock, []libshare.Namespace{ns})
765-
if err != nil {
766-
if strings.Contains(err.Error(), "future") {
767-
return lastDABlock - 1
768-
}
769-
t.Fatal("failed to get blobs:", err)
770-
}
771-
if len(blobs) != 0 && testing.Verbose() {
772-
t.Log("+++ DA block: ", lastDABlock, " blobs: ", len(blobs))
773-
}
774-
lastDABlock++
775-
}
768+
require.NotNil(t, header)
769+
return header.Height
776770
}
777771

778772
type nodeDetails struct {

0 commit comments

Comments
 (0)