-
Notifications
You must be signed in to change notification settings - Fork 19
feat: index BackwardLET event
#1379
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Stefan-Ethernal
wants to merge
45
commits into
develop
Choose a base branch
from
feat/index-backward-let
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
45 commits
Select commit
Hold shift + click to select a range
38c00a1
remove unused var
Stefan-Ethernal e9834af
backward let event indexing scaffolding
Stefan-Ethernal 003112a
introduce new migration and refactor migrations resolution to be generic
Stefan-Ethernal c3dbef4
TestBuildAppender increase coverage
Stefan-Ethernal 928cf5f
delete bridges on backward let
Stefan-Ethernal c72e102
feat: backwards on merkle tree (#1378)
goran-ethernal aea7e8f
update exit tree on backward LET
Stefan-Ethernal 6ae4adb
formatting
Stefan-Ethernal b2dccc5
remove bridges whose deposit count is greater than new deposit count
Stefan-Ethernal aa2cd0c
remove InvalidClaim struct
Stefan-Ethernal a9c7035
correctly determine leaf index
Stefan-Ethernal 44774fa
archive bridges to bridge_archive table and handle reorgs
Stefan-Ethernal 275aed8
increase code coverage, ignore double insertions to bridge_archive table
Stefan-Ethernal 4d4d220
Merge branch 'develop' into feat/index-backward-let
Stefan-Ethernal ecc3ded
address 1st round of comments
Stefan-Ethernal f98e350
reverse the steps, first delete the bridges and then update the exit β¦
Stefan-Ethernal a74ca6e
Apply suggestions from code review
Stefan-Ethernal b2035c2
fix sql syntax error
Stefan-Ethernal 38f1fbe
leaf index is the same as deposit count
Stefan-Ethernal 752f986
invoke BackwardLET string function
Stefan-Ethernal 7c941ab
remove redundant check
Stefan-Ethernal 7ffebfd
fix sql syntax in migration file (2nd part)
Stefan-Ethernal 2b1ce28
reinsert exit tree leaves on reorg of backward let event
Stefan-Ethernal ba08508
add bridge source column and add ordering by deposit_count
Stefan-Ethernal e4c8f62
move the new sql migrations to bridgesync0012 migration file
Stefan-Ethernal 3600cd6
formatting
Stefan-Ethernal dba8654
Merge branch 'develop' into feat/index-backward-let
Stefan-Ethernal c900f0a
TestProcessor_BackwardLET
Stefan-Ethernal 2e39f39
increase code coverage in common pkg
Stefan-Ethernal 72fa419
TestProcessor_BackwardLET, backward LET on empty bridge table
Stefan-Ethernal a6ac3d8
add source column to bridge_archive table and copy the value on deletβ¦
Stefan-Ethernal 39c37b3
log the deleted bridges by deposit counts
Stefan-Ethernal 4b8235f
backward let in between of bridges
Stefan-Ethernal 04f3b2e
Merge branch 'develop' into feat/index-backward-let
Stefan-Ethernal e8dc5e0
fix: lint
Stefan-Ethernal d24339d
fix unit tests
Stefan-Ethernal b093169
refactor processing of backward let event
Stefan-Ethernal 3d9814f
remove bridges and leafs from exit tree, and then restore only the suβ¦
Stefan-Ethernal 3eeb0b9
Merge branch 'develop' into feat/index-backward-let
Stefan-Ethernal 60e78cc
address copilot's comments
Stefan-Ethernal 5ffbd31
small optimization
Stefan-Ethernal c40e7ac
Merge branch 'develop' into feat/index-backward-let
Stefan-Ethernal a7390c2
drop the bridge archive trigger and do it programatically, tweak test
Stefan-Ethernal 8eae344
Merge branch 'develop' into feat/index-backward-let
Stefan-Ethernal 1f4efd4
Merge branch 'develop' into feat/index-backward-let
Stefan-Ethernal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,41 @@ | ||
| -- +migrate Down | ||
| DROP TABLE IF EXISTS bridge_archive; | ||
| DROP TABLE IF EXISTS backward_let; | ||
| ALTER TABLE bridge DROP COLUMN source; | ||
| ALTER TABLE bridge DROP COLUMN to_address; | ||
|
|
||
| -- +migrate Up | ||
| CREATE TABLE IF NOT EXISTS backward_let ( | ||
| block_num INTEGER NOT NULL REFERENCES block (num) ON DELETE CASCADE, | ||
| block_pos INTEGER NOT NULL, | ||
| previous_deposit_count TEXT NOT NULL, | ||
| previous_root VARCHAR NOT NULL, | ||
| new_deposit_count TEXT NOT NULL, | ||
| new_root VARCHAR NOT NULL, | ||
| PRIMARY KEY (block_num, block_pos) | ||
| ); | ||
|
|
||
| ALTER TABLE bridge ADD COLUMN source TEXT DEFAULT ''; | ||
| ALTER TABLE bridge ADD COLUMN to_address VARCHAR; | ||
|
|
||
| ------------------------------------------------------------------------------ | ||
| -- Create bridge_archive table | ||
| ------------------------------------------------------------------------------ | ||
| CREATE TABLE IF NOT EXISTS bridge_archive ( | ||
| deposit_count INTEGER PRIMARY KEY, | ||
Stefan-Ethernal marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| block_num INTEGER NOT NULL, | ||
| block_pos INTEGER NOT NULL, | ||
| leaf_type INTEGER NOT NULL, | ||
| origin_network INTEGER NOT NULL, | ||
| origin_address VARCHAR NOT NULL, | ||
| destination_network INTEGER NOT NULL, | ||
| destination_address VARCHAR NOT NULL, | ||
| amount TEXT NOT NULL, | ||
| metadata BLOB, | ||
| tx_hash VARCHAR, | ||
| block_timestamp INTEGER, | ||
| txn_sender VARCHAR, | ||
| from_address VARCHAR, | ||
| source TEXT DEFAULT '', | ||
| to_address VARCHAR | ||
Stefan-Ethernal marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,100 +1,70 @@ | ||
| package migrations | ||
|
|
||
| import ( | ||
| _ "embed" | ||
| "embed" | ||
| "fmt" | ||
| "sort" | ||
| "strings" | ||
|
|
||
| "github.com/agglayer/aggkit/db" | ||
| "github.com/agglayer/aggkit/db/types" | ||
| treeMigrations "github.com/agglayer/aggkit/tree/migrations" | ||
| treemigrations "github.com/agglayer/aggkit/tree/migrations" | ||
| ) | ||
|
|
||
| //go:embed bridgesync0001.sql | ||
| var mig0001 string | ||
|
|
||
| //go:embed bridgesync0002.sql | ||
| var mig0002 string | ||
| var ( | ||
| //go:embed *.sql | ||
| migrationFS embed.FS | ||
Stefan-Ethernal marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| migrations []types.Migration | ||
| ) | ||
|
|
||
| //go:embed bridgesync0003.sql | ||
| var mig0003 string | ||
| func init() { | ||
| entries, err := migrationFS.ReadDir(".") | ||
| if err != nil { | ||
| panic(fmt.Errorf("failed to read embedded migrations: %w", err)) | ||
| } | ||
|
|
||
| //go:embed bridgesync0004.sql | ||
| var mig0004 string | ||
| for _, e := range entries { | ||
| name := e.Name() // e.g. "bridgesync0004.sql" | ||
|
|
||
| //go:embed bridgesync0005.sql | ||
| var mig0005 string | ||
| sqlBytes, err := migrationFS.ReadFile(name) | ||
| if err != nil { | ||
| panic(err) | ||
| } | ||
|
|
||
| //go:embed bridgesync0006.sql | ||
| var mig0006 string | ||
| id := strings.TrimSuffix(name, ".sql") // "bridgesync0004" | ||
|
|
||
| //go:embed bridgesync0007.sql | ||
| var mig0007 string | ||
| migrations = append(migrations, types.Migration{ | ||
| ID: id, | ||
| SQL: string(sqlBytes), | ||
| }) | ||
| } | ||
|
|
||
| //go:embed bridgesync0008.sql | ||
| var mig0008 string | ||
| // Ensure deterministic canonical order | ||
| sort.Slice(migrations, func(i, j int) bool { | ||
| return migrations[i].ID < migrations[j].ID | ||
| }) | ||
| } | ||
|
|
||
| //go:embed bridgesync0009.sql | ||
| var mig0009 string | ||
| func RunMigrations(dbPath string) error { | ||
| // Allocate slice with exact capacity to avoid reallocations when combining migrations | ||
| total := len(migrations) + len(treemigrations.Migrations) | ||
|
|
||
| //go:embed bridgesync0010.sql | ||
| var mig0010 string | ||
| combined := make([]types.Migration, 0, total) | ||
| // Copy migrations | ||
| combined = append(combined, migrations...) | ||
| combined = append(combined, treemigrations.Migrations...) | ||
|
|
||
| //go:embed bridgesync0011.sql | ||
| var mig0011 string | ||
| // Pass the copy to db.RunMigrations | ||
| return db.RunMigrations(dbPath, combined) | ||
| } | ||
|
|
||
| //go:embed bridgesync0012.sql | ||
| var mig0012 string | ||
| // GetUpTo returns all migrations up to and including the migration with the given ID. | ||
| func GetUpTo(lastID string) []types.Migration { | ||
| idx := sort.Search(len(migrations), func(i int) bool { | ||
| return migrations[i].ID > lastID | ||
| }) | ||
|
|
||
| func RunMigrations(dbPath string) error { | ||
| migrations := []types.Migration{ | ||
| { | ||
| ID: "bridgesync0001", | ||
| SQL: mig0001, | ||
| }, | ||
| { | ||
| ID: "bridgesync0002", | ||
| SQL: mig0002, | ||
| }, | ||
| { | ||
| ID: "bridgesync0003", | ||
| SQL: mig0003, | ||
| }, | ||
| { | ||
| ID: "bridgesync0004", | ||
| SQL: mig0004, | ||
| }, | ||
| { | ||
| ID: "bridgesync0005", | ||
| SQL: mig0005, | ||
| }, | ||
| { | ||
| ID: "bridgesync0006", | ||
| SQL: mig0006, | ||
| }, | ||
| { | ||
| ID: "bridgesync0007", | ||
| SQL: mig0007, | ||
| }, | ||
| { | ||
| ID: "bridgesync0008", | ||
| SQL: mig0008, | ||
| }, | ||
| { | ||
| ID: "bridgesync0009", | ||
| SQL: mig0009, | ||
| }, | ||
| { | ||
| ID: "bridgesync0010", | ||
| SQL: mig0010, | ||
| }, | ||
| { | ||
| ID: "bridgesync0011", | ||
| SQL: mig0011, | ||
| }, | ||
| { | ||
| ID: "bridgesync0012", | ||
| SQL: mig0012, | ||
| }, | ||
| } | ||
| migrations = append(migrations, treeMigrations.Migrations...) | ||
| return db.RunMigrations(dbPath, migrations) | ||
| out := make([]types.Migration, idx) | ||
| copy(out, migrations[:idx]) | ||
| return out | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.