-
Notifications
You must be signed in to change notification settings - Fork 291
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
multi: Move mining code into mining package #1965
Conversation
96822d3
to
765b350
Compare
765b350
to
bede8da
Compare
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.
Seems a reasonable effort, though there's still more abstracting to do.
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.
Thanks for the effort. I started to review this, but I quickly realized that this really needs to be reversed in how it makes the changes (that is to say make the changes first, and then move things to the separate package as the final commit) for at least a couple of reasons:
- The intermediate commits do not build and pass the tests. I do not merge intermediate broken states to master.
- I can't reasonably review this with any degree of accuracy when there are big changes made when a file is moved since the diff is the entire file.
Hence, the inline comments are only for a portion of the first commit. That said, there are a several changes here that I think we can certainly start with though such as
- mining: use chainParams on block template generator rather than from blockManager since they are the same instance.
- mining: use chain on block template generator rather than blockManager since they are the same instance.
- multi: remove unnecessary methods exposed on blockmanager interface.
Also, I did this refactoring upstream a long time ago which hasn't made it into dcrd yet. I would suggest taking a look at some of the lead up to it as it will be substantially similar and it is already known to work well:
- cpuminer: Introduce cpuminerConfig (btcsuite/btcd@6719014)
- mining: Break dependency on block manager instance. (btcsuite/btcd@6604672)
- mining: Use generator state versus local state. (btcsuite/btcd@a952a3a)
- mining: Refactor template code into mining package. (btcsuite/btcd@61ca40e)
Finally, please note that your commits themselves are not following the code contribution guidelines in terms of length and proper formatting.
fdcdab8
to
85180b3
Compare
mining.go
Outdated
@@ -1900,6 +1898,12 @@ func (g *BlkTmplGenerator) UpdateBlockTime(header *wire.BlockHeader) error { | |||
return nil | |||
} | |||
|
|||
// UpdateBlockTime invokes `UpdateBlockTime` on the underlying | |||
// BgBlkTmplGenerator. |
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.
BgBlkTmplGenerator -> BlkTmplGenerator.
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.
This method is exposed since rpcserver needs to access BlkTmplGenerator.UpdateBlockTime. Where to get a reference to the BlkTmplGenerator in that module without exposing it directly is not standing out at the moment, so I left it.
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 misunderstood this feedback when revisiting this PR. You were highlighting that the comment needs to change, not the method signature. Agreed that this should be altered, but given the timing and commits built on this already I think it might be best to handle in a later PR. Sorry I didn't catch and fix that earlier, and thanks for the review.
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 already updated it via #2276.
Tested this PR with dcrpool's simnet harness, no errors/issues noted. I think it should be good once the issues identified in the review are resolved. |
@sefbkn Very nice job on the updates since the first iteration. Would you mind rebasing this to the latest master to resolve the conflicts so I can merge this? I would very much like to get this in for the 1.6.0 release that is rapidly approaching. I reviewed it and while there are a few minor things that I see and I also agree with the things that @dnldd pointed out, given this has been sitting here for so long, I think this is good enough to go in as is and I can follow up with another PR to address the minor things I see as well as @dnldd points. |
This removes coupling between the mining code, blockManager, and the main configuration. This change is a step towards moving the mining code into its own package.
This change wraps the CPUMiner's WaitGroup reference in preparation for moving the CPUMiner under the mining package.
85180b3
to
d0a9466
Compare
Thanks for the update. Looks like it failed CI due to:
In other words, |
d0a9466
to
4c086ba
Compare
Hmm, looks like it's still failing due to lack of tidy. I ran it locally and looks like this should do it: diff --git a/mining/go.sum b/mining/go.sum
index 5f5f1522..a4b22c82 100644
--- a/mining/go.sum
+++ b/mining/go.sum
@@ -6,12 +6,12 @@ github.com/btcsuite/snappy-go v1.0.0 h1:ZxaA6lo2EpxGddsA8JwWOcxlzRybb444sgmeJQMJ
github.com/btcsuite/snappy-go v1.0.0/go.mod h1:8woku9dyThutzjeg+3xrA5iCpBRH8XEEg3lh6TiUghc=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
+github.com/dchest/siphash v1.2.1 h1:4cLinnzVJDKxTCl9B01807Yiy+W7ZzVHj/KIroQRvT4=
+github.com/dchest/siphash v1.2.1/go.mod h1:q+IRvb2gOSrUnYoPqHiyHXS0FOBBOdl6tONBlVnOnt4=
github.com/decred/base58 v1.0.1 h1:w5qTcb0hYpKuIBYIn4Ckirkj1aOWrSq8onPQpb3eGg8=
github.com/decred/base58 v1.0.1/go.mod h1:H2ENcsJjye1G7CbRa67kV9OFaui0LGr56ntKKoY5g9c=
github.com/decred/base58 v1.0.3 h1:KGZuh8d1WEMIrK0leQRM47W85KqCAdl2N+uagbctdDI=
github.com/decred/base58 v1.0.3/go.mod h1:pXP9cXCfM2sFLb2viz2FNIdeMWmZDBKG3ZBYbiSM78E=
-github.com/decred/dcrd/chaincfg/chainhash v1.0.2 h1:rt5Vlq/jM3ZawwiacWjPa+smINyLRN07EO0cNBV6DGU=
-github.com/decred/dcrd/chaincfg/chainhash v1.0.2/go.mod h1:BpbrGgrPTr3YJYRN3Bm+D9NuaFd+zGyNeIKgrhCXK60=
github.com/decred/dcrd/chaincfg/v2 v2.3.0 h1:ItmU+7DeUtyiabrcW+16MJFgY/BBeeYaPfkBLrFLyjo=
github.com/decred/dcrd/chaincfg/v2 v2.3.0/go.mod h1:7qUJTvn+y/kswSRZ4sT2+EmvlDTDyy2InvNFtX/hxk0=
github.com/decred/dcrd/crypto/blake256 v1.0.0 h1:/8DMNYp9SGi5f0w7uCm6d6M4OU2rGFK09Y2A4Xv7EE0=
@@ -32,8 +32,6 @@ github.com/decred/dcrd/dcrec/secp256k1/v2 v2.0.0 h1:3GIJYXQDAKpLEFriGFN8SbSffak1
github.com/decred/dcrd/dcrec/secp256k1/v2 v2.0.0/go.mod h1:3s92l0paYkZoIHuj4X93Teg/HB7eGM9x/zokGw+u4mY=
github.com/decred/dcrd/dcrutil/v2 v2.0.1 h1:aL+c7o7Q66HV1gIif+XkNYo9DeorN3l01Vns8mh0mqs=
github.com/decred/dcrd/dcrutil/v2 v2.0.1/go.mod h1:JdEgF6eh0TTohPeiqDxqDSikTSvAczq0J7tFMyyeD+k=
-github.com/decred/dcrd/wire v1.3.0 h1:X76I2/a8esUmxXmFpJpAvXEi014IA4twgwcOBeIS8lE=
-github.com/decred/dcrd/wire v1.3.0/go.mod h1:fnKGlUY2IBuqnpxx5dYRU5Oiq392OBqAuVjRVSkIoXM=
github.com/decred/slog v1.0.0 h1:Dl+W8O6/JH6n2xIFN2p3DNjCmjYwvrXsjlSJTQQ4MhE=
github.com/decred/slog v1.0.0/go.mod h1:zR98rEZHSnbZ4WHZtO0iqmSZjDLKhkXfrPTZQKtAonQ=
github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I= |
This contains the changes necessary to move the mining code into the mining package. The motivation behind these changes is to decouple the block template generation from other modules in the codebase to simplify extending it with new features and tests.
4c086ba
to
bfbce16
Compare
Thank you Dave, this did it. Didn't catch your first comment until a bit later, sorry for the PR spam :) |
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.
Nicely done 👍, tested updates with no issues noticed.
This PR moves the mining code from the main module to the mining module. This work is part of a larger effort to support prioritizing transactions with dependencies by fee.
#1884 #1556
Expose NewBlkTmplGenerator from mining package.
Expose NewBgBlkTmplGenerator from mining package.
Expose CPUMiner from mining package.
Modify activeNetParams -> g.chainParams in mining code.
Add logger to mining package
Inject blockManager to mining module and create private blockManager type within mining package.
Use chain & chainParams on BlkTmplGenerator rather than from blockManager in main package.