pull/4149/head
Lutty 2 years ago
parent 2ec4ccf9ee
commit 21bd53938d
  1. 3
      core/blockchain.go
  2. 8
      core/blockchain_impl.go
  3. 18
      core/blockchain_stub.go
  4. 3
      internal/shardchain/shardchains.go

@ -1,6 +1,7 @@
package core package core
import ( import (
harmonyconfig "github.com/harmony-one/harmony/internal/configs/harmony"
"math/big" "math/big"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
@ -341,6 +342,8 @@ type BlockChain interface {
RedisPreempt() *redis_helper.RedisPreempt RedisPreempt() *redis_helper.RedisPreempt
// SyncFromTiKVWriter used for tikv mode, all reader or follower writer used to sync block from master writer // SyncFromTiKVWriter used for tikv mode, all reader or follower writer used to sync block from master writer
SyncFromTiKVWriter(newBlkNum uint64, logs []*types.Log) error SyncFromTiKVWriter(newBlkNum uint64, logs []*types.Log) error
// InitTiKV used for tikv mode, init the tikv mode
InitTiKV(conf *harmonyconfig.TiKVConfig)
// ========== Only For Tikv End ========== // ========== Only For Tikv End ==========
} }

@ -199,11 +199,11 @@ type BlockChainImpl struct {
// NewBlockChainWithOptions same as NewBlockChain but can accept additional behaviour options. // NewBlockChainWithOptions same as NewBlockChain but can accept additional behaviour options.
func NewBlockChainWithOptions( 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, engine consensus_engine.Engine, vmConfig vm.Config,
shouldPreserve func(block *types.Block) bool, options Options, shouldPreserve func(block *types.Block) bool, options Options,
) (*BlockChainImpl, error) { ) (*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 // NewBlockChain returns a fully initialised block chain using information
@ -214,11 +214,11 @@ func NewBlockChain(
engine consensus_engine.Engine, vmConfig vm.Config, engine consensus_engine.Engine, vmConfig vm.Config,
shouldPreserve func(block *types.Block) bool, shouldPreserve func(block *types.Block) bool,
) (*BlockChainImpl, error) { ) (*BlockChainImpl, error) {
return newBlockChainWithOptions(db, cacheConfig, chainConfig, engine, vmConfig, shouldPreserve, Options{}) return newBlockChainWithOptions(db, stateCache, cacheConfig, chainConfig, engine, vmConfig, shouldPreserve, Options{})
} }
func newBlockChainWithOptions( 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, engine consensus_engine.Engine, vmConfig vm.Config,
shouldPreserve func(block *types.Block) bool, options Options) (*BlockChainImpl, error) { shouldPreserve func(block *types.Block) bool, options Options) (*BlockChainImpl, error) {
if cacheConfig == nil { if cacheConfig == nil {

@ -1,6 +1,8 @@
package core package core
import ( import (
harmonyconfig "github.com/harmony-one/harmony/internal/configs/harmony"
"github.com/harmony-one/harmony/internal/tikv/redis_helper"
"math/big" "math/big"
"github.com/ethereum/go-ethereum/common" "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) { 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) 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
}

@ -121,6 +121,9 @@ func (sc *CollectionImpl) ShardChain(shardID uint32, options ...core.Options) (c
bc, err = core.NewEpochChain(db, &chainConfig, sc.engine, vm.Config{}) bc, err = core.NewEpochChain(db, &chainConfig, sc.engine, vm.Config{})
} else { } else {
stateCache, err := initStateCache(db, sc, shardID) stateCache, err := initStateCache(db, sc, shardID)
if err != nil {
return nil, err
}
bc, err = core.NewBlockChainWithOptions( bc, err = core.NewBlockChainWithOptions(
db, stateCache, cacheConfig, &chainConfig, sc.engine, vm.Config{}, nil, opts, db, stateCache, cacheConfig, &chainConfig, sc.engine, vm.Config{}, nil, opts,

Loading…
Cancel
Save