Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions bridgetracker/db/sqlite_activity_reorg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,40 @@ func TestActivityReorg_BridgeReincludedInAnotherBlock(t *testing.T) {
})
}

// TestActivityReorg_BridgeReincludedBecomesFinal: the finality of a bridge re-included in another
// block is the one of its new block. The entry is not final while that block is not, becomes
// final with it (still a single entry, at the new location), and that last step alone does not
// change the revision
func TestActivityReorg_BridgeReincludedBecomesFinal(t *testing.T) {
runOnBothStores(t, func(h *activityHarness) {
t := h.t
h.scan([]*domain.ScannedBridge{reorgBridge(1, 100, "0xb1", false)})
h.unclaimed(false)
entries := h.refresh()
require.False(t, entries[0].Finalized)

h.scan([]*domain.ScannedBridge{reorgBridge(1, 200, "0xb2", false)})
h.unclaimed(false)
entries = h.refresh()
require.Len(t, entries, 1)
require.Equal(t, uint64(200), entries[0].Bridge.BlockNum)
require.False(t, entries[0].Finalized, "the new block is not final either")

h.scan([]*domain.ScannedBridge{reorgBridge(1, 200, "0xb2", true)})
h.unclaimed(false)
entries = h.refresh()
require.Len(t, entries, 1, "no duplicate left behind at the old block")
require.Equal(t, uint64(200), entries[0].Bridge.BlockNum)
require.Equal(t, bridgeservicetypes.Hash("0xb2"), entries[0].Bridge.TxHash)
require.True(t, entries[0].Finalized, "final once the block it was re-included in is final")
require.Equal(t, types.TrackerClaimStatusPending, entries[0].TrackerClaimStatus)

require.Len(t, h.revisions, 3)
require.NotEqual(t, h.revisions[0], h.revisions[1], "the correction changes the revision")
require.Equal(t, h.revisions[1], h.revisions[2], "becoming final does not")
})
}

// TestActivityReorg_BridgeReplacedBySameGlobalIndex: a different bridge taking the same deposit
// count (so global index) replaces the entry's data
func TestActivityReorg_BridgeReplacedBySameGlobalIndex(t *testing.T) {
Expand Down
56 changes: 56 additions & 0 deletions bridgetracker/engine_reorg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,62 @@ func TestEngineOriginReorgedOut(t *testing.T) {
require.Equal(t, types.TrackerClaimStatusReadyToClaim, tracking.ClaimStatus())
}

// TestEngineOriginReorgedOutNeverReincluded pins what the tracker reports for a tracked tx that a
// reorg removes for good: the tracking goes back to registered with a fresh UnresolvedTimeout
// (counted from the reorg, not from when the tx was first tracked) and, once that elapses without
// the tx being mined again, ends in the terminal error of a tx that does not exist, with nothing
// left of the bridge that had been resolved
func TestEngineOriginReorgedOutNeverReincluded(t *testing.T) {
id := TrackingID{NetworkID: 0, TxHash: testHash}
f := &fakeSources{bridge: l1ToL2ReorgBridge()}
facts := &reorgFacts{}
store := newMemoryRegistry(0)
engine, clock := newReorgTestEngine(t, store, f, facts)
updates, unsubscribe, err := store.Subscribe(id)
require.NoError(t, err)
defer unsubscribe()

driveToReadyToClaim(f)
engine.tick(t.Context())
tracking := receiveUpdate(t, updates)
require.Equal(t, types.TrackerClaimStatusReadyToClaim, tracking.ClaimStatus())

// tracked for longer than UnresolvedTimeout before the reorg: the timeout of the first
// resolution must not count against the tx once it is reorged out
*clock = clock.Add(3 * engine.cfg.UnresolvedTimeout)
facts.set(func(r *reorgFacts) { r.canonical = common.HexToHash("0xa2") })
f.bridge, f.bridgeErr = nil, ErrBridgeTxNotFound
engine.tick(t.Context())
tracking = receiveUpdate(t, updates)
require.Equal(t, types.TrackingStatusRegistered, tracking.TrackingStatus(), "a fresh UnresolvedTimeout starts at the reorg")
require.Equal(t, types.TrackerClaimStatusPending, tracking.ClaimStatus())
require.Nil(t, tracking.Info())
require.Nil(t, tracking.AllSteps())
require.False(t, tracking.Failed())
require.Len(t, mustGetTrackerActives(t, store), 1)

// still missing just before the timeout: still looked for
*clock = clock.Add(engine.cfg.UnresolvedTimeout - time.Second)
engine.tick(t.Context())
tracking = mustGetFrom(t, store, id)
require.Equal(t, types.TrackingStatusRegistered, tracking.TrackingStatus())
require.False(t, tracking.Failed())

// never re-included: given up on, like any tx that does not exist on the network
*clock = clock.Add(time.Second)
engine.tick(t.Context())
tracking = mustGetFrom(t, store, id)
require.Equal(t, types.TrackingStatusError, tracking.TrackingStatus())
require.Equal(t, types.TrackerClaimStatusError, tracking.ClaimStatus())
require.Nil(t, tracking.Info(), "the bridge resolved before the reorg must not come back")
require.Nil(t, tracking.StepIndex())
require.Nil(t, tracking.AllSteps())
require.True(t, tracking.Failed())
require.NotNil(t, tracking.Error())
require.Equal(t, types.StepErrorExhausted, tracking.Error().ErrorType)
require.Empty(t, mustGetTrackerActives(t, store), "a tx given up on leaves the active list")
}

// TestEngineOriginReincludedInAnotherBlockSameTick pins the common case: the reorged-out bridge
// tx is already re-mined when the reorg is seen, so it moves to its new block in the same tick
func TestEngineOriginReincludedInAnotherBlockSameTick(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Every scenario goes in the same order, so a failure points at the right componen

| Test (CI group) | Scenarios |
| --- | --- |
| `TestProxyReorgActivity` (`proxy-reorg-activity`) | A1 bridge from network 1 reorged out; A2 same bridge re-included in another block; A3 bridge replaced by another one with the same deposit count; A4 L1 -> L2 bridge reorged out of L1; A5 bridge of network 2 seen only through the RPC fallback, reorged out; A6 final bridge, shallower reorg |
| `TestProxyReorgActivity` (`proxy-reorg-activity`) | A1 bridge from network 1 reorged out; A2 same bridge re-included in another block, then final there; A3 bridge replaced by another one with the same deposit count; A4 L1 -> L2 bridge reorged out of L1; A5 bridge of network 2 seen only through the RPC fallback, reorged out; A6 final bridge, shallower reorg |
| `TestProxyReorgClaims` (`proxy-reorg-claims`) | B1 claim reorged out, claimed again, final; B2 reorg removes the claim and the GER injection; B3 final claim stays `claimed_finalized` and is not rechecked; B4 claim re-included in another block; C1 reorg removes only the GER injection |
| `TestProxyReorgTracker` (`proxy-reorg-tracker-revision`) | D1 origin transaction moves and then disappears while tracked; D2 `Claimed` goes back to `WaitingClaim` and a WebSocket subscriber is told, then the connection closes once the claim is final |
| `TestProxyReorgRevision` (`proxy-reorg-tracker-revision`) | E1 `revision` unchanged by refreshes and by a not-final -> final transition; E2 and E3 a claim on page 2 reorged out while a client paginates; E4 same `revision` on `aggkit-proxy-001` and `-002`, and after a restart |
Expand Down
17 changes: 17 additions & 0 deletions test/e2e/proxy_reorg_activity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,23 @@ func TestProxyReorgActivity(t *testing.T) {
require.Equal(t, s.item.Bridge.GlobalIndex, item.Bridge.GlobalIndex)
require.False(t, item.isFinalized(), "the new block is not final either")
require.NotEqual(t, s.before.Revision, after.Revision, "a bridge moved to another block must change the revision")

// finality is the one of the new block: once that block is final the same single entry is final,
// and that alone does not change the revision.
// NOTE: an unclaimed bridge in a final block reads finalized=true (open decision (b) of #1986: the
// assertion follows the current behaviour)
_, err := l2.MineUntilFinalized(ctx, moved.BlockNumber.Uint64())
require.NoError(t, err)
requireBridgeServed(ctx, t, s.bs, s.networkID, s.depositCount, moved, true)
final := s.waitForActivity(ctx, t, "the bridge is final at its new block",
func(a *proxyActivityResponse) bool {
item := a.find(s.networkID, s.depositCount)
return itemMatchesReceipt(item, moved) && item.isFinalized()
})
require.Equal(t, 1, final.Count, "a corrected bridge must stay a single entry: %s", final)
require.Equal(t, claimStatusPending, final.find(s.networkID, s.depositCount).ClaimStatus,
"with the aggsender held the bridge cannot become claimable")
require.Equal(t, after.Revision, final.Revision, "going from not final to final must not change the revision")
})

t.Run("A3 bridge replaced by a different one with the same deposit count", func(t *testing.T) {
Expand Down
Loading