diff --git a/core/blockchain.go b/core/blockchain.go index 19f9f7123..30aea5ab0 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -1,6 +1,7 @@ package core import ( + harmonyconfig "github.com/harmony-one/harmony/internal/configs/harmony" "math/big" "github.com/ethereum/go-ethereum/common" @@ -341,6 +342,8 @@ type BlockChain interface { RedisPreempt() *redis_helper.RedisPreempt // SyncFromTiKVWriter used for tikv mode, all reader or follower writer used to sync block from master writer SyncFromTiKVWriter(newBlkNum uint64, logs []*types.Log) error + // InitTiKV used for tikv mode, init the tikv mode + InitTiKV(conf *harmonyconfig.TiKVConfig) // ========== Only For Tikv End ========== } diff --git a/core/blockchain_impl.go b/core/blockchain_impl.go index 84ef26d83..cab5b2ee7 100644 --- a/core/blockchain_impl.go +++ b/core/blockchain_impl.go @@ -199,11 +199,11 @@ type BlockChainImpl struct { // NewBlockChainWithOptions same as NewBlockChain but can accept additional behaviour options. func NewBlockChainWithOptions( - db ethdb.Database, cacheConfig *CacheConfig, chainConfig *params.ChainConfig, + db ethdb.Database, stateCache state.Database, cacheConfig *CacheConfig, chainConfig *params.ChainConfig, engine consensus_engine.Engine, vmConfig vm.Config, shouldPreserve func(block *types.Block) bool, options Options, ) (*BlockChainImpl, error) { - return newBlockChainWithOptions(db, cacheConfig, chainConfig, engine, vmConfig, shouldPreserve, options) + return newBlockChainWithOptions(db, stateCache, cacheConfig, chainConfig, engine, vmConfig, shouldPreserve, options) } // NewBlockChain returns a fully initialised block chain using information @@ -214,11 +214,11 @@ func NewBlockChain( engine consensus_engine.Engine, vmConfig vm.Config, shouldPreserve func(block *types.Block) bool, ) (*BlockChainImpl, error) { - return newBlockChainWithOptions(db, cacheConfig, chainConfig, engine, vmConfig, shouldPreserve, Options{}) + return newBlockChainWithOptions(db, stateCache, cacheConfig, chainConfig, engine, vmConfig, shouldPreserve, Options{}) } func newBlockChainWithOptions( - db ethdb.Database, cacheConfig *CacheConfig, chainConfig *params.ChainConfig, + db ethdb.Database, stateCache state.Database, cacheConfig *CacheConfig, chainConfig *params.ChainConfig, engine consensus_engine.Engine, vmConfig vm.Config, shouldPreserve func(block *types.Block) bool, options Options) (*BlockChainImpl, error) { if cacheConfig == nil { diff --git a/core/blockchain_stub.go b/core/blockchain_stub.go index 388cfd713..85956bb0c 100644 --- a/core/blockchain_stub.go +++ b/core/blockchain_stub.go @@ -1,6 +1,8 @@ package core import ( + harmonyconfig "github.com/harmony-one/harmony/internal/configs/harmony" + "github.com/harmony-one/harmony/internal/tikv/redis_helper" "math/big" "github.com/ethereum/go-ethereum/common" @@ -400,3 +402,19 @@ func (a Stub) IsEnablePruneBeaconChainFeature() bool { func (a Stub) CommitOffChainData(batch rawdb.DatabaseWriter, block *types.Block, receipts []*types.Receipt, cxReceipts []*types.CXReceipt, stakeMsgs []staking.StakeMsg, payout reward.Reader, state *state.DB) (status WriteStatus, err error) { return 0, errors.Errorf("method CommitOffChainData not implemented for %s", a.Name) } + +func (a Stub) IsTikvWriterMaster() bool { + return false +} + +func (a Stub) RedisPreempt() *redis_helper.RedisPreempt { + return nil +} + +func (a Stub) SyncFromTiKVWriter(newBlkNum uint64, logs []*types.Log) error { + return errors.Errorf("method SyncFromTiKVWriter not implemented for %s", a.Name) +} + +func (a Stub) InitTiKV(conf *harmonyconfig.TiKVConfig) { + return +} diff --git a/internal/shardchain/shardchains.go b/internal/shardchain/shardchains.go index 9ad6f6cc8..15b4b1804 100644 --- a/internal/shardchain/shardchains.go +++ b/internal/shardchain/shardchains.go @@ -121,6 +121,9 @@ func (sc *CollectionImpl) ShardChain(shardID uint32, options ...core.Options) (c bc, err = core.NewEpochChain(db, &chainConfig, sc.engine, vm.Config{}) } else { stateCache, err := initStateCache(db, sc, shardID) + if err != nil { + return nil, err + } bc, err = core.NewBlockChainWithOptions( db, stateCache, cacheConfig, &chainConfig, sc.engine, vm.Config{}, nil, opts,