diff --git a/blockchain/chain.go b/blockchain/chain.go index d0c05264d0..80a673390c 100644 --- a/blockchain/chain.go +++ b/blockchain/chain.go @@ -137,7 +137,6 @@ type BlockChain struct { deploymentVers map[string]uint32 db database.DB dbInfo *databaseInfo - utxoDb database.DB chainParams *chaincfg.Params timeSource MedianTimeSource notifications NotificationCallback @@ -2114,11 +2113,6 @@ type Config struct { // This field is required. UtxoBackend UtxoBackend - // UtxoDB defines the database which houses the UTXO set. - // - // This field is required. - UtxoDB database.DB - // ChainParams identifies which chain parameters the chain is associated // with. // @@ -2190,9 +2184,6 @@ func New(ctx context.Context, config *Config) (*BlockChain, error) { if config.UtxoBackend == nil { return nil, AssertError("blockchain.New UTXO backend is nil") } - if config.UtxoDB == nil { - return nil, AssertError("blockchain.New UTXO database is nil") - } if config.ChainParams == nil { return nil, AssertError("blockchain.New chain parameters nil") } @@ -2233,7 +2224,6 @@ func New(ctx context.Context, config *Config) (*BlockChain, error) { checkpointsByHeight: checkpointsByHeight, deploymentVers: deploymentVers, db: config.DB, - utxoDb: config.UtxoDB, chainParams: params, timeSource: config.TimeSource, notifications: config.Notifications, diff --git a/blockchain/common_test.go b/blockchain/common_test.go index 4705297d03..47238716fd 100644 --- a/blockchain/common_test.go +++ b/blockchain/common_test.go @@ -141,14 +141,12 @@ func chainSetup(dbName string, params *chaincfg.Params) (*BlockChain, func(), er chain, err := New(context.Background(), &Config{ DB: db, - UtxoDB: utxoDb, UtxoBackend: utxoBackend, ChainParams: ¶msCopy, TimeSource: NewMedianTime(), SigCache: sigCache, UtxoCache: NewUtxoCache(&UtxoCacheConfig{ Backend: utxoBackend, - DB: utxoDb, FlushBlockDB: func() error { // Don't flush to disk since it is slow and this is used in a lot of // tests. diff --git a/blockchain/example_test.go b/blockchain/example_test.go index bc6165e26f..f3c0d5bafe 100644 --- a/blockchain/example_test.go +++ b/blockchain/example_test.go @@ -54,7 +54,6 @@ func ExampleBlockChain_ProcessBlock() { TimeSource: blockchain.NewMedianTime(), UtxoCache: blockchain.NewUtxoCache(&blockchain.UtxoCacheConfig{ Backend: blockchain.NewLevelDbUtxoBackend(db), - DB: db, FlushBlockDB: func() error { return nil }, diff --git a/blockchain/fullblocks_test.go b/blockchain/fullblocks_test.go index d9690f9736..dbb48496d4 100644 --- a/blockchain/fullblocks_test.go +++ b/blockchain/fullblocks_test.go @@ -134,13 +134,11 @@ func chainSetup(dbName string, params *chaincfg.Params) (*blockchain.BlockChain, &blockchain.Config{ DB: db, UtxoBackend: utxoBackend, - UtxoDB: utxoDb, ChainParams: ¶msCopy, TimeSource: blockchain.NewMedianTime(), SigCache: sigCache, UtxoCache: blockchain.NewUtxoCache(&blockchain.UtxoCacheConfig{ Backend: utxoBackend, - DB: utxoDb, FlushBlockDB: func() error { // Don't flush to disk since it is slow and this is used in a lot of // tests. diff --git a/blockchain/utxocache.go b/blockchain/utxocache.go index 642fa76a30..5e1d92bd59 100644 --- a/blockchain/utxocache.go +++ b/blockchain/utxocache.go @@ -114,33 +114,29 @@ type UtxoCacher interface { } // UtxoCache is an unspent transaction output cache that sits on top of the -// utxo set database and provides significant runtime performance benefits at +// utxo set backend and provides significant runtime performance benefits at // the cost of some additional memory usage. It drastically reduces the amount // of reading and writing to disk, especially during initial block download when // a very large number of blocks are being processed in quick succession. // // The UtxoCache is a read-through cache. All utxo reads go through the cache. // When there is a cache miss, the cache loads the missing data from the -// database, caches it, and returns it to the caller. +// backend, caches it, and returns it to the caller. // // The UtxoCache is a write-back cache. Writes to the cache are acknowledged -// by the cache immediately but are only periodically flushed to the database. +// by the cache immediately but are only periodically flushed to the backend. // This allows intermediate steps to effectively be skipped. For example, a // utxo that is created and then spent in between flushes never needs to be -// written to the utxo set in the database. +// written to the utxo set in the backend. // -// Due to the write-back nature of the cache, at any given time the database +// Due to the write-back nature of the cache, at any given time the backend // may not be in sync with the cache, and therefore all utxo reads and writes -// MUST go through the cache, and never read or write to the database directly. +// MUST go through the cache, and never read or write to the backend directly. type UtxoCache struct { // backend is the backend that contains the UTXO set. It is set when the // instance is created and is not changed afterward. backend UtxoBackend - // db is the database that contains the utxo set. It is set when the instance - // is created and is not changed afterward. - db database.DB - // flushBlockDB defines the function to use to flush the block database to // disk. The block database is always flushed to disk before the UTXO cache // writes to disk in order to maintain a recoverable state in the event of an @@ -205,11 +201,6 @@ type UtxoCacheConfig struct { // This field is required. Backend UtxoBackend - // DB defines the database which houses the utxo set. - // - // This field is required. - DB database.DB - // FlushBlockDB defines the function to use to flush the block database to // disk. The block database is always flushed to disk before the UTXO cache // writes to disk in order to maintain a recoverable state in the event of an @@ -235,7 +226,6 @@ func NewUtxoCache(config *UtxoCacheConfig) *UtxoCache { return &UtxoCache{ backend: config.Backend, - db: config.DB, flushBlockDB: config.FlushBlockDB, maxSize: config.MaxSize, entries: make(map[wire.OutPoint]*UtxoEntry, uint64(maxEntries)), @@ -331,12 +321,12 @@ func (c *UtxoCache) spendEntry(outpoint wire.OutPoint) { } // If the entry is fresh, and is now being spent, it can safely be removed. - // This is an optimization to skip writing to the database for outputs that - // are added and spent in between flushes to the database. + // This is an optimization to skip writing to the backend for outputs that + // are added and spent in between flushes to the backend. if cachedEntry.isFresh() { // The entry in the map is marked as nil rather than deleting it so that // subsequent lookups for the outpoint will still result in a cache hit and - // avoid querying the database. + // avoid querying the backend. c.entries[outpoint] = nil c.totalEntrySize -= cachedEntry.size() return diff --git a/blockchain/utxocache_test.go b/blockchain/utxocache_test.go index 8929c5f040..bec0025325 100644 --- a/blockchain/utxocache_test.go +++ b/blockchain/utxocache_test.go @@ -515,7 +515,6 @@ func TestFetchEntry(t *testing.T) { // Create a utxo cache with the cached entries specified by the test. utxoCache := createTestUtxoCache(t, test.cachedEntries) utxoCache.backend = backend - utxoCache.db = backend.db wantTotalEntrySize := utxoCache.totalEntrySize // Add entries specified by the test to the test backend. @@ -612,7 +611,6 @@ func TestFetchEntries(t *testing.T) { // Create a utxo cache with the cached entries specified by the test. utxoCache := createTestUtxoCache(t, test.cachedEntries) utxoCache.backend = backend - utxoCache.db = backend.db // Add entries specified by the test to the test backend. err := backend.PutUtxos(test.backendEntries, &UtxoSetState{}) @@ -962,7 +960,6 @@ func TestMaybeFlush(t *testing.T) { // Create a utxo cache with the cached entries specified by the test. utxoCache := createTestUtxoCache(t, test.cachedEntries) utxoCache.backend = backend - utxoCache.db = backend.db utxoCache.maxSize = test.maxSize utxoCache.lastEvictionHeight = test.lastEvictionHeight utxoCache.lastFlushHash = *test.lastFlushHash @@ -1074,7 +1071,6 @@ func TestInitialize(t *testing.T) { resetTestUtxoCache := func() *testUtxoCache { testUtxoCache := newTestUtxoCache(&UtxoCacheConfig{ Backend: backend, - DB: backend.db, FlushBlockDB: g.chain.db.Flush, MaxSize: 100 * 1024 * 1024, // 100 MiB }) @@ -1223,7 +1219,6 @@ func TestShutdownUtxoCache(t *testing.T) { backend := createTestUtxoBackend(t) testUtxoCache := newTestUtxoCache(&UtxoCacheConfig{ Backend: backend, - DB: backend.db, FlushBlockDB: g.chain.db.Flush, MaxSize: 100 * 1024 * 1024, // 100 MiB }) diff --git a/blockchain/validate_test.go b/blockchain/validate_test.go index 0e0900182f..8a526f57f9 100644 --- a/blockchain/validate_test.go +++ b/blockchain/validate_test.go @@ -296,12 +296,10 @@ func TestCheckBlockHeaderContext(t *testing.T) { &Config{ DB: db, UtxoBackend: utxoBackend, - UtxoDB: utxoDb, ChainParams: params, TimeSource: NewMedianTime(), UtxoCache: NewUtxoCache(&UtxoCacheConfig{ Backend: utxoBackend, - DB: utxoDb, FlushBlockDB: func() error { return nil }, diff --git a/server.go b/server.go index d9320d511d..0a255b3384 100644 --- a/server.go +++ b/server.go @@ -3405,7 +3405,6 @@ func newServer(ctx context.Context, listenAddrs []string, db database.DB, utxoBackend := blockchain.NewLevelDbUtxoBackend(utxoDb) utxoCache := blockchain.NewUtxoCache(&blockchain.UtxoCacheConfig{ Backend: utxoBackend, - DB: utxoDb, FlushBlockDB: s.db.Flush, MaxSize: uint64(cfg.UtxoCacheMaxSize) * 1024 * 1024, }) @@ -3413,7 +3412,6 @@ func newServer(ctx context.Context, listenAddrs []string, db database.DB, &blockchain.Config{ DB: s.db, UtxoBackend: utxoBackend, - UtxoDB: utxoDb, ChainParams: s.chainParams, Checkpoints: checkpoints, TimeSource: s.timeSource,