Skip to content

Commit

Permalink
Add Grandine support (#27)
Browse files Browse the repository at this point in the history
* Add Grandine support

* Fix line wrapping
  • Loading branch information
michaelsproul authored Aug 8, 2023
1 parent 02c9f80 commit 2910089
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 7 deletions.
13 changes: 7 additions & 6 deletions build_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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),
)
Expand Down
9 changes: 9 additions & 0 deletions docs/migrations.md
Original file line number Diff line number Diff line change
@@ -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"
```
28 changes: 28 additions & 0 deletions migrations/00_pr_grandine.sql
Original file line number Diff line number Diff line change
@@ -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;
3 changes: 2 additions & 1 deletion prepare_training_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]*.*"],
Expand Down

0 comments on commit 2910089

Please sign in to comment.