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/dcr: Identify unknown txs #2748

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

martonp
Copy link
Contributor

@martonp martonp commented Apr 26, 2024

This diff updates the DCR wallet to identify any unknown transaction and add it to the transaction history. Redeems, refunds, and bond refund transactions are updated to use an external address instead of an internal one. Otherwise, the RPC wallet's listsinceblock command would not return them.

Closes #2744

This diff updates the DCR wallet to identify any unknown transaction and
add it to the transaction history. Redeems, refunds, and bond refund
transactions are updated to use an external address instead of an internal
one. Otherwise, the RPC wallet's listsinceblock command would not return
them.
@martonp martonp marked this pull request as ready for review May 21, 2024 09:33
@JoeGruffins
Copy link
Member

Testing well. I notice that the amounts we use from the database are whole numbers while I guess the amounts we id have the tx fees removed. Here I made some swaps and then restored from seed and made another, you can see the difference:

image

Comment on lines 5851 to 5861
accountsToCheck := make([]string, 0, 3)

if accounts.PrimaryAccount != "" {
accountsToCheck = append(accountsToCheck, accounts.PrimaryAccount)
}
if accounts.TradingAccount != "" {
accountsToCheck = append(accountsToCheck, accounts.TradingAccount)
}
if accounts.UnmixedAccount != "" {
accountsToCheck = append(accountsToCheck, accounts.UnmixedAccount)
}
Copy link
Member

Choose a reason for hiding this comment

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

Isn't this (*ExchangeWallet).allAccounts?

Comment on lines 5895 to 5918
if *tx.TxType == walletjson.LTTTVote {
return &asset.WalletTransaction{
Type: asset.TicketVote,
ID: tx.TxID,
Amount: totalOut,
Fees: fee,
}, nil
}
if *tx.TxType == walletjson.LTTTRevocation {
return &asset.WalletTransaction{
Type: asset.TicketRevocation,
ID: tx.TxID,
Amount: totalOut,
Fees: fee,
}, nil
}
if *tx.TxType == walletjson.LTTTTicket {
return &asset.WalletTransaction{
Type: asset.TicketPurchase,
ID: tx.TxID,
Amount: totalOut,
Fees: fee,
}, nil
}
Copy link
Member

Choose a reason for hiding this comment

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

switch *tx.TxType {
case walletjson.LTTTVote:
	return &asset.WalletTransaction{
		Type:   asset.TicketVote,
		ID:     tx.TxID,
		Amount: totalOut,
		Fees:   fee,
	}, nil
case walletjson.LTTTRevocation:
	return &asset.WalletTransaction{
		Type:   asset.TicketRevocation,
		ID:     tx.TxID,
		Amount: totalOut,
		Fees:   fee,
	}, nil
case walletjson.LTTTTicket:
	return &asset.WalletTransaction{
		Type:   asset.TicketPurchase,
		ID:     tx.TxID,
		Amount: totalOut,
		Fees:   fee,
	}, nil
}


if tx.Send && allOutputsPayUs(msgTx) && len(msgTx.TxIn) == 1 {
return &asset.WalletTransaction{
Type: asset.Split,
Copy link
Member

Choose a reason for hiding this comment

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

Could be a SelfSend I guess, but split is more likely.

Comment on lines 6542 to 6547
go func() {
dcr.tipMtx.RLock()
tip := dcr.currentTip
dcr.tipMtx.RUnlock()
dcr.syncTxHistory(ctx, uint64(tip.height))
}()
Copy link
Member

Choose a reason for hiding this comment

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

Why does this need to be asynchronous?

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 guess it can only be a longer running function on the initial call in Connect. After your rescanning PR gets merged though and this can get reset to 0, it could become a longer running function whenever the rescan completes.

@@ -6198,7 +6588,7 @@ func (dcr *ExchangeWallet) handleTipChange(ctx context.Context, newTipHash *chai
dcr.cycleMixer()
}

go dcr.checkPendingTxs(ctx, uint64(newTipHeight))
go dcr.syncTxHistory(ctx, uint64(newTipHeight))
Copy link
Member

Choose a reason for hiding this comment

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

We now are launching two unmonitored goroutines in handleTipChange. Maybe we should make handleTipChange synchronous and use a waitgroup internally.

@@ -1084,6 +1087,8 @@ func (dcr *ExchangeWallet) Connect(ctx context.Context) (*sync.WaitGroup, error)
dcr.monitorPeers(ctx)
}()

go dcr.syncTxHistory(ctx, uint64(tip.height))
Copy link
Member

Choose a reason for hiding this comment

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

We have a WaitGroup. Why not use it?

Same thing in btc I guess.

@martonp
Copy link
Contributor Author

martonp commented May 25, 2024

Testing well. I notice that the amounts we use from the database are whole numbers while I guess the amounts we id have the tx fees removed. Here I made some swaps and then restored from seed and made another, you can see the difference:

We don't have access to the counterparty's swap transaction, so we cannot know the fee. I guess we could implement it for full nodes though.

@JoeGruffins
Copy link
Member

We don't have access to the counterparty's swap transaction, so we cannot know the fee. I guess we could implement it for full nodes though.

If we have the redemption or refund transaction isn't the fee in - out?

@martonp
Copy link
Contributor Author

martonp commented May 28, 2024

If we have the redemption or refund transaction isn't the fee in - out?

Yes, but the SPV wallet does not have access to the counterparty's swap transaction, so how will we get the input?

@JoeGruffins
Copy link
Member

I thought we would have the input witness data as part of the raw transaction. Let me make sure...

@JoeGruffins
Copy link
Member

I'm pretty sure we can get the tx fee if we have the raw tx of the transaction. I just tried this with a native wallet and it worked:

	amtIn := int64(0)
	for _, in := range msgTx.TxIn {
		amtIn += in.ValueIn
	}

	amtOut := int64(0)
	for _, out := range msgTx.TxOut {
		amtOut += out.Value
	}

	fee := amtIn-amtOut

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.

dcr: wallet sees incoming tx and updates balance, but not tx history
3 participants