Skip to content

Commit

Permalink
blockchain: Export ViewFilteredSet.
Browse files Browse the repository at this point in the history
This exports the ViewFilteredSet type since it is used in the UtxoCacher
interface.
  • Loading branch information
rstaudt2 committed May 25, 2021
1 parent ce56291 commit b5f4d54
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
4 changes: 2 additions & 2 deletions blockchain/utxocache.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ type UtxoCacher interface {
// Upon completion of this function, the view will contain an entry for each
// requested outpoint. Spent outputs, or those which otherwise don't exist,
// will result in a nil entry in the view.
FetchEntries(filteredSet viewFilteredSet, view *UtxoViewpoint) error
FetchEntries(filteredSet ViewFilteredSet, view *UtxoViewpoint) error

// FetchEntry returns the specified transaction output from the utxo set. If
// the output exists in the cache, it is returned immediately. Otherwise, it
Expand Down Expand Up @@ -417,7 +417,7 @@ func (c *UtxoCache) FetchEntry(outpoint wire.OutPoint) (*UtxoEntry, error) {
// will result in a nil entry in the view.
//
// This function is safe for concurrent access.
func (c *UtxoCache) FetchEntries(filteredSet viewFilteredSet, view *UtxoViewpoint) error {
func (c *UtxoCache) FetchEntries(filteredSet ViewFilteredSet, view *UtxoViewpoint) error {
c.cacheLock.Lock()
for outpoint := range filteredSet {
entry, err := c.fetchEntry(outpoint)
Expand Down
4 changes: 2 additions & 2 deletions blockchain/utxocache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,7 @@ func TestFetchEntries(t *testing.T) {
name string
cachedEntries map[wire.OutPoint]*UtxoEntry
backendEntries map[wire.OutPoint]*UtxoEntry
filteredSet viewFilteredSet
filteredSet ViewFilteredSet
wantEntries map[wire.OutPoint]*UtxoEntry
}{{
name: "entries are fetched from the cache and the backend",
Expand All @@ -595,7 +595,7 @@ func TestFetchEntries(t *testing.T) {
backendEntries: map[wire.OutPoint]*UtxoEntry{
outpoint1200: entry1200Modified,
},
filteredSet: viewFilteredSet{
filteredSet: ViewFilteredSet{
outpoint299: struct{}{},
outpoint1100: struct{}{},
outpoint1200: struct{}{},
Expand Down
14 changes: 7 additions & 7 deletions blockchain/utxoviewpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -612,13 +612,13 @@ func (view *UtxoViewpoint) Entries() map[wire.OutPoint]*UtxoEntry {
return view.entries
}

// viewFilteredSet represents a set of utxos to fetch from the database that are
// ViewFilteredSet represents a set of utxos to fetch from the database that are
// not already in a view.
type viewFilteredSet map[wire.OutPoint]struct{}
type ViewFilteredSet map[wire.OutPoint]struct{}

// add conditionally adds the provided outpoint to the set if it does not
// already exist in the provided view.
func (set viewFilteredSet) add(view *UtxoViewpoint, outpoint *wire.OutPoint) {
func (set ViewFilteredSet) add(view *UtxoViewpoint, outpoint *wire.OutPoint) {
if _, ok := view.entries[*outpoint]; !ok {
set[*outpoint] = struct{}{}
}
Expand All @@ -631,7 +631,7 @@ func (set viewFilteredSet) add(view *UtxoViewpoint, outpoint *wire.OutPoint) {
// Upon completion of this function, the view will contain an entry for each
// requested outpoint. Spent outputs, or those which otherwise don't exist,
// will result in a nil entry in the view.
func (view *UtxoViewpoint) fetchUtxosMain(filteredSet viewFilteredSet) error {
func (view *UtxoViewpoint) fetchUtxosMain(filteredSet ViewFilteredSet) error {
// Nothing to do if there are no requested outputs.
if len(filteredSet) == 0 {
return nil
Expand All @@ -645,7 +645,7 @@ func (view *UtxoViewpoint) fetchUtxosMain(filteredSet viewFilteredSet) error {
// located later in the regular tree of the block and returns a set of the
// referenced outputs that are not already in the view and thus need to be
// fetched from the database.
func (view *UtxoViewpoint) addRegularInputUtxos(block *dcrutil.Block, isTreasuryEnabled bool) viewFilteredSet {
func (view *UtxoViewpoint) addRegularInputUtxos(block *dcrutil.Block, isTreasuryEnabled bool) ViewFilteredSet {
// Build a map of in-flight transactions because some of the inputs in the
// regular transaction tree of this block could be referencing other
// transactions earlier in the block which are not yet in the chain.
Expand All @@ -658,7 +658,7 @@ func (view *UtxoViewpoint) addRegularInputUtxos(block *dcrutil.Block, isTreasury
// Loop through all of the inputs of the transactions in the regular
// transaction tree (except for the coinbase which has no inputs) collecting
// them into sets of what is needed and what is already known (in-flight).
filteredSet := make(viewFilteredSet)
filteredSet := make(ViewFilteredSet)
for i, tx := range regularTxns[1:] {
for _, txIn := range tx.MsgTx().TxIn {
// It is acceptable for a transaction input in the regular tree to
Expand Down Expand Up @@ -827,7 +827,7 @@ func (b *BlockChain) FetchUtxoView(tx *dcrutil.Tx, includeRegularTxns bool) (*Ut
// Create a set of needed transactions based on those referenced by the
// inputs of the passed transaction. Also, add the outputs of the transaction
// as a way for the caller to detect duplicates that are not fully spent.
filteredSet := make(viewFilteredSet)
filteredSet := make(ViewFilteredSet)
msgTx := tx.MsgTx()
txType := stake.DetermineTxType(msgTx, isTreasuryEnabled)
tree := wire.TxTreeRegular
Expand Down
2 changes: 1 addition & 1 deletion blockchain/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -1858,7 +1858,7 @@ func (b *BlockChain) checkDupTxs(txSet []*dcrutil.Tx, view *UtxoViewpoint, tree

// Fetch utxos for all of the transaction outputs in this block.
// Typically, there will not be any utxos for any of the outputs.
filteredSet := make(viewFilteredSet)
filteredSet := make(ViewFilteredSet)
for _, tx := range txSet {
outpoint := wire.OutPoint{Hash: *tx.Hash(), Tree: tree}
for txOutIdx := range tx.MsgTx().TxOut {
Expand Down

0 comments on commit b5f4d54

Please sign in to comment.