diff options
-rw-r--r-- | coreth.go | 7 | ||||
-rw-r--r-- | eth/backend.go | 13 | ||||
-rw-r--r-- | examples/chain/main.go | 2 |
3 files changed, 13 insertions, 9 deletions
@@ -14,6 +14,7 @@ import ( "github.com/ava-labs/go-ethereum/core/state" "github.com/ava-labs/go-ethereum/core/types" "github.com/ava-labs/go-ethereum/crypto" + "github.com/ava-labs/go-ethereum/ethdb" "github.com/ava-labs/go-ethereum/event" "github.com/ava-labs/go-ethereum/log" "github.com/ava-labs/go-ethereum/rpc" @@ -34,7 +35,7 @@ func isLocalBlock(block *types.Block) bool { return false } -func NewETHChain(config *eth.Config, nodecfg *node.Config, etherBase *common.Address) *ETHChain { +func NewETHChain(config *eth.Config, nodecfg *node.Config, etherBase *common.Address, chainDB ethdb.Database) *ETHChain { if config == nil { config = ð.DefaultConfig } @@ -47,11 +48,11 @@ func NewETHChain(config *eth.Config, nodecfg *node.Config, etherBase *common.Add panic(err) } if ep != "" { - log.Info(fmt.Sprintf("ephemeral = %s", ep)) + log.Info(fmt.Sprintf("temporary keystore = %s", ep)) } cb := new(dummy.ConsensusCallbacks) mcb := new(miner.MinerCallbacks) - backend, _ := eth.New(&ctx, config, cb, mcb) + backend, _ := eth.New(&ctx, config, cb, mcb, chainDB) chain := ÐChain{backend: backend, cb: cb, mcb: mcb} if etherBase == nil { etherBase = &common.Address{ diff --git a/eth/backend.go b/eth/backend.go index 4281d96..d119e89 100644 --- a/eth/backend.go +++ b/eth/backend.go @@ -119,7 +119,7 @@ func (s *Ethereum) SetContractBackend(backend bind.ContractBackend) { // New creates a new Ethereum object (including the // initialisation of the common Ethereum object) -func New(ctx *node.ServiceContext, config *Config, cb *dummy.ConsensusCallbacks, mcb *miner.MinerCallbacks) (*Ethereum, error) { +func New(ctx *node.ServiceContext, config *Config, cb *dummy.ConsensusCallbacks, mcb *miner.MinerCallbacks, chainDb ethdb.Database) (*Ethereum, error) { // Ensure configuration values are compatible and sane if config.SyncMode == downloader.LightSync { return nil, errors.New("can't run eth.Ethereum in light sync mode, use les.LightEthereum") @@ -137,10 +137,13 @@ func New(ctx *node.ServiceContext, config *Config, cb *dummy.ConsensusCallbacks, } log.Info("Allocated trie memory caches", "clean", common.StorageSize(config.TrieCleanCache)*1024*1024, "dirty", common.StorageSize(config.TrieDirtyCache)*1024*1024) - // Assemble the Ethereum object - chainDb, err := ctx.OpenDatabaseWithFreezer("chaindata", config.DatabaseCache, config.DatabaseHandles, config.DatabaseFreezer, "eth/db/chaindata/") - if err != nil { - return nil, err + var err error + if chainDb == nil { + // Assemble the Ethereum object + chainDb, err = ctx.OpenDatabaseWithFreezer("chaindata", config.DatabaseCache, config.DatabaseHandles, config.DatabaseFreezer, "eth/db/chaindata/") + if err != nil { + return nil, err + } } chainConfig, genesisHash, genesisErr := mycore.SetupGenesisBlock(chainDb, config.Genesis) if _, ok := genesisErr.(*params.ConfigCompatError); genesisErr != nil && !ok { diff --git a/examples/chain/main.go b/examples/chain/main.go index 92350d3..d129acb 100644 --- a/examples/chain/main.go +++ b/examples/chain/main.go @@ -47,7 +47,7 @@ func NewTestChain(name string, config *eth.Config, hasBlock: make(map[common.Hash]struct{}), blocks: make([]common.Hash, 0), blkCount: 0, - chain: coreth.NewETHChain(config, nil, nil), + chain: coreth.NewETHChain(config, nil, nil, nil), outBlockCh: outBlockCh, } tc.insertBlock(tc.chain.GetGenesisBlock()) |