forked from 0xPolygon/polygon-edge
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Storage] Use same storage interface for blockchain and trie storage (#…
…193) # Description refactoring blocakchain storage interface # Changes include - [ ] Bugfix (non-breaking change that solves an issue) - [ ] Hotfix (change that solves an urgent issue, and requires immediate attention) - [x] New feature (non-breaking change that adds functionality) - [ ] Breaking change (change that is not backwards-compatible and/or changes current functionality) # Breaking changes Please complete this section if any breaking changes have been made, otherwise delete it # Checklist - [x] I have assigned this PR to myself - [x] I have added at least 1 reviewer - [x] I have added the relevant labels - [ ] I have updated the official documentation - [x] I have added sufficient documentation in code ## Testing - [x] I have tested this code with the official test suite - [ ] I have tested this code manually
- Loading branch information
Showing
22 changed files
with
448 additions
and
351 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package storage | ||
|
||
import "fmt" | ||
|
||
var ErrNotFound = fmt.Errorf("not found") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package kvstorage | ||
|
||
import ( | ||
"github.com/dogechain-lab/dogechain/blockchain/storage" | ||
"github.com/dogechain-lab/dogechain/helper/kvdb" | ||
"github.com/hashicorp/go-hclog" | ||
) | ||
|
||
type leveldbStorageBuilder struct { | ||
logger hclog.Logger | ||
leveldbBuilder kvdb.LevelDBBuilder | ||
} | ||
|
||
func (builder *leveldbStorageBuilder) Build() (storage.Storage, error) { | ||
db, err := builder.leveldbBuilder.Build() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return newKeyValueStorage(builder.logger.Named("leveldb"), db), nil | ||
} | ||
|
||
// NewLevelDBStorageBuilder creates the new blockchain storage builder | ||
func NewLevelDBStorageBuilder(logger hclog.Logger, leveldbBuilder kvdb.LevelDBBuilder) storage.StorageBuilder { | ||
return &leveldbStorageBuilder{ | ||
logger: logger, | ||
leveldbBuilder: leveldbBuilder, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package kvstorage | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
|
||
"github.com/dogechain-lab/dogechain/blockchain/storage" | ||
"github.com/dogechain-lab/dogechain/helper/kvdb" | ||
"github.com/hashicorp/go-hclog" | ||
) | ||
|
||
func newLevelDBStorage(t *testing.T) (storage.Storage, func()) { | ||
t.Helper() | ||
|
||
path, err := os.MkdirTemp("/tmp", "minimal_storage") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
logger := hclog.NewNullLogger() | ||
|
||
s, err := NewLevelDBStorageBuilder( | ||
logger, kvdb.NewLevelDBBuilder(logger, path)).Build() | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
closeFn := func() { | ||
if err := s.Close(); err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
if err := os.RemoveAll(path); err != nil { | ||
t.Fatal(err) | ||
} | ||
} | ||
|
||
return s, closeFn | ||
} | ||
|
||
func TestLevelDBStorage(t *testing.T) { | ||
storage.TestStorage(t, newLevelDBStorage) | ||
} |
18 changes: 14 additions & 4 deletions
18
blockchain/storage/memory/memory.go → blockchain/storage/kvstorage/memory.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 4 additions & 3 deletions
7
blockchain/storage/memory/memory_test.go → blockchain/storage/kvstorage/memory_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.