From 58afb9d45c0ec3820b2d55d3e15c783c227a5de6 Mon Sep 17 00:00:00 2001 From: Nodar Date: Tue, 25 Jul 2023 14:32:30 +0200 Subject: [PATCH 1/2] Export errNotFound from memorydb so that we can use it in error checks in nitro --- ethdb/memorydb/memorydb.go | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/ethdb/memorydb/memorydb.go b/ethdb/memorydb/memorydb.go index 7e4fd7e5e7f0..8460bc42de1b 100644 --- a/ethdb/memorydb/memorydb.go +++ b/ethdb/memorydb/memorydb.go @@ -28,17 +28,17 @@ import ( ) var ( - // errMemorydbClosed is returned if a memory database was already closed at the + // ErrMemorydbClosed is returned if a memory database was already closed at the // invocation of a data access operation. - errMemorydbClosed = errors.New("database closed") + ErrMemorydbClosed = errors.New("database closed") - // errMemorydbNotFound is returned if a key is requested that is not found in + // ErrMemorydbNotFound is returned if a key is requested that is not found in // the provided memory database. - errMemorydbNotFound = errors.New("not found") + ErrMemorydbNotFound = errors.New("not found") - // errSnapshotReleased is returned if callers want to retrieve data from a + // ErrSnapshotReleased is returned if callers want to retrieve data from a // released snapshot. - errSnapshotReleased = errors.New("snapshot released") + ErrSnapshotReleased = errors.New("snapshot released") ) // Database is an ephemeral key-value store. Apart from basic data storage @@ -81,7 +81,7 @@ func (db *Database) Has(key []byte) (bool, error) { defer db.lock.RUnlock() if db.db == nil { - return false, errMemorydbClosed + return false, ErrMemorydbClosed } _, ok := db.db[string(key)] return ok, nil @@ -93,12 +93,12 @@ func (db *Database) Get(key []byte) ([]byte, error) { defer db.lock.RUnlock() if db.db == nil { - return nil, errMemorydbClosed + return nil, ErrMemorydbClosed } if entry, ok := db.db[string(key)]; ok { return common.CopyBytes(entry), nil } - return nil, errMemorydbNotFound + return nil, ErrMemorydbNotFound } // Put inserts the given value into the key-value store. @@ -107,7 +107,7 @@ func (db *Database) Put(key []byte, value []byte) error { defer db.lock.Unlock() if db.db == nil { - return errMemorydbClosed + return ErrMemorydbClosed } db.db[string(key)] = common.CopyBytes(value) return nil @@ -119,7 +119,7 @@ func (db *Database) Delete(key []byte) error { defer db.lock.Unlock() if db.db == nil { - return errMemorydbClosed + return ErrMemorydbClosed } delete(db.db, string(key)) return nil @@ -356,7 +356,7 @@ func (snap *snapshot) Has(key []byte) (bool, error) { defer snap.lock.RUnlock() if snap.db == nil { - return false, errSnapshotReleased + return false, ErrSnapshotReleased } _, ok := snap.db[string(key)] return ok, nil @@ -369,12 +369,12 @@ func (snap *snapshot) Get(key []byte) ([]byte, error) { defer snap.lock.RUnlock() if snap.db == nil { - return nil, errSnapshotReleased + return nil, ErrSnapshotReleased } if entry, ok := snap.db[string(key)]; ok { return common.CopyBytes(entry), nil } - return nil, errMemorydbNotFound + return nil, ErrMemorydbNotFound } // Release releases associated resources. Release should always succeed and can From 8a5f649c37dc6d35ec3754849abe839b957c4d7e Mon Sep 17 00:00:00 2001 From: Nodar Date: Thu, 10 Aug 2023 18:06:58 +0200 Subject: [PATCH 2/2] revert exporting errSnapshotReleased/errMemorydbClosed to avoid merge conflicts with upstream geth --- ethdb/memorydb/memorydb.go | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/ethdb/memorydb/memorydb.go b/ethdb/memorydb/memorydb.go index 8460bc42de1b..2663caa11b2c 100644 --- a/ethdb/memorydb/memorydb.go +++ b/ethdb/memorydb/memorydb.go @@ -28,17 +28,17 @@ import ( ) var ( - // ErrMemorydbClosed is returned if a memory database was already closed at the + // errMemorydbClosed is returned if a memory database was already closed at the // invocation of a data access operation. - ErrMemorydbClosed = errors.New("database closed") + errMemorydbClosed = errors.New("database closed") // ErrMemorydbNotFound is returned if a key is requested that is not found in // the provided memory database. ErrMemorydbNotFound = errors.New("not found") - // ErrSnapshotReleased is returned if callers want to retrieve data from a + // errSnapshotReleased is returned if callers want to retrieve data from a // released snapshot. - ErrSnapshotReleased = errors.New("snapshot released") + errSnapshotReleased = errors.New("snapshot released") ) // Database is an ephemeral key-value store. Apart from basic data storage @@ -81,7 +81,7 @@ func (db *Database) Has(key []byte) (bool, error) { defer db.lock.RUnlock() if db.db == nil { - return false, ErrMemorydbClosed + return false, errMemorydbClosed } _, ok := db.db[string(key)] return ok, nil @@ -93,7 +93,7 @@ func (db *Database) Get(key []byte) ([]byte, error) { defer db.lock.RUnlock() if db.db == nil { - return nil, ErrMemorydbClosed + return nil, errMemorydbClosed } if entry, ok := db.db[string(key)]; ok { return common.CopyBytes(entry), nil @@ -107,7 +107,7 @@ func (db *Database) Put(key []byte, value []byte) error { defer db.lock.Unlock() if db.db == nil { - return ErrMemorydbClosed + return errMemorydbClosed } db.db[string(key)] = common.CopyBytes(value) return nil @@ -119,7 +119,7 @@ func (db *Database) Delete(key []byte) error { defer db.lock.Unlock() if db.db == nil { - return ErrMemorydbClosed + return errMemorydbClosed } delete(db.db, string(key)) return nil @@ -356,7 +356,7 @@ func (snap *snapshot) Has(key []byte) (bool, error) { defer snap.lock.RUnlock() if snap.db == nil { - return false, ErrSnapshotReleased + return false, errSnapshotReleased } _, ok := snap.db[string(key)] return ok, nil @@ -369,7 +369,7 @@ func (snap *snapshot) Get(key []byte) ([]byte, error) { defer snap.lock.RUnlock() if snap.db == nil { - return nil, ErrSnapshotReleased + return nil, errSnapshotReleased } if entry, ok := snap.db[string(key)]; ok { return common.CopyBytes(entry), nil