Skip to content
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

feat: add StateRoot migration construct #216

Merged
merged 1 commit into from
Feb 5, 2025

Conversation

seanmcgary
Copy link
Member

@seanmcgary seanmcgary commented Feb 3, 2025

This PR introduces the concept of a state migration. When introducing new features, it's possible that there is existing transaction data that was not codified into a model that now needs to be. Rather than truncating the database, re-indexing blocks resulting in modifying existing StateRoots, this migration construct allows us to populate new models with existing data, leaving existing StateRoots unchanged, and codifying the changes in a sub-tree whos root is represented in the top-level StateRoot tree.

Screenshot 2025-02-04 at 8 25 47 AM

The StateMigrator specifies which migrations run at which block height for a given chain. Multiple migrations can be run for a single block and will be run in the order specified. Each migration will produce a root representing the changes made. Each of those roots are composed of the same StateRoot structure used at the very top-level, one for each block that was touched in the migration process. In the majority of cases where we're populating models with only a few events, these StateRoot trees will be rather sparse and only include the new model.

Each migration works by:

  • Creating a new instance of the StateManager
  • Querying the database for the TransactionLogs that need to be processed
  • Groups them by block number
  • In the order of blockNumber ascending, feeds each log through the StateManager as it would have if it came through in real time.

The same lifecycle of HandleLogStateChange --> CommitFinalState --> GenerateStateRoot is followed.

todo:

  • Update fork block heights and dates

@seanmcgary seanmcgary changed the title feat: add stateRoot migration construct feat: add StateRoot migration construct Feb 4, 2025
@seanmcgary seanmcgary marked this pull request as ready for review February 5, 2025 13:54
@seanmcgary seanmcgary requested a review from a team as a code owner February 5, 2025 13:54
@seanmcgary seanmcgary requested a review from 0xrajath February 5, 2025 13:54
0xrajath
0xrajath previously approved these changes Feb 5, 2025
Copy link
Contributor

@0xrajath 0xrajath left a comment

Choose a reason for hiding this comment

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

LGTM! I think we just need to update the fork height and date for preprod.

0xrajath
0xrajath previously approved these changes Feb 5, 2025
@seanmcgary seanmcgary merged commit 11f99a1 into release/rewards-v2.1 Feb 5, 2025
9 checks passed
@seanmcgary seanmcgary deleted the sm-stateMigration branch February 5, 2025 18:13
seanmcgary added a commit that referenced this pull request Feb 10, 2025
This PR introduces the concept of a state migration. When introducing
new features, it's possible that there is existing transaction data that
was not codified into a model that now needs to be. Rather than
truncating the database, re-indexing blocks resulting in modifying
existing StateRoots, this migration construct allows us to populate new
models with existing data, leaving existing StateRoots unchanged, and
codifying the changes in a sub-tree whos root is represented in the
top-level StateRoot tree.

![Screenshot 2025-02-04 at 8 25
47 AM](https://github.com/user-attachments/assets/149021bc-7457-49f0-b4f2-2091a4d0b46c)

The StateMigrator specifies which migrations run at which block height
for a given chain. Multiple migrations can be run for a single block and
will be run in the order specified. Each migration will produce a root
representing the changes made. Each of those roots are composed of the
same StateRoot structure used at the very top-level, one for each block
that was touched in the migration process. In the majority of cases
where we're populating models with only a few events, these StateRoot
trees will be rather sparse and only include the new model.

Each migration works by:

* Creating a new instance of the StateManager
* Querying the database for the TransactionLogs that need to be
processed
* Groups them by block number
* In the order of blockNumber ascending, feeds each log through the
StateManager as it would have if it came through in real time.

The same lifecycle of HandleLogStateChange --> CommitFinalState -->
GenerateStateRoot is followed.
seanmcgary added a commit that referenced this pull request Feb 11, 2025
This PR introduces the concept of a state migration. When introducing
new features, it's possible that there is existing transaction data that
was not codified into a model that now needs to be. Rather than
truncating the database, re-indexing blocks resulting in modifying
existing StateRoots, this migration construct allows us to populate new
models with existing data, leaving existing StateRoots unchanged, and
codifying the changes in a sub-tree whos root is represented in the
top-level StateRoot tree.

![Screenshot 2025-02-04 at 8 25
47 AM](https://github.com/user-attachments/assets/149021bc-7457-49f0-b4f2-2091a4d0b46c)

The StateMigrator specifies which migrations run at which block height
for a given chain. Multiple migrations can be run for a single block and
will be run in the order specified. Each migration will produce a root
representing the changes made. Each of those roots are composed of the
same StateRoot structure used at the very top-level, one for each block
that was touched in the migration process. In the majority of cases
where we're populating models with only a few events, these StateRoot
trees will be rather sparse and only include the new model.

Each migration works by:

* Creating a new instance of the StateManager
* Querying the database for the TransactionLogs that need to be
processed
* Groups them by block number
* In the order of blockNumber ascending, feeds each log through the
StateManager as it would have if it came through in real time.

The same lifecycle of HandleLogStateChange --> CommitFinalState -->
GenerateStateRoot is followed.
seanmcgary added a commit that referenced this pull request Feb 11, 2025
This PR introduces the concept of a state migration. When introducing
new features, it's possible that there is existing transaction data that
was not codified into a model that now needs to be. Rather than
truncating the database, re-indexing blocks resulting in modifying
existing StateRoots, this migration construct allows us to populate new
models with existing data, leaving existing StateRoots unchanged, and
codifying the changes in a sub-tree whos root is represented in the
top-level StateRoot tree.

![Screenshot 2025-02-04 at 8 25
47 AM](https://github.com/user-attachments/assets/149021bc-7457-49f0-b4f2-2091a4d0b46c)

The StateMigrator specifies which migrations run at which block height
for a given chain. Multiple migrations can be run for a single block and
will be run in the order specified. Each migration will produce a root
representing the changes made. Each of those roots are composed of the
same StateRoot structure used at the very top-level, one for each block
that was touched in the migration process. In the majority of cases
where we're populating models with only a few events, these StateRoot
trees will be rather sparse and only include the new model.

Each migration works by:

* Creating a new instance of the StateManager
* Querying the database for the TransactionLogs that need to be
processed
* Groups them by block number
* In the order of blockNumber ascending, feeds each log through the
StateManager as it would have if it came through in real time.

The same lifecycle of HandleLogStateChange --> CommitFinalState -->
GenerateStateRoot is followed.
seanmcgary added a commit that referenced this pull request Feb 12, 2025
This PR introduces the concept of a state migration. When introducing
new features, it's possible that there is existing transaction data that
was not codified into a model that now needs to be. Rather than
truncating the database, re-indexing blocks resulting in modifying
existing StateRoots, this migration construct allows us to populate new
models with existing data, leaving existing StateRoots unchanged, and
codifying the changes in a sub-tree whos root is represented in the
top-level StateRoot tree.

![Screenshot 2025-02-04 at 8 25
47 AM](https://github.com/user-attachments/assets/149021bc-7457-49f0-b4f2-2091a4d0b46c)

The StateMigrator specifies which migrations run at which block height
for a given chain. Multiple migrations can be run for a single block and
will be run in the order specified. Each migration will produce a root
representing the changes made. Each of those roots are composed of the
same StateRoot structure used at the very top-level, one for each block
that was touched in the migration process. In the majority of cases
where we're populating models with only a few events, these StateRoot
trees will be rather sparse and only include the new model.

Each migration works by:

* Creating a new instance of the StateManager
* Querying the database for the TransactionLogs that need to be
processed
* Groups them by block number
* In the order of blockNumber ascending, feeds each log through the
StateManager as it would have if it came through in real time.

The same lifecycle of HandleLogStateChange --> CommitFinalState -->
GenerateStateRoot is followed.
seanmcgary added a commit that referenced this pull request Feb 14, 2025
This PR introduces the concept of a state migration. When introducing
new features, it's possible that there is existing transaction data that
was not codified into a model that now needs to be. Rather than
truncating the database, re-indexing blocks resulting in modifying
existing StateRoots, this migration construct allows us to populate new
models with existing data, leaving existing StateRoots unchanged, and
codifying the changes in a sub-tree whos root is represented in the
top-level StateRoot tree.

![Screenshot 2025-02-04 at 8 25
47 AM](https://github.com/user-attachments/assets/149021bc-7457-49f0-b4f2-2091a4d0b46c)

The StateMigrator specifies which migrations run at which block height
for a given chain. Multiple migrations can be run for a single block and
will be run in the order specified. Each migration will produce a root
representing the changes made. Each of those roots are composed of the
same StateRoot structure used at the very top-level, one for each block
that was touched in the migration process. In the majority of cases
where we're populating models with only a few events, these StateRoot
trees will be rather sparse and only include the new model.

Each migration works by:

* Creating a new instance of the StateManager
* Querying the database for the TransactionLogs that need to be
processed
* Groups them by block number
* In the order of blockNumber ascending, feeds each log through the
StateManager as it would have if it came through in real time.

The same lifecycle of HandleLogStateChange --> CommitFinalState -->
GenerateStateRoot is followed.
seanmcgary added a commit that referenced this pull request Feb 20, 2025
This PR introduces the concept of a state migration. When introducing
new features, it's possible that there is existing transaction data that
was not codified into a model that now needs to be. Rather than
truncating the database, re-indexing blocks resulting in modifying
existing StateRoots, this migration construct allows us to populate new
models with existing data, leaving existing StateRoots unchanged, and
codifying the changes in a sub-tree whos root is represented in the
top-level StateRoot tree.

![Screenshot 2025-02-04 at 8 25
47 AM](https://github.com/user-attachments/assets/149021bc-7457-49f0-b4f2-2091a4d0b46c)

The StateMigrator specifies which migrations run at which block height
for a given chain. Multiple migrations can be run for a single block and
will be run in the order specified. Each migration will produce a root
representing the changes made. Each of those roots are composed of the
same StateRoot structure used at the very top-level, one for each block
that was touched in the migration process. In the majority of cases
where we're populating models with only a few events, these StateRoot
trees will be rather sparse and only include the new model.

Each migration works by:

* Creating a new instance of the StateManager
* Querying the database for the TransactionLogs that need to be
processed
* Groups them by block number
* In the order of blockNumber ascending, feeds each log through the
StateManager as it would have if it came through in real time.

The same lifecycle of HandleLogStateChange --> CommitFinalState -->
GenerateStateRoot is followed.
seanmcgary added a commit that referenced this pull request Feb 26, 2025
This PR introduces the concept of a state migration. When introducing
new features, it's possible that there is existing transaction data that
was not codified into a model that now needs to be. Rather than
truncating the database, re-indexing blocks resulting in modifying
existing StateRoots, this migration construct allows us to populate new
models with existing data, leaving existing StateRoots unchanged, and
codifying the changes in a sub-tree whos root is represented in the
top-level StateRoot tree.

![Screenshot 2025-02-04 at 8 25
47 AM](https://github.com/user-attachments/assets/149021bc-7457-49f0-b4f2-2091a4d0b46c)

The StateMigrator specifies which migrations run at which block height
for a given chain. Multiple migrations can be run for a single block and
will be run in the order specified. Each migration will produce a root
representing the changes made. Each of those roots are composed of the
same StateRoot structure used at the very top-level, one for each block
that was touched in the migration process. In the majority of cases
where we're populating models with only a few events, these StateRoot
trees will be rather sparse and only include the new model.

Each migration works by:

* Creating a new instance of the StateManager
* Querying the database for the TransactionLogs that need to be
processed
* Groups them by block number
* In the order of blockNumber ascending, feeds each log through the
StateManager as it would have if it came through in real time.

The same lifecycle of HandleLogStateChange --> CommitFinalState -->
GenerateStateRoot is followed.
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.

2 participants