nostrdb

an unfairly fast embedded nostr database backed by lmdb
git clone git://jb55.com/nostrdb
Log | Files | Refs | Submodules | README | LICENSE

commit 181d8d5a9b352a1f88a0cffdf7652c9a4b386e89
parent 70d8b9f3622e8a663e5853833be740794be8464d
Author: William Casarin <jb55@jb55.com>
Date:   Wed,  9 Aug 2023 21:06:32 -0700

ndb: only validate signature if don't have the note already

This is already an optimization over strfry's implementation

Diffstat:
Mnostrdb.c | 15+++++++--------
1 file changed, 7 insertions(+), 8 deletions(-)

diff --git a/nostrdb.c b/nostrdb.c @@ -177,14 +177,6 @@ static int ndb_ingester_process_event(secp256k1_context *ctx, case NDB_TCE_OK: goto cleanup; case NDB_TCE_EVENT: note = tce.event.note; - - // Verify! If it's an invalid note we don't need to bothter - // writing it to the database - if (!ndb_note_verify(ctx, note->pubkey, note->id, note->sig)) { - ndb_debug("signature verification failed\n"); - goto cleanup; - } - if (note != buf) { ndb_debug("note buffer not equal to malloc'd buffer\n"); goto cleanup; @@ -197,6 +189,13 @@ static int ndb_ingester_process_event(secp256k1_context *ctx, rc = mdb_get(read_txn, lmdb->dbis[NDB_DBI_ID], &key, &val); if (rc == MDB_NOTFOUND) { + // Verify! If it's an invalid note we don't need to + // bothter writing it to the database + if (!ndb_note_verify(ctx, note->pubkey, note->id, note->sig)) { + ndb_debug("signature verification failed\n"); + goto cleanup; + } + // we didn't find anything. let's send it // to the writer thread note = realloc(note, note_size);