Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
178 commits
Select commit Hold shift + click to select a range
b877b39
Move state account and object to stypes package
DarianShawn Dec 16, 2022
f59fd56
More types and tests
DarianShawn Dec 17, 2022
b605bf0
Extract address hash key
DarianShawn Dec 17, 2022
2623c99
More comments on kvdb interface
DarianShawn Dec 17, 2022
07b8f71
Remove iterator not use methods
DarianShawn Dec 17, 2022
742fef3
Refactor leveldb test cases
DarianShawn Dec 17, 2022
26b7d42
Extract datadir path joiner
DarianShawn Dec 19, 2022
3998922
Fix e2e reverify test
DarianShawn Dec 19, 2022
d8e9872
Fix lint error
DarianShawn Dec 19, 2022
e611671
Basic framework of snapshot layers
DarianShawn Dec 19, 2022
4c9cdfb
Add io reader/writer rlp mashaler/unmarshaler
DarianShawn Dec 19, 2022
b1c94c9
Use schema for state db entry prefix
DarianShawn Dec 19, 2022
724dd0c
Minimize statedb transanction lock range
DarianShawn Dec 19, 2022
2c4f578
Fix rlp lint error
DarianShawn Dec 20, 2022
765c96b
Fix rlp test crash
DarianShawn Dec 20, 2022
4f537ca
Fix rlp test failure
DarianShawn Dec 20, 2022
a7a1885
refactor kvdb module with interface and different implementations
DarianShawn Dec 20, 2022
7257547
Fix rlp output test failure
DarianShawn Dec 20, 2022
d6b4701
iterator of snapshot
DarianShawn Dec 20, 2022
56562b4
migrate difflayer logic from geth
DarianShawn Dec 20, 2022
9ee9430
migrate difflayer tests from geth
DarianShawn Dec 20, 2022
6211046
Pass difflayer tests
DarianShawn Dec 20, 2022
a26ce3d
panic when data was corrupted
DarianShawn Dec 20, 2022
12b930f
migrate disklayer logic from geth
DarianShawn Dec 20, 2022
d3632ad
Refactor storage with option mode instead of hard-to-read builder mode
DarianShawn Dec 21, 2022
5297321
Fix test file lint error
DarianShawn Dec 21, 2022
464bde3
Remove conflict snapshot key prefix
DarianShawn Dec 21, 2022
624d218
Strict iterator key match
DarianShawn Dec 21, 2022
aa80354
Extract logger interface to kvdb package
DarianShawn Dec 22, 2022
6fb0927
Replace snapshot hclog.Logger with kvdb.Logger
DarianShawn Dec 22, 2022
b86caa6
Add methods to Batch interface
DarianShawn Dec 22, 2022
79f9c29
Remove redundent and bad-implemented storage abstraction
DarianShawn Dec 22, 2022
bab82df
disklayer tests
DarianShawn Dec 22, 2022
f5693d7
Fix difflayer tests compile error
DarianShawn Dec 22, 2022
0c94b59
Fix disklayer test panic with new logger field
DarianShawn Dec 22, 2022
94134ea
Fix disklayer tests failure
DarianShawn Dec 22, 2022
80d9dfd
iterator tests
DarianShawn Dec 22, 2022
c8e1ea1
Fix lint error
DarianShawn Dec 22, 2022
b82b2df
Fix iterator tests compile error
DarianShawn Dec 22, 2022
cf82308
Pass iterator tests
DarianShawn Dec 22, 2022
41c5c96
Fix iterator tests panic
DarianShawn Dec 22, 2022
f5626b6
Close blockchain storage on the created module to break weird depende…
DarianShawn Dec 22, 2022
47632bf
Close database instead of storage in test
DarianShawn Dec 27, 2022
7578dd7
Refactor server setup
DarianShawn Dec 27, 2022
ffaacc5
Extract kvstorage schema/read/write to rawdb
DarianShawn Dec 27, 2022
a84916a
Pass tests
DarianShawn Dec 28, 2022
9198c15
Break ugly initializtion circle
DarianShawn Dec 28, 2022
566934b
Remove meaningless chain attribute
DarianShawn Dec 28, 2022
2d2f016
Close http servers when shut down
DarianShawn Dec 28, 2022
04106fd
Fix lint error
DarianShawn Dec 28, 2022
1cd9799
Less usage of executor field
DarianShawn Dec 28, 2022
2c85b1b
server command cache flags
DarianShawn Jan 3, 2023
53c343e
Delete snapshot in batch
DarianShawn Jan 3, 2023
6e1e795
Setup snapshots when initilize Transition
DarianShawn Jan 5, 2023
033f752
Fix crash on snapshot account unmarshal
DarianShawn Jan 5, 2023
17ec5c4
Fix state test failure due to not getting data from database
DarianShawn Jan 5, 2023
b043d8e
Fix state object method typo
DarianShawn Jan 5, 2023
821cf92
Merge dev to fix conflict
DarianShawn Jan 6, 2023
bee955d
Fix lint error
DarianShawn Jan 6, 2023
d1971f1
Migrate trie module
DarianShawn Jan 11, 2023
1b84ed8
Remove not used method in memorydb
DarianShawn Jan 11, 2023
7c18fe4
Add enable snapshot flag to param
DarianShawn Jan 11, 2023
45bc8c1
Add missing iterator and load snapshot feature
DarianShawn Jan 11, 2023
628934c
Fix lint error
DarianShawn Jan 11, 2023
ee5bc5b
Merge dev to fix conflict
DarianShawn Jan 13, 2023
20193af
Wait reverify test process unlock leveldb file lock
DarianShawn Jan 13, 2023
deae5c6
Fix reverify e2e test crash
DarianShawn Jan 13, 2023
255e7f9
Enable snapshots config by command line flags
DarianShawn Jan 30, 2023
c77072c
Fix load genesis snapshots panic
DarianShawn Jan 30, 2023
d5ccb23
Fix slim account unmarshal to account panic
DarianShawn Jan 31, 2023
0686606
Use empty hash variable instead of the same one when return
DarianShawn Jan 31, 2023
f7658b7
Fix lint error
DarianShawn Jan 31, 2023
0b822f9
Add generate tests
DarianShawn Jan 31, 2023
73b91cc
Remove redundent state schema
DarianShawn Feb 1, 2023
fa9db8a
Use snapshot prefix key length instead of constant 1
DarianShawn Feb 1, 2023
d45ef11
Update go module crypto with specific version
DarianShawn Feb 3, 2023
c81e9ec
Fix generator tests
DarianShawn Feb 3, 2023
a378ce7
Use logger in generate tests
DarianShawn Feb 3, 2023
927f49a
Fix compile failure due to missing module version
DarianShawn Feb 6, 2023
9627628
Journal snapshots when closing server
DarianShawn Feb 8, 2023
a56f0f4
Fix: trie journal dir not in datadir
DarianShawn Feb 8, 2023
940c093
Fix: panic when not enable graphql service
DarianShawn Feb 8, 2023
22bcf46
print hex instead of raw bytes when journal root mismatch
DarianShawn Feb 8, 2023
1e4362d
Merge dev to fix conflict
DarianShawn Feb 10, 2023
e9ae20b
Fix e2e tests due to nil Account Copy
DarianShawn Feb 10, 2023
5ac58a0
Remove not used StateObject field
DarianShawn Feb 10, 2023
f42c3e7
Rename param root to stateRoot
DarianShawn Feb 11, 2023
0c2702d
Fix get storage always empty
DarianShawn Feb 11, 2023
8ce5efb
Return hash instead of byte slice on GetStorage
DarianShawn Feb 11, 2023
0bbda24
Update schema comment
DarianShawn Feb 13, 2023
46fe346
Merge dev to fix conflict
DarianShawn Feb 13, 2023
2a1eaf0
tidy go module
DarianShawn Feb 13, 2023
3220600
Persist difflayer and disklayer when journal snapshots
DarianShawn Feb 13, 2023
e9f9b74
Use keccake Read instead of Sum for better performance
DarianShawn Feb 13, 2023
4374def
Fix lint error
DarianShawn Feb 13, 2023
3e19538
Add live state objects to Txn for faster query
DarianShawn Feb 14, 2023
bcb913f
Update snap account state root and storage when transition Commit
DarianShawn Feb 15, 2023
096912d
Query snapshot first when getting storage state
DarianShawn Feb 15, 2023
4493bcc
Fix snapAccounts not filter when update stateroot due to not correct …
DarianShawn Feb 15, 2023
a70c8bf
Fix snapshot Storage filter miss due to not correct slot hash
DarianShawn Feb 15, 2023
067414f
Fix snapshot Storage return empty due to uncorrect rlp split
DarianShawn Feb 15, 2023
76926dd
Fix TestSnapshotUpdateData
DarianShawn Feb 15, 2023
420c7da
Fix TestState
DarianShawn Feb 15, 2023
5da59db
Use keccake256hash instead of repeat logic in keccake256
DarianShawn Feb 16, 2023
d8dc516
Fix eth TestState
DarianShawn Feb 16, 2023
e20d8b9
Enable parallel in eth tests
DarianShawn Feb 16, 2023
576c68b
Fix lint
DarianShawn Feb 16, 2023
c3729e4
Migrate all address hash in state
DarianShawn Feb 20, 2023
1402f64
Tests for crypto Keccak256
DarianShawn Feb 20, 2023
53e58be
Fix state root not right due to storage not rlp unmarshal
DarianShawn Feb 20, 2023
efceaf8
Rename account root to storage root for clearness
DarianShawn Feb 20, 2023
513fe74
Remove some TODO marks
DarianShawn Feb 21, 2023
2552428
Fix lint
DarianShawn Feb 21, 2023
4285b45
Remove not used stateObjects
DarianShawn Feb 21, 2023
c4146b1
Fix panic when resurrect account
DarianShawn Feb 21, 2023
0bee491
Set snap storage to nil if the account is deleted
DarianShawn Feb 21, 2023
0797722
Use snapshot in jsonrpc backend for faster query
DarianShawn Feb 21, 2023
a9e2c3c
Fix snap storage always return 0 due to value not rlp marshal
DarianShawn Feb 21, 2023
eb3cf0f
Set directory to 0755 for normal read
DarianShawn Feb 22, 2023
6d0fb5b
Update account balance by create a new object
DarianShawn Feb 22, 2023
75c7a61
Remove repeat logic in getStorageCommitted
DarianShawn Feb 22, 2023
9f219d5
//TODELETE: debug logs on contract gas changing
DarianShawn Feb 22, 2023
bd61597
Fix TestState due to not create empty account when balance is 0
DarianShawn Feb 22, 2023
db5c526
Set logger as default to avoid passing it around
DarianShawn Feb 22, 2023
fa62ad7
Fix account nonce uint64 overflow
DarianShawn Feb 23, 2023
cca9cdc
Seal stateobject so as to journal and revert
DarianShawn Feb 23, 2023
99b5af4
Hash store key only when snap enable
DarianShawn Feb 23, 2023
18afe3c
Rename file from state to state_object
DarianShawn Feb 23, 2023
b111434
Fix transaction snapshot revert not rollback live snapAccounts
DarianShawn Feb 23, 2023
53b5c13
Use journal to revert transition Txn snap accounts
DarianShawn Feb 24, 2023
fc1fd2f
Snapshot background build flag and default false
DarianShawn Feb 24, 2023
6ca6c10
Fix snapshot revert panic due to create account failed
DarianShawn Feb 24, 2023
ce43c58
Fix lint
DarianShawn Feb 24, 2023
3a4d824
Do not return error when snapshot getting data failed
DarianShawn Feb 26, 2023
2b4fc28
Merge dev to fix conflict
DarianShawn Mar 1, 2023
ca0b682
Merge branch 'dev' into feat-state-snapshot
DarianShawn Mar 1, 2023
7a78af3
Stop ibft consensus cycle when sequence error or not validator any more
DarianShawn Mar 2, 2023
91a80cb
Merge dev to fix conflict
DarianShawn Mar 2, 2023
0f98309
[dependency] update golang sub-repositories (#306)
0xcb9ff9 Feb 17, 2023
19ee0b4
[dependency] update third-party packages (#307)
0xcb9ff9 Feb 27, 2023
19722a3
[network] Improved Connection Manager (#305)
0xcb9ff9 Mar 2, 2023
d44fd51
more debug logs on blockchain execution
DarianShawn Mar 3, 2023
5fbf9eb
rename jsonrpc store metric to not expose struct
DarianShawn Mar 3, 2023
ddda70b
add metrics fileds to snapshot
DarianShawn Mar 3, 2023
647aa8a
Fix panic TestState due to non-reentrant call of fastrlp parser Parse…
DarianShawn Mar 6, 2023
3b6b672
Create eth state tests with snapshot enable
DarianShawn Mar 2, 2023
9ae12f7
Enable parrallel in eth evm tests
DarianShawn Mar 6, 2023
f67e7b2
Create eth evm tests with snapshot enable
DarianShawn Mar 6, 2023
b1087a6
More metrics in snapshot
DarianShawn Mar 7, 2023
d874f09
Change snapshot metrics types
DarianShawn Mar 7, 2023
7f7f94c
collect metrics in difflayer
DarianShawn Mar 7, 2023
ff03722
collect metrics in disklayer
DarianShawn Mar 7, 2023
ef115f6
collect metrics in generate
DarianShawn Mar 7, 2023
c27277a
collect metrics in snapshot
DarianShawn Mar 7, 2023
303e9ba
Fix panic TestMergeDelete due to not-set snapmetrics
DarianShawn Mar 7, 2023
e942734
Fix panic snapshot tests due to missing snapmetrics
DarianShawn Mar 7, 2023
d72c9b3
Revert ugly sleeping logic to make validator syncing work
DarianShawn Mar 7, 2023
10a8dfa
Remove repeat update module logic in accept state
DarianShawn Mar 7, 2023
c55ce24
Wait group done no matter ibft validator or not
DarianShawn Mar 7, 2023
46476fc
Refactor ibft consensus running context
DarianShawn Mar 7, 2023
cd46f81
Seperate generate metrics from snapshot metrics
DarianShawn Mar 8, 2023
749c808
Fix panic of snapshot tests
DarianShawn Mar 9, 2023
2aab8f1
Fix snapshot tests compile failed
DarianShawn Mar 9, 2023
2664b1b
Use file mask constant directly in creating dir
DarianShawn Mar 11, 2023
50e6902
Remove repeat account flush item count
DarianShawn Mar 13, 2023
1c25645
Remove not used metric structs
DarianShawn Mar 13, 2023
4440033
Revert ibft consensus logic to make validator mining back
DarianShawn Mar 13, 2023
be0d698
Fix lint
DarianShawn Mar 13, 2023
6f11a34
Remove update submodule log due to too much printing
DarianShawn Mar 13, 2023
3c49d51
Merge branch 'dev' into feat-state-snapshot
DarianShawn Mar 15, 2023
766006a
Use Lock instead of TryLock due to golang 1.17 not exists method
DarianShawn Mar 15, 2023
38a70e4
Disable parallel tests on evm and state tests due to eating out memory
DarianShawn Mar 16, 2023
53a2688
Larger leveldb block size for less CRC checksum
DarianShawn Mar 16, 2023
0544d02
Use prometheus metrics instead of custom ones in generating snapshot
DarianShawn Mar 16, 2023
b74dae5
Parallel run evm and state tests on file instead of folder
DarianShawn Mar 16, 2023
da27165
Collect storage clean metrics
DarianShawn Mar 17, 2023
44633af
Collect dangling storage metrics
DarianShawn Mar 17, 2023
b8b3d57
Collect snapshot generate used and eta metrics
DarianShawn Mar 20, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ jobs:
cache-dependency-path: go.sum

- name: Run Go Test
run: go test -coverprofile coverage.out -timeout 20m `go list ./... | grep -v e2e`
run: go test -coverprofile coverage.out -timeout 25m `go list ./... | grep -v e2e`

- name: Upload coverage file to Codecov
uses: codecov/codecov-action@v3
Expand Down
8 changes: 7 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,15 @@ issues:
exclude-rules:
- path: _test\.go
linters:
- dupl
- errorlint
- forcetypeassert
- gosec
- unparam
- lll
- nlreturn
- prealloc
- unparam
- wsl
- linters:
- staticcheck
path: "state/runtime/precompiled/base.go"
Expand Down
78 changes: 21 additions & 57 deletions blockchain/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/dogechain-lab/dogechain/contracts/upgrader"
"github.com/dogechain-lab/dogechain/contracts/validatorset"
"github.com/dogechain-lab/dogechain/helper/common"
"github.com/dogechain-lab/dogechain/helper/rawdb"
"github.com/dogechain-lab/dogechain/state"
"github.com/dogechain-lab/dogechain/types"
"github.com/dogechain-lab/dogechain/types/buildroot"
Expand Down Expand Up @@ -118,7 +119,7 @@ func (b *Blockchain) updateGasPriceAvg(newValues []*big.Int) {
defer b.gpAverage.Unlock()

// Sum the values for quick reference
sum := big.NewInt(0)
sum := new(big.Int)
for _, val := range newValues {
sum = sum.Add(sum, val)
}
Expand Down Expand Up @@ -194,19 +195,16 @@ func (b *Blockchain) GetAvgGasPrice() *big.Int {
func NewBlockchain(
logger hclog.Logger,
config *chain.Chain,
storageBuilder storage.StorageBuilder,
consensus Verifier,
db storage.Storage,
executor Executor,
metrics *Metrics,
) (*Blockchain, error) {
if storageBuilder == nil {
return nil, ErrNilStorageBuilder
}

b := &Blockchain{
logger: logger.Named("blockchain"),
config: config,
consensus: consensus,
db: db,
executor: executor,
stream: newEventStream(context.Background()),
gpAverage: &gasPriceAverage{
Expand All @@ -216,17 +214,6 @@ func NewBlockchain(
metrics: NewDummyMetrics(metrics),
}

var (
db storage.Storage
err error
)

if db, err = storageBuilder.Build(); err != nil {
return nil, err
}

b.db = db

if err := b.initCaches(defaultCacheSize); err != nil {
return nil, err
}
Expand Down Expand Up @@ -483,7 +470,7 @@ func (b *Blockchain) writeCanonicalHeader(event *Event, h *types.Header) error {
return fmt.Errorf("parent difficulty not found")
}

newTD := big.NewInt(0).Add(parentTD, new(big.Int).SetUint64(h.Difficulty))
newTD := new(big.Int).Add(parentTD, new(big.Int).SetUint64(h.Difficulty))
if err := b.db.WriteCanonicalHeader(h, newTD); err != nil {
return err
}
Expand Down Expand Up @@ -515,7 +502,7 @@ func (b *Blockchain) advanceHead(newHeader *types.Header) (*big.Int, error) {
}

// Check if there was a parent difficulty
parentTD := big.NewInt(0)
parentTD := new(big.Int)

if newHeader.ParentHash != types.StringToHash("") {
td, ok := b.readTotalDifficulty(newHeader.ParentHash)
Expand All @@ -527,7 +514,7 @@ func (b *Blockchain) advanceHead(newHeader *types.Header) (*big.Int, error) {
}

// Calculate the new total difficulty
newTD := big.NewInt(0).Add(parentTD, big.NewInt(0).SetUint64(newHeader.Difficulty))
newTD := new(big.Int).Add(parentTD, new(big.Int).SetUint64(newHeader.Difficulty))
if err := b.db.WriteTotalDifficulty(newHeader.Hash, newTD); err != nil {
return nil, err
}
Expand Down Expand Up @@ -717,11 +704,15 @@ func (b *Blockchain) VerifyFinalizedBlock(block *types.Block) error {
return ErrNoBlockHeader
}

b.logger.Debug("verify finalized block header", "number", block.Number())

// Make sure the consensus layer verifies this block header
if err := b.consensus.VerifyHeader(block.Header); err != nil {
return fmt.Errorf("failed to verify the header: %w", err)
}

b.logger.Debug("verify finalized block body", "number", block.Number())

// Do the initial block verification
if err := b.verifyBlock(block); err != nil {
return err
Expand Down Expand Up @@ -1072,6 +1063,7 @@ func (b *Blockchain) extractBlockReceipts(block *types.Block) ([]*types.Receipt,
// Check the cache for the block receipts
receipts, ok := b.receiptsCache.Get(block.Header.Hash)
if !ok {
b.logger.Info("execute block transactions due to no receipts cache")
// No receipts found in the cache, execute the transactions from the block
// and fetch them
blockResult, err := b.executeBlockTransactions(block)
Expand Down Expand Up @@ -1136,7 +1128,7 @@ func (b *Blockchain) writeBody(block *types.Block) error {
// ReadTxLookup returns the block hash using the transaction hash
func (b *Blockchain) ReadTxLookup(hash types.Hash) (types.Hash, bool) {
if b.isStopped() {
return types.ZeroHash, false
return types.Hash{}, false
}

v, ok := b.db.ReadTxLookup(hash)
Expand Down Expand Up @@ -1185,43 +1177,15 @@ func (b *Blockchain) verifyGasLimit(header, parentHeader *types.Header) error {
return nil
}

// GetHashHelper is used by the EVM, so that the SC can get the hash of the header number
func (b *Blockchain) GetHashHelper(header *types.Header) func(i uint64) (res types.Hash) {
return func(i uint64) (res types.Hash) {
num, hash := header.Number-1, header.ParentHash

for {
if num == i {
res = hash

return
}

h, ok := b.GetHeaderByHash(hash)
if !ok {
return
}

hash = h.ParentHash

if num == 0 {
return
}

num--
}
}
}

// GetHashByNumber returns the block hash using the block number
func (b *Blockchain) GetHashByNumber(blockNumber uint64) types.Hash {
if b.isStopped() {
return types.ZeroHash
return types.Hash{}
}

block, ok := b.GetBlockByNumber(blockNumber, false)
if !ok {
return types.ZeroHash
return types.Hash{}
}

return block.Hash()
Expand Down Expand Up @@ -1260,9 +1224,9 @@ func (b *Blockchain) writeHeaderImpl(evnt *Event, header *types.Header) error {
// Write the difficulty
if err := b.db.WriteTotalDifficulty(
header.Hash,
big.NewInt(0).Add(
new(big.Int).Add(
parentTD,
big.NewInt(0).SetUint64(header.Difficulty),
new(big.Int).SetUint64(header.Difficulty),
),
); err != nil {
return err
Expand All @@ -1282,7 +1246,7 @@ func (b *Blockchain) writeHeaderImpl(evnt *Event, header *types.Header) error {
// Update the headers cache
b.headersCache.Add(header.Hash, header)

incomingTD := big.NewInt(0).Add(parentTD, big.NewInt(0).SetUint64(header.Difficulty))
incomingTD := new(big.Int).Add(parentTD, new(big.Int).SetUint64(header.Difficulty))
if incomingTD.Cmp(currentTD) > 0 {
// new block has higher difficulty, reorg the chain
if err := b.handleReorg(evnt, currentHeader, header); err != nil {
Expand All @@ -1305,7 +1269,8 @@ func (b *Blockchain) writeHeaderImpl(evnt *Event, header *types.Header) error {
func (b *Blockchain) writeFork(header *types.Header) error {
forks, err := b.db.ReadForks()
if err != nil {
if errors.Is(err, storage.ErrNotFound) {
// too many error types
if err.Error() == rawdb.ErrNotFound.Error() {
forks = []types.Hash{}
} else {
return err
Expand Down Expand Up @@ -1484,8 +1449,7 @@ func (b *Blockchain) Close() error {

b.wg.Wait()

// close db at last
return b.db.Close()
return nil
}

func (b *Blockchain) stop() {
Expand Down
20 changes: 10 additions & 10 deletions blockchain/blockchain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ import (
"github.com/dogechain-lab/dogechain/blockchain/storage"
"github.com/dogechain-lab/dogechain/blockchain/storage/kvstorage"
"github.com/dogechain-lab/dogechain/chain"
"github.com/dogechain-lab/dogechain/helper/kvdb/memorydb"
"github.com/dogechain-lab/dogechain/helper/rawdb"
"github.com/dogechain-lab/dogechain/state"
"github.com/dogechain-lab/dogechain/types"
"github.com/hashicorp/go-hclog"
"github.com/stretchr/testify/assert"
)

Expand Down Expand Up @@ -490,7 +491,7 @@ func TestInsertHeaders(t *testing.T) {
assert.Equal(t, head.Hash, expected.Hash)

forks, err := b.GetForks()
if err != nil && !errors.Is(err, storage.ErrNotFound) {
if err != nil && (err.Error() != rawdb.ErrNotFound.Error()) {
t.Fatal(err)
}

Expand Down Expand Up @@ -545,8 +546,7 @@ func TestForkUnknownParents(t *testing.T) {
}

func TestBlockchainWriteBody(t *testing.T) {
storage, err := kvstorage.NewMemoryStorageBuilder(hclog.NewNullLogger()).Build()
assert.NoError(t, err)
storage := kvstorage.NewKeyValueStorage(memorydb.New())

b := &Blockchain{
db: storage,
Expand Down Expand Up @@ -704,8 +704,8 @@ func TestBlockchain_VerifyBlockParent(t *testing.T) {
t.Parallel()

emptyHeader := &types.Header{
Hash: types.ZeroHash,
ParentHash: types.ZeroHash,
Hash: types.Hash{},
ParentHash: types.Hash{},
}
emptyHeader.ComputeHash()

Expand All @@ -729,7 +729,7 @@ func TestBlockchain_VerifyBlockParent(t *testing.T) {
// Create a dummy block
block := &types.Block{
Header: &types.Header{
ParentHash: types.ZeroHash,
ParentHash: types.Hash{},
},
}

Expand Down Expand Up @@ -855,8 +855,8 @@ func TestBlockchain_VerifyBlockBody(t *testing.T) {
t.Parallel()

emptyHeader := &types.Header{
Hash: types.ZeroHash,
ParentHash: types.ZeroHash,
Hash: types.Hash{},
ParentHash: types.Hash{},
}

t.Run("Invalid SHA3 Uncles root", func(t *testing.T) {
Expand All @@ -869,7 +869,7 @@ func TestBlockchain_VerifyBlockBody(t *testing.T) {

block := &types.Block{
Header: &types.Header{
Sha3Uncles: types.ZeroHash,
Sha3Uncles: types.Hash{},
},
}

Expand Down
5 changes: 0 additions & 5 deletions blockchain/storage/errors.go

This file was deleted.

Loading