-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathsimulator_geth.go
56 lines (44 loc) · 1.55 KB
/
simulator_geth.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package sibyl
import (
"errors"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/consensus/ethash"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/rawdb"
"github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/eth/ethconfig"
"github.com/ethereum/go-ethereum/params"
)
// NewGethSimulator returns a new simulator that utilizes the go-ethereum LevelDB Database.
func NewGethSimulator(path string) (*Simulator, error) {
chainDb, err := rawdb.NewLevelDBDatabase(path, 48, 48, "", true)
if err != nil {
return nil, err
}
currentHead := rawdb.ReadHeadBlockHash(chainDb)
if currentHead == (common.Hash{}) {
return nil, errors.New("current head is nil, check db")
}
cfg := vm.Config{}
engine := ethash.New(ethash.Config{
CachesInMem: ethconfig.Defaults.Ethash.CachesInMem,
CachesOnDisk: ethconfig.Defaults.Ethash.CachesOnDisk,
CachesLockMmap: ethconfig.Defaults.Ethash.CachesLockMmap,
DatasetsInMem: ethconfig.Defaults.Ethash.DatasetsInMem,
DatasetsOnDisk: ethconfig.Defaults.Ethash.DatasetsOnDisk,
DatasetsLockMmap: ethconfig.Defaults.Ethash.DatasetsLockMmap,
}, nil, false)
cache := &core.CacheConfig{
TrieCleanLimit: ethconfig.Defaults.TrieCleanCache,
TrieDirtyLimit: ethconfig.Defaults.TrieDirtyCache,
TrieTimeLimit: ethconfig.Defaults.TrieTimeout,
SnapshotLimit: 0,
}
chain, err := core.NewBlockChain(
chainDb, cache, params.MainnetChainConfig, engine, cfg, nil, nil,
)
if err != nil {
return nil, err
}
return NewSimulator(chain), nil
}