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

mulit: remove voting public key from config and check fee public key on start up #422

Closed
wants to merge 10 commits into from
7 changes: 2 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,12 +158,9 @@ $ dcrwallet --create
$ dcrwallet
```

- Get the master pubkey from the default account. This will be used for
JoeGruffins marked this conversation as resolved.
Show resolved Hide resolved
votingwalletextpub in dcrstakepool.conf.
- The master extended public key for the "default" account will be retrieved
automatically from the stakepoold wallets upon starting dcrstakepool

```bash
$ dcrctl --wallet getmasterpubkey default
```

### MySQL

Expand Down
11 changes: 11 additions & 0 deletions backend/stakepoold/rpc/api.proto
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ service StakepooldService {
rpc AccountSyncAddressIndex (AccountSyncAddressIndexRequest) returns (AccountSyncAddressIndexResponse);
rpc CreateMultisig (CreateMultisigRequest) returns (CreateMultisigResponse);
rpc GetStakeInfo (GetStakeInfoRequest) returns (GetStakeInfoResponse);
rpc WalletMasterPubKeys (WalletMasterPubKeysRequest) returns (WalletMasterPubKeysResponse);
}

service VersionService {
Expand Down Expand Up @@ -175,3 +176,13 @@ message GetStakeInfoResponse {
double ProportionMissed = 15;
uint32 Expired = 16;
}

message WalletMasterPubKeysRequest {}

message WalletMasterPubKeysResponse {
message PubKey {
string account = 1;
string pub_key = 2;
}
repeated PubKey master_pub_keys = 1;
}
22 changes: 22 additions & 0 deletions backend/stakepoold/rpc/rpcserver/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,28 @@ func (ctx *AppContext) UpdateUserDataFromMySQL() error {
return nil
}

// WalletMasterPubKeys returns a map of extended master public key to
// account for all accounts visible to dcrwallet.
func (ctx *AppContext) WalletMasterPubKeys() (map[string]string, error) {
acctMap, err := ctx.WalletConnection.RPCClient().ListAccounts()
if err != nil {
return nil, fmt.Errorf("WalletMasterPubKeys: ListAccounts rpc failed: %v", err)
}
keyMap := make(map[string]string)
for acct := range acctMap {
// Skip the imported account.
if acct == "imported" {
continue
}
key, err := ctx.WalletConnection.RPCClient().GetMasterPubkey(acct, ctx.Params)
if err != nil {
return nil, fmt.Errorf("WalletMasterPubKeys: GetMasterPubKey rpc failed: %v", err)
}
keyMap[acct] = key.String()
}
return keyMap, nil
}

// vote Generates a vote and send it off to the network. This is a go routine!
func (ctx *AppContext) vote(wg *sync.WaitGroup, blockHash *chainhash.Hash, blockHeight int64, w *ticketMetadata) {
start := time.Now()
Expand Down
21 changes: 19 additions & 2 deletions backend/stakepoold/rpc/rpcserver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ const (
// collection cycle to also trigger a timeout but the current allocation
// pattern of stakepoold is not known to cause such conditions at this time.
GRPCCommandTimeout = time.Millisecond * 100
semverString = "8.0.0"
semverMajor = 8
semverString = "9.0.0"
Copy link
Member

Choose a reason for hiding this comment

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

Needs to be updated to 9.1.0. We incremented to 9.0.0 in #526, and this PR adds a new method without breaking backwards compatability.

semverMajor = 9
semverMinor = 0
semverPatch = 0
)
Expand Down Expand Up @@ -301,3 +301,20 @@ func (s *stakepooldServer) GetStakeInfo(ctx context.Context, req *pb.GetStakeInf
Expired: response.Expired,
}, nil
}

func (s *stakepooldServer) WalletMasterPubKeys(ctx context.Context, req *pb.WalletMasterPubKeysRequest) (*pb.WalletMasterPubKeysResponse, error) {
keyMap, err := s.appContext.WalletMasterPubKeys()
if err != nil {
return nil, err
}
pubKeys := make([]*pb.WalletMasterPubKeysResponse_PubKey, len(keyMap))
var i int
for acct, key := range keyMap {
pubKey := pb.WalletMasterPubKeysResponse_PubKey{Account: acct, PubKey: key}
pubKeys[i] = &pubKey
i++
}
return &pb.WalletMasterPubKeysResponse{
MasterPubKeys: pubKeys,
}, nil
}
348 changes: 255 additions & 93 deletions backend/stakepoold/rpc/stakepoolrpc/api.pb.go

Large diffs are not rendered by default.

22 changes: 6 additions & 16 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ type config struct {
WalletUsers []string `long:"walletusers" description:"Deprecated: dcrstakepool no longer connects to dcrwallet"`
WalletPasswords []string `long:"walletpasswords" description:"Deprecated: dcrstakepool no longer connects to dcrwallet"`
WalletCerts []string `long:"walletcerts" description:"Deprecated: dcrstakepool no longer connects to dcrwallet"`
VotingWalletExtPub string `long:"votingwalletextpub" description:"The extended public key of the default account of the voting wallet"`
VotingWalletExtPub string `long:"votingwalletextpub" description:"Deprecated: Do not use. This will not be an option in a future release of dcrstakepool, and setting it will cause a startup error."`
AdminIPs []string `long:"adminips" description:"Expected admin host"`
AdminUserIDs []string `long:"adminuserids" description:"User IDs of users who are allowed to access administrative functions."`
MinServers int `long:"minservers" description:"Deprecated: Do not use. Minimum of 2 servers are required when running on mainnet. Testnet and simnet require minimum 1."`
Expand Down Expand Up @@ -278,14 +278,6 @@ func (c *config) parsePubKeys(params *chaincfg.Params) error {
if !coldWalletFeeKey.IsForNet(params) {
return fmt.Errorf("cold wallet extended public key is for wrong network")
}
// Parse the extended public key for the voting addresses.
votingWalletVoteKey, err = hdkeychain.NewKeyFromString(c.VotingWalletExtPub)
if err != nil {
return fmt.Errorf("voting wallet extended public key: %v", err)
}
if !votingWalletVoteKey.IsForNet(params) {
return fmt.Errorf("voting wallet extended public key is for wrong network")
}
return nil
}

Expand Down Expand Up @@ -522,13 +514,6 @@ func loadConfig() (*config, []string, error) {
return nil, nil, err
}

if len(cfg.VotingWalletExtPub) == 0 {
str := "%s: votingwalletextpub is not set in config"
err := fmt.Errorf(str, funcName)
fmt.Fprintln(os.Stderr, err)
return nil, nil, err
}

if err := cfg.parsePubKeys(activeNetParams.Params); err != nil {
err := fmt.Errorf("%s: failed to parse extended public keys: %v", funcName, err)
fmt.Fprintln(os.Stderr, err)
Expand Down Expand Up @@ -659,6 +644,11 @@ func loadConfig() (*config, []string, error) {
log.Warnf(str, funcName)
}

if cfg.VotingWalletExtPub != "" {
str := "%s: Config VotingWalletExtPub is deprecated and has no effect. Please remove from your config file. This will not be an option in a future release of dcrstakepool, and setting it will cause a startup error."
log.Warnf(str, funcName)
}

// Warn about missing config file only after all other configuration is
// done. This prevents the warning on help messages and invalid
// options. Note this should go directly before the return.
Expand Down
43 changes: 16 additions & 27 deletions config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,37 +21,27 @@ const (
simnetXPub2 = "spubVVBn1KgTWoDRefX2cjSRjhBYFahdbTvhMzB1Lia3hCseDjB4tdxFJ3FDPG3NGkBpA6XEjRxw1r9LnU5nRpkvKGkfxfAqqFtc72kaU5Fmn6r"
)

type keysIn struct {
coldFeeWallet string
voteWallet string
}

type keysOut struct {
coldFeeWallet *hdkeychain.ExtendedKey
voteWallet *hdkeychain.ExtendedKey
}

type keyParse struct {
params *chaincfg.Params
keysIn keysIn
keysOut keysOut
isError bool
params *chaincfg.Params
coldFeeIn string
coldFeeOut *hdkeychain.ExtendedKey
isError bool
}

//in keys, expected out keys, and error value
var keyTestValues = []keyParse{
//testnet
{testNet3Params.Params, keysIn{testnetXPub1, testnetXPub2}, keysOut{hd(testnetXPub1), hd(testnetXPub2)}, false},
{testNet3Params.Params, keysIn{testnetXPub1, mainnetXPub2}, keysOut{hd(testnetXPub1), hd(mainnetXPub2)}, true},
{testNet3Params.Params, keysIn{"", mainnetXPub2}, keysOut{hd(""), hd(mainnetXPub2)}, true},
{testNet3Params.Params, testnetXPub1, hd(testnetXPub1), false},
{testNet3Params.Params, mainnetXPub2, hd(mainnetXPub2), true},
{testNet3Params.Params, "", hd(""), true},
//mainnet
{mainNetParams.Params, keysIn{mainnetXPub1, mainnetXPub2}, keysOut{hd(mainnetXPub1), hd(mainnetXPub2)}, false},
{mainNetParams.Params, keysIn{simnetXPub1, mainnetXPub2}, keysOut{hd(simnetXPub1), hd(mainnetXPub2)}, true},
{mainNetParams.Params, keysIn{mainnetXPub1, mainnetXPub2 + "a"}, keysOut{hd(mainnetXPub1), hd(mainnetXPub2 + "a")}, true},
{mainNetParams.Params, mainnetXPub1, hd(mainnetXPub1), false},
{mainNetParams.Params, simnetXPub2, hd(simnetXPub2), true},
{mainNetParams.Params, mainnetXPub2 + "a", hd(mainnetXPub2 + "a"), true},
//simnnet
{simNetParams.Params, keysIn{simnetXPub1, simnetXPub2}, keysOut{hd(simnetXPub1), hd(simnetXPub2)}, false},
{simNetParams.Params, keysIn{testnetXPub1, simnetXPub2}, keysOut{hd(testnetXPub1), hd(simnetXPub2)}, true},
{simNetParams.Params, keysIn{simnetXPub1[:len(simnetXPub1)-1], simnetXPub2}, keysOut{hd(simnetXPub1[:len(simnetXPub1)-1]), hd(simnetXPub2)}, true},
{simNetParams.Params, simnetXPub1, hd(simnetXPub1), false},
{simNetParams.Params, testnetXPub2, hd(testnetXPub2), true},
{simNetParams.Params, simnetXPub1[:len(simnetXPub1)-1], hd(simnetXPub1[:len(simnetXPub1)-1]), true},
}

//helper func string to extended key
Expand All @@ -73,13 +63,12 @@ func TestParsePubKeys(t *testing.T) {
var cfg config
for _, test := range keyTestValues {
//parsePubKeys uses these fields
cfg.ColdWalletExtPub = test.keysIn.coldFeeWallet
cfg.VotingWalletExtPub = test.keysIn.voteWallet
cfg.ColdWalletExtPub = test.coldFeeIn
//testing func
err := cfg.parsePubKeys(test.params)
//err if expected output key strings and real output key strings don't match or expected error status is different
if strFromHd(test.keysOut.coldFeeWallet) != strFromHd(coldWalletFeeKey) || strFromHd(test.keysOut.voteWallet) != strFromHd(votingWalletVoteKey) || (err != nil) != test.isError {
t.Error("for", test.keysIn, "expected", strFromHd(test.keysOut.coldFeeWallet), strFromHd(test.keysOut.voteWallet), "and is error=", test.isError, "got", strFromHd(coldWalletFeeKey), strFromHd(votingWalletVoteKey), "and is error=", err != nil)
if strFromHd(test.coldFeeOut) != strFromHd(coldWalletFeeKey) || (err != nil) != test.isError {
t.Error("for", test.coldFeeIn, "expected", strFromHd(test.coldFeeOut), "and is error=", test.isError, "got", strFromHd(coldWalletFeeKey), "and is error=", err != nil)
}
}
}
Loading