@@ -3,37 +3,27 @@ package rawdb
3
3
import (
4
4
"fmt"
5
5
6
+ "github.com/ava-labs/libevm/common"
6
7
"github.com/ava-labs/libevm/ethdb"
7
8
)
8
9
9
10
func ExampleInspectDatabase () {
10
- extendRight := func (base []byte , totalLength int ) []byte {
11
- if len (base ) > totalLength {
12
- return base [:totalLength ]
13
- }
14
- extended := make ([]byte , totalLength )
15
- copy (extended , base )
16
- return extended
17
- }
18
-
19
11
db := & stubDatabase {
20
- iterator : & stubIterator {
21
- kvs : []keyValue {
22
- // Extra metadata keys: (17 + 1) + (9 + 1) = 28 bytes
23
- {key : snapshotBlockHashKey , value : []byte ("a" )},
24
- {key : syncRootKey , value : []byte ("b" )},
25
- // Trie segments: 77 + 1 = 78 bytes
26
- {key : extendRight (syncSegmentsPrefix , syncSegmentsKeyLength ), value : []byte ("c" )},
27
- // Storage tries to fetch: 76 + 1 = 77 bytes
28
- {key : extendRight (syncStorageTriesPrefix , syncStorageTriesKeyLength ), value : []byte ("d" )},
29
- // Code to fetch: 34 + 1 = 35 bytes
30
- {key : extendRight (CodeToFetchPrefix , codeToFetchKeyLength ), value : []byte ("e" )},
31
- // Block numbers synced to: 22 + 1 = 23 bytes
32
- {key : extendRight (syncPerformedPrefix , syncPerformedKeyLength ), value : []byte ("f" )},
33
- },
34
- },
12
+ iterator : & stubIterator {},
35
13
}
36
14
15
+ // Extra metadata keys: (17 + 32) + (12 + 32) = 93 bytes
16
+ WriteSnapshotBlockHash (db , common.Hash {})
17
+ WriteSnapshotRoot (db , common.Hash {})
18
+ // Trie segments: (77 + 2) + 1 = 80 bytes
19
+ _ = WriteSyncSegment (db , common.Hash {}, common.Hash {}.Bytes ())
20
+ // Storage tries to fetch: 76 + 1 = 77 bytes
21
+ _ = WriteSyncStorageTrie (db , common.Hash {}, common.Hash {})
22
+ // Code to fetch: 34 + 0 = 34 bytes
23
+ AddCodeToFetch (db , common.Hash {})
24
+ // Block numbers synced to: 22 + 1 = 23 bytes
25
+ _ = WriteSyncPerformed (db , 0 )
26
+
37
27
keyPrefix := []byte (nil )
38
28
keyStart := []byte (nil )
39
29
@@ -61,21 +51,21 @@ func ExampleInspectDatabase() {
61
51
// | Key-Value store | Account snapshot | 0.00 B | 0 |
62
52
// | Key-Value store | Storage snapshot | 0.00 B | 0 |
63
53
// | Key-Value store | Clique snapshots | 0.00 B | 0 |
64
- // | Key-Value store | Singleton metadata | 28 .00 B | 2 |
54
+ // | Key-Value store | Singleton metadata | 93 .00 B | 2 |
65
55
// | Light client | CHT trie nodes | 0.00 B | 0 |
66
56
// | Light client | Bloom trie nodes | 0.00 B | 0 |
67
57
// | State sync | Trie segments | 78.00 B | 1 |
68
58
// | State sync | Storage tries to fetch | 77.00 B | 1 |
69
- // | State sync | Code to fetch | 35 .00 B | 1 |
59
+ // | State sync | Code to fetch | 34 .00 B | 1 |
70
60
// | State sync | Block numbers synced to | 23.00 B | 1 |
71
61
// +-----------------+-------------------------+----------+-------+
72
- // | TOTAL | 241 .00 B | |
62
+ // | TOTAL | 305 .00 B | |
73
63
// +-----------------+-------------------------+----------+-------+
74
64
}
75
65
76
66
type stubDatabase struct {
77
67
ethdb.Database
78
- iterator ethdb. Iterator
68
+ iterator * stubIterator
79
69
}
80
70
81
71
func (s * stubDatabase ) NewIterator (keyPrefix , keyStart []byte ) ethdb.Iterator {
@@ -95,6 +85,11 @@ func (s *stubDatabase) Tail() (uint64, error) {
95
85
return 0 , nil
96
86
}
97
87
88
+ func (s * stubDatabase ) Put (key , value []byte ) error {
89
+ s .iterator .kvs = append (s .iterator .kvs , keyValue {key : key , value : value })
90
+ return nil
91
+ }
92
+
98
93
func (s * stubDatabase ) Get (key []byte ) ([]byte , error ) {
99
94
return nil , nil
100
95
}
0 commit comments