Immuclient Add support of preconditions during verifySet - #76
Conversation
vchaindz
left a comment
There was a problem hiding this comment.
Thanks for the contribution! The overall approach looks good — the proto already supports SetRequest.preconditions, the old verifiedSet(byte[], byte[]) cleanly delegates to the new overload, and it compiles fine against master. A few things I'd like to see addressed before merge, plus some smaller suggestions.
Should fix
-
withPreconditions(null)blows up atbuild()— theVerifySetOptionsconstructor callsCollections.unmodifiableList(builder.preconditions), which throws an NPE if someone passes null. That also makes thepreconditions != nullcheck inhavePreconditions()dead code. Easiest fix: have the builder fall back to an empty list (or throw a clear IAE) when null is passed. -
No key/value validation in the builder —
build()happily accepts a null key or value, and sinceUtils.toByteString(null)silently returnsByteString.EMPTY, a misconfigured options object would end up writing an empty key instead of failing fast. A null check inbuild()would catch this early. -
Javadoc on the new
verifiedSet(VerifySetOptions)got mangled — "Commits a change of a value for a single key. server-provided proof validation." reads like a sentence lost half of itself in a copy-paste. Should probably be "Equivalent to set but with additional server-provided proof validation" like the other overloads. -
Missing license headers —
Precondition.javaandVerifySetOptions.javaare missing the Apache 2.0 header that every other source file in the repo carries. -
Copy-paste bug in test
t6— the result of the secondverifiedSetcall is discarded, so the assertion "The result of second verifiedSet must not be null" is re-checking the firsttxHdr. -
Exact error message assertions are brittle — the tests compare full strings like
"FAILED_PRECONDITION: precondition failed: KeyMustNotExist", which will break the moment the server tweaks its wording. Assertingexception.getStatus().getCode() == Status.Code.FAILED_PRECONDITION(and maybe acontains()on the precondition name) would be more resilient.
Suggestions / nits
havePreconditions()→hasPreconditions()reads more naturally; andVerifiedSetOptionsmight be a better name to match theverifiedSetmethod it belongs to.Precondition.toProto()usesByteString.copyFromdirectly, while the rest of the codebase goes throughUtils.toByteString— worth keeping consistent. Same file also mixeskeyandthis.key.- The
if (options.havePreconditions())guard plus the stream inImmuClientisn't needed —addAllPreconditionson an empty list is a no-op, so you can just always add them. - The builder could use a
withKey(String)/withValue(String)convenience, givenPreconditionalready offersof(String)overloads. - Indentation in test
t4is off around theVerifySetOptions options = ...block. - A note rather than a request: precondition failures surface as a raw
io.grpc.StatusRuntimeException, which leaks the transport layer into the API. That's partly consistent with existing SDK behavior, but might be worth wrapping in a typed exception at some point. - Only
verifiedSetgains preconditions here, while plainset/setAll(which the proto also supports) don't. Fine for the scope of this PR, just flagging the asymmetry.
Nothing blocking correctness-wise on the happy path — mostly hardening and polish. Happy to re-review once updated.
|
Hi @vchaindz thank you for your detailed review, I have submitted suggested changes.
I have added null check for |
|
Hi @artiomi, thanks for the quick turnaround — I went through the updated changes and this looks much better. All the points from my first review are addressed: the null-safe Regarding your note on the value null check: good thinking, and you're right. Passing a null value currently works (it's written as an empty value), so adding a check there would indeed break existing clients. Leaving Three small things I'd still like to see before merge:
Nothing blocking correctness-wise — once these three are sorted this is good to merge. Thanks again for the contribution! |
|
Hi @artiomi, sure, let me clarify — there's actually no code change being asked for in #1. What I meant: since I think the new behavior is the right one — failing fast beats silently writing a broken entry. But it's technically a breaking change for the existing methods: any client out there that (probably by accident) passes a null key will start getting exceptions after upgrading. So the two things I meant were:
Also had a look at your latest push — #2 and #3 both look good, imports are explicit again and |
|
Hi @vchaindz Artiom |
Add support of
KeyMustExistPrecondition,KeyMustNotExistPreconditionandKeyNotModifiedAfterTXPreconditionduring execution ofverifiedSet