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

multi: Move mining code into mining package #1965

Merged
merged 3 commits into from
Jul 19, 2020

Conversation

sefbkn
Copy link
Member

@sefbkn sefbkn commented Oct 26, 2019

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.

@sefbkn sefbkn marked this pull request as ready for review October 26, 2019 16:09
@sefbkn sefbkn changed the title multi: Move mining code into mining module multi: Move mining code into mining package Oct 27, 2019
Copy link
Member

@matheusd matheusd left a 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.

@davecgh davecgh added this to the 1.6.0 milestone Oct 28, 2019
Copy link
Member

@davecgh davecgh left a 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:

  1. The intermediate commits do not build and pass the tests. I do not merge intermediate broken states to master.
  2. 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:

Finally, please note that your commits themselves are not following the code contribution guidelines in terms of length and proper formatting.

blockmanager.go Outdated Show resolved Hide resolved
log.go Outdated Show resolved Hide resolved
rpcserver.go Outdated Show resolved Hide resolved
@sefbkn sefbkn force-pushed the move_mining_module branch 3 times, most recently from fdcdab8 to 85180b3 Compare February 19, 2020 04:06
mining.go Outdated Show resolved Hide resolved
mining.go Outdated Show resolved Hide resolved
mining.go Outdated
@@ -1900,6 +1898,12 @@ func (g *BlkTmplGenerator) UpdateBlockTime(header *wire.BlockHeader) error {
return nil
}

// UpdateBlockTime invokes `UpdateBlockTime` on the underlying
// BgBlkTmplGenerator.
Copy link
Member

Choose a reason for hiding this comment

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

BgBlkTmplGenerator -> BlkTmplGenerator.

Copy link
Member Author

@sefbkn sefbkn Jul 19, 2020

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.

Copy link
Member Author

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.

Copy link
Member

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.

@dnldd
Copy link
Member

dnldd commented Apr 15, 2020

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.

@davecgh
Copy link
Member

davecgh commented Jul 15, 2020

@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.

@sefbkn
Copy link
Member Author

sefbkn commented Jul 17, 2020

@davecgh I also agree with what @dnldd highlighted and will rebase and resolve conflicts shortly, sorry for the delay. Thank you for the review and patience.

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.
@davecgh
Copy link
Member

davecgh commented Jul 18, 2020

Thanks for the update. Looks like it failed CI due to:

+ go mod tidy
+ git status --porcelain go.mod go.sum
+ UPDATED_MOD_STATUS= M mempool/go.sum
+ [  M mempool/go.sum !=  ]
+ go mod tidy
+ echo Running  modified go.mod and/or go.sum
+ exit 1
Running  modified go.mod and/or go.sum

In other words, go mod tidy needs to be run in the mempool module (and really anything that imports the mining module, but that is only mempool I believe).

@davecgh
Copy link
Member

davecgh commented Jul 19, 2020

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.
@sefbkn
Copy link
Member Author

sefbkn commented Jul 19, 2020

Thanks for the update. Looks like it failed CI due to:

+ go mod tidy
+ git status --porcelain go.mod go.sum
+ UPDATED_MOD_STATUS= M mempool/go.sum
+ [  M mempool/go.sum !=  ]
+ go mod tidy
+ echo Running  modified go.mod and/or go.sum
+ exit 1
Running  modified go.mod and/or go.sum

In other words, go mod tidy needs to be run in the mempool module (and really anything that imports the mining module, but that is only mempool I believe).

Thank you Dave, this did it. Didn't catch your first comment until a bit later, sorry for the PR spam :)

Copy link
Member

@dnldd dnldd left a 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.

@davecgh davecgh merged commit a1630f5 into decred:master Jul 19, 2020
@sefbkn sefbkn deleted the move_mining_module branch January 26, 2021 05:20
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.

4 participants