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

Add federation sync configuration SQL table and RPC endpoints #537

Merged
merged 4 commits into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions perms/perms.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,14 @@ var (
Entity: "universe",
Action: "read",
}},
"/universerpc.Universe/SetFederationSyncConfig": {{
Entity: "universe",
Action: "write",
}},
"/universerpc.Universe/QueryFederationSyncConfig": {{
Entity: "universe",
Action: "read",
}},
"/tapdevrpc.TapDev/ImportProof": {{
Entity: "proofs",
Action: "write",
Expand Down
4 changes: 3 additions & 1 deletion tapdb/sqlc/migrations/000007_universe.down.sql
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
DROP TABLE IF EXISTS universe_leaves;
DROP TABLE IF EXISTS universe_roots;
DROP TABLE IF EXISTS universe_servers;
DROP TABLE IF EXISTS federation_global_sync_config;
DROP TABLE IF EXISTS federation_uni_sync_config;
DROP INDEX IF EXISTS universe_servers_host;
DROP TABLE IF EXISTS universe_events;
DROP INDEX IF EXISTS universe_events_event_time_idx;
DROP INDEX IF EXISTS universe_events_type_idx;
DROP INDEX IF EXISTS universe_roots_asset_id_idx;
DROP INDEX IF EXISTS universe_roots_group_key_idx;
DROP INDEX IF EXISTS universe_leaves_key_idx;
DROP INDEX IF EXISTS universe_leaves_namespace;
DROP INDEX IF EXISTS universe_leaves_namespace;
49 changes: 49 additions & 0 deletions tapdb/sqlc/migrations/000007_universe.up.sql
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,52 @@ CREATE VIEW universe_stats AS
FROM universe_events u
JOIN universe_roots roots ON u.universe_root_id = roots.id
GROUP BY roots.asset_id, roots.group_key, roots.namespace_root;

-- This table contains global configuration for universe federation syncing.
CREATE TABLE IF NOT EXISTS federation_global_sync_config (
-- This field is an enum representing the proof type stored in the given
-- universe.
proof_type TEXT NOT NULL PRIMARY KEY CHECK(proof_type IN ('issuance', 'transfer')),

-- This field is a boolean that indicates whether or not a universe of the
-- given proof type should accept remote proof insertion via federation
-- sync.
allow_sync_insert BOOLEAN NOT NULL,

-- This field is a boolean that indicates whether or not a universe of the
-- given proof type should accept remote proof export via federation sync.
allow_sync_export BOOLEAN NOT NULL
);

-- This table contains universe (asset/asset group) specific federation sync
-- configuration.
CREATE TABLE IF NOT EXISTS federation_uni_sync_config (
ffranr marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Member

Choose a reason for hiding this comment

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

IIUC, in order for something to later on have a foreign key that refs this table, it does in fact still need a primary key.

I think we just want a composite primary key here. Though I saw you had to re-work things slightly tho, non-blocking comment.

-- This field contains the byte serialized ID of the asset to which this
-- configuration is applicable
asset_id BLOB CHECK(length(asset_id) = 32) NULL,

-- This field contains the byte serialized compressed group key public key
-- of the asset group to which this configuration is applicable.
group_key BLOB CHECK(LENGTH(group_key) = 33) NULL,

-- This field is an enum representing the proof type stored in the given
-- universe.
proof_type TEXT NOT NULL CHECK(proof_type IN ('issuance', 'transfer')),

-- This field is a boolean that indicates whether or not the given universe
-- should accept remote proof insertion via federation sync.
allow_sync_insert BOOLEAN NOT NULL,

-- This field is a boolean that indicates whether or not the given universe
-- should accept remote proof export via federation sync.
allow_sync_export BOOLEAN NOT NULL,

-- Both the asset ID and group key cannot be null at the same time.
CHECK (
(asset_id IS NOT NULL AND group_key IS NULL) OR
(asset_id IS NULL AND group_key IS NOT NULL)
),

-- Ensure that the universe identifier fields form a unique tuple.
UNIQUE (asset_id, group_key, proof_type)
);
14 changes: 14 additions & 0 deletions tapdb/sqlc/models.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions tapdb/sqlc/querier.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 30 additions & 0 deletions tapdb/sqlc/queries/universe.sql
Original file line number Diff line number Diff line change
Expand Up @@ -262,3 +262,33 @@ WHERE event_type IN ('SYNC', 'NEW_PROOF') AND
event_timestamp >= @start_time AND event_timestamp <= @end_time
GROUP BY day
ORDER BY day;

-- name: UpsertFederationGlobalSyncConfig :exec
INSERT INTO federation_global_sync_config (
proof_type, allow_sync_insert, allow_sync_export
)
VALUES (@proof_type, @allow_sync_insert, @allow_sync_export)
ON CONFLICT(proof_type)
ffranr marked this conversation as resolved.
Show resolved Hide resolved
DO UPDATE SET
allow_sync_insert = @allow_sync_insert,
allow_sync_export = @allow_sync_export;

-- name: QueryFederationGlobalSyncConfigs :many
SELECT proof_type, allow_sync_insert, allow_sync_export
FROM federation_global_sync_config;

-- name: UpsertFederationUniSyncConfig :exec
INSERT INTO federation_uni_sync_config (
asset_id, group_key, proof_type, allow_sync_insert, allow_sync_export
)
VALUES(
@asset_id, @group_key, @proof_type, @allow_sync_insert, @allow_sync_export
)
ON CONFLICT(asset_id, group_key, proof_type)
DO UPDATE SET
allow_sync_insert = @allow_sync_insert,
allow_sync_export = @allow_sync_export;

-- name: QueryFederationUniSyncConfigs :many
SELECT asset_id, group_key, proof_type, allow_sync_insert, allow_sync_export
FROM federation_uni_sync_config;
116 changes: 116 additions & 0 deletions tapdb/sqlc/universe.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading