-
Notifications
You must be signed in to change notification settings - Fork 296
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: add BlkTmplGenerator. #1422
Conversation
742aaa8
to
c9e3928
Compare
mining.go
Outdated
// BlkTmplGenerator generates block templates based on a given mining policy | ||
// and a transactions source. It also houses additional state required in | ||
// order to ensure the templates are built on top of the current best | ||
// chain and adhere to the consensus rules. |
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 is missing some of the verbiage from the commit being ported. Also, it needs to be updated to reflect reality for Decred. Specifically that templates can either be on the best chain tip or its parent in the case the best chain tip is unable to get enough votes.
mining.go
Outdated
@@ -1365,7 +1380,7 @@ mempoolLoop: | |||
|
|||
// Skip if we already have too many SStx. | |||
if isSStx && (numSStx >= | |||
int(server.chainParams.MaxFreshStakePerBlock)) { | |||
int(g.blockManager.server.chainParams.MaxFreshStakePerBlock)) { |
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.
Please make the creation of the block template generator takes the chain params and use it directly from g
. A large reason for having the block template generator is to reduce the dependencies on the other types so that it can be more easily split into a separate package.
mining.go
Outdated
@@ -1499,15 +1514,16 @@ mempoolLoop: | |||
// The fraud proof is not checked because it will be filled in | |||
// by the miner. | |||
_, err = blockchain.CheckTransactionInputs(subsidyCache, tx, | |||
nextBlockHeight, blockUtxos, false, server.chainParams) | |||
nextBlockHeight, blockUtxos, false, | |||
g.blockManager.server.chainParams) |
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 here regarding chain params.
mining.go
Outdated
if err != nil { | ||
minrLog.Tracef("Skipping tx %s due to error in "+ | ||
"CheckTransactionInputs: %v", tx.Hash(), err) | ||
logSkippedDeps(tx, deps) | ||
continue | ||
} | ||
err = blockchain.ValidateTransactionScripts(tx, blockUtxos, | ||
scriptFlags, server.sigCache) | ||
scriptFlags, g.blockManager.server.sigCache) |
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.
The same applies to the signature cache. It should be specified as part of BlkTmplGenerator
and directly accessible in order to break the dependency on server, just like the upstream commit does.
e.g.
type BlkTmplGenerator struct {
policy *mining.Policy
txSource mining.TxSource
sigCache *txscript.SigCache
blockManager *blockManager
timeSource blockchain.MedianTimeSource
}
mining.go
Outdated
@@ -1751,7 +1768,7 @@ mempoolLoop: | |||
nextBlockHeight, | |||
payToAddress, | |||
uint16(voters), | |||
server.chainParams) | |||
g.blockManager.server.chainParams) |
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.
g.chainParams
mining.go
Outdated
@@ -1633,7 +1649,7 @@ mempoolLoop: | |||
|
|||
// Retrieve the current top block, whose TxTreeRegular was voted | |||
// out. | |||
topBlock, err := blockManager.chain.BlockByHash(&prevHash) | |||
topBlock, err := g.blockManager.chain.BlockByHash(&prevHash) |
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 thing here regarding the chain. Basically anything that is a component of block manager should be provided in the BlkTmplGenerator
struct instead to decouple them.
mining.go
Outdated
@@ -1853,13 +1870,13 @@ mempoolLoop: | |||
// bit for the mempool to sync with the votes map and we end up down | |||
// here despite having the relevant votes available in the votes map. | |||
minimumVotesRequired := | |||
int((server.chainParams.TicketsPerBlock / 2) + 1) | |||
int((g.blockManager.server.chainParams.TicketsPerBlock / 2) + 1) |
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.
g.chainParams
mining.go
Outdated
@@ -1938,13 +1955,13 @@ mempoolLoop: | |||
|
|||
// Choose the block version to generate based on the network. | |||
blockVersion := int32(generatedBlockVersion) | |||
if server.chainParams.Net != wire.MainNet { | |||
if g.blockManager.server.chainParams.Net != wire.MainNet { |
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.
g.chainParams
mining.go
Outdated
generatedStakeVersion, err := blockManager.chain. | ||
CalcStakeVersionByHash(&prevHash) | ||
generatedStakeVersion, err := | ||
g.blockManager.chain.CalcStakeVersionByHash(&prevHash) |
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.
g.chain
mining.go
Outdated
@@ -1991,7 +2008,7 @@ mempoolLoop: | |||
// consensus rules to ensure it properly connects to the current best | |||
// chain with no issues. | |||
block := dcrutil.NewBlockDeepCopyCoinbase(&msgBlock) | |||
err = blockManager.chain.CheckConnectBlockTemplate(block) | |||
err = g.blockManager.chain.CheckConnectBlockTemplate(block) |
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.
g.chain
af75e2c
to
c906c86
Compare
c906c86
to
3b33c0c
Compare
Port of upstream commit 74fe2a4. In preparation of moving all mining related code into the mining package.
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.
In addition to manual review, I also tested this with a simnet setup to ensure the mining is still working properly.
This PR requires #1417, #1418, #1419, #1420 and #1421
Port of upstream commit 74fe2a4. In preparation of moving all
mining related code into the mining package.