From b74af2628ed835fad514347e9c11dc7dfe090d5a Mon Sep 17 00:00:00 2001 From: padreug Date: Tue, 6 Jan 2026 23:53:37 +0100 Subject: [PATCH] fix(nostrrelay): populate size field for event storage accounting MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Changes: - relay/event.py: Add `size: int = 0` field to NostrEvent model - relay/client_connection.py: Set `event.size = event.size_bytes` when creating events from WebSocket messages The size field has existed in the database schema since migration m001 but was never populated, causing: - Incorrect storage accounting (always 0) - Broken storage quota enforcement - Failed event pruning when storage limits reached The size field is internal relay metadata and is excluded from the nostr_dict() output, maintaining NIP-01 compliance. The size_bytes property calculates the actual byte size of the event's JSON representation. Fixes: Database constraint violation when inserting events without the required size column value. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- relay/client_connection.py | 2 ++ relay/event.py | 1 + 2 files changed, 3 insertions(+) diff --git a/relay/client_connection.py b/relay/client_connection.py index e7ebe34..8b5fdfd 100644 --- a/relay/client_connection.py +++ b/relay/client_connection.py @@ -121,6 +121,8 @@ class NostrClientConnection: } event = NostrEvent(**event_dict) + # Set the size field from the size_bytes property + event.size = event.size_bytes await self._handle_event(event) return [] if message_type == NostrEventType.REQ: diff --git a/relay/event.py b/relay/event.py index 7154ece..8cee1b9 100644 --- a/relay/event.py +++ b/relay/event.py @@ -23,6 +23,7 @@ class NostrEvent(BaseModel): tags: list[list[str]] = Field(default=[], no_database=True) content: str = "" sig: str + size: int = 0 def nostr_dict(self) -> dict: _nostr_dict = dict(self)