Repository navigation
feat: allow several fallback keypers in KEYPER_HTTP_URL - #141
Open
steven3002 wants to merge 1 commit into
Open
steven3002 wants to merge 1 commit into
steven3002 wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This closes #68.
What was wrong
The API looks for a key in its own database first. If the key is not there, it asks the one keyper in
KEYPER_HTTP_URL. The variable holds one URL, and there was no setting for a second one:url.Parsewhole, sohttp://a:3000,http://b:3000becomes one request to the hosta:3000,http. That request fails even whenbis up.http://a:3000, http://b:3000fails on the space, andhttp://a:3000,on the trailing comma.The fallback request also had no overall time limit.
QueryExternalKeyperuseshttp.DefaultClient, which has no timeout, and the GET key handlers pass the*gin.Context, whoseDone()is nil becauseContextWithFallbackis not set. Go's default transport limits the connection attempt (30 s) and the TLS handshake (10 s), but not the wait for the answer. In the test runs, a keyper that took the request and never answered had not returned after 15 s over http and 40 s over https. With several keypers this matters more: without a limit, a first keyper that never answers keeps the second from being asked.What changes
KEYPER_HTTP_URLtakes one URL, as before, or several separated by commas, asP2P_BOOTSTRAP_ADDRESSESdoes. White space around entries and empty entries are ignored. Each entry is parsed withurl.Parse, as before, and an empty value is still accepted.Config.KeyperHTTPURLbecomesConfig.KeyperHTTPURLs.getDecryptionKeyFromExternalKeyperasks the keypers in the configured order and returns the first key it gets./decrypt_commitmenthandles that result as it does today: after a 404 for the event key, it tries the identity as a time-based key.defaultKeyperFailoverTimeout). The last keyper, or the only one, gets 5 s (defaultKeyperRequestTimeout). Both are set the same way asdefaultTransactionSubmissionTimeout. The shorter bound for all but the last keyper is what Lighthouse does for its--beacon-nodeslist unless it is set to use long timeouts ("Use quicker timeouts if a fallback beacon node exists").QueryExternalKeyper, both callers and all error texts are unchanged.What operators see
main, a keyper that answered later was waited for and its key served (measured at 8 s); a dropped connection attempt failed after 30 s and a stalled TLS handshake after 10 s, the limits of Go's default transport; and a keyper that took the request and never answered held it with no limit;main, a leading space, a tab, a newline, or a space after the host or port stopped startup, and a space after a path was kept in the request path (/v1%20/decryptionKey/...);/decrypt_commitmentcan make two lookups (as an event key, then, after a 404, as a time-based key), so it can wait up to twice as long: 13.8 s measured with two keypers, the first answering 404 after 1.9 s and the second hanging./time/get_decryption_keymakes no lookup before the identity's timestamp.http://user:pa,ss@keyper:3000, whichmainaccepts, now stops startup, andhttp://a:1/x?q=1,2becomes two entries,http://a:1/x?q=1and2..env.exampledocuments the list form, the bounds and this limit.docker-compose.ymlneeds no change.How I checked it
All Go runs used Go 1.26.11 in containers with no network. The stand-in keypers are
httptestservers on loopback, except two plain loopback listeners: one that drops connection attempts (below) and one that accepts connections and never writes, for the TLS handshake.main, the new tests inkeyper_fallback_test.goshow the problem: two URLs fail withlookup 127.0.0.1:<port>,http: no such host, the list with spaces inListWithSpacesAndTrailingCommafails to parse, and a hung keyper does not return within 8 s. The single-URL tests (key, down, 404, empty value) pass there, and they still pass with this change.-race. The timing tests check each bound from above as well as below. Among them:mainone such keyper fails after 30 s, Go's default dial timeout. With this change, a list with such a keyper first returns the second keyper's key after 2 s, and one such keyper alone fails after 5 s.gofmton the changed files,go build,go vet ./...andgo teston every unit package pass.tests/suite, with its database pointed at a local Postgres instead of testcontainers, onmainand with this change. On both, the same 3 registration tests fail in every run, and in some runs other tests fail in the test helpermakeKeys. Both causes are in the tests' own fixture and helper.TestDecryptionCommitmentNotFound, the one suite test that reaches the fallback, passed in every run in which itsmakeKeyscall did.patch --dry-run).What I did not check
GET /decryptionKey/{eon}/{epochID}.tests/integrationneeds live keypers and a chain, so I did not run it.