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

Upgrade dcrwallet to master branch (future version v4) #48

Closed
wants to merge 11 commits into from

Conversation

dmigwi
Copy link
Collaborator

@dmigwi dmigwi commented Aug 16, 2023

Closes #47

Only reconcile VSP fees if an error occurred when processing it initially

@dreacot
Copy link
Member

dreacot commented Aug 16, 2023

still getting same error after purchasing a new ticket

2023-08-16 21:48:56.171 [INF] WLLT: Inserting unconfirmed transaction 3d506c347********
2023-08-16 21:48:56.187 [INF] DCR: [5] New Transaction 3d506c347********
2023-08-16 21:49:40.085 [INF] DCR: Published ticket purchase 3d506c347********
2023-08-16 21:49:41.309 [INF] VSPC: VSP requires fee 0.0013613 DCR
2023-08-16 21:49:41.321 [INF] DCR: Returning address (account=1 branch=1 child=75)
2023-08-16 21:49:41.338 [INF] WLLT: Inserting unconfirmed transaction 3d506c347********
2023-08-16 21:49:41.359 [INF] DCR: [5] New Transaction 3d506c347********
2023-08-16 21:49:41.505 [INF] VSPC: successfully processed 3d506c347********
2023-08-16 21:49:41.506 [INF] DCR: [5] Purchased ticket 3d506c347******** at stake difficulty 238.68897954 DCR
2023-08-16 21:50:49.871 [ERR] VSPC: ticket 3d506c347********: reconcile payment: payfee: error: status: 400 Bad Request resp: {"code":3,"message":"fee tx already received for ticket"}

i have also confirmed i have the right branch

commit b87f8d5721161bb6d030917ebc104e926ac66e6c (HEAD -> pr-48)
Author: dmigwi <migwindungu0@gmail.com>
Date:   Wed Aug 16 23:11:42 2023 +0300

    Confirm fee processing error happened before re-initiating it

@dmigwi
Copy link
Collaborator Author

dmigwi commented Aug 16, 2023

Can you see this statement logged: Attempting to process the unconfirmed VSP fee for tx.. for that specific tx?

@dreacot
Copy link
Member

dreacot commented Aug 16, 2023

Can you see this statement logged: Attempting to process the unconfirmed VSP fee for tx.. for that specific tx?

no, not anywhere in the logs for now

@dmigwi
Copy link
Collaborator Author

dmigwi commented Aug 16, 2023

Can you see this statement logged: Attempting to process the unconfirmed VSP fee for tx.. for that specific tx?

no, not anywhere in the logs for now

It implies that this is a new error. Triggered by different issues. I will look into it.

@dmigwi
Copy link
Collaborator Author

dmigwi commented Aug 17, 2023

The whole vsp implementation seems to have a bug. Its initiates the first VSP fee payment which is successful, it then goes to initiate more payment requests at intervals which all fail because the first one was successful.

2023-08-17 15:22:20.367 [INF] DCR: [123] Transaction index finished at 1192829, 4094 transaction(s) indexed in total
2023-08-17 15:31:25.511 [INF] DCR: The wallet has been unlocked without a time limit
2023-08-17 15:31:26.172 [INF] DCR: [10] Running ticket buyer
2023-08-17 15:31:27.542 [INF] DCR: Reserved credits for 1 tickets: total fee: 0.00036284 DCR
2023-08-17 15:31:27.542 [INF] DCR: Returning address (account=0 branch=1 child=44)
2023-08-17 15:31:27.543 [INF] DCR: selected input 019138750e6ae185e29306388f0603422005a7d4990a2d8ca2ace174b8727b0f:2 (0.16777216 DCR) for ticket purchase split transaction
2023-08-17 15:31:27.543 [INF] DCR: selected input b31bd5dbfabb36fd035c5f031f7439f2ba3797b460e4986fac91e5fc42ba2cbe:0 (0.16777216 DCR) for ticket purchase split transaction
2023-08-17 15:31:27.543 [INF] DCR: selected input 5f96bccac14157a3b0ffa5ac76119b9b2487da4b0f332030856e7a9d16d87063:2 (0.00262144 DCR) for ticket purchase split transaction
2023-08-17 15:31:27.543 [INF] DCR: selected input 2b5975f148d8ad8d4e984f79b896bd595e2a1502d9c5d5adc57b2a5ffaf6f325:2 (0.01048576 DCR) for ticket purchase split transaction
2023-08-17 15:31:27.543 [INF] DCR: selected input b31bd5dbfabb36fd035c5f031f7439f2ba3797b460e4986fac91e5fc42ba2cbe:12 (0.16777216 DCR) for ticket purchase split transaction
2023-08-17 15:31:27.543 [INF] DCR: selected input 0411b75263ed63c71bc04e3d09534656a6acc650fc55d5140a802b2b1e5a3fd1:0 (10.73632583 DCR) for ticket purchase split transaction
2023-08-17 15:31:27.543 [INF] DCR: selected input 2b5975f148d8ad8d4e984f79b896bd595e2a1502d9c5d5adc57b2a5ffaf6f325:11 (0.01048576 DCR) for ticket purchase split transaction
2023-08-17 15:31:27.543 [INF] DCR: selected input 39a6f02b9c4fcb2d5d0b075364c2fcc9d17202d83279ba48c9335a3507e1a016:8 (10.73741824 DCR) for ticket purchase split transaction
2023-08-17 15:31:27.543 [INF] DCR: selected input 2b5975f148d8ad8d4e984f79b896bd595e2a1502d9c5d5adc57b2a5ffaf6f325:0 (0.01048576 DCR) for ticket purchase split transaction
2023-08-17 15:31:27.543 [INF] DCR: selected input b31bd5dbfabb36fd035c5f031f7439f2ba3797b460e4986fac91e5fc42ba2cbe:3 (0.16777216 DCR) for ticket purchase split transaction
2023-08-17 15:31:27.543 [INF] DCR: selected input 39a6f02b9c4fcb2d5d0b075364c2fcc9d17202d83279ba48c9335a3507e1a016:4 (10.73741824 DCR) for ticket purchase split transaction
2023-08-17 15:31:27.543 [INF] DCR: selected input 8976424b6ae646adb76631b7d9fb328965154ecf341a1211ecb81a4e4d23451a:11 (2.68435456 DCR) for ticket purchase split transaction
2023-08-17 15:31:27.543 [INF] DCR: selected input d60bd8bb76f197e3eaba8369f47bf7d708afcc9d284051b15e0990ab993f8bf9:1 (0.04194304 DCR) for ticket purchase split transaction
2023-08-17 15:31:27.543 [INF] DCR: selected input 8eeb89df8c7ea879e8ec75573998dc063967a6ae61be8cfcc1057f148a0be4dd:16 (0.01048576 DCR) for ticket purchase split transaction
2023-08-17 15:31:27.543 [INF] DCR: selected input 8976424b6ae646adb76631b7d9fb328965154ecf341a1211ecb81a4e4d23451a:3 (2.68435456 DCR) for ticket purchase split transaction
2023-08-17 15:31:27.543 [INF] DCR: selected input 8976424b6ae646adb76631b7d9fb328965154ecf341a1211ecb81a4e4d23451a:8 (2.68435456 DCR) for ticket purchase split transaction
2023-08-17 15:31:27.543 [INF] DCR: selected input c85ada939c2ea4a7ecbdbb893827d10353434137103e4e85bf214f88779387ed:14 (0.00262144 DCR) for ticket purchase split transaction
2023-08-17 15:31:27.543 [INF] DCR: selected input 8eeb89df8c7ea879e8ec75573998dc063967a6ae61be8cfcc1057f148a0be4dd:7 (0.01048576 DCR) for ticket purchase split transaction
2023-08-17 15:31:27.543 [INF] DCR: selected input c85ada939c2ea4a7ecbdbb893827d10353434137103e4e85bf214f88779387ed:16 (0.00262144 DCR) for ticket purchase split transaction
2023-08-17 15:31:27.543 [INF] DCR: selected input c85ada939c2ea4a7ecbdbb893827d10353434137103e4e85bf214f88779387ed:1 (0.00262144 DCR) for ticket purchase split transaction
2023-08-17 15:31:27.543 [INF] DCR: selected input 4d314665df6f325124d2c148a16b2120c6e6da77f4d3c02756c58211051ff804:14 (2.68435456 DCR) for ticket purchase split transaction
2023-08-17 15:31:27.543 [INF] DCR: selected input c85ada939c2ea4a7ecbdbb893827d10353434137103e4e85bf214f88779387ed:7 (0.00262144 DCR) for ticket purchase split transaction
2023-08-17 15:31:27.543 [INF] DCR: selected input c9fbaafcff53465e66a6ed90dcb55a9ef7d7154f39305b64a460bcd2d138ddf0:3 (0.04194304 DCR) for ticket purchase split transaction
2023-08-17 15:31:27.543 [INF] DCR: selected input 4d314665df6f325124d2c148a16b2120c6e6da77f4d3c02756c58211051ff804:11 (2.68435456 DCR) for ticket purchase split transaction
2023-08-17 15:31:27.543 [INF] DCR: selected input 4d314665df6f325124d2c148a16b2120c6e6da77f4d3c02756c58211051ff804:6 (2.68435456 DCR) for ticket purchase split transaction
2023-08-17 15:31:27.543 [INF] DCR: selected input c85ada939c2ea4a7ecbdbb893827d10353434137103e4e85bf214f88779387ed:4 (0.00262144 DCR) for ticket purchase split transaction
2023-08-17 15:31:27.543 [INF] DCR: selected input c9fbaafcff53465e66a6ed90dcb55a9ef7d7154f39305b64a460bcd2d138ddf0:18 (0.04194304 DCR) for ticket purchase split transaction
2023-08-17 15:31:27.543 [INF] DCR: selected input 8bb3a794219cb55cb3dcca9033de4f6e5d5a6ab258bb31f6a3666a87a0197bba:2 (10.73741824 DCR) for ticket purchase split transaction
2023-08-17 15:31:28.394 [INF] DCR: Dialed CSPPServer 192.168.8.105:55926 -> 149.28.110.221:15760
2023-08-17 15:35:37.284 [INF] DCR: Returning address (account=1 branch=0 child=126)
2023-08-17 15:35:42.705 [INF] DCR: Completed CoinShuffle++ mix of ticket split transaction ca59aabd68c1a4baf7ee7860a8b23ef3d418c33eadfbf245084db8a1e7ac6428
2023-08-17 15:35:42.706 [INF] WLLT: Inserting unconfirmed transaction ca59aabd68c1a4baf7ee7860a8b23ef3d418c33eadfbf245084db8a1e7ac6428
2023-08-17 15:35:42.709 [INF] DCR: Split output is ca59aabd68c1a4baf7ee7860a8b23ef3d418c33eadfbf245084db8a1e7ac6428:2
2023-08-17 15:35:42.710 [INF] DCR: Returning address (account=0 branch=1 child=45)
2023-08-17 15:35:42.710 [INF] DCR: [10] New Transaction ca59aabd68c1a4baf7ee7860a8b23ef3d418c33eadfbf245084db8a1e7ac6428
2023-08-17 15:35:42.711 [INF] DCR: Returning address (account=1 branch=0 child=127)
2023-08-17 15:35:42.711 [INF] WLLT: Inserting unconfirmed transaction 08672206c9dacc148ca46206274b88a6514d797f510c7b38708b99e5e9c0dbc5
2023-08-17 15:35:42.713 [INF] DCR: [10] New Transaction 08672206c9dacc148ca46206274b88a6514d797f510c7b38708b99e5e9c0dbc5
2023-08-17 15:36:08.776 [INF] DCR: Published ticket purchase 08672206c9dacc148ca46206274b88a6514d797f510c7b38708b99e5e9c0dbc5
2023-08-17 15:36:09.956 [INF] VSPC: VSP requires fee 0.00036284 DCR
2023-08-17 15:36:09.957 [INF] DCR: Returning address (account=1 branch=1 child=7)
2023-08-17 15:36:09.958 [INF] WLLT: Inserting unconfirmed transaction f39932ff15304a60f41ac2321fa4086206758d3cfbe93de9db9ec55e87a4c810
2023-08-17 15:36:09.960 [INF] DCR: [10] New Transaction f39932ff15304a60f41ac2321fa4086206758d3cfbe93de9db9ec55e87a4c810
2023-08-17 15:36:10.275 [INF] VSPC: successfully processed 08672206c9dacc148ca46206274b88a6514d797f510c7b38708b99e5e9c0dbc5
2023-08-17 15:36:10.276 [INF] DCR: [10] Purchased ticket 08672206c9dacc148ca46206274b88a6514d797f510c7b38708b99e5e9c0dbc5 at stake difficulty 51.8998795 DCR
2023-08-17 15:36:47.686 [ERR] VSPC: ticket 08672206c9dacc148ca46206274b88a6514d797f510c7b38708b99e5e9c0dbc5: reconcile payment: payfee: error: status: 400 Bad Request resp: {"code":3,"message":"fee tx already received for ticket"}
2023-08-17 15:37:42.954 [ERR] VSPC: ticket 08672206c9dacc148ca46206274b88a6514d797f510c7b38708b99e5e9c0dbc5: reconcile payment: payfee: error: status: 400 Bad Request resp: {"code":3,"message":"fee tx already received for ticket"}
2023-08-17 15:38:24.832 [ERR] VSPC: ticket 08672206c9dacc148ca46206274b88a6514d797f510c7b38708b99e5e9c0dbc5: reconcile payment: payfee: error: status: 400 Bad Request resp: {"code":3,"message":"fee tx already received for ticket"}
2023-08-17 15:40:03.849 [ERR] VSPC: ticket 08672206c9dacc148ca46206274b88a6514d797f510c7b38708b99e5e9c0dbc5: reconcile payment: payfee: error: status: 400 Bad Request resp: {"code":3,"message":"fee tx already received for ticket"}
2023-08-17 15:40:17.939 [ERR] VSPC: ticket 08672206c9dacc148ca46206274b88a6514d797f510c7b38708b99e5e9c0dbc5: reconcile payment: payfee: error: status: 400 Bad Request resp: {"code":3,"message":"fee tx already received for ticket"}
2023-08-17 15:40:45.848 [ERR] VSPC: ticket 08672206c9dacc148ca46206274b88a6514d797f510c7b38708b99e5e9c0dbc5: reconcile payment: payfee: error: status: 400 Bad Request resp: {"code":3,"message":"fee tx already received for ticket"}
2023-08-17 15:42:07.676 [ERR] VSPC: ticket 08672206c9dacc148ca46206274b88a6514d797f510c7b38708b99e5e9c0dbc5: reconcile payment: payfee: error: status: 400 Bad Request resp: {"code":3,"message":"fee tx already received for ticket"}
2023-08-17 15:43:05.105 [ERR] VSPC: ticket 08672206c9dacc148ca46206274b88a6514d797f510c7b38708b99e5e9c0dbc5: reconcile payment: payfee: error: status: 400 Bad Request resp: {"code":3,"message":"fee tx already received for ticket"}
2023-08-17 15:44:56.293 [ERR] VSPC: ticket 08672206c9dacc148ca46206274b88a6514d797f510c7b38708b99e5e9c0dbc5: reconcile payment: payfee: error: status: 400 Bad Request resp: {"code":3,"message":"fee tx already received for ticket"}
2023-08-17 15:44:59.243 [ERR] VSPC: ticket 08672206c9dacc148ca46206274b88a6514d797f510c7b38708b99e5e9c0dbc5: reconcile payment: payfee: error: status: 400 Bad Request resp: {"code":3,"message":"fee tx already received for ticket"}
2023-08-17 15:45:45.102 [ERR] VSPC: ticket 08672206c9dacc148ca46206274b88a6514d797f510c7b38708b99e5e9c0dbc5: reconcile payment: payfee: error: status: 400 Bad Request resp: {"code":3,"message":"fee tx already received for ticket"}
2023-08-17 15:46:24.201 [ERR] VSPC: ticket 08672206c9dacc148ca46206274b88a6514d797f510c7b38708b99e5e9c0dbc5: reconcile payment: payfee: error: status: 400 Bad Request resp: {"code":3,"message":"fee tx already received for ticket"}
2023-08-17 15:46:27.811 [ERR] VSPC: ticket 08672206c9dacc148ca46206274b88a6514d797f510c7b38708b99e5e9c0dbc5: reconcile payment: payfee: error: status: 400 Bad Request resp: {"code":3,"message":"fee tx already received for ticket"}
2023-08-17 15:46:50.021 [ERR] VSPC: ticket 08672206c9dacc148ca46206274b88a6514d797f510c7b38708b99e5e9c0dbc5: reconcile payment: payfee: error: status: 400 Bad Request resp: {"code":3,"message":"fee tx already received for ticket"}
2023-08-17 15:47:20.801 [ERR] VSPC: ticket 08672206c9dacc148ca46206274b88a6514d797f510c7b38708b99e5e9c0dbc5: reconcile payment: payfee: error: status: 400 Bad Request resp: {"code":3,"message":"fee tx already received for ticket"}

@dmigwi dmigwi changed the title Confirm fee processing error happened before re-initiating it Upgrade dcrwallet to version v4 Aug 18, 2023
@dmigwi
Copy link
Collaborator Author

dmigwi commented Aug 18, 2023

The title has been changed to Upgrade dcrwallet to version v4 because that is the main fix that resolves the ticket issues.

@dreacot
Copy link
Member

dreacot commented Aug 21, 2023

Cryptopower currently requires go 1.19 to build, but this PR require go1.20, means the go mod would need to be updated

@dmigwi
Copy link
Collaborator Author

dmigwi commented Aug 21, 2023

The ticket buying error seems to have been finally resolved:

2023-08-21 14:49:49.920 [INF] DCR: The wallet has been unlocked without a time limit
2023-08-21 14:49:50.124 [INF] DCR: [10] Running ticket buyer
2023-08-21 14:50:09.876 [INF] DCR: Setting the ticket(s) purchasing account info
2023-08-21 14:50:10.485 [INF] DCR: Reserved credits for 1 tickets: total fee: 0.00035925 DCR
2023-08-21 14:50:10.485 [INF] DCR: Returning address (account=0 branch=1 child=53)
2023-08-21 14:50:10.485 [INF] DCR: selected input d60bd8bb76f197e3eaba8369f47bf7d708afcc9d284051b15e0990ab993f8bf9:4 (0.04194304 DCR) for ticket purchase split transaction
2023-08-21 14:50:10.485 [INF] DCR: selected input 5b6b487fcc9003b8646aa566236ae21bb105162a0947cb068398817f38191671:2 (51.91347257 DCR) for ticket purchase split transaction
2023-08-21 14:50:10.485 [INF] DCR: selected input 08245efa500fe2680c04c8c5f16cdc3fa32c04446cb234f6e220196b91c5f673:5 (42.94967296 DCR) for ticket purchase split transaction
2023-08-21 14:50:11.346 [INF] DCR: Dialed CSPPServer 192.168.8.105:33946 -> 149.28.110.221:15760
2023-08-21 14:51:25.395 [INF] DCR: Returning address (account=1 branch=0 child=137)
2023-08-21 14:51:30.945 [INF] DCR: Completed CoinShuffle++ mix of ticket split transaction 1c1b0a6ec97d0ad646bb83ba5894ccec842aabad4d6aa95d412be3c8832df29d
2023-08-21 14:51:30.946 [INF] WLLT: Inserting unconfirmed transaction 1c1b0a6ec97d0ad646bb83ba5894ccec842aabad4d6aa95d412be3c8832df29d
2023-08-21 14:51:30.948 [INF] DCR: Split output is 1c1b0a6ec97d0ad646bb83ba5894ccec842aabad4d6aa95d412be3c8832df29d:0
2023-08-21 14:51:30.949 [INF] DCR: [10] New Transaction 1c1b0a6ec97d0ad646bb83ba5894ccec842aabad4d6aa95d412be3c8832df29d
2023-08-21 14:51:30.949 [INF] DCR: Returning address (account=0 branch=1 child=54)
2023-08-21 14:51:30.950 [INF] DCR: Returning address (account=1 branch=0 child=138)
2023-08-21 14:51:30.951 [INF] WLLT: Inserting unconfirmed transaction 40ddd505a06607598a6cf697e1870a49274aced216840df22c9ff94d185d91f2
2023-08-21 14:51:30.953 [INF] DCR: [10] New Transaction 40ddd505a06607598a6cf697e1870a49274aced216840df22c9ff94d185d91f2
2023-08-21 14:52:24.335 [INF] DCR: Published ticket purchase 40ddd505a06607598a6cf697e1870a49274aced216840df22c9ff94d185d91f2
2023-08-21 14:52:25.936 [INF] VSPC: VSP requires fee 0.00035925 DCR
2023-08-21 14:52:25.937 [INF] DCR: Returning address (account=1 branch=1 child=8)
2023-08-21 14:52:25.939 [INF] WLLT: Inserting unconfirmed transaction ee2ebc0e6b167a6ebcc93e32c2e7b5ab2610eddd8e67031ab07c06bda59edc51
2023-08-21 14:52:25.940 [INF] DCR: [10] New Transaction ee2ebc0e6b167a6ebcc93e32c2e7b5ab2610eddd8e67031ab07c06bda59edc51
2023-08-21 14:52:26.255 [INF] VSPC: successfully processed 40ddd505a06607598a6cf697e1870a49274aced216840df22c9ff94d185d91f2
2023-08-21 14:52:26.256 [INF] DCR: [10] Purchased ticket 40ddd505a06607598a6cf697e1870a49274aced216840df22c9ff94d185d91f2 at stake difficulty 56.26454584 DCR

@dmigwi dmigwi force-pushed the reconcile-payment-error branch 5 times, most recently from 87e9639 to 527a113 Compare August 21, 2023 12:38
go.mod Show resolved Hide resolved
@dreacot
Copy link
Member

dreacot commented Aug 24, 2023

i'm unable to vote on treasury spending

Screenshot 2023-08-24 at 5 36 25 PM

go.mod Show resolved Hide resolved
libwallet/assets/dcr/consensus.go Outdated Show resolved Hide resolved
libwallet/assets/dcr/consensus.go Outdated Show resolved Hide resolved
libwallet/assets/dcr/ticket.go Outdated Show resolved Hide resolved
libwallet/assets/dcr/wallet.go Show resolved Hide resolved
libwallet/assets/dcr/wallet.go Show resolved Hide resolved
libwallet/internal/vsp/feepayment.go Outdated Show resolved Hide resolved
libwallet/internal/vsp/feepayment.go Outdated Show resolved Hide resolved
Comment on lines +52 to +54
// Default policy for fee payments unless another is provided by the
// caller.
Policy *Policy
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do callers provide policy anywhere? Looks like all methods have been modified to no longer pass a policy.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Upstream uses a default policy for all ticket purchases. Because here we ought to purchase tickets from any account, a default policy can't work here and thus the work around.

Comment on lines +101 to +105
// SetAccountInfo set the account purchase information
func (c *Client) SetAccountInfo(feeAcc, changeAcc int32) {
c.policy.FeeAcct = uint32(feeAcc)
c.policy.ChangeAcct = uint32(changeAcc)
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could separate processes try to set this info, leading to unexpected results? Why don't callers provide the policy to use, at the point the policy is needed?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

By separate processes, do you two mean instances where two source accounts are being used simultaneously? Its always been one account at a go.
Also this account information is set before the ticket buying loop starts, so we don't have any scenario of multiple synchronous writes to those variables would happen.

@dmigwi
Copy link
Collaborator Author

dmigwi commented Aug 28, 2023

@dreacot and @itswisdomagain much of the code introduced here is copied word for word from here: https://github.com/decred/dcrwallet/tree/master/internal/vsp

The reason why its copied, is because the code is implemented in an internal folder making it hard to reference it as a package. Those changes introduced depend on dcrwallet v4 and this is why I ported dcrwallet v4 to here.

@dmigwi dmigwi changed the title Upgrade dcrwallet to version v4 Upgrade dcrwallet to master branch (future version v4) Aug 28, 2023
Copy link
Collaborator

@itswisdomagain itswisdomagain left a comment

Choose a reason for hiding this comment

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

Pausing here first to revisit the original issue and possibly propose alternative solutions.

Comment on lines +114 to 117
if ok && currentChoice == strings.ToLower(choiceID) {
// Do not set the same choice again
return nil
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Might it be necessary to continue even if it's the same value? Below, the specified ticket or all unvoted tickets are updated with the vsp to use this choice. I'm wondering if it's possible that a ticket in that list doesn't already have the correct vote choice set with the vsp.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The purpose of this is to prevent unnecessary API calls. It does this by preventing the existing choice being set again.
I don't think setting the same choice again is necessary.

Comment on lines +244 to 249
for agendaID, choiceID := range choices {
if agendaID == d.Vote.Id {
votingPreference = choiceID
break
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

This look correct?
votingPreference = choices[d.Vote.Id]

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is double query; during the map for loop, choices[d.Vote.Id] already exists as choiceID.

@@ -181,7 +177,7 @@ func (asset *Asset) SetVoteChoice(agendaID, choiceID, hash, passphrase string) e
firstErr = err
Copy link
Collaborator

Choose a reason for hiding this comment

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

One of the new dcrwallet commits since v3.0.1 abolished the concept of firstErr and returns any error encountered immediately. We should adopt that. Can possibly create a separate issue but generally, when upgrading the dcrwallet dep, I often do a comparison of the code changes between the last version in our go.mod and the new version we're introducing. The comparison for this version bump is https://github.com/decred/dcrwallet/compare/v3.0.1..a87fa843495e (file changes) and decred/dcrwallet@v3.0.1...a87fa84 (commits).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This could be done app wide so a separate issue can best address this.

Comment on lines 135 to 137
VSPFeePaymentProcess: func(ctx context.Context, ticketHash *chainhash.Hash, feeTx *wire.MsgTx) error {
return vspClient.Process(ctx, ticketHash, feeTx, asset.GetvspPolicy(account))
return vspClient.Process(ctx, ticketHash, feeTx)
},
Copy link
Collaborator

Choose a reason for hiding this comment

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

VSPFeePaymentProcess: vspClient.Process

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

VSPFeePaymentProcess requires a different method signature than supported by vspClient.Process.

libwallet/assets/dcr/ticket.go Outdated Show resolved Hide resolved
Comment on lines +127 to +128
log.Info("Setting the ticket(s) purchasing account info")
vspClient.SetAccountInfo(account, account)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Upstream dcrwallet doesn't modify the fee and change accounts after the vsp is created with a policy that defines those values. All subsequent calls to wallet.PurchaseTickets continue to use the same accounts initially set in the policy, even if the PurchaseTicketsRequest uses a different source account.

Modifying that policy everytime this PurchaseTickets method is called is potentially problematic. There's nothing to ensure that this method isn't called twice in quick succession, with the callers passing different accounts in each call, and ending up getting unexpected outcomes.

I understand the desire to use the same purchasing account as fee and change account but perhaps go with dcrwallet's style for now and never change those account values once they've been set at the time of creating the vspClient.

Or come up with a safer way to make this value dynamic.

I remember I'd discussed this issue with the upstream repo maintainer before, even opened a PR to resolve it then.
decred/dcrwallet#2129

Copy link
Collaborator Author

@dmigwi dmigwi Sep 11, 2023

Choose a reason for hiding this comment

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

Our implementation here reuses the VSP clients therefore we cannot set default fee and change accounts when creating a client. In dcrwallet, they use default policy accounts but that doesn't apply to use because a user can manage many wallets with many accounts and any of the accounts can be selected as the source of funds.

There's nothing to ensure that this method isn't called twice in quick succession theoretically this is possible but how vspClient.SetAccountInfo( is used in the code, that case scenario is impossible to replicate. I feel adding those extra safeguards will only make the method more complicated and error prone.

As mentioned earlier:

..this account information is set before the ticket buying loop starts, so we don't have any scenario of multiple synchronous writes to those variables would happen...

That account information is set only once together with other ticket information and it doesn't happen more than one per given ticket purchase trigger. Only the following methods set the account information:

  • func (asset *Asset) PurchaseTickets(account, numTickets int32, vspHost, passphrase string, vspPubKey []byte) ([]*chainhash.Hash, error) {
  • func (asset *Asset) runTicketBuyer(ctx context.Context, passphrase string, cfg *TicketBuyerConfig) error {

None of them can execute in multiple quick successions and if it does, this is a bug where that is triggered.

@JustinBeBoy
Copy link
Collaborator

@dmigwi seem like this pr not need, please close it

@dmigwi
Copy link
Collaborator Author

dmigwi commented Jul 10, 2024

PR superseded by this #544

@dmigwi dmigwi closed this Jul 10, 2024
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.

reconcile payment error when running ticket buyer
4 participants