multi: Add FetchUtxoEntry to mining Config.
This adds a FetchUtxoEntry method to the mining Config. This allows the template generation logic to fetch unspent transaction outputs from the point of view of the main chain tip. This has not been necessary in the past since typically, the mining code uses FetchUtxoView to construct a viewpoint for transactions that it includes in a block template. However, with the automatic ticket revocations agenda, the template generation code will need to create new revocation transactions, which will require fetching utxos for the input tickets.
This commit is contained in:
parent
18ac610212
commit
00830fa570
@ -115,6 +115,19 @@ type Config struct {
|
||||
// transaction.
|
||||
CountSigOps func(tx *dcrutil.Tx, isCoinBaseTx bool, isSSGen bool, isTreasuryEnabled bool) int
|
||||
|
||||
// FetchUtxoEntry defines the function to use to load and return the requested
|
||||
// unspent transaction output from the point of view of the main chain tip.
|
||||
//
|
||||
// NOTE: Requesting an output for which there is no data will NOT return an
|
||||
// error. Instead both the entry and the error will be nil. This is done to
|
||||
// allow pruning of spent transaction outputs. In practice this means the
|
||||
// caller must check if the returned entry is nil before invoking methods on
|
||||
// it.
|
||||
//
|
||||
// This function is safe for concurrent access however the returned entry (if
|
||||
// any) is NOT.
|
||||
FetchUtxoEntry func(outpoint wire.OutPoint) (*blockchain.UtxoEntry, error)
|
||||
|
||||
// FetchUtxoView defines the function to use to fetch unspent transaction
|
||||
// output information. The returned instance should be treated as immutable.
|
||||
FetchUtxoView func(tx *dcrutil.Tx, includeRegularTxns bool) (*blockchain.UtxoViewpoint, error)
|
||||
|
||||
@ -61,6 +61,7 @@ type fakeChain struct {
|
||||
checkConnectBlockTemplateErr error
|
||||
checkTicketExhaustionErr error
|
||||
checkTSpendHasVotesErr error
|
||||
fetchUtxoEntryErr error
|
||||
fetchUtxoViewErr error
|
||||
fetchUtxoViewParentTemplateErr error
|
||||
forceHeadReorganizationErr error
|
||||
@ -133,6 +134,12 @@ func (c *fakeChain) CheckTSpendHasVotes(prevHash chainhash.Hash, tspend *dcrutil
|
||||
return c.checkTSpendHasVotesErr
|
||||
}
|
||||
|
||||
// FetchUtxoEntry returns the requested unspent transaction output from the
|
||||
// mocked utxos.
|
||||
func (c *fakeChain) FetchUtxoEntry(outpoint wire.OutPoint) (*blockchain.UtxoEntry, error) {
|
||||
return c.utxos.LookupEntry(outpoint), c.fetchUtxoEntryErr
|
||||
}
|
||||
|
||||
// FetchUtxoView loads unspent transaction outputs for the inputs referenced by
|
||||
// the passed transaction from the point of view of the main chain tip while
|
||||
// taking into account whether or not the transactions in the regular tree of
|
||||
@ -1389,6 +1396,7 @@ func newMiningHarness(chainParams *chaincfg.Params) (*miningHarness, []spendable
|
||||
},
|
||||
CheckTSpendHasVotes: chain.CheckTSpendHasVotes,
|
||||
CountSigOps: blockchain.CountSigOps,
|
||||
FetchUtxoEntry: chain.FetchUtxoEntry,
|
||||
FetchUtxoView: chain.FetchUtxoView,
|
||||
FetchUtxoViewParentTemplate: chain.FetchUtxoViewParentTemplate,
|
||||
ForceHeadReorganization: chain.ForceHeadReorganization,
|
||||
|
||||
@ -3566,6 +3566,7 @@ func newServer(ctx context.Context, listenAddrs []string, db database.DB,
|
||||
},
|
||||
CheckTSpendHasVotes: s.chain.CheckTSpendHasVotes,
|
||||
CountSigOps: blockchain.CountSigOps,
|
||||
FetchUtxoEntry: s.chain.FetchUtxoEntry,
|
||||
FetchUtxoView: s.chain.FetchUtxoView,
|
||||
FetchUtxoViewParentTemplate: s.chain.FetchUtxoViewParentTemplate,
|
||||
ForceHeadReorganization: s.chain.ForceHeadReorganization,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user