Commit Graph
470 Commits
Author SHA1 Message Date
jwinterm 3fba1319fb Merge upstream staging (#755 multi-LMDB backend) into contracts
Reconcile the contract feature with #755, which replaced the WalletBackend
trait with a concrete WalletBackend<C,K> struct (libwallet/src/backend.rs) and
removed impls/src/backends/lmdb.rs.

- Port the contract module and contract API entry points from the trait form
  (T: WalletBackend<'a,C,K>) to the concrete struct.
- Re-home next_child_for and a parent_id+log_id get_tx_log_entry onto backend.rs.
- Re-apply the self-spend tx-log filters, cancel-loop, v5 payment-proof fields,
  and Context contract fields onto staging's rewritten files.
- Adapt to fallible iter()/tx_log_iter() and self-consuming batch commit.

Full suite green (53 binaries / 191 tests).
2026-06-10 13:48:34 -04:00
06ab92a619 Update lmdb (#755)
* wallet: update lmdb from store crate, migrate single backend from trait to struct, update tests cargo deps and design doc

* backend: do not panic on iter and directory creation

* return  iterator errors

* build: update to last node revision

* fix: height selection for scan, remove unused mutability for wallet

* wallet: remove unused mutability conversion

* tx: store slate state at database

* build: cargo fmt

* fix: do not return error when slate not found on tx slate state update

* lmdb: do not collect all tx log records at iterator, show read errors at log

* fix: save slate state, return error if slate not found

* tx: specify amount of bad txs on slate state update error

---------

Co-authored-by: Joerg <wiesche89@googlemail.com>
2026-06-09 13:54:51 +02:00
jwinterm db52b2e58c Contracts: resolve remaining review TODOs
Comment-only follow-ups to the review:
- selection: a negative change output is already rejected; drop the stale TODO.
- utils: note the per-participant kernel fee is rounded up (overpay bounded to
  under one unit per participant), and that add_outputs/parent_key_id are handled
  by the sign step and the stored Context.
- types: drop the "custom outputs imply payjoin" TODO; make_outputs is valid
  without a payjoin (e.g. a receiver splitting its output), so the check would be
  incorrect.

Addresses PR #754 review (selection.rs, utils.rs, types.rs).
2026-06-07 20:15:13 -04:00
jwinterm 18167be1e5 Contracts: tidy review TODOs, document the owner API, simplify get_net_change
Comment/doc cleanups from review; the only behavior-adjacent change is the
get_net_change signature.
- get_net_change takes the slate id instead of the whole slate.
- replace the owner-API contract methods' `/// TODO` placeholders with real docs.
- narrow or remove now-resolved TODOs (slate proof fns, context, utils stored_tx,
  a doc-comment that should be //, wallet_args parse notes); reword the rest as
  concrete FUTURE notes.
- prune the contract actions README of items already fixed.

Addresses PR #754 review (comment hygiene).
2026-06-07 19:50:52 -04:00
jwinterm 1b3d773fab Contracts: delete the canceled context on revoke
revoke left the canceled slate's private context in place when the contract
had not been signed (signing already deletes it). Look up the revoked slate id
from its tx log entry and delete the context after cancelling, if one still
exists. Resolves the stale revoke TODOs about the cancelled context.

Addresses PR #754 review (revoke.rs).
2026-06-07 19:15:22 -04:00
jwinterm 1d89ec2682 Contracts: report agreed_net_change in contract view
contract view hardcoded agreed_net_change to None. When a local context exists
we've agreed on the net change, so read it from the context and report it
(None when there's no context); other errors propagate.

Addresses PR #754 review (view.rs).
2026-06-07 19:10:22 -04:00
jwinterm bcea98be2a Contracts: remove the commented-out contract_setup
The separate contract_setup step is superseded by contract_sign, which runs
setup internally. Remove the dead commented-out function (libwallet, controller,
api), its CLI subcommand (grin-wallet.yml), and its dispatch arm (wallet_args).
The contract_sign path and the parse_contract_setup_args parser are unaffected.

Addresses PR #754 review (command.rs, owner.rs).
2026-06-07 19:07:24 -04:00
jwinterm 756664e654 Contracts: remove the unused target_slate_version field
ContractNewArgsAPI and ContractView carried a target_slate_version that was only
ever None and never read; the emitted slatepack version is chosen from the slate
content. Remove it. The legacy InitTxArgs/IssueInvoiceTxArgs fields are unrelated
and untouched.

Addresses PR #754 review (types.rs).
2026-06-07 18:43:48 -04:00
jwinterm 5569d38df2 Contracts: test selection-args consistency and fee splitting
Adds the two regression tests requested in review:
- verify_selection_consistency: same/default args are accepted; changed
  non-default args after setup are rejected.
- my_fee_contribution: a single participant pays the whole kernel cost, two
  participants each pay ceil(kernel/2), and the shares cover the full cost.

Also resolves the related TODOs (selection.rs "test that this works",
utils.rs fee-encoding compatibility note).

Addresses PR #754 review (selection.rs, utils.rs).
2026-06-07 17:16:44 -04:00
jwinterm 7982f17926 Contracts: reject a slate that already has all participants
add_keys added our participant info without checking the slate wasn't already
full, so a tampered slate could exceed num_participants. Block adding when the
participant set is already full and we aren't already in it (re-adding our own
info stays idempotent).

Addresses PR #754 review (slate.rs).
2026-06-07 17:00:50 -04:00
jwinterm 9bf11fbc8d Contracts: derive the proof address under the contract's account
generate_invoice_signature derived the receiver's proof address from the active
account's parent key. Like the output-derivation fix, use context.parent_key_id
so the proof address belongs to the contract's account, not whatever account is
active.

Addresses PR #754 review (proofs.rs, utils.rs).
2026-06-07 16:45:53 -04:00
jwinterm 62fc9421f1 Contracts: use Error::Fee for the fee-overshoot error
The committed-fee-exceeded check returned a GenericError. Use the existing
Error::Fee variant and fold the "cancel and retry" hint into the message.

Addresses PR #754 review (selection.rs).
2026-06-07 16:42:16 -04:00
jwinterm b3f75ee2b5 Contracts: use checked conversions for amount -> i64
A large u64 amount could wrap when cast `as i64`. Convert with i64::try_from in
the CLI net-change derivation and in contract view, returning an error instead.
get_net_change / to_api_args now return Result (the two arg panics become
errors too), and the to_api_args call moves out of the owner-session closure.

Addresses PR #754 review (command.rs, view.rs).
2026-06-07 16:37:54 -04:00
jwinterm 5cc1683a1b Contracts: validate num_participants before fee math
num_participants is divided into the kernel cost, so 0 caused a divide-by-zero
(inf -> garbage fee). Validate it in context::create, the common setup path for
every party: the initiator's value comes from args and the signer's from the
slate, so this also rejects a tampered slate. Only 1 (self-spend) and 2
(standard) are supported today; lift the upper bound when multi-party contracts
are implemented.

Addresses PR #754 review (wallet_args.rs:1039).
2026-06-07 16:33:59 -04:00
jwinterm d4d5f97bd8 Contracts: validate net_change in the foreign sign path
The foreign contract_sign API unwrapped the optional net_change field, so an
incomplete request could panic the wallet. Return an error instead, matching
the foreign contract_new path.

Addresses PR #754 review (foreign.rs).
2026-06-07 16:14:02 -04:00
jwinterm 502d2ae336 Contracts: revoke under the inputs' account, not the active one
revoke() cancelled the original tx and built the self-spend using the wallet's
active account, but the locked inputs belong to the account that created the
contract. Revoking while a different account was active would fail to find and
cancel the original tx and would recover funds into the wrong account.

- derive the account from the locked input's root_key_id; use it for cancel_tx
  and as the self-spend's src_acct_name.
- test: revoke a contract while a different account is active.

Addresses PR #754 review (revoke.rs).
2026-06-04 20:41:11 -04:00
jwinterm 62ede419dd Contracts: emit the lowest slatepack version needed
create_slatepack always serialized to V5, so every slatepack went out V5 and
V4-only peers could not read it. Emit V4 unless the slate carries a payment
proof: only the (opt-in) proof needs the V5-only fields (timestamp/memo) that
V4 cannot represent. The slate's declared version is set to match the emitted
structure so readers select the right variant.

- packer: V5 when payment_proof is present, else V4.
- test: a proof slate round-trips as V5 (memo preserved); a no-proof slate as V4.

Addresses PR #754 review (packer.rs).
2026-06-04 20:14:52 -04:00
jwinterm 15cbbc96e8 Contracts: validate net_change instead of unwrapping
contract `new` and the foreign `contract_new` API unwrapped the optional
net_change field, so a request omitting it panicked the wallet. Return an
error instead.

- new::compute and foreign::contract_new: net_change.ok_or_else(..).
- test: contract_new with no net change errors rather than panicking.

Addresses PR #754 review (new.rs, foreign.rs).
2026-06-04 19:34:21 -04:00
jwinterm 571b1f968a 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).
2026-06-04 19:34:21 -04:00
jwinterm 382cf869c9 Contracts: parse amounts exactly, not via f64
Custom output amounts (--make-outputs) and the CLI amount parser converted
grin to nanogrin with `(g * GRIN_BASE as f64) as u64`, which can't represent
all values exactly. Use core::amount_from_hr_string — the same exact integer
parser already used by `send` and `invoice`.

- contract OutputSelectionArgs::output_amounts (covers selection.rs).
- wallet_args::parse_grin_amount.

Addresses PR #754 review (types.rs, selection.rs, wallet_args.rs).
2026-06-04 16:53:16 -04:00
jwinterm 8c7c0d049d Contracts: derive output keys under the contract's account
New contract outputs were derived with next_child(), which uses the wallet's
active account. During a late-lock the active account can differ from the one the
contract context was created under, so an output could be created in the wrong
account. Derive under context.parent_key_id instead.

- WalletBackend: add next_child_for(parent_key_id, mask); next_child delegates to it.
- add_outputs_to_ctx derives via next_child_for(&context.parent_key_id, ..).
- parent_key_for returns Result and errors (UnknownAccountLabel) on an unknown
  account name instead of silently falling back to the active account.
- test: a contract referencing an unknown account now errors.

Addresses PR #754 review (context.rs, utils.rs).
2026-06-04 16:53:16 -04:00
dependabot[bot]andGitHub 9570ed4731 Bump openssl from 0.10.68 to 0.10.80 (#752) 2026-06-04 20:13:47 +02:00
jwinterm 4fcb6053d5 Make contract slatepack encryption optional
--encrypt-for is no longer required. `contract new` without it produces an
unencrypted slatepack; `contract sign` without it replies to the incoming slate's
sender when known, otherwise unencrypted. Passing --encrypt-for is unchanged. The
slatepack layer already produced plaintext for an empty recipient list — this only
removes the CLI-side requirement.
2026-06-04 07:40:03 -04:00
jwinterm b7b7a6d21d Merge upstream staging into contracts
Bring the branch current with upstream staging (= master + #748). The earlier
"Merge branch master into contracts" used a stale local master snapshot, which
left the branch ~41 commits behind; this merges the current tip, including the
grin 5.4.0 dependency bump (#745) and the tx-delete / retrieve_txs fixes.

Only Cargo.lock conflicted (regenerated). Full cargo test --workspace green
(52 binaries / 185 tests).
2026-06-03 15:27:43 -04:00
jwinterm 3fcf3b7816 De-panic output_amounts(): fallible make-outputs parsing
OutputSelectionArgs::output_amounts() unwrap()'d the float parse of each
make-outputs value, panicking on bad input via the API path (the CLI now
validates earlier). Return Result instead; sum_output_amounts() propagates.
num_custom_outputs() now counts CSV entries without parsing, so it stays
infallible and the debug! macros that use it are unaffected.
2026-06-03 13:56:32 -04:00
jwinterm 2e3b04498c De-panic and validate contract CLI input handling
Bad input to the contract CLI could abort the process:
- a non-numeric --make-outputs value reached output_amounts(), which
  unwrap()s the float parse;
- `contract new` with neither --send nor --receive hit a panic in
  get_net_change;
- `contract sign` panicked ("No address to encrypt for") when given no
  --encrypt-for and an incoming slate with no embedded sender.

Validate --make-outputs and require exactly one of --send/--receive at
parse time (ParseError, before reaching the panicking paths), and return a
typed error instead of panicking when there is no address to encrypt for.
Verified at runtime: each now yields a clean "Invalid Arguments" error.
2026-06-03 09:33:11 -04:00
jwinterm 9d040b40f1 Harden the contract signing-context forget invariant
Remove the broken, commented-out SEC_KEY_FAKE key-scrubbing: a zero secret
key is rejected by secp, and the scrubbing was redundant. The signing
context holding sec_key/sec_nonce is forgotten by deleting the private
context in save_step once signed (retained only at step2 for safe cancel),
and contexts are keyed by slate.id so a nonce is never reused across
messages.

Make that guarantee enforced rather than assumed: after a signed,
non-step2 save_step, verify the private context was actually removed and
error otherwise. Document the invariant at the sign site.
2026-06-03 08:03:35 -04:00
jwinterm 3a86bb4fce Replace reachable panics in contract flow with typed errors
Contract setup/sign and output selection used panic! on
protocol-reachable invariant violations: receiver fee exceeding
net_change, net_change / num_participants mismatch between the setup and
sign phases, a negative change output, conflicting selection args, and a
failed kernel-excess computation. A crafted or inconsistent counterparty
slate could abort the wallet. Return Error::GenericError (or propagate the
underlying error) instead; build_output_amount_list now returns Result.
2026-06-03 07:29:04 -04:00
jwinterm 311140f6f6 De-panic contract CLI argument parsing
The contract new/sign/revoke parsers panicked or unwrapped on user input:
conflicting --no-payjoin/--use-inputs, and unparseable receive / send /
num-participants / tx-id values would abort the process. Return
ParseError instead, and add a parse_grin_amount helper for the
Grin->nanogram conversion.
2026-06-02 21:02:24 -04:00
jwinterm 25dab9fe5b Harden v5 payment-proof deserialization against malformed input
ProofWrap::read unwrapped on the sender/receiver address, promise
signature, and memo_type while parsing untrusted slatepack bytes, so a
malformed payment proof would panic the wallet. Propagate CorruptedData
instead, matching the timestamp path already in this function.
2026-06-02 20:58:22 -04:00
jwinterm 46999ce9f5 Make payment proofs opt-in to fix #729
Default ProofArgs.suppress_proof to true. With it false, the receiver's
`contract sign` unconditionally built an invoice promise, but the sender
address is never plumbed through, so a bare send/receive failed with
NoSenderAddressProvided (#729). The CLI never sets this field, so every
default `contract sign --receive` hit the broken path; the basic tests
passed only because they set suppress_proof = true by hand.

Drop those workarounds from contract_srs/contract_rsr so they now exercise
the default path, and opt the proof-using tests (contract_early_proofs_srs,
contract_early_proofs_rsr, contract_accounts) into proofs explicitly.
2026-06-02 20:25:48 -04:00
jwinterm 475db1d289 Fix contract_srs_mwmixnet test import after merge
master's mwixnet (#726) keeps the `types` submodule private and re-exports
its items, so use the public `mwixnet::MixnetReqCreationParams` path. The
merge missed this because `cargo check --workspace` does not build test
targets.
2026-06-02 20:15:03 -04:00
jwinterm 79a403127b Fix VersionedSlate::version() misreporting V5 slates as V4
version() returned SlateVersion::V4 for the V5 variant, so any
version-aware logic downstream would misidentify a V5 slate as V4.
Return V5 for V5.
2026-06-02 18:27:12 -04:00
jwinterm f7d3692ee8 Merge branch 'master' into contracts
Bring the contracts feature branch up to current master, which has since
landed rust 1.80 support (#722), the canonical mwixnet onion code (#726),
and node-client proxy support (#738).

Conflict resolution:
- libwallet/src/mwixnet/*: take master's (#726), dropping the contracts
  branch's older divergent copy. owner.rs::create_mwixnet_req updated to
  master's API (use_test_rng) and master's flat re-export imports.
- Cargo manifests/lock/.cargo: master's deps & version; re-add serde_with
  for Slate v5; keep contracts' .cargo/config.toml (Windows static-CRT).
- lib.rs: keep serde_derive AND serde_with macro_use; single mwixnet decl.
- error.rs: union of master + contracts variants; flat mwixnet re-exports.
- api/libwallet owner.rs: master's #738 + create_mwixnet_req plus the
  contract_* entry points; drop duplicate older create_mwixnet_req method.
- slatepack/armor.rs, node_clients/resp_types.rs: take master's.

Workspace builds; libwallet lib tests pass (34/34). The Slate version()
bug, issue #729 fix, and de-panicking follow in subsequent commits.
2026-06-02 18:26:08 -04:00
129ad2f5fb Save last scanned block info for wallet scanning (#748)
* scan: save last scanned block info for initial wallet scanning

* scan: save start height at scanned block info on outputs collecting

* scan: 10k blocks batches

* fix: include last height into batch on scan

* scan: save hash of last block

* scan: add larger window (2880 blocks) to scan outputs when updating wallet state

* add test batched scan and resume, add scan doc

* rename corrupted restore test

---------

Co-authored-by: Joerg <wiesche89@googlemail.com>
2026-06-02 20:09:50 +02:00
ardocratandGitHub 602d79e868 Update rust edition to 2021 (#749)
* build: update rust edition 2021

* cargo: format all

* build: fix tests and warnings
2026-05-14 12:58:22 +02:00
David BurkettandGitHub a3e71a8b2d Merge pull request #732 from Anynomouss/master
Ready for review: Fix for many wallet config errors including solution for -h and -t wrongly setting the node path
2026-05-07 10:06:26 -04:00
AnynomoussandGitHub c337a7aad6 Update default.rs
removed 2fA code 😅
2026-05-07 16:05:16 +02:00
AnynomoussandGitHub 555469fb75 Merge pull request #1 from mimblewimble/master
Trying to merge master 9 commits into my branch. All checks passed.
2026-04-14 10:29:22 +02:00
David BurkettandGitHub e732cbdc44 Merge pull request #745 from ardocrat/grin_5.4.0
Grin 5.4.0 update
2026-03-23 15:54:57 -04:00
David BurkettandGitHub f72784a578 Merge pull request #746 from GetGrin/tx_delete
Ability to delete transaction from database
2026-03-23 15:52:46 -04:00
ardocrat c4f473568f tx: ability to delete transaction from database 2026-03-21 22:48:52 +03:00
ardocrat d2edbe12d3 build: update deps to grin 5.4.0 and hyper 0.14 2026-03-10 03:32:20 +03:00
David BurkettandGitHub 5aa02fdea3 Merge pull request #743 from GetGrin/retrieve_txs_account
Retrieve txs for an account with custom query arguments
2026-03-05 08:28:42 -05:00
David BurkettandGitHub 63a3f5aabf Merge pull request #744 from GetGrin/ci_fix
Github CI Windows tests fix
2026-03-05 08:28:27 -05:00
ardocrat a099078f31 build: update built lib 2026-03-04 20:07:15 +03:00
ardocrat b49e2dfecd fix: retrieve txs for an account with custom query arguments 2026-03-04 18:43:04 +03:00
Anynomouss a6ba9c9781 Implemented all feedback from aglkm 2025-10-09 09:18:00 +02:00
AnynomoussandGitHub cb245d6ed1 Update transaction.rs - no real changes, revert small fromat change 2025-09-19 09:36:17 +02:00
AnynomoussandGitHub a51121ce2a Update command.rs cleaning up irrelevant changes 2 2025-09-19 09:34:14 +02:00