Skip to content

Commit 01a8e47

Browse files
authored
Merge branch 'master' into pebble-sublevels-metric
2 parents 3e228d6 + 4758974 commit 01a8e47

File tree

14 files changed

+114
-41
lines changed

14 files changed

+114
-41
lines changed

arbitrum/recordingdb.go

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
"github.com/ethereum/go-ethereum/rlp"
2222
"github.com/ethereum/go-ethereum/triedb"
2323
"github.com/ethereum/go-ethereum/triedb/hashdb"
24-
flag "github.com/spf13/pflag"
2524
)
2625

2726
var (
@@ -159,18 +158,8 @@ func (r *RecordingChainContext) GetMinBlockNumberAccessed() uint64 {
159158
}
160159

161160
type RecordingDatabaseConfig struct {
162-
TrieDirtyCache int `koanf:"trie-dirty-cache"`
163-
TrieCleanCache int `koanf:"trie-clean-cache"`
164-
}
165-
166-
var DefaultRecordingDatabaseConfig = RecordingDatabaseConfig{
167-
TrieDirtyCache: 1024,
168-
TrieCleanCache: 16,
169-
}
170-
171-
func RecordingDatabaseConfigAddOptions(prefix string, f *flag.FlagSet) {
172-
f.Int(prefix+".trie-dirty-cache", DefaultRecordingDatabaseConfig.TrieDirtyCache, "like trie-dirty-cache for the separate, recording database (used for validation)")
173-
f.Int(prefix+".trie-clean-cache", DefaultRecordingDatabaseConfig.TrieCleanCache, "like trie-clean-cache for the separate, recording database (used for validation)")
161+
TrieDirtyCache int
162+
TrieCleanCache int
174163
}
175164

176165
type RecordingDatabase struct {

cmd/geth/main.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -349,8 +349,6 @@ func geth(ctx *cli.Context) error {
349349
// it unlocks any requested accounts, and starts the RPC/IPC interfaces and the
350350
// miner.
351351
func startNode(ctx *cli.Context, stack *node.Node, backend ethapi.Backend, isConsole bool) {
352-
debug.Memsize.Add("node", stack)
353-
354352
// Start up the node itself
355353
utils.StartNode(ctx, stack, isConsole)
356354

core/rawdb/accessors_snapshot.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,8 @@ func DeleteSnapshotRoot(db ethdb.KeyValueWriter) {
7373
}
7474

7575
// ReadAccountSnapshot retrieves the snapshot entry of an account trie leaf.
76-
func ReadAccountSnapshot(db ethdb.KeyValueReader, hash common.Hash) []byte {
77-
data, _ := db.Get(accountSnapshotKey(hash))
78-
return data
76+
func ReadAccountSnapshot(db ethdb.KeyValueReader, hash common.Hash) ([]byte, error) {
77+
return ignoreNotFound(db.Get(accountSnapshotKey(hash)))
7978
}
8079

8180
// WriteAccountSnapshot stores the snapshot entry of an account trie leaf.
@@ -93,9 +92,8 @@ func DeleteAccountSnapshot(db ethdb.KeyValueWriter, hash common.Hash) {
9392
}
9493

9594
// ReadStorageSnapshot retrieves the snapshot entry of an storage trie leaf.
96-
func ReadStorageSnapshot(db ethdb.KeyValueReader, accountHash, storageHash common.Hash) []byte {
97-
data, _ := db.Get(storageSnapshotKey(accountHash, storageHash))
98-
return data
95+
func ReadStorageSnapshot(db ethdb.KeyValueReader, accountHash, storageHash common.Hash) ([]byte, error) {
96+
return ignoreNotFound(db.Get(storageSnapshotKey(accountHash, storageHash)))
9997
}
10098

10199
// WriteStorageSnapshot stores the snapshot entry of an storage trie leaf.

core/rawdb/arbitrum_not_found.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright 2024 The go-ethereum Authors
2+
// This file is part of the go-ethereum library.
3+
//
4+
// The go-ethereum library is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU Lesser General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// The go-ethereum library is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU Lesser General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU Lesser General Public License
15+
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
16+
17+
package rawdb
18+
19+
// Arbitrum specific code to handle database errors
20+
21+
func ignoreNotFound(blob []byte, err error) ([]byte, error) {
22+
if isDbErrNotFound(err) {
23+
return nil, nil
24+
}
25+
return blob, err
26+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Copyright 2024 The go-ethereum Authors
2+
// This file is part of the go-ethereum library.
3+
//
4+
// The go-ethereum library is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU Lesser General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// The go-ethereum library is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU Lesser General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU Lesser General Public License
15+
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
16+
17+
//go:build !wasm
18+
// +build !wasm
19+
20+
package rawdb
21+
22+
import (
23+
"errors"
24+
25+
"github.com/cockroachdb/pebble"
26+
"github.com/ethereum/go-ethereum/ethdb/memorydb"
27+
"github.com/syndtr/goleveldb/leveldb"
28+
)
29+
30+
func isDbErrNotFound(err error) bool {
31+
return errors.Is(err, leveldb.ErrNotFound) || errors.Is(err, pebble.ErrNotFound) || errors.Is(err, memorydb.ErrMemorydbNotFound)
32+
}

core/rawdb/arbitrum_not_found_wasm.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Copyright 2024 The go-ethereum Authors
2+
// This file is part of the go-ethereum library.
3+
//
4+
// The go-ethereum library is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU Lesser General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// The go-ethereum library is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU Lesser General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU Lesser General Public License
15+
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
16+
17+
//go:build wasm
18+
// +build wasm
19+
20+
package rawdb
21+
22+
import (
23+
"errors"
24+
25+
"github.com/ethereum/go-ethereum/ethdb/memorydb"
26+
)
27+
28+
func isDbErrNotFound(err error) bool {
29+
return errors.Is(err, memorydb.ErrMemorydbNotFound)
30+
}

core/state/snapshot/disklayer.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,10 @@ func (dl *diskLayer) AccountRLP(hash common.Hash) ([]byte, error) {
117117
return blob, nil
118118
}
119119
// Cache doesn't contain account, pull from disk and cache for later
120-
blob := rawdb.ReadAccountSnapshot(dl.diskdb, hash)
120+
blob, err := rawdb.ReadAccountSnapshot(dl.diskdb, hash)
121+
if err != nil {
122+
return nil, err
123+
}
121124
dl.cache.Set(hash[:], blob)
122125

123126
snapshotCleanAccountMissMeter.Mark(1)
@@ -157,7 +160,10 @@ func (dl *diskLayer) Storage(accountHash, storageHash common.Hash) ([]byte, erro
157160
return blob, nil
158161
}
159162
// Cache doesn't contain storage slot, pull from disk and cache for later
160-
blob := rawdb.ReadStorageSnapshot(dl.diskdb, accountHash, storageHash)
163+
blob, err := rawdb.ReadStorageSnapshot(dl.diskdb, accountHash, storageHash)
164+
if err != nil {
165+
return nil, err
166+
}
161167
dl.cache.Set(key, blob)
162168

163169
snapshotCleanStorageMissMeter.Mark(1)

core/state/snapshot/disklayer_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ func TestDiskMerge(t *testing.T) {
183183
// assertDatabaseAccount ensures that an account from the database matches the given blob.
184184
assertDatabaseAccount := func(account common.Hash, data []byte) {
185185
t.Helper()
186-
if blob := rawdb.ReadAccountSnapshot(db, account); !bytes.Equal(blob, data) {
186+
if blob, _ := rawdb.ReadAccountSnapshot(db, account); !bytes.Equal(blob, data) {
187187
t.Errorf("account database access (%x) mismatch: have %x, want %x", account, blob, data)
188188
}
189189
}
@@ -197,7 +197,7 @@ func TestDiskMerge(t *testing.T) {
197197
// assertDatabaseStorage ensures that a storage slot from the database matches the given blob.
198198
assertDatabaseStorage := func(account common.Hash, slot common.Hash, data []byte) {
199199
t.Helper()
200-
if blob := rawdb.ReadStorageSnapshot(db, account, slot); !bytes.Equal(blob, data) {
200+
if blob, _ := rawdb.ReadStorageSnapshot(db, account, slot); !bytes.Equal(blob, data) {
201201
t.Errorf("storage database access (%x:%x) mismatch: have %x, want %x", account, slot, blob, data)
202202
}
203203
}
@@ -387,7 +387,7 @@ func TestDiskPartialMerge(t *testing.T) {
387387
// exist otherwise.
388388
assertDatabaseAccount := func(account common.Hash, data []byte) {
389389
t.Helper()
390-
blob := rawdb.ReadAccountSnapshot(db, account)
390+
blob, _ := rawdb.ReadAccountSnapshot(db, account)
391391
if bytes.Compare(account[:], genMarker) > 0 && blob != nil {
392392
t.Fatalf("test %d: post-marker (%x) account database access (%x) succeeded: %x", i, genMarker, account, blob)
393393
}
@@ -407,7 +407,7 @@ func TestDiskPartialMerge(t *testing.T) {
407407
// and does not exist otherwise.
408408
assertDatabaseStorage := func(account common.Hash, slot common.Hash, data []byte) {
409409
t.Helper()
410-
blob := rawdb.ReadStorageSnapshot(db, account, slot)
410+
blob, _ := rawdb.ReadStorageSnapshot(db, account, slot)
411411
if bytes.Compare(append(account[:], slot[:]...), genMarker) > 0 && blob != nil {
412412
t.Fatalf("test %d: post-marker (%x) storage database access (%x:%x) succeeded: %x", i, genMarker, account, slot, blob)
413413
}

core/state/snapshot/generate_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,7 @@ func testGenerateWithExtraAccounts(t *testing.T, scheme string) {
578578
root := helper.Commit()
579579

580580
// To verify the test: If we now inspect the snap db, there should exist extraneous storage items
581-
if data := rawdb.ReadStorageSnapshot(helper.diskdb, hashData([]byte("acc-2")), hashData([]byte("b-key-1"))); data == nil {
581+
if data, _ := rawdb.ReadStorageSnapshot(helper.diskdb, hashData([]byte("acc-2")), hashData([]byte("b-key-1"))); data == nil {
582582
t.Fatalf("expected snap storage to exist")
583583
}
584584
snap := generateSnapshot(helper.diskdb, helper.triedb, 16, root)
@@ -596,7 +596,7 @@ func testGenerateWithExtraAccounts(t *testing.T, scheme string) {
596596
snap.genAbort <- stop
597597
<-stop
598598
// If we now inspect the snap db, there should exist no extraneous storage items
599-
if data := rawdb.ReadStorageSnapshot(helper.diskdb, hashData([]byte("acc-2")), hashData([]byte("b-key-1"))); data != nil {
599+
if data, _ := rawdb.ReadStorageSnapshot(helper.diskdb, hashData([]byte("acc-2")), hashData([]byte("b-key-1"))); data != nil {
600600
t.Fatalf("expected slot to be removed, got %v", string(data))
601601
}
602602
}
@@ -746,7 +746,7 @@ func testGenerateWithMalformedSnapdata(t *testing.T, scheme string) {
746746
snap.genAbort <- stop
747747
<-stop
748748
// If we now inspect the snap db, there should exist no extraneous storage items
749-
if data := rawdb.ReadStorageSnapshot(helper.diskdb, hashData([]byte("acc-2")), hashData([]byte("b-key-1"))); data != nil {
749+
if data, _ := rawdb.ReadStorageSnapshot(helper.diskdb, hashData([]byte("acc-2")), hashData([]byte("b-key-1"))); data != nil {
750750
t.Fatalf("expected slot to be removed, got %v", string(data))
751751
}
752752
}

core/state/snapshot/utils.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func checkDanglingDiskStorage(chaindb ethdb.KeyValueStore) error {
6161
log.Info("Iterating snap storage", "at", fmt.Sprintf("%#x", accKey), "elapsed", common.PrettyDuration(time.Since(start)))
6262
lastReport = time.Now()
6363
}
64-
if data := rawdb.ReadAccountSnapshot(chaindb, common.BytesToHash(accKey)); len(data) == 0 {
64+
if data, _ := rawdb.ReadAccountSnapshot(chaindb, common.BytesToHash(accKey)); len(data) == 0 {
6565
log.Warn("Dangling storage - missing account", "account", fmt.Sprintf("%#x", accKey), "storagekey", fmt.Sprintf("%#x", k))
6666
return fmt.Errorf("dangling snapshot storage account %#x", accKey)
6767
}
@@ -97,7 +97,7 @@ func CheckJournalAccount(db ethdb.KeyValueStore, hash common.Hash) error {
9797
// Look up the disk layer first
9898
baseRoot := rawdb.ReadSnapshotRoot(db)
9999
fmt.Printf("Disklayer: Root: %x\n", baseRoot)
100-
if data := rawdb.ReadAccountSnapshot(db, hash); data != nil {
100+
if data, _ := rawdb.ReadAccountSnapshot(db, hash); data != nil {
101101
account, err := types.FullAccount(data)
102102
if err != nil {
103103
panic(err)

0 commit comments

Comments
 (0)