Skip to content

[group key addrs 4/5]: implement mailbox server and message store database #1614

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

Merged
merged 4 commits into from
Jun 25, 2025

Conversation

guggero
Copy link
Member

@guggero guggero commented Jun 23, 2025

Depends on #1611.

Extracted some commits from #1587.

Implements the SQL store for the auth mailbox server and fully hooks up the server in tapd.
The implementation is covered by a basic message send and receive integration test.

@guggero guggero requested review from Roasbeef and ffranr June 23, 2025 14:56
@guggero guggero added this to the v0.7 milestone Jun 23, 2025
@guggero guggero self-assigned this Jun 23, 2025
@levmi levmi moved this from 🆕 New to 🏗 In progress in Taproot-Assets Project Board Jun 23, 2025
@guggero guggero moved this from 🏗 In progress to 👀 In review in Taproot-Assets Project Board Jun 23, 2025
@guggero guggero changed the base branch from misc-refactor to main June 24, 2025 08:25
@guggero guggero force-pushed the add-mailbox-server branch from 094b31e to 3d1a126 Compare June 24, 2025 08:27
@levmi levmi added the P0 label Jun 24, 2025
if err != nil {
return nil, fmt.Errorf("error storing message: %w", err)
}

// Publish the message to all subscribers, meaning it will be
// distributed to all subscribed streams. Each stream will filter by
// recipient ID by itself.
msg.ID = msgID
Copy link
Contributor

Choose a reason for hiding this comment

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

We assign msg.ID to the db table’s auto-incrementing primary key. Exposing that surrogate key externally couples the database to the API.

Another possible solution: generate a UUIDv4 for each message instead, store it in the db row, and keep the integer primary key internal to the db only. This decouples external identifiers from the DB’s bookkeeping (makes table rebuilds/merge safer because message IDs never collide?).

Not a big deal, but something that might be worth exploring.

Copy link
Member

Choose a reason for hiding this comment

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

Do we actually even use this ID on the proto layer?

IIUC, the client uses a block height range to scan for new messages.

Copy link
Member Author

Choose a reason for hiding this comment

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

We use the ID to query as well. That makes things a bit easier if you know exactly which ID you received last. Because there could be multiple messages per block, so just using the block height might give you messages you've already seen.

Having a comparable (e.g. numeric) ID is useful here, exactly for the above case. Why do you think exposing the database primary ID is a bad thing on the API level, @ffranr? It's really just a number...

@@ -234,13 +236,14 @@ func (s *Server) SendMessage(ctx context.Context,
// We didn't have the proof before, so we store it now. If at
// the same time a different goroutine is trying to store the
// same proof, we expect the database to handle the concurrency.
err = s.cfg.TxProofStore.StoreProof(txProof.ClaimedOutPoint)
err = s.cfg.TxProofStore.StoreProof(ctx, *txProof)
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

@Roasbeef
Copy link
Member

Needs to be rebased due to recent merges increasing the highest migration number.

Copy link
Member

@Roasbeef Roasbeef left a comment

Choose a reason for hiding this comment

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

LGTM 🐩

-- The timestamp when the message was created on the server. This is a unix
-- timestamp in seconds to allow for easy querying and sorting of messages
-- based on their arrival time, without time zone complications.
arrival_timestamp BIGINT NOT NULL,
Copy link
Member

Choose a reason for hiding this comment

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

👍

// Add context to unique constraint errors.
var uniqueConstraintErr *ErrSqlUniqueConstraintViolation
if errors.As(dbErr, &uniqueConstraintErr) {
return 0, proof.ErrTxMerkleProofExists
Copy link
Member

Choose a reason for hiding this comment

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

👍

ReadOnly() bool
}

// BaseTxOptions defines the set of db txn options the database understands.
type BaseTxOptions struct {
Copy link
Member

Choose a reason for hiding this comment

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

Nice. TBH, we can prob get rid of all the specific tx options we have like BaseUniverseStoreOptions and just use this instead. Non-blocking can do it in some other PR as it'll increase the diff size and scope here.

@@ -418,9 +419,9 @@ func UnmarshalTxProof(
type TxProofStore interface {
// HaveProof returns true if the proof for the given outpoint exists in
// the store.
HaveProof(wire.OutPoint) (bool, error)
HaveProof(context.Context, wire.OutPoint) (bool, error)
Copy link
Member

Choose a reason for hiding this comment

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

👍

@guggero guggero force-pushed the add-mailbox-server branch 2 times, most recently from 636d80d to dc426c6 Compare June 25, 2025 07:48
@coveralls
Copy link

coveralls commented Jun 25, 2025

Pull Request Test Coverage Report for Build 15873763187

Details

  • 251 of 359 (69.92%) changed or added relevant lines in 16 files are covered.
  • 23 unchanged lines in 6 files lost coverage.
  • Overall coverage increased (+0.2%) to 38.759%

Changes Missing Coverage Covered Lines Changed/Added Lines %
itest/tapd_harness.go 0 1 0.0%
tapcfg/config.go 0 1 0.0%
authmailbox/mock.go 6 8 75.0%
cmd/commands/conn.go 0 3 0.0%
itest/loadtest/utils.go 0 3 0.0%
log.go 0 3 0.0%
proof/mock.go 0 6 0.0%
tapdb/sqlc/authmailbox.sql.go 73 81 90.12%
tapcfg/server.go 0 12 0.0%
server.go 0 22 0.0%
Files with Coverage Reduction New Missed Lines %
cmd/commands/conn.go 1 0.0%
address/mock.go 2 88.24%
commitment/tap.go 3 71.14%
tapchannel/aux_leaf_signer.go 3 43.43%
tapdb/multiverse.go 6 53.28%
tapgarden/caretaker.go 8 67.53%
Totals Coverage Status
Change from base Build 15865241809: 0.2%
Covered Lines: 29824
Relevant Lines: 76948

💛 - Coveralls

guggero added 3 commits June 25, 2025 10:49
This commit implements the MailboxStore which implements a SQL based
implementation for the authmailbox.MsgStore and proof.TxProofStore
interfaces.
To avoid collisions with the universerpc.Info RPC method, we rename our
authmailbox Info RPC method to MailboxInfo.
We now plug everything together and make sure that the auth mailbox
server works by adding a new integration test.
@guggero guggero force-pushed the add-mailbox-server branch from dc426c6 to 74953ff Compare June 25, 2025 08:49
The rapid generator for strings seems to occasionally produce invalid
UTF-8 strings, causing an error with the Postgres driver.
We fix that by using hex encoded bytes instead.
@guggero guggero merged commit 443d61a into main Jun 25, 2025
18 checks passed
@github-project-automation github-project-automation bot moved this from 👀 In review to ✅ Done in Taproot-Assets Project Board Jun 25, 2025
@guggero guggero deleted the add-mailbox-server branch June 26, 2025 10:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: ✅ Done
Development

Successfully merging this pull request may close these issues.

5 participants