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

Identity database schema and publishing algorithm #374

Merged
merged 8 commits into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
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
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ You must have the _exact_ go version listed in `go.mod` - you can verify this by

1. `dev/migrate-message $MIGRATION_NAME`

### Create a migration for the MLS database

1. `dev/migrate-mls $MIGRATION_NAME`

### Create a migration for the authz database

1. `dev/migrate-authz $MIGRATION_NAME`
Expand Down
31 changes: 31 additions & 0 deletions pkg/identity/api/v1/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,45 @@ func (s *Service) Close() {
s.log.Info("closed")
}

/*
Algorithm:

Start transaction

1. Insert the update into the inbox_log table
2. Read the log for the inbox_id, ordering by sequence_id
3. If the log has more than 256 entries, abort the transaction.
3. Validate it sequentially. If failed, abort the transaction.
4. For each affected address:
a. Insert the update into the address_log table
-- Note: There may be races across multiple inboxes. The address_log can use
-- inbox_log_sequence_ID to establish ordering.
b. Read the log for the address, ordering by *inbox_log_sequence_id*
c. If the log has more than 256 entries, abort the transaction.
c. Process the address log (without signature validation) and compute the final inbox ID
richardhuaaa marked this conversation as resolved.
Show resolved Hide resolved
d. Update the inserted entry with the result.

End transaction
*/
func (s *Service) PublishIdentityUpdate(ctx context.Context, req *api.PublishIdentityUpdateRequest) (*api.PublishIdentityUpdateResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "unimplemented")
}

func (s *Service) GetIdentityUpdates(ctx context.Context, req *api.GetIdentityUpdatesRequest) (*api.GetIdentityUpdatesResponse, error) {
/*
Algorithm for each request:
1. Query the inbox_log table for the inbox_id, ordering by sequence_id
2. Return all of the entries
*/
return nil, status.Errorf(codes.Unimplemented, "unimplemented")
}

func (s *Service) GetInboxIds(ctx context.Context, req *api.GetInboxIdsRequest) (*api.GetInboxIdsResponse, error) {
/*
Algorithm for each request:
1. Query the address_log table for the latest sequence_id on the address
-- Note: NOT inbox_log_sequence_id
2. Return the value of the 'inbox_id' column
*/
return nil, status.Errorf(codes.Unimplemented, "unimplemented")
}
9 changes: 9 additions & 0 deletions pkg/migrations/mls/20240411200242_init-identity.down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
SET statement_timeout = 0;

--bun:split

DROP TABLE IF EXISTS inbox_log;

--bun:split

DROP TABLE IF EXISTS address_log;
28 changes: 28 additions & 0 deletions pkg/migrations/mls/20240411200242_init-identity.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
SET statement_timeout = 0;

--bun:split

CREATE TABLE inbox_log (
sequence_id BIGSERIAL PRIMARY KEY,
inbox_id TEXT NOT NULL,
richardhuaaa marked this conversation as resolved.
Show resolved Hide resolved
server_timestamp_ns BIGINT NOT NULL,
identity_update_proto BYTEA NOT NULL
);

--bun:split

CREATE INDEX idx_inbox_log_inbox_id ON inbox_log(inbox_id);

--bun:split

CREATE TABLE address_log (
richardhuaaa marked this conversation as resolved.
Show resolved Hide resolved
sequence_id BIGSERIAL PRIMARY KEY,
inbox_log_sequence_id BIGINT,
address TEXT NOT NULL,
inbox_id TEXT,
identity_update_proto BYTEA NOT NULL
);

--bun:split

CREATE INDEX idx_address_log_address ON address_log(address);
150 changes: 89 additions & 61 deletions pkg/proto/mls/message_contents/content.pb.go

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

Loading