Add beacon.watch (#3362)

> This is currently a WIP and all features are subject to alteration or removal at any time.

## Overview

The successor to #2873.

Contains the backbone of `beacon.watch` including syncing code, the initial API, and several core database tables.

See `watch/README.md` for more information, requirements and usage.
This commit is contained in:
Mac L
2023-04-03 05:35:11 +00:00
parent 1e029ce538
commit 8630ddfec4
80 changed files with 7663 additions and 236 deletions

View File

View File

@@ -0,0 +1,6 @@
-- This file was automatically created by Diesel to setup helper functions
-- and other internal bookkeeping. This file is safe to edit, any future
-- changes will be added to existing projects as new migrations.
DROP FUNCTION IF EXISTS diesel_manage_updated_at(_tbl regclass);
DROP FUNCTION IF EXISTS diesel_set_updated_at();

View File

@@ -0,0 +1,36 @@
-- This file was automatically created by Diesel to setup helper functions
-- and other internal bookkeeping. This file is safe to edit, any future
-- changes will be added to existing projects as new migrations.
-- Sets up a trigger for the given table to automatically set a column called
-- `updated_at` whenever the row is modified (unless `updated_at` was included
-- in the modified columns)
--
-- # Example
--
-- ```sql
-- CREATE TABLE users (id SERIAL PRIMARY KEY, updated_at TIMESTAMP NOT NULL DEFAULT NOW());
--
-- SELECT diesel_manage_updated_at('users');
-- ```
CREATE OR REPLACE FUNCTION diesel_manage_updated_at(_tbl regclass) RETURNS VOID AS $$
BEGIN
EXECUTE format('CREATE TRIGGER set_updated_at BEFORE UPDATE ON %s
FOR EACH ROW EXECUTE PROCEDURE diesel_set_updated_at()', _tbl);
END;
$$ LANGUAGE plpgsql;
CREATE OR REPLACE FUNCTION diesel_set_updated_at() RETURNS trigger AS $$
BEGIN
IF (
NEW IS DISTINCT FROM OLD AND
NEW.updated_at IS NOT DISTINCT FROM OLD.updated_at
) THEN
NEW.updated_at := current_timestamp;
END IF;
RETURN NEW;
END;
$$ LANGUAGE plpgsql;

View File

@@ -0,0 +1 @@
DROP TABLE canonical_slots

View File

@@ -0,0 +1,6 @@
CREATE TABLE canonical_slots (
slot integer PRIMARY KEY,
root bytea NOT NULL,
skipped boolean NOT NULL,
beacon_block bytea UNIQUE
)

View File

@@ -0,0 +1 @@
DROP TABLE beacon_blocks

View File

@@ -0,0 +1,7 @@
CREATE TABLE beacon_blocks (
slot integer PRIMARY KEY REFERENCES canonical_slots(slot) ON DELETE CASCADE,
root bytea REFERENCES canonical_slots(beacon_block) NOT NULL,
parent_root bytea NOT NULL,
attestation_count integer NOT NULL,
transaction_count integer
)

View File

@@ -0,0 +1 @@
DROP TABLE validators

View File

@@ -0,0 +1,7 @@
CREATE TABLE validators (
index integer PRIMARY KEY,
public_key bytea NOT NULL,
status text NOT NULL,
activation_epoch integer,
exit_epoch integer
)

View File

@@ -0,0 +1 @@
DROP TABLE proposer_info

View File

@@ -0,0 +1,5 @@
CREATE TABLE proposer_info (
slot integer PRIMARY KEY REFERENCES beacon_blocks(slot) ON DELETE CASCADE,
proposer_index integer REFERENCES validators(index) ON DELETE CASCADE NOT NULL,
graffiti text NOT NULL
)

View File

@@ -0,0 +1 @@
DROP TABLE active_config

View File

@@ -0,0 +1,5 @@
CREATE TABLE active_config (
id integer PRIMARY KEY CHECK (id=1),
config_name text NOT NULL,
slots_per_epoch integer NOT NULL
)

View File

@@ -0,0 +1 @@
DROP TABLE blockprint

View File

@@ -0,0 +1,4 @@
CREATE TABLE blockprint (
slot integer PRIMARY KEY REFERENCES beacon_blocks(slot) ON DELETE CASCADE,
best_guess text NOT NULL
)

View File

@@ -0,0 +1 @@
DROP TABLE block_rewards

View File

@@ -0,0 +1,6 @@
CREATE TABLE block_rewards (
slot integer PRIMARY KEY REFERENCES beacon_blocks(slot) ON DELETE CASCADE,
total integer NOT NULL,
attestation_reward integer NOT NULL,
sync_committee_reward integer NOT NULL
)

View File

@@ -0,0 +1 @@
DROP TABLE block_packing

View File

@@ -0,0 +1,6 @@
CREATE TABLE block_packing (
slot integer PRIMARY KEY REFERENCES beacon_blocks(slot) ON DELETE CASCADE,
available integer NOT NULL,
included integer NOT NULL,
prior_skip_slots integer NOT NULL
)

View File

@@ -0,0 +1 @@
DROP TABLE suboptimal_attestations

View File

@@ -0,0 +1,8 @@
CREATE TABLE suboptimal_attestations (
epoch_start_slot integer CHECK (epoch_start_slot % 32 = 0) REFERENCES canonical_slots(slot) ON DELETE CASCADE,
index integer NOT NULL REFERENCES validators(index) ON DELETE CASCADE,
source boolean NOT NULL,
head boolean NOT NULL,
target boolean NOT NULL,
PRIMARY KEY(epoch_start_slot, index)
)

View File

@@ -0,0 +1,2 @@
ALTER TABLE beacon_blocks
DROP COLUMN withdrawal_count;

View File

@@ -0,0 +1,3 @@
ALTER TABLE beacon_blocks
ADD COLUMN withdrawal_count integer;