Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inserting transactions in the Wallet should always include a last_seen. #1644

Conversation

evanlinjin
Copy link
Member

@evanlinjin evanlinjin commented Oct 9, 2024

Partially fixes #1642

Description

As mentioned in #1642, Wallet::insert_tx has some confusing behavior. Callers typically expect that anything inserted into the wallet will not be replaced, and transaction inserted later will have precedence (in the case when we have conflicting txs).

This PR modifies the behavior of Wallet::insert_tx to always add the current unix timestamp as the last_seen-in-mempool value alongside the transaction being inserted. Since this is now a std-only method, we also introduce a Wallet::insert_tx_at where the last_seen timestamp is provided by the caller. We expect callers to only insert txs into the wallet after a successful broadcast. The documentation is updated to reflect this. Wallet::unbroadcast_transactions is removed since callers are not expected to store unbroadcasted transactions in wallet anymore.

In addition, the seen_at input is made mandatory for Wallet::apply_update_at. Without this, callers may end up replacing unconfirmed txs when building txs.

Notes to the reviewers

I don't think this is the perfect solution because a failed broadcast may be due to a network issue. In this case, the caller may need to persist the transaction external to wallet.

Changelog notice

  • Change Wallet::insert_tx to always insert the tx alongside a last_seen-in-mempool timestamp (using the current timestamp).
  • Add Wallet::insert_tx_at, which is a version og insert_tx where the user can explicitly set the last_seen timestamp.
  • Change Wallet::apply_update_at to always expect a last_seen value (not have it wrapped in Option).
  • Remove Wallet::unbroadcast_transactions.

Checklists

All Submissions:

  • I've signed all my commits
  • I followed the contribution guidelines
  • I ran cargo fmt and cargo clippy before committing

Bugfixes:

  • This pull request breaks the existing API
  • I've added tests to reproduce the issue which are now passing
  • I'm linking the issue being fixed by this PR

We rm `ConfirmationTime` because it is essentially the same thing as
`ChainPosition<ConfirmationBlockTime>` without the block hash.

We also impl `serde::Deserialize` and `serde::Serialize` for
`ChainPosition`.
Previously, `Wallet::insert_tx` would insert a tx without a `last_seen`
value. This meant that inserted transactions will not show up in the
canonical history, nor be part of the UTXO set. Hence, new transactions
created by the wallet may implicitly replace inserted transactions. This
is somewhat unexpected for users.

The new behavior of `insert_tx` inserts a tx with the current timestamp
as `last_seen`. This, of course requires `std`. Therefore, we also
introduced `insert_tx_at` which allows the caller to manually specify
the `last_seen` timestamp.

In addition, `test_insert_tx_balance_and_utxos` is removed since the
behavior being tested is no longer expected.
This is no longer relevant as we direct callers to only insert tx into
the wallet after a successful broadcast.
Not including a `seen_at` alongside the update means the unconfirmed txs
of the update will not be considered to be part of the canonical
history. Therefore, transactions created with this wallet may replace
the update's unconfirmed txs (which is unintuitive behavior).

Also updated the docs.
@evanlinjin evanlinjin self-assigned this Oct 10, 2024
@evanlinjin evanlinjin added bug Something isn't working discussion There's still a discussion ongoing module-wallet api A breaking API change labels Oct 10, 2024
@notmandatory notmandatory added this to the 1.0.0-beta milestone Oct 15, 2024
Copy link
Contributor

@oleonardolima oleonardolima left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Concept ACK 4f73a77

However, a3d4eef should be dropped as it has another context and is covered in #1643.

I'd try to repurpose the test_insert_tx_balance_and_utxos instead of removing it.

@notmandatory
Copy link
Member

notmandatory commented Nov 12, 2024

Can you rebase this now that #1658 is merged with just what you need for a3d4eef ?

@oleonardolima
Copy link
Contributor

Can you rebase this now that #1658 is merged with just what you need for a3d4eef ?

After #1658, is a3d4eef the only commit that interests here? 🤔 (I guess so)

I guess we could close this PR then, as a3d4eef has already been merged in #1643.

@notmandatory
Copy link
Member

@oleonardolima good catch, I didn't notice a3d4eef was already merged. Closing for now and @evanlinjin please re-open if you don't agree all the commits here were already merged.

@notmandatory notmandatory removed this from the 1.0.0-beta milestone Nov 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api A breaking API change bug Something isn't working discussion There's still a discussion ongoing module-wallet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Transactions inserted with Wallet::insert_tx will be replaced by the wallet when creating a new tx.
3 participants