limit on events that can be processed by a sync

This commit is contained in:
Doug Hoyte
2023-07-20 17:45:00 -04:00
parent 78033bf03b
commit 0d21dc3255
6 changed files with 28 additions and 1 deletions

View File

@ -54,6 +54,7 @@ Current reason codes are:
* `RESULTS_TOO_BIG`
* Relays can optionally reject queries that would require them to process too many records, or records that are too old
* The maximum number of records that can be processed can optionally be returned as the 4th element in the response
* `CLOSED`
* Because the `NEG-OPEN` queries are stateful, relays may choose to time-out inactive queries to recover memory resources
* `FILTER_NOT_FOUND`

View File

@ -149,6 +149,9 @@ void cmd_sync(const std::vector<std::string> &subArgs) {
} else if (msg.at(0) == "EOSE") {
inFlightDown = false;
writer.wait();
} else if (msg.at(0) == "NEG-ERR") {
LE << "Got NEG-ERR response from relay: " << msg;
::exit(1);
} else {
LW << "Unexpected message from relay: " << msg;
}

View File

@ -121,7 +121,7 @@ void RelayServer::ingesterProcessNegentropy(lmdb::txn &txn, Decompressor &decomp
if (arr.get_array().size() < 5) throw herr("negentropy query missing elements");
NostrFilterGroup filter;
auto maxFilterLimit = MAX_U64;
auto maxFilterLimit = cfg().relay__negentropy__maxSyncEvents + 1;
if (arr.at(2).is_string()) {
auto ev = lookupEventById(txn, from_hex(arr.at(2).get_string()));

View File

@ -80,6 +80,20 @@ void RelayServer::runNegentropy(ThreadPool<MsgNegentropy>::Thread &thr) {
LI << "[" << sub.connId << "] Negentropy query matched " << view->ne.items.size() << " events in "
<< (hoytech::curr_time_us() - view->startTime) << "us";
if (view->ne.items.size() > cfg().relay__negentropy__maxSyncEvents) {
LI << "[" << sub.connId << "] Negentropy query size exceeeded " << cfg().relay__negentropy__maxSyncEvents;
sendToConn(sub.connId, tao::json::to_string(tao::json::value::array({
"NEG-ERR",
sub.subId.str(),
"RESULTS_TOO_BIG",
cfg().relay__negentropy__maxSyncEvents
})));
views.removeView(sub.connId, sub.subId);
return;
}
view->ne.seal();
auto resp = view->ne.reconcile(view->initialMsg);

View File

@ -94,3 +94,7 @@ config:
desc: negentropy threads: Handle negentropy protocol messages
default: 2
noReload: true
- name: relay__negentropy__maxSyncEvents
desc: "Maximum records that sync will process before returning an error"
default: 1000000

View File

@ -124,4 +124,9 @@ relay {
# negentropy threads: Handle negentropy protocol messages (restart required)
negentropy = 2
}
negentropy {
# Maximum records that sync will process before returning an error
maxSyncEvents = 1000000
}
}