From 1b00d37715ddd1242cb2ddb20e8efa47fee0389b Mon Sep 17 00:00:00 2001 From: i-norden Date: Wed, 29 Dec 2021 00:17:09 -0600 Subject: [PATCH] updates to satisfy the v1.10.14 ethdb.Database interface --- batch.go | 6 ++++-- database.go | 11 +++++++++-- iterator.go | 2 ++ mock_blockservice.go | 6 +++--- postgres/batch.go | 2 ++ postgres/database.go | 28 ++++++++++++++++++---------- postgres/iterator.go | 2 ++ postgres/util.go | 4 ++-- util.go | 2 +- 9 files changed, 43 insertions(+), 20 deletions(-) diff --git a/batch.go b/batch.go index f53b576..b27a615 100644 --- a/batch.go +++ b/batch.go @@ -21,8 +21,8 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/ethdb" - "github.com/hashicorp/golang-lru" - "github.com/ipfs/go-block-format" + lru "github.com/hashicorp/golang-lru" + blocks "github.com/ipfs/go-block-format" "github.com/ipfs/go-blockservice" ) @@ -30,6 +30,8 @@ var ( EvictionWarningErr = errors.New("warn: batch has exceeded capacity, data has been evicted") ) +var _ ethdb.Batch = &Batch{} + // Batch is the type that satisfies the ethdb.Batch interface for IPFS Ethereum data using the ipfs blockservice interface // This is ipfs-backing-datastore agnostic but must operate through a configured ipfs node (and so is subject to lockfile contention with e.g. an ipfs daemon) // If blockservice block exchange is configured the blockservice can fetch data that are missing locally from IPFS peers diff --git a/database.go b/database.go index aaa7b0f..9f6c8cc 100644 --- a/database.go +++ b/database.go @@ -33,6 +33,8 @@ var ( errNotSupported = errors.New("this operation is not supported") ) +var _ ethdb.Database = &Database{} + // Database is the type that satisfies the ethdb.Database and ethdb.KeyValueStore interfaces for IPFS Ethereum data // This is ipfs-backing-datastore agnostic but must operate through a configured ipfs node (and so is subject to lockfile contention with e.g. an ipfs daemon) // If blockservice block exchange is configured the blockservice can fetch data that are missing locally from IPFS peers @@ -205,15 +207,20 @@ func (d *Database) AppendAncient(number uint64, hash, header, body, receipt, td return errNotSupported } -// ReadAncients retrieves multiple items in sequence, starting from the index 'start'. +// AncientRange retrieves all the items in a range, starting from the index 'start'. // It will return // - at most 'count' items, // - at least 1 item (even if exceeding the maxBytes), but will otherwise // return as many items as fit into maxBytes. -func (d *Database) ReadAncients(kind string, start, count, maxBytes uint64) ([][]byte, error) { +func (d *Database) AncientRange(kind string, start, count, maxBytes uint64) ([][]byte, error) { return nil, errNotSupported } +// ReadAncients applies the provided AncientReader function +func (d *Database) ReadAncients(fn func(ethdb.AncientReader) error) (err error) { + return errNotSupported +} + // TruncateAncients satisfies the ethdb.AncientWriter interface // TruncateAncients discards all but the first n ancient data from the ancient store func (d *Database) TruncateAncients(n uint64) error { diff --git a/iterator.go b/iterator.go index 0fba100..41c2f9c 100644 --- a/iterator.go +++ b/iterator.go @@ -23,6 +23,8 @@ import ( "github.com/ipfs/go-blockservice" ) +var _ ethdb.Iterator = &Iterator{} + // Iterator is the type that satisfies the ethdb.Iterator interface for IPFS Ethereum data // Iteratee interface is used in Geth for various tests, trie/sync_bloom.go (for fast sync), // rawdb.InspectDatabase, and the new core/state/snapshot features. diff --git a/mock_blockservice.go b/mock_blockservice.go index fe25177..eb33818 100644 --- a/mock_blockservice.go +++ b/mock_blockservice.go @@ -20,11 +20,11 @@ import ( "context" "errors" - "github.com/ipfs/go-block-format" + blocks "github.com/ipfs/go-block-format" "github.com/ipfs/go-blockservice" "github.com/ipfs/go-cid" - "github.com/ipfs/go-ipfs-blockstore" - "github.com/ipfs/go-ipfs-exchange-interface" + blockstore "github.com/ipfs/go-ipfs-blockstore" + exchange "github.com/ipfs/go-ipfs-exchange-interface" ) var ( diff --git a/postgres/batch.go b/postgres/batch.go index d023868..1ceeaf8 100644 --- a/postgres/batch.go +++ b/postgres/batch.go @@ -21,6 +21,8 @@ import ( "github.com/jmoiron/sqlx" ) +var _ ethdb.Batch = &Batch{} + // Batch is the type that satisfies the ethdb.Batch interface for PG-IPFS Ethereum data using a direct Postgres connection type Batch struct { db *sqlx.DB diff --git a/postgres/database.go b/postgres/database.go index d7a861b..d65b06c 100644 --- a/postgres/database.go +++ b/postgres/database.go @@ -20,6 +20,7 @@ import ( "context" "errors" "fmt" + "strconv" "strings" "time" @@ -38,6 +39,8 @@ var ( dbSizePgStr = "SELECT pg_database_size(current_database())" ) +var _ ethdb.Database = &Database{} + // Database is the type that satisfies the ethdb.Database and ethdb.KeyValueStore interfaces for PG-IPFS Ethereum data using a direct Postgres connection type Database struct { db *sqlx.DB @@ -63,7 +66,7 @@ func NewKeyValueStore(db *sqlx.DB, cacheConfig CacheConfig) ethdb.KeyValueStore } // NewDatabase returns a ethdb.Database interface for PG-IPFS -func NewDatabase(db *sqlx.DB, cacheConfig CacheConfig) *Database { +func NewDatabase(db *sqlx.DB, cacheConfig CacheConfig) ethdb.Database { database := Database{db: db} database.InitCache(cacheConfig) @@ -212,19 +215,19 @@ func (d *Database) Stat(property string) (string, error) { var byteSize string return byteSize, d.db.Get(&byteSize, dbSizePgStr) case Idle: - return string(d.db.Stats().Idle), nil + return strconv.Itoa(d.db.Stats().Idle), nil case InUse: - return string(d.db.Stats().InUse), nil + return strconv.Itoa(d.db.Stats().InUse), nil case MaxIdleClosed: - return string(d.db.Stats().MaxIdleClosed), nil + return strconv.FormatInt(d.db.Stats().MaxIdleClosed, 10), nil case MaxLifetimeClosed: - return string(d.db.Stats().MaxLifetimeClosed), nil + return strconv.FormatInt(d.db.Stats().MaxLifetimeClosed, 10), nil case MaxOpenConnections: - return string(d.db.Stats().MaxOpenConnections), nil + return strconv.Itoa(d.db.Stats().MaxOpenConnections), nil case OpenConnections: - return string(d.db.Stats().OpenConnections), nil + return strconv.Itoa(d.db.Stats().OpenConnections), nil case WaitCount: - return string(d.db.Stats().WaitCount), nil + return strconv.FormatInt(d.db.Stats().WaitCount, 10), nil case WaitDuration: return d.db.Stats().WaitDuration.String(), nil default: @@ -292,15 +295,20 @@ func (d *Database) AppendAncient(number uint64, hash, header, body, receipt, td return errNotSupported } -// ReadAncients retrieves multiple items in sequence, starting from the index 'start'. +// AncientRange retrieves all the items in a range, starting from the index 'start'. // It will return // - at most 'count' items, // - at least 1 item (even if exceeding the maxBytes), but will otherwise // return as many items as fit into maxBytes. -func (d *Database) ReadAncients(kind string, start, count, maxBytes uint64) ([][]byte, error) { +func (d *Database) AncientRange(kind string, start, count, maxBytes uint64) ([][]byte, error) { return nil, errNotSupported } +// ReadAncients applies the provided AncientReader function +func (d *Database) ReadAncients(fn func(ethdb.AncientReader) error) (err error) { + return errNotSupported +} + // TruncateAncients satisfies the ethdb.AncientWriter interface // TruncateAncients discards all but the first n ancient data from the ancient store func (d *Database) TruncateAncients(n uint64) error { diff --git a/postgres/iterator.go b/postgres/iterator.go index f673729..0d3a0a4 100644 --- a/postgres/iterator.go +++ b/postgres/iterator.go @@ -21,6 +21,8 @@ import ( "github.com/jmoiron/sqlx" ) +var _ ethdb.Iterator = &Iterator{} + // Iterator is the type that satisfies the ethdb.Iterator interface for PG-IPFS Ethereum data using a direct Postgres connection // Iteratee interface is used in Geth for various tests, trie/sync_bloom.go (for fast sync), // rawdb.InspectDatabase, and the new core/state/snapshot features. diff --git a/postgres/util.go b/postgres/util.go index cdd818f..69e9cdf 100644 --- a/postgres/util.go +++ b/postgres/util.go @@ -17,8 +17,8 @@ package pgipfsethdb import ( - "github.com/ipfs/go-ipfs-blockstore" - "github.com/ipfs/go-ipfs-ds-help" + blockstore "github.com/ipfs/go-ipfs-blockstore" + dshelp "github.com/ipfs/go-ipfs-ds-help" "github.com/jmoiron/sqlx" _ "github.com/lib/pq" //postgres driver "github.com/multiformats/go-multihash" diff --git a/util.go b/util.go index 177a9fa..5735952 100644 --- a/util.go +++ b/util.go @@ -17,7 +17,7 @@ package ipfsethdb import ( - "github.com/ipfs/go-block-format" + blocks "github.com/ipfs/go-block-format" "github.com/ipfs/go-cid" _ "github.com/lib/pq" //postgres driver "github.com/multiformats/go-multihash"