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: Add staking methods. #2290

Merged
merged 1 commit into from
Aug 7, 2023
Merged

Conversation

JoeGruffins
Copy link
Member

part of #2264

This pr only adds capabilities to the asset and simnet testing framework.

Many of the changes are files copied from vspd and wallet. Hopefully the fee paying logic can be exported from wallet so we won't need to add here.

This will be updated.

@martonp
Copy link
Contributor

martonp commented Apr 11, 2023

Would it make sense to have a separate VSP library in a new repo containing all the files you copied? And then vspd, dex, and other projects could just import it.

@buck54321
Copy link
Member

Would it make sense to have a separate VSP library in a new repo containing all the files you copied? And then vspd, dex, and other projects could just import it.

@jholdstock wanted to put it in the vspd repo anyway. Maybe @JoeGruffins could open up a pull request over there too. But we don't want to wait for them either. We'll delete this stuff once it's available.

@chappjc
Copy link
Member

chappjc commented Apr 11, 2023

If decred/dcrwallet#2224 (or something like it) happens, are we still left with a bunch of copied files? I didn't see the discussion with @jholdstock about putting this stuff in the vspd repo.

@buck54321
Copy link
Member

If decred/dcrwallet#2224 (or something like it) happens, are we still left with a bunch of copied files? I didn't see the discussion with @jholdstock about putting this stuff in the vspd repo.

I didn't know about #2224. @JoeGruffins shouldn't we be targeting a move to vspd?

@JoeGruffins
Copy link
Member Author

Asking on matrix if there were plans to move the rest of the dcrwallet/internal/vsp package to the decred/vspd repo.

Not sure about the files in dex/testing/dcr/vspdtemplates but the simnet vspd panics without them so I guess we need to copy to use vspd from the test folder location. I believe dexc also used to require files in a certain location like this but we build them into the executable at some point.

@buck54321
Copy link
Member

Could do this while waiting for decred/vspd#382.

@buck54321
Copy link
Member

buck54321 commented Apr 24, 2023

I was playing with this a little. Please consider these changes.

  1. Consolidates pure getters into a single call
  2. Adds extra ticket details
  3. Prepares for pagination

*untested

@JoeGruffins
Copy link
Member Author

replace github.com/decred/vspd/client/v2 => github.com/jholdstock/vspd/client/v2 v2.0.0-20230424165325-5d3f56b5c4e4 Wow didn't realize that was a thing we could do. Will adjust.

@JoeGruffins
Copy link
Member Author

JoeGruffins commented Apr 25, 2023

Made the buck change suggestions. For some reason go mod tidy does not error when I run it but does with the testing script. invalid version: unknown revision 000000000000

Oh yeah, loadbot's go.mod. Ok now.

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.

Do we need to do something with (*AutoClient).ProcessUnprocessedTickets?

client/asset/dcr/dcr.go Outdated Show resolved Hide resolved
client/asset/dcr/dcr.go Outdated Show resolved Hide resolved
}

// PurchaseTickets purchases n amout of tickets. Ability to purchase should be
// checked with CanPurchaseTickets. Part of the asset.TicketBuyer interface.
Copy link
Member

Choose a reason for hiding this comment

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

CanPurchaseTickets?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah. The original plan was to check the wallet config before purchasing over rpc, and we would deny if not using a vsp. But, giving up on that since it seems we cannot get the config. User will just have to know what they are doing. Anyway, removing the reference to the removed method.

client/asset/interface.go Outdated Show resolved Hide resolved
Comment on lines +4577 to +5184
if !dcr.connected.Load() {
return nil, errors.New("not connected, login first")
}
Copy link
Member

Choose a reason for hiding this comment

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

I'm wondering what these dcr.connected checks do for us. We could theoretically add this check to almost any ExchangeWallet method, but we don't because we expect the caller to know better, and continuing without being connected would generate an error anyway. What would happen if we didn't check this?

Copy link
Member Author

Choose a reason for hiding this comment

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

My memory is fuzzy, but these will panic if the dcr.ctx is nil, which is so before the first connect.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I added this to any methods that use dcr.ctx to avoid using a nil context and panic inside the rpcclient. Should I handle this differently?


func (w *rpcWallet) Tickets(ctx context.Context) ([]*asset.Ticket, error) {
const includeImmature = true
// GetTickets only works for clients with a dcrd backend.
Copy link
Member

Choose a reason for hiding this comment

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

Wow. I didn't know that. That's unfortunate. It looks like it's just for the extraTickets checks in (*Wallet).LiveTicketHashes. Otherwise all the data is just from the db.

client/asset/dcr/spv.go Outdated Show resolved Hide resolved
w.log.Warnf("unable to get VSP associated with ticket %s: %v", hash, err)
return nil
}
info, err := vspInfo(vspHost)
Copy link
Member

Choose a reason for hiding this comment

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

Probably shouldn't call vspInfo in a loop since it contains an http request. Maybe keep a cache map[string]*vspclient.AutoClient that you can check first.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good idea. A map local to the function good enough?

client/asset/dcr/spv_test.go Outdated Show resolved Hide resolved
@buck54321
Copy link
Member

Can get rid of the replace and rebase now, I think. Probably good to pull out of draft too.

@JoeGruffins
Copy link
Member Author

vsp still has several replaces, https://github.com/decred/vspd/blob/master/go.mod

If we import vspd I guess we also need to use those replaces? And does the entire repo need to move to dcrwallet/v3 then?

@JoeGruffins JoeGruffins force-pushed the dcrstaking branch 2 times, most recently from 0eaf8a3 to 3f91df5 Compare June 8, 2023 06:38
@JoeGruffins
Copy link
Member Author

Do we need to do something with (*AutoClient).ProcessUnprocessedTickets?

Maybe. Client could do this if wallet was reset from seed I think. Is it ok to make a todo for now? Because of automatic revocations now, its not a HUGE deal even if the vsp is not set up. Also, if the fee was paid, and the vspd is ok, the wallet doesnt need to worry about it, really. The vsp will vote and the wallet will get the funds back at some point.

@JoeGruffins JoeGruffins marked this pull request as ready for review June 8, 2023 07:52
@JoeGruffins
Copy link
Member Author

@JoeGruffins
Copy link
Member Author

So, copying the vspd client logic for now but using dcrwallet/v2. Hopefully can be removed sooner or later, but this seems like the only way to continue immediately.

@buck54321
Copy link
Member

vspd cleaned up their go.mod and chappjc is working through the dcrwallet v3 upgrade now.

@chappjc
Copy link
Member

chappjc commented Jul 13, 2023

Nice work. 💪

@JoeGruffins JoeGruffins force-pushed the dcrstaking branch 2 times, most recently from ce32862 to 674e179 Compare July 14, 2023 01:21
@@ -5,7 +5,7 @@ go 1.18
replace decred.org/dcrdex => ../../..

require (
decred.org/dcrdex v0.6.1
decred.org/dcrdex v0.6.0
Copy link
Member

Choose a reason for hiding this comment

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

looks like an unintentional rollback

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed! I guess this value doesn't really matter with the replace?

Copy link
Member

Choose a reason for hiding this comment

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

Sorry to dwell on this, but all the indirect depends resulting from this are still changed. Best just to restore these files from master e.g. git restore --source=master go.mod

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok! Will add that command to my knowledge.

Copy link
Contributor

@ukane-philemon ukane-philemon left a comment

Choose a reason for hiding this comment

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

utAck. Good work @JoeGruffins.

client/asset/dcr/dcr.go Outdated Show resolved Hide resolved
client/asset/dcr/dcr.go Outdated Show resolved Hide resolved
client/asset/dcr/dcr.go Show resolved Hide resolved
client/asset/dcr/dcr.go Outdated Show resolved Hide resolved
client/asset/dcr/dcr.go Outdated Show resolved Hide resolved
client/asset/dcr/dcr.go Outdated Show resolved Hide resolved
@JoeGruffins JoeGruffins force-pushed the dcrstaking branch 3 times, most recently from 2f64728 to e35ffb5 Compare July 18, 2023 08:46
@JoeGruffins
Copy link
Member Author

client/asset/dcr/dcr.go Outdated Show resolved Hide resolved

// SetVSP sets the VSP provider. Ability to set should be checked with CanSetVSP
// first. Part of the asset.TicketBuyer interface.
func (dcr *ExchangeWallet) SetVSP(url string) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems SetVSP and other TicketBuyer methods are not consumed anywhere, except in simnet_test.go, this means consumption of these new methods/features would be in a follow-up PR, no?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes. With the rpcserver in #2316 and webserver not done yet.

client/asset/dcr/simnet_test.go Outdated Show resolved Hide resolved
client/asset/dcr/simnet_test.go Outdated Show resolved Hide resolved
client/asset/dcr/dcr.go Outdated Show resolved Hide resolved
Comment on lines 150 to 151
// PurchaseTickets purchases n tickets. vsp arguments only needed for
// internal wallets.
PurchaseTickets(ctx context.Context, n int, vspHost, vspPubKey string) ([]string, error)
Copy link
Contributor

Choose a reason for hiding this comment

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

Please can we specify the exact arguments that are not needed for RPC wallets? I see only vspHost and vspPubKey are ignored and all other arguments are provided. vsp arguments might not ring a bell the first time.

Copy link
Member Author

Choose a reason for hiding this comment

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

vspHost and vspPubKey only needed for internal wallets. okay?

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.

Mostly just some nits for now. Testing well.

dex/testing/dcr/create-vspd.sh Show resolved Hide resolved
client/asset/dcr/dcr.go Outdated Show resolved Hide resolved
client/asset/dcr/simnet_test.go Outdated Show resolved Hide resolved
client/asset/dcr/simnet_test.go Outdated Show resolved Hide resolved
Comment on lines +335 to +341
MANUAL_TICKETS="1"
"${HARNESS_DIR}/create-wallet.sh" "$SESSION:7" "vspdwallet" ${VSPD_WALLET_SEED} \
${VSPD_WALLET_RPC_PORT} ${USE_SPV} ${ENABLE_VOTING} "_" ${MANUAL_TICKETS}
Copy link
Member

Choose a reason for hiding this comment

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

I may not understand the config option, but why manualtickets=1 for this wallet?

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh I don't really know, just following the guide.

dcrwallet is also required to have the manual tickets option (--manualtickets) enabled which disables dcrwallet adding tickets arriving over the network.

https://github.com/decred/vspd/blob/master/docs/deployment.md#voting-servers

client/asset/dcr/dcr.go Outdated Show resolved Hide resolved
client/asset/dcr/simnet_test.go Outdated Show resolved Hide resolved
client/asset/dcr/simnet_test.go Outdated Show resolved Hide resolved
client/asset/dcr/simnet_test.go Outdated Show resolved Hide resolved
client/asset/dcr/simnet_test.go Outdated Show resolved Hide resolved
client/asset/dcr/dcr.go Show resolved Hide resolved
client/asset/interface.go Outdated Show resolved Hide resolved
@JoeGruffins JoeGruffins force-pushed the dcrstaking branch 2 times, most recently from 467337e to c3b9e76 Compare August 5, 2023 10:44
@JoeGruffins
Copy link
Member Author

Addressing reviews https://github.com/decred/dcrdex/compare/467337e1993823a1ffcac08d0e966282cc789548..c3b9e76eae170af3e91a6573d20c870ad2b36857

Notable changes are removing the vsp file and just getting the fee and pubkey on wallet start and adding some test parameters.

@JoeGruffins
Copy link
Member Author

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.

Good stuff. I'll follow up with a couple of tweaks.

@buck54321 buck54321 merged commit ae95dca into decred:master Aug 7, 2023
5 checks passed
@@ -5134,6 +5174,125 @@ func (dcr *ExchangeWallet) EstimateSendTxFee(address string, sendAmount, feeRate
return finalFee, isValidAddress, nil
}

func (dcr *ExchangeWallet) isSPV() bool {
return dcr.walletType == walletTypeSPV
Copy link
Member

Choose a reason for hiding this comment

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

This reminds me. There's a dcr.wallet.SpvMode() which may be true even for a wallet connected via rpc. Put another way, isSPV could be true even if walletType isn't walletTypeSPV.

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.

6 participants