@@ -14,22 +14,18 @@ import (
14
14
"testing"
15
15
"time"
16
16
17
- "github.com/prometheus/client_golang/prometheus"
18
17
"github.com/stretchr/testify/require"
19
18
20
19
"github.com/ava-labs/avalanchego/database"
21
20
"github.com/ava-labs/avalanchego/database/dbtest"
22
21
"github.com/ava-labs/avalanchego/database/memdb"
23
22
"github.com/ava-labs/avalanchego/ids"
24
- "github.com/ava-labs/avalanchego/trace"
25
23
"github.com/ava-labs/avalanchego/utils/hashing"
26
24
"github.com/ava-labs/avalanchego/utils/maybe"
27
25
"github.com/ava-labs/avalanchego/utils/set"
28
26
"github.com/ava-labs/avalanchego/utils/units"
29
27
)
30
28
31
- const defaultHistoryLength = 300
32
-
33
29
// newDB returns a new merkle database with the underlying type so that tests can access unexported fields
34
30
func newDB (ctx context.Context , db database.Database , config Config ) (* merkleDB , error ) {
35
31
db , err := New (ctx , db , config )
@@ -39,22 +35,6 @@ func newDB(ctx context.Context, db database.Database, config Config) (*merkleDB,
39
35
return db .(* merkleDB ), nil
40
36
}
41
37
42
- func newDefaultConfig () Config {
43
- return Config {
44
- BranchFactor : BranchFactor16 ,
45
- Hasher : DefaultHasher ,
46
- RootGenConcurrency : 0 ,
47
- HistoryLength : defaultHistoryLength ,
48
- ValueNodeCacheSize : units .MiB ,
49
- IntermediateNodeCacheSize : units .MiB ,
50
- IntermediateWriteBufferSize : units .KiB ,
51
- IntermediateWriteBatchSize : 256 * units .KiB ,
52
- Reg : prometheus .NewRegistry (),
53
- TraceLevel : InfoTrace ,
54
- Tracer : trace .Noop ,
55
- }
56
- }
57
-
58
38
func Test_MerkleDB_Get_Safety (t * testing.T ) {
59
39
require := require .New (t )
60
40
@@ -134,7 +114,7 @@ func Test_MerkleDB_DB_Load_Root_From_DB(t *testing.T) {
134
114
db , err := New (
135
115
context .Background (),
136
116
baseDB ,
137
- newDefaultConfig (),
117
+ NewConfig (),
138
118
)
139
119
require .NoError (err )
140
120
@@ -162,7 +142,7 @@ func Test_MerkleDB_DB_Load_Root_From_DB(t *testing.T) {
162
142
db , err = New (
163
143
context .Background (),
164
144
baseDB ,
165
- newDefaultConfig (),
145
+ NewConfig (),
166
146
)
167
147
require .NoError (err )
168
148
@@ -176,7 +156,7 @@ func Test_MerkleDB_DB_Rebuild(t *testing.T) {
176
156
177
157
initialSize := 5_000
178
158
179
- config := newDefaultConfig ()
159
+ config := NewConfig ()
180
160
config .ValueNodeCacheSize = uint (initialSize )
181
161
config .IntermediateNodeCacheSize = uint (initialSize )
182
162
@@ -233,7 +213,7 @@ func Test_MerkleDB_Failed_Batch_Commit(t *testing.T) {
233
213
db , err := New (
234
214
context .Background (),
235
215
memDB ,
236
- newDefaultConfig (),
216
+ NewConfig (),
237
217
)
238
218
require .NoError (err )
239
219
@@ -254,7 +234,7 @@ func Test_MerkleDB_Value_Cache(t *testing.T) {
254
234
db , err := New (
255
235
context .Background (),
256
236
memDB ,
257
- newDefaultConfig (),
237
+ NewConfig (),
258
238
)
259
239
require .NoError (err )
260
240
@@ -903,13 +883,17 @@ const (
903
883
)
904
884
905
885
func runRandDBTest (require * require.Assertions , r * rand.Rand , rt randTest , tokenSize int ) {
906
- db , err := getBasicDBWithBranchFactor (tokenSizeToBranchFactor [tokenSize ])
886
+ config := NewConfig ()
887
+ config .BranchFactor = tokenSizeToBranchFactor [tokenSize ]
888
+ db , err := New (
889
+ context .Background (),
890
+ memdb .New (),
891
+ config ,
892
+ )
907
893
require .NoError (err )
908
894
909
- const (
910
- maxProofLen = 100
911
- maxPastRoots = defaultHistoryLength
912
- )
895
+ maxProofLen := 100
896
+ maxPastRoots := int (config .HistoryLength )
913
897
914
898
var (
915
899
values = make (map [Key ][]byte ) // tracks content of the trie
@@ -966,7 +950,7 @@ func runRandDBTest(require *require.Assertions, r *rand.Rand, rt randTest, token
966
950
end ,
967
951
root ,
968
952
tokenSize ,
969
- db . hasher ,
953
+ config . Hasher ,
970
954
))
971
955
case opGenerateChangeProof :
972
956
root , err := db .GetMerkleRoot (context .Background ())
@@ -1301,7 +1285,7 @@ func TestCrashRecovery(t *testing.T) {
1301
1285
merkleDB , err := newDatabase (
1302
1286
context .Background (),
1303
1287
baseDB ,
1304
- newDefaultConfig (),
1288
+ NewConfig (),
1305
1289
& mockMetrics {},
1306
1290
)
1307
1291
require .NoError (err )
@@ -1319,7 +1303,7 @@ func TestCrashRecovery(t *testing.T) {
1319
1303
newMerkleDB , err := newDatabase (
1320
1304
context .Background (),
1321
1305
baseDB ,
1322
- newDefaultConfig (),
1306
+ NewConfig (),
1323
1307
& mockMetrics {},
1324
1308
)
1325
1309
require .NoError (err )
0 commit comments