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

Beacon state import and list feature #1189

Merged
merged 4 commits into from
May 8, 2024
Merged

Conversation

claravanstaden
Copy link
Contributor

@claravanstaden claravanstaden commented May 6, 2024

Adds features for:

  • importing a ssz state file into the beacon store
  • listing all the states in the beacon store
  • fixes a bug in the beacon store module related to file paths

Needs to be cherry-picked into https://github.com/Snowfork/snowbridge/tree/release-v1.0.0 after merge.

@claravanstaden claravanstaden marked this pull request as ready for review May 6, 2024 13:26
Comment on lines +177 to +185
func (s *Store) ListBeaconStates() ([]BeaconState, error) {
var response []BeaconState

query := `SELECT id, attested_slot, finalized_slot, attested_sync_period, finalized_sync_period, attested_state_filename, finalized_state_filename FROM beacon_state ORDER BY attested_slot`

rows, err := s.db.Query(query)
if err != nil {
return response, fmt.Errorf("no match found")
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we want to implement a pagination query here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is limited to 100 states so I thought it is not necessary yet, but will be cool for the future!

@yrong
Copy link
Contributor

yrong commented May 7, 2024

May not be relevant with change in this PR

sqlStmt := `CREATE TABLE IF NOT EXISTS beacon_state (
id INTEGER PRIMARY KEY AUTOINCREMENT,
attested_slot INTEGER NOT NULL,
finalized_slot INTEGER NOT NULL,
attested_sync_period INTEGER NOT NULL,
finalized_sync_period INTEGER NOT NULL,
attested_state_filename TEXT NOT NULL,
finalized_state_filename TEXT NOT NULL,
timestamp INTEGER DEFAULT (strftime('%s', 'now'))
);`
_, err := s.db.Exec(sqlStmt)

Do we want to add an unique constraint on finalized_slot to make sure we're not importing duplicate entry into the db?

@claravanstaden
Copy link
Contributor Author

May not be relevant with change in this PR

sqlStmt := `CREATE TABLE IF NOT EXISTS beacon_state (
id INTEGER PRIMARY KEY AUTOINCREMENT,
attested_slot INTEGER NOT NULL,
finalized_slot INTEGER NOT NULL,
attested_sync_period INTEGER NOT NULL,
finalized_sync_period INTEGER NOT NULL,
attested_state_filename TEXT NOT NULL,
finalized_state_filename TEXT NOT NULL,
timestamp INTEGER DEFAULT (strftime('%s', 'now'))
);`
_, err := s.db.Exec(sqlStmt)

Do we want to add an unique constraint on finalized_slot to make sure we're not importing duplicate entry into the db?

Good idea! :) 65d9e68

Copy link
Contributor

@yrong yrong left a comment

Choose a reason for hiding this comment

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

+1

@claravanstaden claravanstaden merged commit 378f89d into main May 8, 2024
1 check passed
@claravanstaden claravanstaden deleted the import-beacon-state branch May 8, 2024 14:29
claravanstaden added a commit that referenced this pull request May 9, 2024
* beacon state import and list feature

* correct description

* add unique constraint on finalized_slot

* few fixes
claravanstaden added a commit that referenced this pull request May 30, 2024
* beacon state import and list feature

* correct description

* add unique constraint on finalized_slot

* few fixes
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.

3 participants