Removed engine dependency.

pull/4389/head
frozen 2 years ago committed by Casey Gardiner
parent 47386c06a5
commit 8c2ff803f7
  1. 4
      api/service/legacysync/syncing.go
  2. 1
      api/service/stagedstreamsync/adapter.go
  3. 4
      api/service/stagedstreamsync/sig_verify.go
  4. 2
      api/service/stagedsync/stage_state.go
  5. 4
      api/service/stagedsync/stagedsync.go
  6. 5
      block/header.go
  7. 7
      cmd/harmony/main.go
  8. 7
      consensus/engine/errors.go
  9. 2
      consensus/validator.go
  10. 16
      core/block_validator.go
  11. 2
      core/blockchain.go
  12. 30
      core/blockchain_impl.go
  13. 10
      core/epochchain.go
  14. 2
      core/epochchain_test.go
  15. 4
      core/evm.go
  16. 4
      core/evm_test.go
  17. 10
      core/headerchain.go
  18. 18
      core/state_processor.go
  19. 5
      core/tx_pool_test.go
  20. 1
      hmy/downloader/adapter.go
  21. 4
      hmy/downloader/downloader.go
  22. 7
      hmy/tracer.go
  23. 8
      internal/chain/engine.go
  24. 11
      internal/shardchain/shardchains.go
  25. 4
      node/node.go
  26. 3
      node/node_cross_link.go
  27. 17
      node/node_handler_test.go
  28. 6
      node/node_newblock_test.go
  29. 6
      node/node_test.go
  30. 8
      node/worker/worker.go
  31. 11
      node/worker/worker_test.go
  32. 13
      test/chain/chain/chain_makers.go
  33. 6
      test/chain/main.go
  34. 4
      test/chain/reward/main.go

@ -880,12 +880,12 @@ func (ss *StateSync) UpdateBlockAndStatus(block *types.Block, bc core.BlockChain
} }
startTime := time.Now() startTime := time.Now()
if err := bc.Engine().VerifyHeaderSignature(bc, block.Header(), sig, bitmap); err != nil { if err := chain.Engine().VerifyHeaderSignature(bc, block.Header(), sig, bitmap); err != nil {
return errors.Wrapf(err, "verify header signature %v", block.Hash().String()) return errors.Wrapf(err, "verify header signature %v", block.Hash().String())
} }
utils.Logger().Debug().Int64("elapsed time", time.Now().Sub(startTime).Milliseconds()).Msg("[Sync] VerifyHeaderSignature") utils.Logger().Debug().Int64("elapsed time", time.Now().Sub(startTime).Milliseconds()).Msg("[Sync] VerifyHeaderSignature")
} }
err := bc.Engine().VerifyHeader(bc, block.Header(), verifySeal) err := chain.Engine().VerifyHeader(bc, block.Header(), verifySeal)
if err == engine.ErrUnknownAncestor { if err == engine.ErrUnknownAncestor {
return err return err
} else if err != nil { } else if err != nil {

@ -27,7 +27,6 @@ type syncProtocol interface {
type blockChain interface { type blockChain interface {
engine.ChainReader engine.ChainReader
Engine() engine.Engine
InsertChain(chain types.Blocks, verifyHeaders bool) (int, error) InsertChain(chain types.Blocks, verifyHeaders bool) (int, error)
WriteCommitSig(blockNum uint64, lastCommits []byte) error WriteCommitSig(blockNum uint64, lastCommits []byte) error

@ -47,10 +47,10 @@ func verifyAndInsertBlock(bc blockChain, block *types.Block, nextBlocks ...*type
} }
} }
if err := bc.Engine().VerifyHeaderSignature(bc, block.Header(), sigBytes, bitmap); err != nil { if err := chain.Engine().VerifyHeaderSignature(bc, block.Header(), sigBytes, bitmap); err != nil {
return &sigVerifyErr{err} return &sigVerifyErr{err}
} }
if err := bc.Engine().VerifyHeader(bc, block.Header(), true); err != nil { if err := chain.Engine().VerifyHeader(bc, block.Header(), true); err != nil {
return errors.Wrap(err, "[VerifyHeader]") return errors.Wrap(err, "[VerifyHeader]")
} }
if _, err := bc.InsertChain(types.Blocks{block}, false); err != nil { if _, err := bc.InsertChain(types.Blocks{block}, false); err != nil {

@ -250,7 +250,7 @@ func (stg *StageStates) verifyBlockSignatures(bc core.BlockChain, block *types.B
} }
startTime := time.Now() startTime := time.Now()
if err := bc.Engine().VerifyHeaderSignature(bc, block.Header(), sig, bitmap); err != nil { if err := chain.Engine().VerifyHeaderSignature(bc, block.Header(), sig, bitmap); err != nil {
return errors.Wrapf(err, "verify header signature %v", block.Hash().String()) return errors.Wrapf(err, "verify header signature %v", block.Hash().String())
} }
utils.Logger().Debug(). utils.Logger().Debug().

@ -1052,14 +1052,14 @@ func (ss *StagedSync) UpdateBlockAndStatus(block *types.Block, bc core.BlockChai
} }
startTime := time.Now() startTime := time.Now()
if err := bc.Engine().VerifyHeaderSignature(bc, block.Header(), sig, bitmap); err != nil { if err := chain.Engine().VerifyHeaderSignature(bc, block.Header(), sig, bitmap); err != nil {
return errors.Wrapf(err, "verify header signature %v", block.Hash().String()) return errors.Wrapf(err, "verify header signature %v", block.Hash().String())
} }
utils.Logger().Debug(). utils.Logger().Debug().
Int64("elapsed time", time.Now().Sub(startTime).Milliseconds()). Int64("elapsed time", time.Now().Sub(startTime).Milliseconds()).
Msg("[STAGED_SYNC] VerifyHeaderSignature") Msg("[STAGED_SYNC] VerifyHeaderSignature")
} }
err := bc.Engine().VerifyHeader(bc, block.Header(), verifySeal) err := chain.Engine().VerifyHeader(bc, block.Header(), verifySeal)
if err == engine.ErrUnknownAncestor { if err == engine.ErrUnknownAncestor {
return err return err
} else if err != nil { } else if err != nil {

@ -153,6 +153,11 @@ func (h *Header) IsLastBlockInEpoch() bool {
return len(h.ShardState()) > 0 return len(h.ShardState()) > 0
} }
// NumberU64 returns the block number in uint64.
func (h Header) NumberU64() uint64 {
return h.Number().Uint64()
}
// HeaderRegistry is the taggedrlp type registry for versioned headers. // HeaderRegistry is the taggedrlp type registry for versioned headers.
var HeaderRegistry = taggedrlp.NewRegistry() var HeaderRegistry = taggedrlp.NewRegistry()

@ -16,7 +16,6 @@ import (
"time" "time"
"github.com/harmony-one/harmony/consensus/quorum" "github.com/harmony-one/harmony/consensus/quorum"
"github.com/harmony-one/harmony/internal/chain"
"github.com/harmony-one/harmony/internal/registry" "github.com/harmony-one/harmony/internal/registry"
"github.com/harmony-one/harmony/internal/shardchain/tikv_manage" "github.com/harmony-one/harmony/internal/shardchain/tikv_manage"
"github.com/harmony-one/harmony/internal/tikv/redis_helper" "github.com/harmony-one/harmony/internal/tikv/redis_helper"
@ -701,11 +700,9 @@ func setupConsensusAndNode(hc harmonyconfig.HarmonyConfig, nodeConfig *nodeconfi
chainDBFactory = &shardchain.LDBFactory{RootDir: nodeConfig.DBDir} chainDBFactory = &shardchain.LDBFactory{RootDir: nodeConfig.DBDir}
} }
engine := chain.NewEngine()
chainConfig := nodeConfig.GetNetworkType().ChainConfig() chainConfig := nodeConfig.GetNetworkType().ChainConfig()
collection := shardchain.NewCollection( collection := shardchain.NewCollection(
&hc, chainDBFactory, &core.GenesisInitializer{NetworkType: nodeConfig.GetNetworkType()}, engine, &chainConfig, &hc, chainDBFactory, &core.GenesisInitializer{NetworkType: nodeConfig.GetNetworkType()}, &chainConfig,
) )
for shardID, archival := range nodeConfig.ArchiveModes() { for shardID, archival := range nodeConfig.ArchiveModes() {
if archival { if archival {
@ -740,7 +737,7 @@ func setupConsensusAndNode(hc harmonyconfig.HarmonyConfig, nodeConfig *nodeconfi
os.Exit(1) os.Exit(1)
} }
currentNode := node.New(myHost, currentConsensus, engine, collection, blacklist, allowedTxs, localAccounts, nodeConfig.ArchiveModes(), &hc, registry) currentNode := node.New(myHost, currentConsensus, collection, blacklist, allowedTxs, localAccounts, nodeConfig.ArchiveModes(), &hc, registry)
if hc.Legacy != nil && hc.Legacy.TPBroadcastInvalidTxn != nil { if hc.Legacy != nil && hc.Legacy.TPBroadcastInvalidTxn != nil {
currentNode.BroadcastInvalidTx = *hc.Legacy.TPBroadcastInvalidTxn currentNode.BroadcastInvalidTx = *hc.Legacy.TPBroadcastInvalidTxn

@ -31,13 +31,6 @@ var (
// to the current node. // to the current node.
ErrFutureBlock = errors.New("block in the future") ErrFutureBlock = errors.New("block in the future")
// ErrInvalidNumber is returned if a block's number doesn't equal it's parent's
// plus one.
ErrInvalidNumber = errors.New("invalid block number")
// ErrViewIDNotMatch is returned if the current viewID is not equal message's viewID // ErrViewIDNotMatch is returned if the current viewID is not equal message's viewID
ErrViewIDNotMatch = errors.New("viewID not match") ErrViewIDNotMatch = errors.New("viewID not match")
// ErrInvalidConsensusMessage is returned is the consensus message received is invalid
ErrInvalidConsensusMessage = errors.New("invalid consensus message")
) )

@ -331,7 +331,7 @@ func (consensus *Consensus) onCommitted(recvMsg *FBFTMessage) {
Msg("[OnCommitted] Failed to parse commit sigBytes and bitmap") Msg("[OnCommitted] Failed to parse commit sigBytes and bitmap")
return return
} }
if err := consensus.Blockchain().Engine().VerifyHeaderSignature(consensus.Blockchain(), blockObj.Header(), if err := chain.Engine().VerifyHeaderSignature(consensus.Blockchain(), blockObj.Header(),
sigBytes, bitmap); err != nil { sigBytes, bitmap); err != nil {
consensus.getLogger().Error(). consensus.getLogger().Error().
Uint64("blockNum", recvMsg.BlockNum). Uint64("blockNum", recvMsg.BlockNum).

@ -26,6 +26,8 @@ import (
"github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/rlp" "github.com/ethereum/go-ethereum/rlp"
"github.com/harmony-one/harmony/block" "github.com/harmony-one/harmony/block"
"github.com/harmony-one/harmony/internal/chain"
chain2 "github.com/harmony-one/harmony/internal/chain"
"github.com/pkg/errors" "github.com/pkg/errors"
consensus_engine "github.com/harmony-one/harmony/consensus/engine" consensus_engine "github.com/harmony-one/harmony/consensus/engine"
@ -40,16 +42,14 @@ import (
// //
// BlockValidator implements validator. // BlockValidator implements validator.
type BlockValidator struct { type BlockValidator struct {
config *params.ChainConfig // Chain configuration options config *params.ChainConfig // Chain configuration options
bc BlockChain // Canonical blockchain bc BlockChain // Canonical blockchain
engine consensus_engine.Engine // Consensus engine used for validating
} }
// NewBlockValidator returns a new block validator which is safe for re-use // NewBlockValidator returns a new block validator which is safe for re-use
func NewBlockValidator(config *params.ChainConfig, blockchain BlockChain, engine consensus_engine.Engine) *BlockValidator { func NewBlockValidator(config *params.ChainConfig, blockchain BlockChain) *BlockValidator {
validator := &BlockValidator{ validator := &BlockValidator{
config: config, config: config,
engine: engine,
bc: blockchain, bc: blockchain,
} }
return validator return validator
@ -131,7 +131,7 @@ func (v *BlockValidator) ValidateHeader(block *types.Block, seal bool) error {
return errors.New("block is nil") return errors.New("block is nil")
} }
if h := block.Header(); h != nil { if h := block.Header(); h != nil {
return v.engine.VerifyHeader(v.bc, h, true) return chain.Engine().VerifyHeader(v.bc, h, true)
} }
return errors.New("header field was nil") return errors.New("header field was nil")
} }
@ -147,7 +147,7 @@ func (v *BlockValidator) ValidateHeaders(chain []*types.Block) (chan<- struct{},
headers[i] = block.Header() headers[i] = block.Header()
seals[i] = true seals[i] = true
} }
return v.engine.VerifyHeaders(v.bc, headers, seals) return chain2.Engine().VerifyHeaders(v.bc, headers, seals)
} }
// CalcGasLimit computes the gas limit of the next block after parent. It aims // CalcGasLimit computes the gas limit of the next block after parent. It aims
@ -249,5 +249,5 @@ func (v *BlockValidator) ValidateCXReceiptsProof(cxp *types.CXReceiptsProof) err
// (4) verify blockHeader with seal // (4) verify blockHeader with seal
var commitSig bls.SerializedSignature var commitSig bls.SerializedSignature
copy(commitSig[:], cxp.CommitSig) copy(commitSig[:], cxp.CommitSig)
return v.engine.VerifyHeaderSignature(v.bc, cxp.Header, commitSig, cxp.CommitBitmap) return chain.Engine().VerifyHeaderSignature(v.bc, cxp.Header, commitSig, cxp.CommitBitmap)
} }

@ -126,8 +126,6 @@ type BlockChain interface {
GetHeaderByNumber(number uint64) *block.Header GetHeaderByNumber(number uint64) *block.Header
// Config retrieves the blockchain's chain configuration. // Config retrieves the blockchain's chain configuration.
Config() *params.ChainConfig Config() *params.ChainConfig
// Engine retrieves the blockchain's consensus engine.
Engine() engine.Engine
// SubscribeRemovedLogsEvent registers a subscription of RemovedLogsEvent. // SubscribeRemovedLogsEvent registers a subscription of RemovedLogsEvent.
SubscribeRemovedLogsEvent(ch chan<- RemovedLogsEvent) event.Subscription SubscribeRemovedLogsEvent(ch chan<- RemovedLogsEvent) event.Subscription
// SubscribeTraceEvent registers a subscription of ChainEvent. // SubscribeTraceEvent registers a subscription of ChainEvent.

@ -49,6 +49,8 @@ import (
"github.com/harmony-one/harmony/core/types" "github.com/harmony-one/harmony/core/types"
"github.com/harmony-one/harmony/core/vm" "github.com/harmony-one/harmony/core/vm"
"github.com/harmony-one/harmony/crypto/bls" "github.com/harmony-one/harmony/crypto/bls"
"github.com/harmony-one/harmony/internal/chain"
chain2 "github.com/harmony-one/harmony/internal/chain"
harmonyconfig "github.com/harmony-one/harmony/internal/configs/harmony" harmonyconfig "github.com/harmony-one/harmony/internal/configs/harmony"
"github.com/harmony-one/harmony/internal/params" "github.com/harmony-one/harmony/internal/params"
"github.com/harmony-one/harmony/internal/tikv" "github.com/harmony-one/harmony/internal/tikv"
@ -190,7 +192,6 @@ type BlockChainImpl struct {
// procInterrupt must be atomically called // procInterrupt must be atomically called
procInterrupt int32 // interrupt signaler for block processing procInterrupt int32 // interrupt signaler for block processing
engine consensus_engine.Engine
processor Processor // block processor interface processor Processor // block processor interface
validator Validator // block and state validator interface validator Validator // block and state validator interface
vmConfig vm.Config vmConfig vm.Config
@ -204,9 +205,9 @@ 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, stateCache state.Database, beaconChain BlockChain, cacheConfig *CacheConfig, chainConfig *params.ChainConfig, db ethdb.Database, stateCache state.Database, beaconChain BlockChain, cacheConfig *CacheConfig, chainConfig *params.ChainConfig,
engine consensus_engine.Engine, vmConfig vm.Config, options Options, vmConfig vm.Config, options Options,
) (*BlockChainImpl, error) { ) (*BlockChainImpl, error) {
return newBlockChainWithOptions(db, stateCache, beaconChain, cacheConfig, chainConfig, engine, vmConfig, options) return newBlockChainWithOptions(db, stateCache, beaconChain, cacheConfig, chainConfig, vmConfig, options)
} }
// NewBlockChain returns a fully initialised block chain using information // NewBlockChain returns a fully initialised block chain using information
@ -214,15 +215,15 @@ func NewBlockChainWithOptions(
// Processor. // Processor.
func NewBlockChain( func NewBlockChain(
db ethdb.Database, stateCache state.Database, beaconChain BlockChain, cacheConfig *CacheConfig, chainConfig *params.ChainConfig, db ethdb.Database, stateCache state.Database, beaconChain BlockChain, cacheConfig *CacheConfig, chainConfig *params.ChainConfig,
engine consensus_engine.Engine, vmConfig vm.Config, vmConfig vm.Config,
) (*BlockChainImpl, error) { ) (*BlockChainImpl, error) {
return newBlockChainWithOptions(db, stateCache, beaconChain, cacheConfig, chainConfig, engine, vmConfig, Options{}) return newBlockChainWithOptions(db, stateCache, beaconChain, cacheConfig, chainConfig, vmConfig, Options{})
} }
func newBlockChainWithOptions( func newBlockChainWithOptions(
db ethdb.Database, stateCache state.Database, beaconChain BlockChain, db ethdb.Database, stateCache state.Database, beaconChain BlockChain,
cacheConfig *CacheConfig, chainConfig *params.ChainConfig, cacheConfig *CacheConfig, chainConfig *params.ChainConfig,
engine consensus_engine.Engine, vmConfig vm.Config, options Options) (*BlockChainImpl, error) { vmConfig vm.Config, options Options) (*BlockChainImpl, error) {
bodyCache, _ := lru.New(bodyCacheLimit) bodyCache, _ := lru.New(bodyCacheLimit)
bodyRLPCache, _ := lru.New(bodyCacheLimit) bodyRLPCache, _ := lru.New(bodyCacheLimit)
@ -266,7 +267,6 @@ func newBlockChainWithOptions(
blockAccumulatorCache: blockAccumulatorCache, blockAccumulatorCache: blockAccumulatorCache,
leaderPubKeyFromCoinbase: leaderPubKeyFromCoinbase, leaderPubKeyFromCoinbase: leaderPubKeyFromCoinbase,
blockchainPruner: newBlockchainPruner(db), blockchainPruner: newBlockchainPruner(db),
engine: engine,
vmConfig: vmConfig, vmConfig: vmConfig,
badBlocks: badBlocks, badBlocks: badBlocks,
pendingSlashes: slash.Records{}, pendingSlashes: slash.Records{},
@ -275,7 +275,7 @@ func newBlockChainWithOptions(
} }
var err error var err error
bc.hc, err = NewHeaderChain(db, chainConfig, engine, bc.getProcInterrupt) bc.hc, err = NewHeaderChain(db, chainConfig, bc.getProcInterrupt)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -294,8 +294,8 @@ func newBlockChainWithOptions(
beaconChain = bc beaconChain = bc
} }
bc.SetValidator(NewBlockValidator(chainConfig, bc, engine)) bc.SetValidator(NewBlockValidator(chainConfig, bc))
bc.SetProcessor(NewStateProcessor(chainConfig, bc, beaconChain, engine)) bc.SetProcessor(NewStateProcessor(chainConfig, bc, beaconChain))
// Take ownership of this particular state // Take ownership of this particular state
go bc.update() go bc.update()
@ -353,7 +353,7 @@ func VerifyCrossLink(blockchain BlockChain, cl types.CrossLink) error {
if blockchain.ShardID() != shard.BeaconChainShardID { if blockchain.ShardID() != shard.BeaconChainShardID {
return errors.New("[VerifyCrossLink] Shard chains should not verify cross links") return errors.New("[VerifyCrossLink] Shard chains should not verify cross links")
} }
engine := blockchain.Engine() engine := chain.Engine()
if err := engine.VerifyCrossLink(blockchain, cl); err != nil { if err := engine.VerifyCrossLink(blockchain, cl); err != nil {
return errors.Wrap(err, "[VerifyCrossLink]") return errors.Wrap(err, "[VerifyCrossLink]")
@ -424,7 +424,7 @@ func (bc *BlockChainImpl) ValidateNewBlock(block *types.Block, beaconChain Block
Msg("[ValidateNewBlock] Cannot validate header for the new block") Msg("[ValidateNewBlock] Cannot validate header for the new block")
return err return err
} }
if err := bc.Engine().VerifyVRF( if err := chain.Engine().VerifyVRF(
bc, block.Header(), bc, block.Header(),
); err != nil { ); err != nil {
utils.Logger().Error(). utils.Logger().Error().
@ -436,7 +436,7 @@ func (bc *BlockChainImpl) ValidateNewBlock(block *types.Block, beaconChain Block
"[ValidateNewBlock] Cannot verify vrf for the new block", "[ValidateNewBlock] Cannot verify vrf for the new block",
) )
} }
err := bc.Engine().VerifyShardState(bc, beaconChain, block.Header()) err := chain.Engine().VerifyShardState(bc, beaconChain, block.Header())
if err != nil { if err != nil {
utils.Logger().Error(). utils.Logger().Error().
Str("blockHash", block.Hash().Hex()). Str("blockHash", block.Hash().Hex()).
@ -1577,7 +1577,7 @@ func (bc *BlockChainImpl) insertChain(chain types.Blocks, verifyHeaders bool) (i
seals[i] = true seals[i] = true
} }
// Note that VerifyHeaders verifies headers in the chain in parallel // Note that VerifyHeaders verifies headers in the chain in parallel
abort, results := bc.Engine().VerifyHeaders(bc, headers, seals) abort, results := chain2.Engine().VerifyHeaders(bc, headers, seals)
verifyHeadersResults = results verifyHeadersResults = results
defer close(abort) defer close(abort)
} }
@ -2045,8 +2045,6 @@ func (bc *BlockChainImpl) GetHeaderByNumber(number uint64) *block.Header {
func (bc *BlockChainImpl) Config() *params.ChainConfig { return bc.chainConfig } func (bc *BlockChainImpl) Config() *params.ChainConfig { return bc.chainConfig }
func (bc *BlockChainImpl) Engine() consensus_engine.Engine { return bc.engine }
func (bc *BlockChainImpl) SubscribeRemovedLogsEvent(ch chan<- RemovedLogsEvent) event.Subscription { func (bc *BlockChainImpl) SubscribeRemovedLogsEvent(ch chan<- RemovedLogsEvent) event.Subscription {
return bc.scope.Track(bc.rmLogsFeed.Subscribe(ch)) return bc.scope.Track(bc.rmLogsFeed.Subscribe(ch))
} }

@ -8,8 +8,6 @@ import (
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/ethdb" "github.com/ethereum/go-ethereum/ethdb"
"github.com/harmony-one/harmony/block" "github.com/harmony-one/harmony/block"
"github.com/harmony-one/harmony/consensus/engine"
consensus_engine "github.com/harmony-one/harmony/consensus/engine"
"github.com/harmony-one/harmony/core/rawdb" "github.com/harmony-one/harmony/core/rawdb"
"github.com/harmony-one/harmony/core/types" "github.com/harmony-one/harmony/core/types"
"github.com/harmony-one/harmony/core/vm" "github.com/harmony-one/harmony/core/vm"
@ -29,7 +27,6 @@ type EpochChain struct {
db ethdb.Database // Low level persistent database to store final content in. db ethdb.Database // Low level persistent database to store final content in.
mu chan struct{} mu chan struct{}
currentHeader atomic.Value // Current head of the blockchain. currentHeader atomic.Value // Current head of the blockchain.
engine consensus_engine.Engine
vmConfig *vm.Config vmConfig *vm.Config
headerCache *lru.Cache // Cache for the most recent block headers headerCache *lru.Cache // Cache for the most recent block headers
@ -46,7 +43,7 @@ func cache(size int) *lru.Cache {
} }
func NewEpochChain(db ethdb.Database, chainConfig *params.ChainConfig, func NewEpochChain(db ethdb.Database, chainConfig *params.ChainConfig,
engine consensus_engine.Engine, vmConfig vm.Config) (*EpochChain, error) { vmConfig vm.Config) (*EpochChain, error) {
hash := rawdb.ReadCanonicalHash(db, 0) hash := rawdb.ReadCanonicalHash(db, 0)
genesisBlock := rawdb.ReadBlock(db, hash, 0) genesisBlock := rawdb.ReadBlock(db, hash, 0)
@ -60,7 +57,6 @@ func NewEpochChain(db ethdb.Database, chainConfig *params.ChainConfig,
db: db, db: db,
mu: make(chan struct{}, 1), mu: make(chan struct{}, 1),
currentHeader: atomic.Value{}, currentHeader: atomic.Value{},
engine: engine,
vmConfig: &vmConfig, vmConfig: &vmConfig,
headerCache: cache(headerCacheLimit), headerCache: cache(headerCacheLimit),
@ -242,10 +238,6 @@ func (bc *EpochChain) Config() *params.ChainConfig {
return bc.chainConfig return bc.chainConfig
} }
func (bc *EpochChain) Engine() engine.Engine {
return bc.engine
}
func (bc *EpochChain) ReadShardState(epoch *big.Int) (*shard.State, error) { func (bc *EpochChain) ReadShardState(epoch *big.Int) (*shard.State, error) {
cacheKey := string(epoch.Bytes()) cacheKey := string(epoch.Bytes())
if cached, ok := bc.shardStateCache.Get(cacheKey); ok { if cached, ok := bc.shardStateCache.Get(cacheKey); ok {

@ -15,7 +15,7 @@ func TestGenesisBlock(t *testing.T) {
err := (&core.GenesisInitializer{NetworkType: nodeconfig.Mainnet}).InitChainDB(db, 0) err := (&core.GenesisInitializer{NetworkType: nodeconfig.Mainnet}).InitChainDB(db, 0)
require.NoError(t, err) require.NoError(t, err)
chain, err := core.NewEpochChain(db, nil, nil, vm.Config{}) chain, err := core.NewEpochChain(db, nil, vm.Config{})
require.NoError(t, err) require.NoError(t, err)
header := chain.GetHeaderByNumber(0) header := chain.GetHeaderByNumber(0)

@ -26,7 +26,6 @@ import (
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/rlp" "github.com/ethereum/go-ethereum/rlp"
"github.com/harmony-one/harmony/block" "github.com/harmony-one/harmony/block"
consensus_engine "github.com/harmony-one/harmony/consensus/engine"
"github.com/harmony-one/harmony/core/types" "github.com/harmony-one/harmony/core/types"
"github.com/harmony-one/harmony/core/vm" "github.com/harmony-one/harmony/core/vm"
"github.com/harmony-one/harmony/internal/params" "github.com/harmony-one/harmony/internal/params"
@ -39,9 +38,6 @@ import (
// ChainContext supports retrieving headers and consensus parameters from the // ChainContext supports retrieving headers and consensus parameters from the
// current blockchain to be used during transaction processing. // current blockchain to be used during transaction processing.
type ChainContext interface { type ChainContext interface {
// Engine retrieves the chain's consensus engine.
Engine() consensus_engine.Engine
// GetHeader returns the hash corresponding to their hash. // GetHeader returns the hash corresponding to their hash.
GetHeader(common.Hash, uint64) *block.Header GetHeader(common.Hash, uint64) *block.Header

@ -21,7 +21,6 @@ import (
"github.com/harmony-one/harmony/core/vm" "github.com/harmony-one/harmony/core/vm"
"github.com/harmony-one/harmony/crypto/bls" "github.com/harmony-one/harmony/crypto/bls"
"github.com/harmony-one/harmony/crypto/hash" "github.com/harmony-one/harmony/crypto/hash"
chain2 "github.com/harmony-one/harmony/internal/chain"
"github.com/harmony-one/harmony/internal/params" "github.com/harmony-one/harmony/internal/params"
"github.com/harmony-one/harmony/numeric" "github.com/harmony-one/harmony/numeric"
staking "github.com/harmony-one/harmony/staking/types" staking "github.com/harmony-one/harmony/staking/types"
@ -41,12 +40,11 @@ func getTestEnvironment(testBankKey ecdsa.PrivateKey) (*BlockChainImpl, *state.D
Alloc: GenesisAlloc{testBankAddress: {Balance: testBankFunds}}, Alloc: GenesisAlloc{testBankAddress: {Balance: testBankFunds}},
ShardID: 0, ShardID: 0,
} }
engine = chain2.NewEngine()
) )
genesis := gspec.MustCommit(database) genesis := gspec.MustCommit(database)
// fake blockchain // fake blockchain
chain, _ := NewBlockChain(database, state.NewDatabase(database), nil, nil, gspec.Config, engine, vm.Config{}) chain, _ := NewBlockChain(database, state.NewDatabase(database), nil, nil, gspec.Config, vm.Config{})
db, _ := chain.StateAt(genesis.Root()) db, _ := chain.StateAt(genesis.Root())
// make a fake block header (use epoch 1 so that locked tokens can be tested) // make a fake block header (use epoch 1 so that locked tokens can be tested)

@ -32,7 +32,6 @@ import (
lru "github.com/hashicorp/golang-lru" lru "github.com/hashicorp/golang-lru"
"github.com/harmony-one/harmony/block" "github.com/harmony-one/harmony/block"
consensus_engine "github.com/harmony-one/harmony/consensus/engine"
"github.com/harmony-one/harmony/core/rawdb" "github.com/harmony-one/harmony/core/rawdb"
"github.com/harmony-one/harmony/core/types" "github.com/harmony-one/harmony/core/types"
"github.com/harmony-one/harmony/internal/utils" "github.com/harmony-one/harmony/internal/utils"
@ -66,8 +65,7 @@ type HeaderChain struct {
procInterrupt func() bool procInterrupt func() bool
rand *mrand.Rand rand *mrand.Rand
engine consensus_engine.Engine
} }
// NewHeaderChain creates a new HeaderChain structure. // NewHeaderChain creates a new HeaderChain structure.
@ -75,7 +73,7 @@ type HeaderChain struct {
// getValidator should return the parent's validator // getValidator should return the parent's validator
// procInterrupt points to the parent's interrupt semaphore // procInterrupt points to the parent's interrupt semaphore
// wg points to the parent's shutdown wait group // wg points to the parent's shutdown wait group
func NewHeaderChain(chainDb ethdb.Database, config *params.ChainConfig, engine consensus_engine.Engine, procInterrupt func() bool) (*HeaderChain, error) { func NewHeaderChain(chainDb ethdb.Database, config *params.ChainConfig, procInterrupt func() bool) (*HeaderChain, error) {
headerCache, _ := lru.New(headerCacheLimit) headerCache, _ := lru.New(headerCacheLimit)
tdCache, _ := lru.New(tdCacheLimit) tdCache, _ := lru.New(tdCacheLimit)
numberCache, _ := lru.New(numberCacheLimit) numberCache, _ := lru.New(numberCacheLimit)
@ -96,7 +94,6 @@ func NewHeaderChain(chainDb ethdb.Database, config *params.ChainConfig, engine c
canonicalCache: canonicalHash, canonicalCache: canonicalHash,
procInterrupt: procInterrupt, procInterrupt: procInterrupt,
rand: mrand.New(mrand.NewSource(seed.Int64())), rand: mrand.New(mrand.NewSource(seed.Int64())),
engine: engine,
} }
hc.genesisHeader = hc.GetHeaderByNumber(0) hc.genesisHeader = hc.GetHeaderByNumber(0)
@ -548,9 +545,6 @@ func (hc *HeaderChain) SetGenesis(head *block.Header) {
// Config retrieves the header chain's chain configuration. // Config retrieves the header chain's chain configuration.
func (hc *HeaderChain) Config() *params.ChainConfig { return hc.config } func (hc *HeaderChain) Config() *params.ChainConfig { return hc.config }
// Engine retrieves the header chain's consensus engine.
func (hc *HeaderChain) Engine() consensus_engine.Engine { return hc.engine }
// GetBlock implements consensus.ChainReader, and returns nil for every input as // GetBlock implements consensus.ChainReader, and returns nil for every input as
// a header chain does not have blocks available for retrieval. // a header chain does not have blocks available for retrieval.
func (hc *HeaderChain) GetBlock(hash common.Hash, number uint64) *types.Block { func (hc *HeaderChain) GetBlock(hash common.Hash, number uint64) *types.Block {

@ -20,13 +20,13 @@ import (
"math/big" "math/big"
"time" "time"
"github.com/harmony-one/harmony/internal/chain"
lru "github.com/hashicorp/golang-lru" lru "github.com/hashicorp/golang-lru"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/rlp" "github.com/ethereum/go-ethereum/rlp"
"github.com/harmony-one/harmony/block" "github.com/harmony-one/harmony/block"
consensus_engine "github.com/harmony-one/harmony/consensus/engine"
"github.com/harmony-one/harmony/consensus/reward" "github.com/harmony-one/harmony/consensus/reward"
"github.com/harmony-one/harmony/core/state" "github.com/harmony-one/harmony/core/state"
"github.com/harmony-one/harmony/core/types" "github.com/harmony-one/harmony/core/types"
@ -50,14 +50,13 @@ const (
// //
// StateProcessor implements Processor. // StateProcessor implements Processor.
type StateProcessor struct { type StateProcessor struct {
config *params.ChainConfig // Chain configuration options config *params.ChainConfig // Chain configuration options
bc BlockChain // Canonical blockchain bc BlockChain // Canonical blockchain
beacon BlockChain // Beacon chain beacon BlockChain // Beacon chain
engine consensus_engine.Engine // Consensus engine used for block rewards resultCache *lru.Cache // Cache for result after a certain block is processed
resultCache *lru.Cache // Cache for result after a certain block is processed
} }
// this structure is cached, and each individual element is returned // ProcessorResult structure is cached, and each individual element is returned
type ProcessorResult struct { type ProcessorResult struct {
Receipts types.Receipts Receipts types.Receipts
CxReceipts types.CXReceipts CxReceipts types.CXReceipts
@ -70,7 +69,7 @@ type ProcessorResult struct {
// NewStateProcessor initialises a new StateProcessor. // NewStateProcessor initialises a new StateProcessor.
func NewStateProcessor( func NewStateProcessor(
config *params.ChainConfig, bc BlockChain, beacon BlockChain, engine consensus_engine.Engine, config *params.ChainConfig, bc BlockChain, beacon BlockChain,
) *StateProcessor { ) *StateProcessor {
if bc == nil { if bc == nil {
panic("bc is nil") panic("bc is nil")
@ -83,7 +82,6 @@ func NewStateProcessor(
config: config, config: config,
bc: bc, bc: bc,
beacon: beacon, beacon: beacon,
engine: engine,
resultCache: resultCache, resultCache: resultCache,
} }
} }
@ -195,7 +193,7 @@ func (p *StateProcessor) Process(
// Block processing don't need to block on reward computation as in block proposal // Block processing don't need to block on reward computation as in block proposal
sigsReady <- true sigsReady <- true
}() }()
_, payout, err := p.engine.Finalize( _, payout, err := chain.Engine().Finalize(
p.bc, p.bc,
p.beacon, p.beacon,
header, statedb, block.Transactions(), header, statedb, block.Transactions(),

@ -28,7 +28,6 @@ import (
"time" "time"
"github.com/ethereum/go-ethereum/core/rawdb" "github.com/ethereum/go-ethereum/core/rawdb"
"github.com/harmony-one/harmony/crypto/bls" "github.com/harmony-one/harmony/crypto/bls"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
@ -41,7 +40,6 @@ import (
"github.com/harmony-one/harmony/core/types" "github.com/harmony-one/harmony/core/types"
"github.com/harmony-one/harmony/core/vm" "github.com/harmony-one/harmony/core/vm"
"github.com/harmony-one/harmony/crypto/hash" "github.com/harmony-one/harmony/crypto/hash"
chain2 "github.com/harmony-one/harmony/internal/chain"
"github.com/harmony-one/harmony/internal/params" "github.com/harmony-one/harmony/internal/params"
"github.com/harmony-one/harmony/numeric" "github.com/harmony-one/harmony/numeric"
staking "github.com/harmony-one/harmony/staking/types" staking "github.com/harmony-one/harmony/staking/types"
@ -160,8 +158,7 @@ func createBlockChain() *BlockChainImpl {
database := rawdb.NewMemoryDatabase() database := rawdb.NewMemoryDatabase()
genesis := gspec.MustCommit(database) genesis := gspec.MustCommit(database)
_ = genesis _ = genesis
engine := chain2.NewEngine() blockchain, _ := NewBlockChain(database, state.NewDatabase(database), nil, nil, gspec.Config, vm.Config{})
blockchain, _ := NewBlockChain(database, state.NewDatabase(database), nil, nil, gspec.Config, engine, vm.Config{})
return blockchain return blockchain
} }

@ -25,7 +25,6 @@ type syncProtocol interface {
type blockChain interface { type blockChain interface {
engine.ChainReader engine.ChainReader
Engine() engine.Engine
InsertChain(chain types.Blocks, verifyHeaders bool) (int, error) InsertChain(chain types.Blocks, verifyHeaders bool) (int, error)
WriteCommitSig(blockNum uint64, lastCommits []byte) error WriteCommitSig(blockNum uint64, lastCommits []byte) error

@ -308,10 +308,10 @@ func verifyAndInsertBlock(bc blockChain, block *types.Block, nextBlocks ...*type
} }
} }
if err := bc.Engine().VerifyHeaderSignature(bc, block.Header(), sigBytes, bitmap); err != nil { if err := chain.Engine().VerifyHeaderSignature(bc, block.Header(), sigBytes, bitmap); err != nil {
return &sigVerifyErr{err} return &sigVerifyErr{err}
} }
if err := bc.Engine().VerifyHeader(bc, block.Header(), true); err != nil { if err := chain.Engine().VerifyHeader(bc, block.Header(), true); err != nil {
return errors.Wrap(err, "[VerifyHeader]") return errors.Wrap(err, "[VerifyHeader]")
} }
if _, err := bc.InsertChain(types.Blocks{block}, false); err != nil { if _, err := bc.InsertChain(types.Blocks{block}, false); err != nil {

@ -39,6 +39,7 @@ import (
"github.com/harmony-one/harmony/core/vm" "github.com/harmony-one/harmony/core/vm"
"github.com/harmony-one/harmony/eth/rpc" "github.com/harmony-one/harmony/eth/rpc"
"github.com/harmony-one/harmony/hmy/tracers" "github.com/harmony-one/harmony/hmy/tracers"
"github.com/harmony-one/harmony/internal/chain"
"github.com/harmony-one/harmony/internal/utils" "github.com/harmony-one/harmony/internal/utils"
) )
@ -347,7 +348,7 @@ func (hmy *Harmony) TraceChain(ctx context.Context, start, end *types.Block, con
// same as TraceBlock, but only use 1 thread // same as TraceBlock, but only use 1 thread
func (hmy *Harmony) traceBlockNoThread(ctx context.Context, block *types.Block, config *TraceConfig) ([]*TxTraceResult, error) { func (hmy *Harmony) traceBlockNoThread(ctx context.Context, block *types.Block, config *TraceConfig) ([]*TxTraceResult, error) {
// Create the parent state database // Create the parent state database
if err := hmy.BlockChain.Engine().VerifyHeader(hmy.BlockChain, block.Header(), true); err != nil { if err := chain.Engine().VerifyHeader(hmy.BlockChain, block.Header(), true); err != nil {
return nil, err return nil, err
} }
parent := hmy.BlockChain.GetBlock(block.ParentHash(), block.NumberU64()-1) parent := hmy.BlockChain.GetBlock(block.ParentHash(), block.NumberU64()-1)
@ -422,7 +423,7 @@ func (hmy *Harmony) TraceBlock(ctx context.Context, block *types.Block, config *
return hmy.traceBlockNoThread(ctx, block, config) return hmy.traceBlockNoThread(ctx, block, config)
} }
// Create the parent state database // Create the parent state database
if err := hmy.BlockChain.Engine().VerifyHeader(hmy.BlockChain, block.Header(), true); err != nil { if err := chain.Engine().VerifyHeader(hmy.BlockChain, block.Header(), true); err != nil {
return nil, err return nil, err
} }
parent := hmy.BlockChain.GetBlock(block.ParentHash(), block.NumberU64()-1) parent := hmy.BlockChain.GetBlock(block.ParentHash(), block.NumberU64()-1)
@ -523,7 +524,7 @@ func (hmy *Harmony) standardTraceBlockToFile(ctx context.Context, block *types.B
} }
} }
// Create the parent state database // Create the parent state database
if err := hmy.BlockChain.Engine().VerifyHeader(hmy.BlockChain, block.Header(), true); err != nil { if err := chain.Engine().VerifyHeader(hmy.BlockChain, block.Header(), true); err != nil {
return nil, err return nil, err
} }
parent := hmy.BlockChain.GetBlock(block.ParentHash(), block.NumberU64()-1) parent := hmy.BlockChain.GetBlock(block.ParentHash(), block.NumberU64()-1)

@ -6,6 +6,7 @@ import (
"sort" "sort"
"time" "time"
"github.com/harmony-one/harmony/consensus/engine"
"github.com/harmony-one/harmony/internal/params" "github.com/harmony-one/harmony/internal/params"
bls2 "github.com/harmony-one/bls/ffi/go/bls" bls2 "github.com/harmony-one/bls/ffi/go/bls"
@ -16,7 +17,6 @@ import (
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/harmony-one/harmony/block" "github.com/harmony-one/harmony/block"
"github.com/harmony-one/harmony/consensus/engine"
"github.com/harmony-one/harmony/consensus/quorum" "github.com/harmony-one/harmony/consensus/quorum"
"github.com/harmony-one/harmony/consensus/reward" "github.com/harmony-one/harmony/consensus/reward"
"github.com/harmony-one/harmony/consensus/signature" "github.com/harmony-one/harmony/consensus/signature"
@ -45,6 +45,8 @@ type engineImpl struct {
verifiedSigCache *lru.Cache // verifiedSigKey -> struct{}{} verifiedSigCache *lru.Cache // verifiedSigKey -> struct{}{}
} }
var internal = NewEngine()
// NewEngine creates Engine with some cache // NewEngine creates Engine with some cache
func NewEngine() *engineImpl { func NewEngine() *engineImpl {
sigCache, _ := lru.New(verifiedSigCache) sigCache, _ := lru.New(verifiedSigCache)
@ -55,6 +57,10 @@ func NewEngine() *engineImpl {
} }
} }
func Engine() *engineImpl {
return internal
}
// VerifyHeader checks whether a header conforms to the consensus rules of the bft engine. // VerifyHeader checks whether a header conforms to the consensus rules of the bft engine.
// Note that each block header contains the bls signature of the parent block // Note that each block header contains the bls signature of the parent block
func (e *engineImpl) VerifyHeader(chain engine.ChainReader, header *block.Header, seal bool) error { func (e *engineImpl) VerifyHeader(chain engine.ChainReader, header *block.Header, seal bool) error {

@ -13,7 +13,6 @@ import (
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/ethdb" "github.com/ethereum/go-ethereum/ethdb"
"github.com/harmony-one/harmony/consensus/engine"
"github.com/harmony-one/harmony/core" "github.com/harmony-one/harmony/core"
"github.com/harmony-one/harmony/core/rawdb" "github.com/harmony-one/harmony/core/rawdb"
"github.com/harmony-one/harmony/core/vm" "github.com/harmony-one/harmony/core/vm"
@ -40,7 +39,6 @@ type Collection interface {
type CollectionImpl struct { type CollectionImpl struct {
dbFactory DBFactory dbFactory DBFactory
dbInit DBInitializer dbInit DBInitializer
engine engine.Engine
mtx sync.Mutex mtx sync.Mutex
pool map[uint32]core.BlockChain pool map[uint32]core.BlockChain
disableCache map[uint32]bool disableCache map[uint32]bool
@ -56,14 +54,13 @@ type CollectionImpl struct {
// the factory is brand new (empty). // the factory is brand new (empty).
func NewCollection( func NewCollection(
harmonyconfig *harmonyconfig.HarmonyConfig, harmonyconfig *harmonyconfig.HarmonyConfig,
dbFactory DBFactory, dbInit DBInitializer, engine engine.Engine, dbFactory DBFactory, dbInit DBInitializer,
chainConfig *params.ChainConfig, chainConfig *params.ChainConfig,
) *CollectionImpl { ) *CollectionImpl {
return &CollectionImpl{ return &CollectionImpl{
harmonyconfig: harmonyconfig, harmonyconfig: harmonyconfig,
dbFactory: dbFactory, dbFactory: dbFactory,
dbInit: dbInit, dbInit: dbInit,
engine: engine,
pool: make(map[uint32]core.BlockChain), pool: make(map[uint32]core.BlockChain),
disableCache: make(map[uint32]bool), disableCache: make(map[uint32]bool),
chainConfig: chainConfig, chainConfig: chainConfig,
@ -128,7 +125,7 @@ func (sc *CollectionImpl) ShardChain(shardID uint32, options ...core.Options) (c
} }
var bc core.BlockChain var bc core.BlockChain
if opts.EpochChain { if opts.EpochChain {
bc, err = core.NewEpochChain(db, &chainConfig, sc.engine, vm.Config{}) bc, err = core.NewEpochChain(db, &chainConfig, vm.Config{})
} else { } else {
stateCache, err := initStateCache(db, sc, shardID) stateCache, err := initStateCache(db, sc, shardID)
if err != nil { if err != nil {
@ -136,7 +133,7 @@ func (sc *CollectionImpl) ShardChain(shardID uint32, options ...core.Options) (c
} }
if shardID == shard.BeaconChainShardID { if shardID == shard.BeaconChainShardID {
bc, err = core.NewBlockChainWithOptions( bc, err = core.NewBlockChainWithOptions(
db, stateCache, bc, cacheConfig, &chainConfig, sc.engine, vm.Config{}, opts, db, stateCache, bc, cacheConfig, &chainConfig, vm.Config{}, opts,
) )
} else { } else {
beacon, ok := sc.pool[shard.BeaconChainShardID] beacon, ok := sc.pool[shard.BeaconChainShardID]
@ -145,7 +142,7 @@ func (sc *CollectionImpl) ShardChain(shardID uint32, options ...core.Options) (c
} }
bc, err = core.NewBlockChainWithOptions( bc, err = core.NewBlockChainWithOptions(
db, stateCache, beacon, cacheConfig, &chainConfig, sc.engine, vm.Config{}, opts, db, stateCache, beacon, cacheConfig, &chainConfig, vm.Config{}, opts,
) )
} }
} }

@ -12,7 +12,6 @@ import (
"sync" "sync"
"time" "time"
"github.com/harmony-one/harmony/consensus/engine"
"github.com/harmony-one/harmony/internal/registry" "github.com/harmony-one/harmony/internal/registry"
"github.com/harmony-one/harmony/internal/shardchain/tikv_manage" "github.com/harmony-one/harmony/internal/shardchain/tikv_manage"
"github.com/harmony-one/harmony/internal/tikv" "github.com/harmony-one/harmony/internal/tikv"
@ -1015,7 +1014,6 @@ func (node *Node) GetSyncID() [SyncIDLength]byte {
func New( func New(
host p2p.Host, host p2p.Host,
consensusObj *consensus.Consensus, consensusObj *consensus.Consensus,
engine engine.Engine,
collection *shardchain.CollectionImpl, collection *shardchain.CollectionImpl,
blacklist map[common.Address]struct{}, blacklist map[common.Address]struct{},
allowedTxs map[common.Address]core.AllowedTxData, allowedTxs map[common.Address]core.AllowedTxData,
@ -1110,7 +1108,7 @@ func New(
node.TxPool = core.NewTxPool(txPoolConfig, node.Blockchain().Config(), blockchain, node.TransactionErrorSink) node.TxPool = core.NewTxPool(txPoolConfig, node.Blockchain().Config(), blockchain, node.TransactionErrorSink)
node.CxPool = core.NewCxPool(core.CxPoolSize) node.CxPool = core.NewCxPool(core.CxPoolSize)
node.Worker = worker.New(node.Blockchain().Config(), blockchain, beaconChain, engine) node.Worker = worker.New(node.Blockchain().Config(), blockchain, beaconChain)
node.deciderCache, _ = lru.New(16) node.deciderCache, _ = lru.New(16)
node.committeeCache, _ = lru.New(16) node.committeeCache, _ = lru.New(16)

@ -8,6 +8,7 @@ import (
ffi_bls "github.com/harmony-one/bls/ffi/go/bls" ffi_bls "github.com/harmony-one/bls/ffi/go/bls"
"github.com/harmony-one/harmony/core" "github.com/harmony-one/harmony/core"
"github.com/harmony-one/harmony/core/types" "github.com/harmony-one/harmony/core/types"
"github.com/harmony-one/harmony/internal/chain"
"github.com/harmony-one/harmony/internal/utils" "github.com/harmony-one/harmony/internal/utils"
"github.com/harmony-one/harmony/shard" "github.com/harmony-one/harmony/shard"
"github.com/pkg/errors" "github.com/pkg/errors"
@ -179,7 +180,7 @@ func (node *Node) VerifyCrossLink(cl types.CrossLink) error {
if cl.ShardID() >= instance.NumShards() { if cl.ShardID() >= instance.NumShards() {
return errors.New("[VerifyCrossLink] ShardID should less than NumShards") return errors.New("[VerifyCrossLink] ShardID should less than NumShards")
} }
engine := node.Blockchain().Engine() engine := chain.Engine()
if err := engine.VerifyCrossLink(node.Blockchain(), cl); err != nil { if err := engine.VerifyCrossLink(node.Blockchain(), cl); err != nil {
return errors.Wrap(err, "[VerifyCrossLink]") return errors.Wrap(err, "[VerifyCrossLink]")

@ -33,10 +33,9 @@ func TestAddNewBlock(t *testing.T) {
if err != nil { if err != nil {
t.Fatalf("newhost failure: %v", err) t.Fatalf("newhost failure: %v", err)
} }
engine := chain.NewEngine()
chainconfig := nodeconfig.GetShardConfig(shard.BeaconChainShardID).GetNetworkType().ChainConfig() chainconfig := nodeconfig.GetShardConfig(shard.BeaconChainShardID).GetNetworkType().ChainConfig()
collection := shardchain.NewCollection( collection := shardchain.NewCollection(
nil, testDBFactory, &core.GenesisInitializer{NetworkType: nodeconfig.GetShardConfig(shard.BeaconChainShardID).GetNetworkType()}, engine, &chainconfig, nil, testDBFactory, &core.GenesisInitializer{NetworkType: nodeconfig.GetShardConfig(shard.BeaconChainShardID).GetNetworkType()}, &chainconfig,
) )
decider := quorum.NewDecider( decider := quorum.NewDecider(
quorum.SuperMajorityVote, shard.BeaconChainShardID, quorum.SuperMajorityVote, shard.BeaconChainShardID,
@ -53,7 +52,7 @@ func TestAddNewBlock(t *testing.T) {
t.Fatalf("Cannot craeate consensus: %v", err) t.Fatalf("Cannot craeate consensus: %v", err)
} }
nodeconfig.SetNetworkType(nodeconfig.Devnet) nodeconfig.SetNetworkType(nodeconfig.Devnet)
node := New(host, consensus, engine, collection, nil, nil, nil, nil, nil, reg) node := New(host, consensus, collection, nil, nil, nil, nil, nil, reg)
txs := make(map[common.Address]types.Transactions) txs := make(map[common.Address]types.Transactions)
stks := staking.StakingTransactions{} stks := staking.StakingTransactions{}
@ -90,10 +89,9 @@ func TestVerifyNewBlock(t *testing.T) {
if err != nil { if err != nil {
t.Fatalf("newhost failure: %v", err) t.Fatalf("newhost failure: %v", err)
} }
engine := chain.NewEngine()
chainconfig := nodeconfig.GetShardConfig(shard.BeaconChainShardID).GetNetworkType().ChainConfig() chainconfig := nodeconfig.GetShardConfig(shard.BeaconChainShardID).GetNetworkType().ChainConfig()
collection := shardchain.NewCollection( collection := shardchain.NewCollection(
nil, testDBFactory, &core.GenesisInitializer{NetworkType: nodeconfig.GetShardConfig(shard.BeaconChainShardID).GetNetworkType()}, engine, &chainconfig, nil, testDBFactory, &core.GenesisInitializer{NetworkType: nodeconfig.GetShardConfig(shard.BeaconChainShardID).GetNetworkType()}, &chainconfig,
) )
decider := quorum.NewDecider( decider := quorum.NewDecider(
quorum.SuperMajorityVote, shard.BeaconChainShardID, quorum.SuperMajorityVote, shard.BeaconChainShardID,
@ -112,7 +110,7 @@ func TestVerifyNewBlock(t *testing.T) {
archiveMode := make(map[uint32]bool) archiveMode := make(map[uint32]bool)
archiveMode[0] = true archiveMode[0] = true
archiveMode[1] = false archiveMode[1] = false
node := New(host, consensus, engine, collection, nil, nil, nil, archiveMode, nil, reg) node := New(host, consensus, collection, nil, nil, nil, archiveMode, nil, reg)
txs := make(map[common.Address]types.Transactions) txs := make(map[common.Address]types.Transactions)
stks := staking.StakingTransactions{} stks := staking.StakingTransactions{}
@ -146,10 +144,9 @@ func TestVerifyVRF(t *testing.T) {
if err != nil { if err != nil {
t.Fatalf("newhost failure: %v", err) t.Fatalf("newhost failure: %v", err)
} }
engine := chain.NewEngine()
chainconfig := nodeconfig.GetShardConfig(shard.BeaconChainShardID).GetNetworkType().ChainConfig() chainconfig := nodeconfig.GetShardConfig(shard.BeaconChainShardID).GetNetworkType().ChainConfig()
collection := shardchain.NewCollection( collection := shardchain.NewCollection(
nil, testDBFactory, &core.GenesisInitializer{NetworkType: nodeconfig.GetShardConfig(shard.BeaconChainShardID).GetNetworkType()}, engine, &chainconfig, nil, testDBFactory, &core.GenesisInitializer{NetworkType: nodeconfig.GetShardConfig(shard.BeaconChainShardID).GetNetworkType()}, &chainconfig,
) )
blockchain, err := collection.ShardChain(shard.BeaconChainShardID) blockchain, err := collection.ShardChain(shard.BeaconChainShardID)
if err != nil { if err != nil {
@ -168,7 +165,7 @@ func TestVerifyVRF(t *testing.T) {
archiveMode := make(map[uint32]bool) archiveMode := make(map[uint32]bool)
archiveMode[0] = true archiveMode[0] = true
archiveMode[1] = false archiveMode[1] = false
node := New(host, consensus, engine, collection, nil, nil, nil, archiveMode, nil, reg) node := New(host, consensus, collection, nil, nil, nil, archiveMode, nil, reg)
txs := make(map[common.Address]types.Transactions) txs := make(map[common.Address]types.Transactions)
stks := staking.StakingTransactions{} stks := staking.StakingTransactions{}
@ -205,7 +202,7 @@ func TestVerifyVRF(t *testing.T) {
node.Blockchain().WriteShardStateBytes(node.Blockchain().ChainDb(), big.NewInt(1), node.Worker.GetCurrentHeader().ShardState()) node.Blockchain().WriteShardStateBytes(node.Blockchain().ChainDb(), big.NewInt(1), node.Worker.GetCurrentHeader().ShardState())
node.Blockchain().Config().VRFEpoch = big.NewInt(0) node.Blockchain().Config().VRFEpoch = big.NewInt(0)
if err := node.Blockchain().Engine().VerifyVRF( if err := chain.Engine().VerifyVRF(
node.Blockchain(), block.Header(), node.Blockchain(), block.Header(),
); err != nil { ); err != nil {
t.Error("New vrf is not verified successfully:", err) t.Error("New vrf is not verified successfully:", err)

@ -10,7 +10,6 @@ import (
"github.com/harmony-one/harmony/core" "github.com/harmony-one/harmony/core"
"github.com/harmony-one/harmony/core/types" "github.com/harmony-one/harmony/core/types"
"github.com/harmony-one/harmony/crypto/bls" "github.com/harmony-one/harmony/crypto/bls"
"github.com/harmony-one/harmony/internal/chain"
nodeconfig "github.com/harmony-one/harmony/internal/configs/node" nodeconfig "github.com/harmony-one/harmony/internal/configs/node"
"github.com/harmony-one/harmony/internal/registry" "github.com/harmony-one/harmony/internal/registry"
"github.com/harmony-one/harmony/internal/shardchain" "github.com/harmony-one/harmony/internal/shardchain"
@ -35,10 +34,9 @@ func TestFinalizeNewBlockAsync(t *testing.T) {
t.Fatalf("newhost failure: %v", err) t.Fatalf("newhost failure: %v", err)
} }
var testDBFactory = &shardchain.MemDBFactory{} var testDBFactory = &shardchain.MemDBFactory{}
engine := chain.NewEngine()
chainconfig := nodeconfig.GetShardConfig(shard.BeaconChainShardID).GetNetworkType().ChainConfig() chainconfig := nodeconfig.GetShardConfig(shard.BeaconChainShardID).GetNetworkType().ChainConfig()
collection := shardchain.NewCollection( collection := shardchain.NewCollection(
nil, testDBFactory, &core.GenesisInitializer{NetworkType: nodeconfig.GetShardConfig(shard.BeaconChainShardID).GetNetworkType()}, engine, &chainconfig, nil, testDBFactory, &core.GenesisInitializer{NetworkType: nodeconfig.GetShardConfig(shard.BeaconChainShardID).GetNetworkType()}, &chainconfig,
) )
blockchain, err := collection.ShardChain(shard.BeaconChainShardID) blockchain, err := collection.ShardChain(shard.BeaconChainShardID)
require.NoError(t, err) require.NoError(t, err)
@ -53,7 +51,7 @@ func TestFinalizeNewBlockAsync(t *testing.T) {
t.Fatalf("Cannot craeate consensus: %v", err) t.Fatalf("Cannot craeate consensus: %v", err)
} }
node := New(host, consensus, engine, collection, nil, nil, nil, nil, nil, registry.New().SetBlockchain(blockchain)) node := New(host, consensus, collection, nil, nil, nil, nil, nil, registry.New().SetBlockchain(blockchain))
node.Worker.UpdateCurrent() node.Worker.UpdateCurrent()

@ -8,7 +8,6 @@ import (
"github.com/harmony-one/harmony/consensus/quorum" "github.com/harmony-one/harmony/consensus/quorum"
"github.com/harmony-one/harmony/core" "github.com/harmony-one/harmony/core"
"github.com/harmony-one/harmony/crypto/bls" "github.com/harmony-one/harmony/crypto/bls"
"github.com/harmony-one/harmony/internal/chain"
nodeconfig "github.com/harmony-one/harmony/internal/configs/node" nodeconfig "github.com/harmony-one/harmony/internal/configs/node"
"github.com/harmony-one/harmony/internal/registry" "github.com/harmony-one/harmony/internal/registry"
"github.com/harmony-one/harmony/internal/shardchain" "github.com/harmony-one/harmony/internal/shardchain"
@ -34,13 +33,12 @@ func TestNewNode(t *testing.T) {
if err != nil { if err != nil {
t.Fatalf("newhost failure: %v", err) t.Fatalf("newhost failure: %v", err)
} }
engine := chain.NewEngine()
decider := quorum.NewDecider( decider := quorum.NewDecider(
quorum.SuperMajorityVote, shard.BeaconChainShardID, quorum.SuperMajorityVote, shard.BeaconChainShardID,
) )
chainconfig := nodeconfig.GetShardConfig(shard.BeaconChainShardID).GetNetworkType().ChainConfig() chainconfig := nodeconfig.GetShardConfig(shard.BeaconChainShardID).GetNetworkType().ChainConfig()
collection := shardchain.NewCollection( collection := shardchain.NewCollection(
nil, testDBFactory, &core.GenesisInitializer{NetworkType: nodeconfig.GetShardConfig(shard.BeaconChainShardID).GetNetworkType()}, engine, &chainconfig, nil, testDBFactory, &core.GenesisInitializer{NetworkType: nodeconfig.GetShardConfig(shard.BeaconChainShardID).GetNetworkType()}, &chainconfig,
) )
blockchain, err := collection.ShardChain(shard.BeaconChainShardID) blockchain, err := collection.ShardChain(shard.BeaconChainShardID)
if err != nil { if err != nil {
@ -54,7 +52,7 @@ func TestNewNode(t *testing.T) {
t.Fatalf("Cannot craeate consensus: %v", err) t.Fatalf("Cannot craeate consensus: %v", err)
} }
node := New(host, consensus, engine, collection, nil, nil, nil, nil, nil, reg) node := New(host, consensus, collection, nil, nil, nil, nil, nil, reg)
if node.Consensus == nil { if node.Consensus == nil {
t.Error("Consensus is not initialized for the node") t.Error("Consensus is not initialized for the node")
} }

@ -8,6 +8,7 @@ import (
"time" "time"
"github.com/harmony-one/harmony/consensus/reward" "github.com/harmony-one/harmony/consensus/reward"
"github.com/harmony-one/harmony/internal/chain"
"github.com/harmony-one/harmony/consensus" "github.com/harmony-one/harmony/consensus"
@ -19,7 +20,6 @@ import (
"github.com/ethereum/go-ethereum/rlp" "github.com/ethereum/go-ethereum/rlp"
"github.com/harmony-one/harmony/block" "github.com/harmony-one/harmony/block"
blockfactory "github.com/harmony-one/harmony/block/factory" blockfactory "github.com/harmony-one/harmony/block/factory"
consensus_engine "github.com/harmony-one/harmony/consensus/engine"
"github.com/harmony-one/harmony/core" "github.com/harmony-one/harmony/core"
"github.com/harmony-one/harmony/core/state" "github.com/harmony-one/harmony/core/state"
"github.com/harmony-one/harmony/core/types" "github.com/harmony-one/harmony/core/types"
@ -59,7 +59,6 @@ type Worker struct {
chain core.BlockChain chain core.BlockChain
beacon core.BlockChain beacon core.BlockChain
current *environment // An environment for current running cycle. current *environment // An environment for current running cycle.
engine consensus_engine.Engine
gasFloor uint64 gasFloor uint64
gasCeil uint64 gasCeil uint64
} }
@ -558,7 +557,7 @@ func (w *Worker) FinalizeNewBlock(
} }
}() }()
block, payout, err := w.engine.Finalize( block, payout, err := chain.Engine().Finalize(
w.chain, w.chain,
w.beacon, w.beacon,
copyHeader, state, w.current.txs, w.current.receipts, copyHeader, state, w.current.txs, w.current.receipts,
@ -574,14 +573,13 @@ func (w *Worker) FinalizeNewBlock(
// New create a new worker object. // New create a new worker object.
func New( func New(
config *params.ChainConfig, chain core.BlockChain, beacon core.BlockChain, engine consensus_engine.Engine, config *params.ChainConfig, chain core.BlockChain, beacon core.BlockChain,
) *Worker { ) *Worker {
worker := &Worker{ worker := &Worker{
config: config, config: config,
factory: blockfactory.NewFactory(config), factory: blockfactory.NewFactory(config),
chain: chain, chain: chain,
beacon: beacon, beacon: beacon,
engine: engine,
} }
worker.gasFloor = 80000000 worker.gasFloor = 80000000
worker.gasCeil = 120000000 worker.gasCeil = 120000000

@ -16,7 +16,6 @@ import (
"github.com/harmony-one/harmony/core" "github.com/harmony-one/harmony/core"
"github.com/harmony-one/harmony/core/types" "github.com/harmony-one/harmony/core/types"
"github.com/harmony-one/harmony/core/vm" "github.com/harmony-one/harmony/core/vm"
chain2 "github.com/harmony-one/harmony/internal/chain"
"github.com/harmony-one/harmony/internal/params" "github.com/harmony-one/harmony/internal/params"
) )
@ -40,18 +39,17 @@ func TestNewWorker(t *testing.T) {
Alloc: core.GenesisAlloc{testBankAddress: {Balance: testBankFunds}}, Alloc: core.GenesisAlloc{testBankAddress: {Balance: testBankFunds}},
ShardID: 10, ShardID: 10,
} }
engine = chain2.NewEngine()
) )
genesis := gspec.MustCommit(database) genesis := gspec.MustCommit(database)
_ = genesis _ = genesis
chain, err := core.NewBlockChain(database, state.NewDatabase(database), &core.BlockChainImpl{}, nil, gspec.Config, engine, vm.Config{}) chain, err := core.NewBlockChain(database, state.NewDatabase(database), &core.BlockChainImpl{}, nil, gspec.Config, vm.Config{})
if err != nil { if err != nil {
t.Error(err) t.Error(err)
} }
// Create a new worker // Create a new worker
worker := New(params.TestChainConfig, chain, nil, engine) worker := New(params.TestChainConfig, chain, nil)
if worker.GetCurrentState().GetBalance(crypto.PubkeyToAddress(testBankKey.PublicKey)).Cmp(testBankFunds) != 0 { if worker.GetCurrentState().GetBalance(crypto.PubkeyToAddress(testBankKey.PublicKey)).Cmp(testBankFunds) != 0 {
t.Error("Worker state is not setup correctly") t.Error("Worker state is not setup correctly")
@ -68,14 +66,13 @@ func TestCommitTransactions(t *testing.T) {
Alloc: core.GenesisAlloc{testBankAddress: {Balance: testBankFunds}}, Alloc: core.GenesisAlloc{testBankAddress: {Balance: testBankFunds}},
ShardID: 0, ShardID: 0,
} }
engine = chain2.NewEngine()
) )
gspec.MustCommit(database) gspec.MustCommit(database)
chain, _ := core.NewBlockChain(database, state.NewDatabase(database), nil, nil, gspec.Config, engine, vm.Config{}) chain, _ := core.NewBlockChain(database, state.NewDatabase(database), nil, nil, gspec.Config, vm.Config{})
// Create a new worker // Create a new worker
worker := New(params.TestChainConfig, chain, nil, engine) worker := New(params.TestChainConfig, chain, nil)
// Generate a test tx // Generate a test tx
baseNonce := worker.GetCurrentState().GetNonce(crypto.PubkeyToAddress(testBankKey.PublicKey)) baseNonce := worker.GetCurrentState().GetNonce(crypto.PubkeyToAddress(testBankKey.PublicKey))

@ -23,6 +23,7 @@ import (
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/ethdb" "github.com/ethereum/go-ethereum/ethdb"
"github.com/harmony-one/harmony/core" "github.com/harmony-one/harmony/core"
"github.com/harmony-one/harmony/internal/chain"
"github.com/harmony-one/harmony/block" "github.com/harmony-one/harmony/block"
blockfactory "github.com/harmony-one/harmony/block/factory" blockfactory "github.com/harmony-one/harmony/block/factory"
@ -49,7 +50,6 @@ type BlockGen struct {
receipts []*types.Receipt receipts []*types.Receipt
uncles []*block.Header uncles []*block.Header
config *params.ChainConfig config *params.ChainConfig
engine consensus_engine.Engine
} }
// SetCoinbase sets the coinbase of the generated block. // SetCoinbase sets the coinbase of the generated block.
@ -167,7 +167,7 @@ func (b *BlockGen) PrevBlock(index int) *types.Block {
// a similar non-validating proof of work implementation. // a similar non-validating proof of work implementation.
func GenerateChain( func GenerateChain(
config *params.ChainConfig, parent *types.Block, config *params.ChainConfig, parent *types.Block,
engine consensus_engine.Engine, db ethdb.Database, db ethdb.Database,
n int, n int,
gen func(int, *BlockGen), gen func(int, *BlockGen),
) ([]*types.Block, []types.Receipts) { ) ([]*types.Block, []types.Receipts) {
@ -185,18 +185,17 @@ func GenerateChain(
statedb: statedb, statedb: statedb,
config: config, config: config,
factory: factory, factory: factory,
engine: engine,
} }
b.header = makeHeader(chainreader, parent, statedb, b.engine, factory) b.header = makeHeader(chainreader, parent, statedb, factory)
// Execute any user modifications to the block // Execute any user modifications to the block
if gen != nil { if gen != nil {
gen(i, b) gen(i, b)
} }
if b.engine != nil { if true {
// Finalize and seal the block // Finalize and seal the block
block, _, err := b.engine.Finalize( block, _, err := chain.Engine().Finalize(
chainreader, nil, b.header, statedb, b.txs, b.receipts, nil, nil, nil, nil, nil, func() uint64 { return 0 }, chainreader, nil, b.header, statedb, b.txs, b.receipts, nil, nil, nil, nil, nil, func() uint64 { return 0 },
) )
if err != nil { if err != nil {
@ -228,7 +227,7 @@ func GenerateChain(
return blocks, receipts return blocks, receipts
} }
func makeHeader(chain consensus_engine.ChainReader, parent *types.Block, state *state.DB, engine consensus_engine.Engine, factory blockfactory.Factory) *block.Header { func makeHeader(chain consensus_engine.ChainReader, parent *types.Block, state *state.DB, factory blockfactory.Factory) *block.Header {
var time *big.Int var time *big.Int
if parent.Time() == nil { if parent.Time() == nil {
time = big.NewInt(10) time = big.NewInt(10)

@ -94,7 +94,7 @@ func fundFaucetContract(chain core.BlockChain) {
fmt.Println("--------- Funding addresses for Faucet Contract Call ---------") fmt.Println("--------- Funding addresses for Faucet Contract Call ---------")
fmt.Println() fmt.Println()
contractworker = pkgworker.New(params.TestChainConfig, chain, nil, chain.Engine()) contractworker = pkgworker.New(params.TestChainConfig, chain, nil)
nonce = contractworker.GetCurrentState().GetNonce(crypto.PubkeyToAddress(FaucetPriKey.PublicKey)) nonce = contractworker.GetCurrentState().GetNonce(crypto.PubkeyToAddress(FaucetPriKey.PublicKey))
dataEnc = common.FromHex(FaucetContractBinary) dataEnc = common.FromHex(FaucetContractBinary)
ftx, _ := types.SignTx( ftx, _ := types.SignTx(
@ -206,7 +206,7 @@ func playFaucetContract(chain core.BlockChain) {
func main() { func main() {
genesis := gspec.MustCommit(database) genesis := gspec.MustCommit(database)
chain, _ := core.NewBlockChain(database, harmonyState.NewDatabase(database), nil, nil, gspec.Config, chain.Engine(), vm.Config{}) chain, _ := core.NewBlockChain(database, harmonyState.NewDatabase(database), nil, nil, gspec.Config, vm.Config{})
txpool := core.NewTxPool(core.DefaultTxPoolConfig, chainConfig, chain, types.NewTransactionErrorSink()) txpool := core.NewTxPool(core.DefaultTxPoolConfig, chainConfig, chain, types.NewTransactionErrorSink())
backend := &testWorkerBackend{ backend := &testWorkerBackend{
@ -223,7 +223,7 @@ func main() {
//// Generate a small n-block chain and an uncle block for it //// Generate a small n-block chain and an uncle block for it
n := 3 n := 3
if n > 0 { if n > 0 {
blocks, _ := chain2.GenerateChain(chainConfig, genesis, chain.Engine(), database, n, func(i int, gen *chain2.BlockGen) { blocks, _ := chain2.GenerateChain(chainConfig, genesis, database, n, func(i int, gen *chain2.BlockGen) {
gen.SetCoinbase(FaucetAddress) gen.SetCoinbase(FaucetAddress)
gen.SetShardID(0) gen.SetShardID(0)
gen.AddTx(pendingTxs[i].(*types.Transaction)) gen.AddTx(pendingTxs[i].(*types.Transaction))

@ -22,7 +22,6 @@ import (
"github.com/harmony-one/harmony/core/state" "github.com/harmony-one/harmony/core/state"
"github.com/harmony-one/harmony/core/vm" "github.com/harmony-one/harmony/core/vm"
"github.com/harmony-one/harmony/crypto/hash" "github.com/harmony-one/harmony/crypto/hash"
"github.com/harmony-one/harmony/internal/chain"
"github.com/harmony-one/harmony/internal/common" "github.com/harmony-one/harmony/internal/common"
protobuf "github.com/golang/protobuf/proto" protobuf "github.com/golang/protobuf/proto"
@ -108,8 +107,7 @@ func main() {
database := rawdb.NewMemoryDatabase() database := rawdb.NewMemoryDatabase()
genesis := gspec.MustCommit(database) genesis := gspec.MustCommit(database)
_ = genesis _ = genesis
engine := chain.NewEngine() bc, _ := core.NewBlockChain(database, state.NewDatabase(database), nil, nil, gspec.Config, vm.Config{})
bc, _ := core.NewBlockChain(database, state.NewDatabase(database), nil, nil, gspec.Config, engine, vm.Config{})
statedb, _ := state.New(common2.Hash{}, state.NewDatabase(rawdb.NewMemoryDatabase())) statedb, _ := state.New(common2.Hash{}, state.NewDatabase(rawdb.NewMemoryDatabase()))
msg := createValidator() msg := createValidator()
statedb.AddBalance(msg.ValidatorAddress, new(big.Int).Mul(big.NewInt(5e18), big.NewInt(2000))) statedb.AddBalance(msg.ValidatorAddress, new(big.Int).Mul(big.NewInt(5e18), big.NewInt(2000)))

Loading…
Cancel
Save