mirror of
https://github.com/hoytech/strfry.git
synced 2025-06-16 16:28:50 +00:00
use 5+27 length for quadrable keys instead of 9+23
- reduces quadrable branching - increases collision resistance - good until year 2514
This commit is contained in:
2
golpe
2
golpe
Submodule golpe updated: a655f8f5b2...f84f71a2f0
@ -1,3 +1,4 @@
|
||||
#pragma once
|
||||
|
||||
const size_t MAX_SUBID_SIZE = 63;
|
||||
const size_t MAX_SUBID_SIZE = 63; // Statically allocated size in SubId
|
||||
const uint64_t MAX_TIMESTAMP = 17179869184; // Safety limit to ensure it can fit in quadrable key. Good until year 2514.
|
||||
|
@ -119,7 +119,7 @@ void verifyEventTimestamp(const NostrIndex::Event *flat) {
|
||||
uint64_t latest = now + cfg().events__rejectEventsNewerThanSeconds;
|
||||
|
||||
if (ts < earliest) throw herr("created_at too early");
|
||||
if (ts > latest) throw herr("created_at too late");
|
||||
if (ts > latest || ts > MAX_TIMESTAMP) throw herr("created_at too late");
|
||||
}
|
||||
|
||||
void parseAndVerifyEvent(const tao::json::value &origJson, secp256k1_context *secpCtx, bool verifyMsg, bool verifyTime, std::string &flatStr, std::string &jsonStr) {
|
||||
|
@ -51,7 +51,9 @@ std::string_view decodeEventPayload(lmdb::txn &txn, Decompressor &decomp, std::s
|
||||
std::string_view getEventJson(lmdb::txn &txn, Decompressor &decomp, uint64_t levId);
|
||||
|
||||
inline quadrable::Key flatEventToQuadrableKey(const NostrIndex::Event *flat) {
|
||||
return quadrable::Key::fromIntegerAndHash(flat->created_at(), sv(flat->id()).substr(0, 23));
|
||||
uint64_t timestamp = flat->created_at();
|
||||
if (timestamp > MAX_TIMESTAMP) throw herr("timestamp is too large to encode in quadrable key");
|
||||
return quadrable::Key::fromIntegerAndHash(timestamp, sv(flat->id()).substr(0, 27));
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user