Skip to content

Commit 18fb002

Browse files
committed
Merge branch 'main' into arr4n/delegatecall-value
2 parents 586cfa7 + 7a59fdd commit 18fb002

File tree

18 files changed

+5915
-182
lines changed

18 files changed

+5915
-182
lines changed

.github/ISSUE_TEMPLATE/feature.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ body:
1010
validations:
1111
required: true
1212
- type: textarea
13-
id: description
13+
id: approach-and-alternatives
1414
attributes:
15-
label: "How would you recommend implementing it?"
15+
label: "Recommended approach and alternatives"

core/rawdb/ancient_utils.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222

2323
"github.com/ava-labs/libevm/common"
2424
"github.com/ava-labs/libevm/ethdb"
25+
"github.com/ava-labs/libevm/libevm/options"
2526
)
2627

2728
type tableSize struct {
@@ -77,7 +78,10 @@ func inspect(name string, order map[string]bool, reader ethdb.AncientReader) (fr
7778
}
7879

7980
// inspectFreezers inspects all freezers registered in the system.
80-
func inspectFreezers(db ethdb.Database) ([]freezerInfo, error) {
81+
func inspectFreezers(db ethdb.Database, opts ...InspectDatabaseOption) ([]freezerInfo, error) {
82+
if options.As[inspectDatabaseConfig](opts...).skipFreezers {
83+
return nil, nil
84+
}
8185
var infos []freezerInfo
8286
for _, freezer := range freezers {
8387
switch freezer {

core/rawdb/database.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -604,7 +604,7 @@ func InspectDatabase(db ethdb.Database, keyPrefix, keyStart []byte, opts ...Insp
604604
{"Light client", "Bloom trie nodes", bloomTrieNodes.Size(), bloomTrieNodes.Count()},
605605
}
606606
// Inspect all registered append-only file store then.
607-
ancients, err := inspectFreezers(db)
607+
ancients, err := inspectFreezers(db, opts...)
608608
if err != nil {
609609
return err
610610
}

core/rawdb/database.libevm.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ type inspectDatabaseConfig struct {
2828
statRecorders []func([]byte, common.StorageSize) bool
2929
isMetas []func([]byte) bool
3030
statsTransformers []func([][]string) [][]string
31+
skipFreezers bool
3132
}
3233

3334
func (c inspectDatabaseConfig) recordStat(key []byte, size common.StorageSize) bool {
@@ -91,3 +92,10 @@ func WithDatabaseStatsTransformer(transform func(rows [][]string) [][]string) In
9192
c.statsTransformers = append(c.statsTransformers, transform)
9293
})
9394
}
95+
96+
// WithSkipFreezers returns an option that causes for freezer inspection to be skipped.
97+
func WithSkipFreezers() InspectDatabaseOption {
98+
return newInspectOpt(func(c *inspectDatabaseConfig) {
99+
c.skipFreezers = true
100+
})
101+
}

core/rawdb/database.libevm_test.go

Lines changed: 22 additions & 171 deletions
Original file line numberDiff line numberDiff line change
@@ -14,185 +14,36 @@
1414
// along with the go-ethereum library. If not, see
1515
// <http://www.gnu.org/licenses/>.
1616

17-
package rawdb_test
17+
package rawdb
1818

1919
import (
20-
"bytes"
21-
"fmt"
22-
"sort"
20+
"testing"
2321

24-
"github.com/ava-labs/libevm/common"
25-
// To ensure that all methods are available to importing packages, this test
26-
// is defined in package `rawdb_test` instead of `rawdb`.
27-
"github.com/ava-labs/libevm/core/rawdb"
28-
"github.com/ava-labs/libevm/ethdb"
22+
"github.com/stretchr/testify/assert"
2923
)
3024

31-
// ExampleDatabaseStat demonstrates the method signatures of DatabaseStat, which
32-
// exposes an otherwise unexported type that won't have its methods documented.
33-
func ExampleDatabaseStat() {
34-
var stat rawdb.DatabaseStat
25+
func TestSkipFreezers(t *testing.T) {
26+
db := NewMemoryDatabase()
3527

36-
stat.Add(common.StorageSize(1)) // only to demonstrate param type
37-
stat.Add(2)
38-
39-
fmt.Println("Sum:", stat.Size()) // sum of all values passed to Add()
40-
fmt.Println("Count:", stat.Count()) // number of calls to Add()
41-
42-
// Output:
43-
// Sum: 3.00 B
44-
// Count: 2
45-
}
46-
47-
func ExampleInspectDatabase() {
48-
db := &stubDatabase{
49-
iterator: &stubIterator{
50-
kvs: []keyValue{
51-
// Bloom bits total = 5 + 1 = 6
52-
{key: []byte("iBxxx"), value: []byte("m")},
53-
// Optional stat record total = 5 + 7 = 12
54-
{key: []byte("mykey"), value: []byte("myvalue")},
55-
// metadata total = (13 + 7) + (14 + 7) = 41
56-
{key: []byte("mymetadatakey"), value: []byte("myvalue")},
57-
{key: []byte("mymetadatakey2"), value: []byte("myvalue")},
58-
},
28+
tests := []struct {
29+
skipFreezers bool
30+
wantErr error
31+
}{
32+
{
33+
skipFreezers: false,
34+
wantErr: errNotSupported,
35+
},
36+
{
37+
skipFreezers: true,
38+
wantErr: nil,
5939
},
6040
}
6141

62-
keyPrefix := []byte(nil)
63-
keyStart := []byte(nil)
64-
65-
var (
66-
myStat rawdb.DatabaseStat
67-
)
68-
options := []rawdb.InspectDatabaseOption{
69-
rawdb.WithDatabaseStatRecorder(func(key []byte, size common.StorageSize) bool {
70-
if bytes.Equal(key, []byte("mykey")) {
71-
myStat.Add(size)
72-
return true
73-
}
74-
return false
75-
}),
76-
rawdb.WithDatabaseMetadataKeys(func(key []byte) bool {
77-
return bytes.Equal(key, []byte("mymetadatakey"))
78-
}),
79-
rawdb.WithDatabaseMetadataKeys(func(key []byte) bool {
80-
return bytes.Equal(key, []byte("mymetadatakey2"))
81-
}),
82-
rawdb.WithDatabaseStatsTransformer(func(rows [][]string) [][]string {
83-
sort.Slice(rows, func(i, j int) bool {
84-
ri, rj := rows[i], rows[j]
85-
if ri[0] != rj[0] {
86-
return ri[0] < rj[0]
87-
}
88-
return ri[1] < rj[1]
89-
})
90-
91-
return append(
92-
rows,
93-
[]string{"My database", "My category", myStat.Size(), myStat.Count()},
94-
)
95-
}),
96-
}
97-
98-
err := rawdb.InspectDatabase(db, keyPrefix, keyStart, options...)
99-
if err != nil {
100-
fmt.Println(err)
42+
for _, tt := range tests {
43+
var opts []InspectDatabaseOption
44+
if tt.skipFreezers {
45+
opts = append(opts, WithSkipFreezers())
46+
}
47+
assert.ErrorIsf(t, InspectDatabase(db, nil, nil, opts...), tt.wantErr, "InspectDatabase(%T, nil, nil, [WithSkipFreezers = %t])", db, tt.skipFreezers)
10148
}
102-
// Output:
103-
// +-----------------------+-------------------------+---------+-------+
104-
// | DATABASE | CATEGORY | SIZE | ITEMS |
105-
// +-----------------------+-------------------------+---------+-------+
106-
// | Ancient store (Chain) | Bodies | 0.00 B | 0 |
107-
// | Ancient store (Chain) | Diffs | 0.00 B | 0 |
108-
// | Ancient store (Chain) | Hashes | 0.00 B | 0 |
109-
// | Ancient store (Chain) | Headers | 0.00 B | 0 |
110-
// | Ancient store (Chain) | Receipts | 0.00 B | 0 |
111-
// | Key-Value store | Account snapshot | 0.00 B | 0 |
112-
// | Key-Value store | Beacon sync headers | 0.00 B | 0 |
113-
// | Key-Value store | Block hash->number | 0.00 B | 0 |
114-
// | Key-Value store | Block number->hash | 0.00 B | 0 |
115-
// | Key-Value store | Bloombit index | 6.00 B | 1 |
116-
// | Key-Value store | Bodies | 0.00 B | 0 |
117-
// | Key-Value store | Clique snapshots | 0.00 B | 0 |
118-
// | Key-Value store | Contract codes | 0.00 B | 0 |
119-
// | Key-Value store | Difficulties | 0.00 B | 0 |
120-
// | Key-Value store | Hash trie nodes | 0.00 B | 0 |
121-
// | Key-Value store | Headers | 0.00 B | 0 |
122-
// | Key-Value store | Path trie account nodes | 0.00 B | 0 |
123-
// | Key-Value store | Path trie state lookups | 0.00 B | 0 |
124-
// | Key-Value store | Path trie storage nodes | 0.00 B | 0 |
125-
// | Key-Value store | Receipt lists | 0.00 B | 0 |
126-
// | Key-Value store | Singleton metadata | 41.00 B | 2 |
127-
// | Key-Value store | Storage snapshot | 0.00 B | 0 |
128-
// | Key-Value store | Transaction index | 0.00 B | 0 |
129-
// | Key-Value store | Trie preimages | 0.00 B | 0 |
130-
// | Light client | Bloom trie nodes | 0.00 B | 0 |
131-
// | Light client | CHT trie nodes | 0.00 B | 0 |
132-
// | My database | My category | 12.00 B | 1 |
133-
// +-----------------------+-------------------------+---------+-------+
134-
// | TOTAL | 59.00 B | |
135-
// +-----------------------+-------------------------+---------+-------+
136-
}
137-
138-
type stubDatabase struct {
139-
ethdb.Database
140-
iterator ethdb.Iterator
141-
}
142-
143-
func (s *stubDatabase) NewIterator(keyPrefix, keyStart []byte) ethdb.Iterator {
144-
return s.iterator
145-
}
146-
147-
// AncientSize is used in [InspectDatabase] to determine the ancient sizes.
148-
func (s *stubDatabase) AncientSize(kind string) (uint64, error) {
149-
return 0, nil
150-
}
151-
152-
func (s *stubDatabase) Ancients() (uint64, error) {
153-
return 0, nil
154-
}
155-
156-
func (s *stubDatabase) Tail() (uint64, error) {
157-
return 0, nil
158-
}
159-
160-
func (s *stubDatabase) Get(key []byte) ([]byte, error) {
161-
return nil, nil
162-
}
163-
164-
func (s *stubDatabase) ReadAncients(fn func(ethdb.AncientReaderOp) error) error {
165-
return nil
166-
}
167-
168-
type stubIterator struct {
169-
ethdb.Iterator
170-
i int // see [stubIterator.pos]
171-
kvs []keyValue
172-
}
173-
174-
type keyValue struct {
175-
key []byte
176-
value []byte
177-
}
178-
179-
// pos returns the true iterator position, which is otherwise off by one because
180-
// Next() is called _before_ usage.
181-
func (s *stubIterator) pos() int {
182-
return s.i - 1
183-
}
184-
185-
func (s *stubIterator) Next() bool {
186-
s.i++
187-
return s.pos() < len(s.kvs)
188-
}
189-
190-
func (s *stubIterator) Release() {}
191-
192-
func (s *stubIterator) Key() []byte {
193-
return s.kvs[s.pos()].key
194-
}
195-
196-
func (s *stubIterator) Value() []byte {
197-
return s.kvs[s.pos()].value
19849
}

0 commit comments

Comments
 (0)