Contracts: only create a context on a genuine miss

get_private_context() flattened "missing context" and real store/keychain
errors into one error, so the contract code created a fresh context on ANY
error (e.g. a decryption failure from a wrong keychain mask), masking the
real problem.

- add Error::NotFoundErr; the grin_store conversion maps NotFoundErr through
  faithfully (other store errors stay Backend).
- contract get_or_create / get_net_change / sign create-or-skip only on
  NotFoundErr and propagate every other error.

Addresses PR #754 review (context.rs, utils.rs, sign.rs).
This commit is contained in:
jwinterm
2026-06-04 19:34:21 -04:00
parent 382cf869c9
commit 571b1f968a
5 changed files with 23 additions and 5 deletions
+2
View File
@@ -377,6 +377,8 @@ where
let (blind_xor_key, nonce_xor_key) =
private_ctx_xor_keys(&self.keychain(keychain_mask)?, slate_id)?;
// A missing context surfaces as Error::NotFoundErr (via the grin_store
// conversion), letting callers distinguish it from other store errors.
let mut ctx: Context = option_to_not_found(self.db.get_ser(&ctx_key, None), || {
format!("Slate id: {:x?}", slate_id.to_vec())
})?;