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
[rebase of #845] rpc: add new btcd extension commands: addminingaddr, delminingaddr, listminingaddrs #1441
base: master
Are you sure you want to change the base?
Conversation
This commit adds three new btcd extension commands: addminingaddr, delminingaddr, and listminingaddrs. These new commands allows users to dynamically add, remove and list the current set of mining addresses available to btcd.
This commit implements a new btcd extension RPC calls: addminingaddr, delminingaddr, and listminingaddrs. These RPC calls allows a caller to add, remove and list mining addresses dynamically without restarting a running btcd node. Within btcd’s set of active mining addresses, all addresses must be unique. Incoming RPC calls that attempt to add duplicate generation addresses are ignored. Similarly, any attempts to delete a non-existent mining address will result in an error. In order to implement this new RPC call in a thread-safe manner, a new mutex has been added to synchronize access the `miningAddrs` attribute within the `config` struct.
This commit modifies the existing `cpuminer.Config` struct to replace with the `MiningAddrs` attribute and manual generation address selection with a new function closure. When called, this function closure returns a mining address to be used within the next generated block. This modification adds a layer of abstraction over the storage and selection logic for obtaining a new mining address.
This commit fixes a slight bug in the parsing of the supplied mining addresses within the configuration. Before this commit, the code was checking the length of `cfg.MiningAddrs` (the populated config value) instead of `cfg.miningAddrs` the value in which the valid mining addresses are stored within.
Would love to have this functionality to test apps w/ btcd (neutrino). @Roasbeef |
FYI was seeing a |
@jcvernaleo (as per #1530)
|
What needs to be done for this to be merged? |
@dannypaz if you could rebase and squash it that would definitely help on my end. I know you rebased this a long time ago but since I'm trying to finally get some of these old PRs in there is going to be some churn. This one is pretty well reviewed already so it is high on my list. |
Will take another quick pass at reviewing in the mean time once rebased |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm really pushing for the use of an interface here, as there is state coupled with the MiningAddr
method, and a struct had to be defined in order to implement MiningAddr
.
// MiningAddr is a function which when called yields an address to | ||
// to use as the payment address for generated blocks. | ||
MiningAddr func() btcutil.Address |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given your implementation of this function requires you to define a struct miningAddrStore
and it exists for the sole purpose of implementing this function, I think it would be a lot cleaner to put an interface here. Then, we don't have to add anything to the server
struct in server.go
.
@@ -331,3 +333,7 @@ func main() { | |||
os.Exit(1) | |||
} | |||
} | |||
|
|||
func init() { | |||
prand.Seed(time.Now().UnixNano()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why create an init()
in the main btcd.go
just for the sake of seeding rand? Maybe this should go somewhere else, as math/rand
is used elsewhere in the codebase - see peer/peer.go
.
@@ -672,7 +675,6 @@ The following is an overview of the RPC methods which are implemented by btcd, b | |||
|Description|Returns the version of the JSON-RPC API built into this release of btcd.| | |||
|Returns|`{ (json object)`<br /> `"btcdjsonrpcapi": {`<br /> `"versionstring": "x.y.z", (string) the version of the JSON-RPC API`<br /> `"major": x, (numeric) the major version of the JSON-RPC API`<br /> `"minor": y, (numeric) the minor version of the JSON-RPC API`<br /> `"patch": z, (numeric) the patch version of the JSON-RPC API`<br /> `"prerelease": "", (string) prerelease info for the JSON-RPC API`<br /> `"buildmetadata": "" (string) metadata about the server build`<br /> `}`<br />`}`| | |||
|Example Return|`{`<br /> `"btcdjsonrpcapi": {`<br /> `"versionstring": "1.0.0",`<br /> `"major": 1, `<br /> `"minor": 0,`<br /> `"patch": 0,`<br /> `"prerelease": "",`<br /> `"buildmetadata": ""`<br /> `}`<br />`}`| | |||
[Return to Overview](#MethodOverview)<br /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should un-delete this
@@ -685,6 +687,43 @@ The following is an overview of the RPC methods which are implemented by btcd, b | |||
|Description|Returns block headers starting with the first known block hash from the request.| | |||
|Returns|`[ (json array of strings)`<br /> `"blockheader",`<br /> `...`<br />`]`| | |||
|Example Return|`[`<br /> `"0000002099417930b2ae09feda10e38b58c0f6bb44b4d60fa33f0e000000000000000000d53...",`<br /> `"000000203ba25a173bfd24d09e0c76002a910b685ca297bd09a17b020000000000000000702..."`<br />`]`| | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to add another "Return to overview" here for getheaders
.
"addnode": handleAddNode, | ||
"createrawtransaction": handleCreateRawTransaction, | ||
"debuglevel": handleDebugLevel, | ||
"decoderawtransaction": handleDecodeRawTransaction, | ||
"decodescript": handleDecodeScript, | ||
"estimatefee": handleEstimateFee, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is estimatefee
removed here?
if err != nil { | ||
return nil, &btcjson.RPCError{ | ||
Code: btcjson.ErrRPCInvalidAddressOrKey, | ||
Message: "Invalid address or key: " + err.Error(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should use a fmt.Sprintf
here
Message: fmt.Sprintf("Mining address %v is on the "+ | ||
"wrong network: ", activeNetParams.Params), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't this just substitute the %v
with activeNetParams.Params
? Maybe the line should be fmt.Sprintf("Mining address %s is on the wrong network: %s", addr.String(), activeNetParams.Params.Name)
or something similar.
if err := s.server.miningAddrs.RemoveAddr(addr); err != nil { | ||
return nil, &btcjson.RPCError{ | ||
Code: btcjson.ErrRPCInvalidAddressOrKey, | ||
Message: fmt.Sprintf("Mining address %v not found", addr), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be useful to use the String()
method on address here rather than just %v
'ing it
Message: "Invalid address or key: " + err.Error(), | ||
} | ||
} | ||
|
||
// Ensure the the passed address belongs to the same network that btcd | ||
// is currently on. | ||
if !addr.IsForNet(activeNetParams.Params) { | ||
return nil, &btcjson.RPCError{ | ||
Code: btcjson.ErrRPCInvalidAddressOrKey, | ||
Message: fmt.Sprintf("Mining address %v is on the "+ | ||
"wrong network: ", activeNetParams.Params), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comments as above, use fmt.Sprintf
for line 926 and modify the Message
to be more informative in line 935 and 936
@@ -29,6 +29,10 @@ var helpDescsEnUS = map[string]string{ | |||
"debuglevel--result0": "The string 'Done.'", | |||
"debuglevel--result1": "The list of subsystems", | |||
|
|||
// AddMiningAddrCmd help. | |||
"addminingaddr--synopsis": "Adds an additional available mining address to the set of mining addresses for the daemon", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe remove "for the daemon"
@yashbhutwala we're going to have to rebase against master to fix these conflicts and get these tests to stop running on travis |
This is a rebase of #845 on master, closes #1411 😃