Skip to content

fix(pgp): throttle trust-db rewrite in RNPPGPHandler::locked_timeStampKey#326

Open
jolavillette wants to merge 1 commit into
RetroShare:masterfrom
jolavillette:fix/rnp-timestamp-trustdb-churn
Open

fix(pgp): throttle trust-db rewrite in RNPPGPHandler::locked_timeStampKey#326
jolavillette wants to merge 1 commit into
RetroShare:masterfrom
jolavillette:fix/rnp-timestamp-trustdb-churn

Conversation

@jolavillette

Copy link
Copy Markdown
Contributor

fix(pgp): throttle trust-db rewrite in RNPPGPHandler::locked_timeStampKey

locked_timeStampKey() is called on every PGP key usage, notably from RNPPGPHandler::VerifySignBin() which runs on every GXS identity validation (p3IdService::pgphash_process -> checkId) and every connection. It updated the key's in-memory usage timestamp AND flagged _trustdb_changed on every call.

Because of that, the whole private trust database was rewritten by locked_syncTrustDatabase() on essentially every AuthGPG tick, its file mtime bumped, and then re-read in full (thousands of trust packets) a few seconds later. On a node with many keys this produced a "Detected change on disk of trust database" + full reload every ~10-30s indefinitely (hundreds of times per session), wasting CPU and flooding the log.

OpenPGPSDKHandler already throttles this exact update to once per hour; the rnp port had dropped the throttle. Restore it: keep updating the in-memory _time_stamp on every call (cheap), but only set _trustdb_changed at most once per hour. The on-disk trust database is then rewritten ~once per hour instead of constantly.

…pKey

locked_timeStampKey() is called on every PGP key usage, notably from
RNPPGPHandler::VerifySignBin() which runs on every GXS identity
validation (p3IdService::pgphash_process -> checkId) and every
connection. It updated the key's in-memory usage timestamp AND flagged
_trustdb_changed on every call.

Because of that, the whole private trust database was rewritten by
locked_syncTrustDatabase() on essentially every AuthGPG tick, its file
mtime bumped, and then re-read in full (thousands of trust packets) a few
seconds later. On a node with many keys this produced a "Detected change
on disk of trust database" + full reload every ~10-30s indefinitely
(hundreds of times per session), wasting CPU and flooding the log.

OpenPGPSDKHandler already throttles this exact update to once per hour;
the rnp port had dropped the throttle. Restore it: keep updating the
in-memory _time_stamp on every call (cheap), but only set
_trustdb_changed at most once per hour. The on-disk trust database is
then rewritten ~once per hour instead of constantly.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@jolavillette jolavillette force-pushed the fix/rnp-timestamp-trustdb-churn branch from 983eb81 to 089b66e Compare July 9, 2026 10:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant