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

client/asset/eth: Transaction History #2504

Merged
merged 3 commits into from
Oct 3, 2023
Merged

Conversation

martonp
Copy link
Contributor

@martonp martonp commented Sep 7, 2023

This diff updates the ETH wallet to support the asset.WalletHistorian interface. Since ETH RPC nodes do not support querying the transactions an account has made, the transactions are stored locally in a database. Initially they are stored with a block number of 0 and the max possible fees, but when the transaction is confirmed, these values are updated.

The pending transaction tracking used for more accurate balance reporting is updated to use the same data as required for tracking pending transactions for the wallet history. Also, the database used for monitoring pending redemption transactions and resubmitting them is upgraded to be used for both that functionality and the new tx history functionality.

@martonp martonp marked this pull request as draft September 7, 2023 05:04
@martonp martonp changed the title client/asset/eth: TxHistory client/asset/eth: Transaction History Sep 17, 2023
@martonp martonp marked this pull request as ready for review September 17, 2023 06:31
Copy link
Member

@buck54321 buck54321 left a comment

Choose a reason for hiding this comment

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

Just a first pass.

I hope we can now get rid of our clunky nonce system. If we're tracking our own confirmed and unconfirmed txs, we can get our nonce from there instead of from an rpc provider.

client/asset/eth/eth.go Outdated Show resolved Hide resolved
client/asset/eth/eth.go Outdated Show resolved Hide resolved
client/asset/eth/txdb.go Show resolved Hide resolved
client/asset/eth/txdb.go Show resolved Hide resolved
client/asset/eth/eth.go Outdated Show resolved Hide resolved
client/asset/eth/eth.go Show resolved Hide resolved
client/asset/eth/eth.go Show resolved Hide resolved
client/asset/eth/txdb.go Show resolved Hide resolved
type extendedWalletTx struct {
mtx sync.RWMutex
*asset.WalletTransaction
// Confirmed will be set to true once the transaction has 3 confirmations.
Copy link
Member

Choose a reason for hiding this comment

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

Wasn't two enough after the merge to ensure it cannot be double spent or am I imagining that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, seems like reorgs are highly unlikely in ETH.

client/asset/eth/txdb.go Outdated Show resolved Hide resolved
client/asset/eth/txdb.go Outdated Show resolved Hide resolved
client/asset/eth/txdb.go Outdated Show resolved Hide resolved
client/asset/eth/txdb.go Outdated Show resolved Hide resolved
client/asset/eth/txdb.go Outdated Show resolved Hide resolved
client/asset/eth/txdb.go Show resolved Hide resolved
if !errors.Is(err, asset.CoinNotFoundError) {
w.log.Errorf("Error getting confirmations for pending tx %s: %v", txHash, err)
}
if time.Since(time.Unix(int64(pendingTx.TimeStamp), 0)) > time.Minute*3 && tip%4 == 0 {
Copy link
Member

Choose a reason for hiding this comment

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

We don't see every block, especially when using an HTTP RPC provider, so tip%4 is going to be unpredictable. Additionally, block times on Polygon are about 2 seconds.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've just removed this additional check completely. It only helps to get rid of this transaction a bit earlier from the pending balance and the tx history which is not really crucial, and only in the case where this wallet has a bug and submits two transactions with the same nonce, or the user exports the wallet and does a transaction externally.

client/asset/eth/txdb.go Outdated Show resolved Hide resolved
client/asset/eth/txdb.go Outdated Show resolved Hide resolved
client/asset/kvdb/kvdb.go Outdated Show resolved Hide resolved
client/asset/eth/eth.go Outdated Show resolved Hide resolved
This diff updates the ETH wallet to support the asset.WalletHistorian
interface. Since ETH RPC nodes do not support querying the transactions
an account has made, the transactions are stored locally in a database.
Initially they are stored with a block number of 0 and the max possible
fees, but when the transaction is confirmed, these values are updated.

The pending transaction tracking used for more accurate balance reporting
is updated to use the same data as required for tracking pending
transactions for the wallet history. Also, the database used for monitoring
pending redemption transactions and resubmitting them is upgraded to be
used for both that functionality and the new tx history functionality.
@buck54321 buck54321 merged commit f389639 into decred:master Oct 3, 2023
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants