diff --git a/internal/mining/mining.go b/internal/mining/mining.go index d7b26f38..e2415ca3 100644 --- a/internal/mining/mining.go +++ b/internal/mining/mining.go @@ -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) diff --git a/internal/mining/mining_harness_test.go b/internal/mining/mining_harness_test.go index da8d29e3..9f5dc837 100644 --- a/internal/mining/mining_harness_test.go +++ b/internal/mining/mining_harness_test.go @@ -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, diff --git a/server.go b/server.go index 5f10aa2e..fd7eaf75 100644 --- a/server.go +++ b/server.go @@ -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,