From 291008979435961845b43e3977fdfd2324e81cad Mon Sep 17 00:00:00 2001 From: Michael Sproul Date: Tue, 8 Aug 2023 10:31:38 +1000 Subject: [PATCH] Add Grandine support (#27) * Add Grandine support * Fix line wrapping --- build_db.py | 13 +++++++------ docs/migrations.md | 9 +++++++++ migrations/00_pr_grandine.sql | 28 ++++++++++++++++++++++++++++ prepare_training_data.py | 3 ++- 4 files changed, 46 insertions(+), 7 deletions(-) create mode 100644 docs/migrations.md create mode 100644 migrations/00_pr_grandine.sql diff --git a/build_db.py b/build_db.py index aabfc6a..afc1205 100755 --- a/build_db.py +++ b/build_db.py @@ -31,6 +31,7 @@ def create_block_db(db_path): proposer_index INT, best_guess_single TEXT, best_guess_multi TEXT, + pr_grandine FLOAT DEFAULT 0.0, pr_lighthouse FLOAT, pr_lodestar FLOAT, pr_nimbus FLOAT, @@ -126,9 +127,9 @@ def insert_block( conn.execute( """INSERT INTO blocks (slot, parent_slot, proposer_index, best_guess_single, - best_guess_multi, pr_lighthouse, pr_lodestar, pr_nimbus, - pr_prysm, pr_teku, graffiti_guess) - VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)""", + best_guess_multi, pr_grandine, pr_lighthouse, pr_lodestar, + pr_nimbus, pr_prysm, pr_teku, graffiti_guess) + VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)""", ( slot, parent_slot, @@ -229,7 +230,7 @@ def get_blocks_per_client(block_db, start_slot, end_slot): def get_validator_blocks(block_db, validator_index, since_slot=None): since_slot = since_slot or 0 rows = block_db.execute( - """SELECT slot, best_guess_single, best_guess_multi, pr_lighthouse, pr_lodestar, + """SELECT slot, best_guess_single, best_guess_multi, pr_grandine, pr_lighthouse, pr_lodestar, pr_nimbus, pr_prysm, pr_teku FROM blocks WHERE proposer_index = ? AND slot >= ?""", (validator_index, since_slot), @@ -277,8 +278,8 @@ def get_blocks(block_db, start_slot, end_slot=None): end_slot = end_slot or (1 << 62) rows = block_db.execute( - """SELECT slot, proposer_index, best_guess_single, best_guess_multi, pr_lighthouse, - pr_lodestar, pr_nimbus, pr_prysm, pr_teku + """SELECT slot, proposer_index, best_guess_single, best_guess_multi, pr_grandine, + pr_lighthouse, pr_lodestar, pr_nimbus, pr_prysm, pr_teku FROM blocks WHERE slot >= ? AND slot < ?""", (start_slot, end_slot), ) diff --git a/docs/migrations.md b/docs/migrations.md new file mode 100644 index 0000000..b690cbc --- /dev/null +++ b/docs/migrations.md @@ -0,0 +1,9 @@ +# Database Migrations + +When the database schema changes, manual intervention is required to update existing databases. + +You should apply each of the migrations in `blockprint/migrations` in order, like so: + +``` +sqlite3 block_db.sqlite ".read migrations/00_pr_grandine.sql" +``` diff --git a/migrations/00_pr_grandine.sql b/migrations/00_pr_grandine.sql new file mode 100644 index 0000000..72224e7 --- /dev/null +++ b/migrations/00_pr_grandine.sql @@ -0,0 +1,28 @@ +ALTER TABLE blocks RENAME TO blocks_legacy; + +CREATE TABLE blocks ( + slot INT, + parent_slot INTEGER, + proposer_index INT, + best_guess_single TEXT, + best_guess_multi TEXT, + pr_grandine FLOAT DEFAULT 0.0, + pr_lighthouse FLOAT, + pr_lodestar FLOAT, + pr_nimbus FLOAT, + pr_prysm FLOAT, + pr_teku FLOAT, + graffiti_guess TEXT, + UNIQUE(slot, proposer_index) +); + +INSERT INTO + blocks(slot, parent_slot, proposer_index, best_guess_single, best_guess_multi, + pr_lighthouse, pr_lodestar, pr_nimbus, pr_prysm, pr_teku, graffiti_guess) +SELECT slot, parent_slot, proposer_index, best_guess_single, best_guess_multi, + pr_lighthouse, pr_lodestar, pr_nimbus, pr_prysm, pr_teku, graffiti_guess +FROM blocks_legacy; + +DROP TABLE blocks_legacy; + +VACUUM; diff --git a/prepare_training_data.py b/prepare_training_data.py index c0e9b6f..af55e40 100755 --- a/prepare_training_data.py +++ b/prepare_training_data.py @@ -12,9 +12,10 @@ from load_blocks import store_block_rewards # In lexicographic order, as that's what SciKit uses internally -CLIENTS = ["Lighthouse", "Lodestar", "Nimbus", "Other", "Prysm", "Teku"] +CLIENTS = ["Grandine", "Lighthouse", "Lodestar", "Nimbus", "Other", "Prysm", "Teku"] REGEX_PATTERNS = { + "Grandine": [], "Lighthouse": [r".*[Ll]ighthouse", r"RP-[A-Z]?L v[0-9]*\.[0-9]*\.[0-9]*.*"], "Teku": [r".*[Tt]eku", r"RP-[A-Z]?T v[0-9]*\.[0-9]*\.[0-9]*.*"], "Nimbus": [r".*[Nn]imbus", r"RP-[A-Z]?N v[0-9]*\.[0-9]*\.[0-9]*.*"],