Skip to content

Conversation

@Stefan-Ethernal
Copy link
Contributor

@Stefan-Ethernal Stefan-Ethernal commented Dec 8, 2025

🔄 Changes Summary

Implement support for indexing of BackwardLET event in the bridge syncer. Also implemented BackwardToIndex method on the tree to roll back the Merkle tree to a specific index by deleting higher-indexed roots

Index of BackwardLET event

Once we index the BackwardLET event, we remove all the bridges whose deposit_count is greater than the new deposit count from the event. We also store the removed bridges into newly introduced bridge_archive table, in order to be able to bring them back in case BackwardLET event gets reorged.

Reorg of BackwardLET event

Once certain BackwardLET events get reorged, we figure out which ranges of bridges, by deposit counts, are affected and we restore them back from the bridge_archive into the bridge table.

⚠️ Breaking Changes

N/A

📋 Config Updates

N/A

✅ Testing

  • 🤖 Automatic: [Optional: Enumerate E2E tests]
  • 🖱️ Manual: [Optional: Steps to verify]

🐞 Issues

🔗 Related PRs

  • [Optional: Enumerate related pull requests]

📝 Notes

  • [Optional: design decisions, tradeoffs, or TODOs]

@Stefan-Ethernal Stefan-Ethernal changed the title Feat/index backward let feat: index backward let Dec 8, 2025
@Stefan-Ethernal Stefan-Ethernal force-pushed the feat/index-backward-let branch 3 times, most recently from 1ddf2c5 to 851ecb5 Compare December 8, 2025 12:38
@Stefan-Ethernal Stefan-Ethernal self-assigned this Dec 8, 2025
@Stefan-Ethernal Stefan-Ethernal force-pushed the feat/index-backward-let branch 2 times, most recently from bf95c12 to e3839b7 Compare December 12, 2025 06:37
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR implements support for indexing the BackwardLET (Backward Local Exit Tree) event in the bridge syncer, enabling the system to handle rollbacks of the local exit tree when they occur on the L2 bridge contract. The implementation includes archiving deleted bridges for potential restoration during reorgs, along with comprehensive test coverage for the new BackwardToIndex functionality in the tree package.

Key Changes:

  • Added BackwardLET event handling that deletes bridges with deposit counts beyond the rollback point and updates the tree state accordingly
  • Introduced a bridge_archive table with a trigger to automatically archive deleted bridges, enabling restoration during reorg scenarios
  • Implemented BackwardToIndex method on the tree to roll back the Merkle tree to a specific index by deleting higher-indexed roots

Reviewed changes

Copilot reviewed 17 out of 17 changed files in this pull request and generated 13 comments.

Show a summary per file
File Description
bridgesync/processor.go Adds BackwardLET event processing logic, bridge archiving/restoration during reorgs, and updates exitTree field type to interface
bridgesync/downloader.go Adds BackwardLET event signature and handler for parsing/appending BackwardLET events from logs
bridgesync/downloader_test.go Adds test coverage for BackwardLET event appender and unknown deployment kind error handling
bridgesync/processor_test.go Adds BackwardLET event to test data and includes reorg test scenario
bridgesync/migrations/bridgesync0011.sql Creates backward_let and bridge_archive tables with archiving trigger
bridgesync/migrations/migrations.go Refactors migration loading to use embed.FS and adds GetUpTo helper function
bridgesync/migrations/migrations_test.go Updates tests to use new GetUpTo helper instead of hardcoded migration lists
tree/tree.go Implements BackwardToIndex method and refactors storeNodes loop for cleaner code
tree/tree_test.go Adds comprehensive test coverage for BackwardToIndex including edge cases
tree/types/interfaces.go Adds BackwardToIndex method to ReorganizeTreer interface
tree/types/mocks/*.go Updates mocks with BackwardToIndex method implementation
db/types/interface.go Adds ExecContext method to Querier interface
db/mocks/*.go Updates mocks with ExecContext method implementation
Comments suppressed due to low confidence (1)

bridgesync/processor.go:523

  • The Event.String() method doesn't include BackwardLET in the string representation. When logging or debugging events that contain BackwardLET, this information will be missing. Add a check for e.BackwardLET and append its string representation to parts.
func (e Event) String() string {
	parts := []string{}
	if e.Bridge != nil {
		parts = append(parts, e.Bridge.String())
	}
	if e.Claim != nil {
		parts = append(parts, e.Claim.String())
	}
	if e.TokenMapping != nil {
		parts = append(parts, e.TokenMapping.String())
	}
	if e.LegacyTokenMigration != nil {
		parts = append(parts, e.LegacyTokenMigration.String())
	}
	if e.RemoveLegacyToken != nil {
		parts = append(parts, e.RemoveLegacyToken.String())
	}
	if e.UnsetClaim != nil {
		parts = append(parts, e.UnsetClaim.String())
	}
	if e.SetClaim != nil {
		parts = append(parts, e.SetClaim.String())
	}
	return "Event{" + strings.Join(parts, ", ") + "}"

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 17 out of 17 changed files in this pull request and generated 6 comments.

Comments suppressed due to low confidence (1)

bridgesync/processor.go:538

  • The Event.String() method is missing the BackwardLET field in its string representation. Add a check for e.BackwardLET and append it to the parts slice to ensure complete event logging and debugging output.
func (e Event) String() string {
	parts := []string{}
	if e.Bridge != nil {
		parts = append(parts, e.Bridge.String())
	}
	if e.Claim != nil {
		parts = append(parts, e.Claim.String())
	}
	if e.TokenMapping != nil {
		parts = append(parts, e.TokenMapping.String())
	}
	if e.LegacyTokenMigration != nil {
		parts = append(parts, e.LegacyTokenMigration.String())
	}
	if e.RemoveLegacyToken != nil {
		parts = append(parts, e.RemoveLegacyToken.String())
	}
	if e.UnsetClaim != nil {
		parts = append(parts, e.UnsetClaim.String())
	}
	if e.SetClaim != nil {
		parts = append(parts, e.SetClaim.String())
	}
	return "Event{" + strings.Join(parts, ", ") + "}"

@Stefan-Ethernal Stefan-Ethernal marked this pull request as ready for review December 18, 2025 08:22
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 19 out of 19 changed files in this pull request and generated 6 comments.

@Stefan-Ethernal Stefan-Ethernal changed the title feat: index backward let feat: index BackwardLET event Dec 23, 2025
@sonarqubecloud
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

index BackwardLET event in bridge syncer

4 participants