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. 12
      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. 8
      core/headerchain.go
  18. 10
      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()
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())
}
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 {
return err
} else if err != nil {

@ -27,7 +27,6 @@ type syncProtocol interface {
type blockChain interface {
engine.ChainReader
Engine() engine.Engine
InsertChain(chain types.Blocks, verifyHeaders bool) (int, 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}
}
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]")
}
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()
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())
}
utils.Logger().Debug().

@ -1052,14 +1052,14 @@ func (ss *StagedSync) UpdateBlockAndStatus(block *types.Block, bc core.BlockChai
}
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())
}
utils.Logger().Debug().
Int64("elapsed time", time.Now().Sub(startTime).Milliseconds()).
Msg("[STAGED_SYNC] VerifyHeaderSignature")
}
err := bc.Engine().VerifyHeader(bc, block.Header(), verifySeal)
err := chain.Engine().VerifyHeader(bc, block.Header(), verifySeal)
if err == engine.ErrUnknownAncestor {
return err
} else if err != nil {

@ -153,6 +153,11 @@ func (h *Header) IsLastBlockInEpoch() bool {
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.
var HeaderRegistry = taggedrlp.NewRegistry()

@ -16,7 +16,6 @@ import (
"time"
"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/shardchain/tikv_manage"
"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}
}
engine := chain.NewEngine()
chainConfig := nodeConfig.GetNetworkType().ChainConfig()
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() {
if archival {
@ -740,7 +737,7 @@ func setupConsensusAndNode(hc harmonyconfig.HarmonyConfig, nodeConfig *nodeconfi
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 {
currentNode.BroadcastInvalidTx = *hc.Legacy.TPBroadcastInvalidTxn

@ -31,13 +31,6 @@ var (
// to the current node.
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 = 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")
return
}
if err := consensus.Blockchain().Engine().VerifyHeaderSignature(consensus.Blockchain(), blockObj.Header(),
if err := chain.Engine().VerifyHeaderSignature(consensus.Blockchain(), blockObj.Header(),
sigBytes, bitmap); err != nil {
consensus.getLogger().Error().
Uint64("blockNum", recvMsg.BlockNum).

@ -26,6 +26,8 @@ import (
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/rlp"
"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"
consensus_engine "github.com/harmony-one/harmony/consensus/engine"
@ -42,14 +44,12 @@ import (
type BlockValidator struct {
config *params.ChainConfig // Chain configuration options
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
func NewBlockValidator(config *params.ChainConfig, blockchain BlockChain, engine consensus_engine.Engine) *BlockValidator {
func NewBlockValidator(config *params.ChainConfig, blockchain BlockChain) *BlockValidator {
validator := &BlockValidator{
config: config,
engine: engine,
bc: blockchain,
}
return validator
@ -131,7 +131,7 @@ func (v *BlockValidator) ValidateHeader(block *types.Block, seal bool) error {
return errors.New("block is 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")
}
@ -147,7 +147,7 @@ func (v *BlockValidator) ValidateHeaders(chain []*types.Block) (chan<- struct{},
headers[i] = block.Header()
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
@ -249,5 +249,5 @@ func (v *BlockValidator) ValidateCXReceiptsProof(cxp *types.CXReceiptsProof) err
// (4) verify blockHeader with seal
var commitSig bls.SerializedSignature
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
// Config retrieves the blockchain's chain configuration.
Config() *params.ChainConfig
// Engine retrieves the blockchain's consensus engine.
Engine() engine.Engine
// SubscribeRemovedLogsEvent registers a subscription of RemovedLogsEvent.
SubscribeRemovedLogsEvent(ch chan<- RemovedLogsEvent) event.Subscription
// SubscribeTraceEvent registers a subscription of ChainEvent.

@ -49,6 +49,8 @@ import (
"github.com/harmony-one/harmony/core/types"
"github.com/harmony-one/harmony/core/vm"
"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"
"github.com/harmony-one/harmony/internal/params"
"github.com/harmony-one/harmony/internal/tikv"
@ -190,7 +192,6 @@ type BlockChainImpl struct {
// procInterrupt must be atomically called
procInterrupt int32 // interrupt signaler for block processing
engine consensus_engine.Engine
processor Processor // block processor interface
validator Validator // block and state validator interface
vmConfig vm.Config
@ -204,9 +205,9 @@ type BlockChainImpl struct {
// NewBlockChainWithOptions same as NewBlockChain but can accept additional behaviour options.
func NewBlockChainWithOptions(
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) {
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
@ -214,15 +215,15 @@ func NewBlockChainWithOptions(
// Processor.
func NewBlockChain(
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) {
return newBlockChainWithOptions(db, stateCache, beaconChain, cacheConfig, chainConfig, engine, vmConfig, Options{})
return newBlockChainWithOptions(db, stateCache, beaconChain, cacheConfig, chainConfig, vmConfig, Options{})
}
func newBlockChainWithOptions(
db ethdb.Database, stateCache state.Database, beaconChain BlockChain,
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)
bodyRLPCache, _ := lru.New(bodyCacheLimit)
@ -266,7 +267,6 @@ func newBlockChainWithOptions(
blockAccumulatorCache: blockAccumulatorCache,
leaderPubKeyFromCoinbase: leaderPubKeyFromCoinbase,
blockchainPruner: newBlockchainPruner(db),
engine: engine,
vmConfig: vmConfig,
badBlocks: badBlocks,
pendingSlashes: slash.Records{},
@ -275,7 +275,7 @@ func newBlockChainWithOptions(
}
var err error
bc.hc, err = NewHeaderChain(db, chainConfig, engine, bc.getProcInterrupt)
bc.hc, err = NewHeaderChain(db, chainConfig, bc.getProcInterrupt)
if err != nil {
return nil, err
}
@ -294,8 +294,8 @@ func newBlockChainWithOptions(
beaconChain = bc
}
bc.SetValidator(NewBlockValidator(chainConfig, bc, engine))
bc.SetProcessor(NewStateProcessor(chainConfig, bc, beaconChain, engine))
bc.SetValidator(NewBlockValidator(chainConfig, bc))
bc.SetProcessor(NewStateProcessor(chainConfig, bc, beaconChain))
// Take ownership of this particular state
go bc.update()
@ -353,7 +353,7 @@ func VerifyCrossLink(blockchain BlockChain, cl types.CrossLink) error {
if blockchain.ShardID() != shard.BeaconChainShardID {
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 {
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")
return err
}
if err := bc.Engine().VerifyVRF(
if err := chain.Engine().VerifyVRF(
bc, block.Header(),
); err != nil {
utils.Logger().Error().
@ -436,7 +436,7 @@ func (bc *BlockChainImpl) ValidateNewBlock(block *types.Block, beaconChain 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 {
utils.Logger().Error().
Str("blockHash", block.Hash().Hex()).
@ -1577,7 +1577,7 @@ func (bc *BlockChainImpl) insertChain(chain types.Blocks, verifyHeaders bool) (i
seals[i] = true
}
// 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
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) Engine() consensus_engine.Engine { return bc.engine }
func (bc *BlockChainImpl) SubscribeRemovedLogsEvent(ch chan<- RemovedLogsEvent) event.Subscription {
return bc.scope.Track(bc.rmLogsFeed.Subscribe(ch))
}

@ -8,8 +8,6 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/ethdb"
"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/types"
"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.
mu chan struct{}
currentHeader atomic.Value // Current head of the blockchain.
engine consensus_engine.Engine
vmConfig *vm.Config
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,
engine consensus_engine.Engine, vmConfig vm.Config) (*EpochChain, error) {
vmConfig vm.Config) (*EpochChain, error) {
hash := rawdb.ReadCanonicalHash(db, 0)
genesisBlock := rawdb.ReadBlock(db, hash, 0)
@ -60,7 +57,6 @@ func NewEpochChain(db ethdb.Database, chainConfig *params.ChainConfig,
db: db,
mu: make(chan struct{}, 1),
currentHeader: atomic.Value{},
engine: engine,
vmConfig: &vmConfig,
headerCache: cache(headerCacheLimit),
@ -242,10 +238,6 @@ func (bc *EpochChain) Config() *params.ChainConfig {
return bc.chainConfig
}
func (bc *EpochChain) Engine() engine.Engine {
return bc.engine
}
func (bc *EpochChain) ReadShardState(epoch *big.Int) (*shard.State, error) {
cacheKey := string(epoch.Bytes())
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)
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)
header := chain.GetHeaderByNumber(0)

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

@ -21,7 +21,6 @@ import (
"github.com/harmony-one/harmony/core/vm"
"github.com/harmony-one/harmony/crypto/bls"
"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/numeric"
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}},
ShardID: 0,
}
engine = chain2.NewEngine()
)
genesis := gspec.MustCommit(database)
// 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())
// 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"
"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/types"
"github.com/harmony-one/harmony/internal/utils"
@ -67,7 +66,6 @@ type HeaderChain struct {
procInterrupt func() bool
rand *mrand.Rand
engine consensus_engine.Engine
}
// NewHeaderChain creates a new HeaderChain structure.
@ -75,7 +73,7 @@ type HeaderChain struct {
// getValidator should return the parent's validator
// procInterrupt points to the parent's interrupt semaphore
// 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)
tdCache, _ := lru.New(tdCacheLimit)
numberCache, _ := lru.New(numberCacheLimit)
@ -96,7 +94,6 @@ func NewHeaderChain(chainDb ethdb.Database, config *params.ChainConfig, engine c
canonicalCache: canonicalHash,
procInterrupt: procInterrupt,
rand: mrand.New(mrand.NewSource(seed.Int64())),
engine: engine,
}
hc.genesisHeader = hc.GetHeaderByNumber(0)
@ -548,9 +545,6 @@ func (hc *HeaderChain) SetGenesis(head *block.Header) {
// Config retrieves the header chain's chain configuration.
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
// a header chain does not have blocks available for retrieval.
func (hc *HeaderChain) GetBlock(hash common.Hash, number uint64) *types.Block {

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

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

@ -25,7 +25,6 @@ type syncProtocol interface {
type blockChain interface {
engine.ChainReader
Engine() engine.Engine
InsertChain(chain types.Blocks, verifyHeaders bool) (int, 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}
}
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]")
}
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/eth/rpc"
"github.com/harmony-one/harmony/hmy/tracers"
"github.com/harmony-one/harmony/internal/chain"
"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
func (hmy *Harmony) traceBlockNoThread(ctx context.Context, block *types.Block, config *TraceConfig) ([]*TxTraceResult, error) {
// 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
}
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)
}
// 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
}
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
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
}
parent := hmy.BlockChain.GetBlock(block.ParentHash(), block.NumberU64()-1)

@ -6,6 +6,7 @@ import (
"sort"
"time"
"github.com/harmony-one/harmony/consensus/engine"
"github.com/harmony-one/harmony/internal/params"
bls2 "github.com/harmony-one/bls/ffi/go/bls"
@ -16,7 +17,6 @@ import (
"github.com/pkg/errors"
"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/reward"
"github.com/harmony-one/harmony/consensus/signature"
@ -45,6 +45,8 @@ type engineImpl struct {
verifiedSigCache *lru.Cache // verifiedSigKey -> struct{}{}
}
var internal = NewEngine()
// NewEngine creates Engine with some cache
func NewEngine() *engineImpl {
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.
// 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 {

@ -13,7 +13,6 @@ import (
"github.com/ethereum/go-ethereum/common"
"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/rawdb"
"github.com/harmony-one/harmony/core/vm"
@ -40,7 +39,6 @@ type Collection interface {
type CollectionImpl struct {
dbFactory DBFactory
dbInit DBInitializer
engine engine.Engine
mtx sync.Mutex
pool map[uint32]core.BlockChain
disableCache map[uint32]bool
@ -56,14 +54,13 @@ type CollectionImpl struct {
// the factory is brand new (empty).
func NewCollection(
harmonyconfig *harmonyconfig.HarmonyConfig,
dbFactory DBFactory, dbInit DBInitializer, engine engine.Engine,
dbFactory DBFactory, dbInit DBInitializer,
chainConfig *params.ChainConfig,
) *CollectionImpl {
return &CollectionImpl{
harmonyconfig: harmonyconfig,
dbFactory: dbFactory,
dbInit: dbInit,
engine: engine,
pool: make(map[uint32]core.BlockChain),
disableCache: make(map[uint32]bool),
chainConfig: chainConfig,
@ -128,7 +125,7 @@ func (sc *CollectionImpl) ShardChain(shardID uint32, options ...core.Options) (c
}
var bc core.BlockChain
if opts.EpochChain {
bc, err = core.NewEpochChain(db, &chainConfig, sc.engine, vm.Config{})
bc, err = core.NewEpochChain(db, &chainConfig, vm.Config{})
} else {
stateCache, err := initStateCache(db, sc, shardID)
if err != nil {
@ -136,7 +133,7 @@ func (sc *CollectionImpl) ShardChain(shardID uint32, options ...core.Options) (c
}
if shardID == shard.BeaconChainShardID {
bc, err = core.NewBlockChainWithOptions(
db, stateCache, bc, cacheConfig, &chainConfig, sc.engine, vm.Config{}, opts,
db, stateCache, bc, cacheConfig, &chainConfig, vm.Config{}, opts,
)
} else {
beacon, ok := sc.pool[shard.BeaconChainShardID]
@ -145,7 +142,7 @@ func (sc *CollectionImpl) ShardChain(shardID uint32, options ...core.Options) (c
}
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"
"time"
"github.com/harmony-one/harmony/consensus/engine"
"github.com/harmony-one/harmony/internal/registry"
"github.com/harmony-one/harmony/internal/shardchain/tikv_manage"
"github.com/harmony-one/harmony/internal/tikv"
@ -1015,7 +1014,6 @@ func (node *Node) GetSyncID() [SyncIDLength]byte {
func New(
host p2p.Host,
consensusObj *consensus.Consensus,
engine engine.Engine,
collection *shardchain.CollectionImpl,
blacklist map[common.Address]struct{},
allowedTxs map[common.Address]core.AllowedTxData,
@ -1110,7 +1108,7 @@ func New(
node.TxPool = core.NewTxPool(txPoolConfig, node.Blockchain().Config(), blockchain, node.TransactionErrorSink)
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.committeeCache, _ = lru.New(16)

@ -8,6 +8,7 @@ import (
ffi_bls "github.com/harmony-one/bls/ffi/go/bls"
"github.com/harmony-one/harmony/core"
"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/shard"
"github.com/pkg/errors"
@ -179,7 +180,7 @@ func (node *Node) VerifyCrossLink(cl types.CrossLink) error {
if cl.ShardID() >= instance.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 {
return errors.Wrap(err, "[VerifyCrossLink]")

@ -33,10 +33,9 @@ func TestAddNewBlock(t *testing.T) {
if err != nil {
t.Fatalf("newhost failure: %v", err)
}
engine := chain.NewEngine()
chainconfig := nodeconfig.GetShardConfig(shard.BeaconChainShardID).GetNetworkType().ChainConfig()
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(
quorum.SuperMajorityVote, shard.BeaconChainShardID,
@ -53,7 +52,7 @@ func TestAddNewBlock(t *testing.T) {
t.Fatalf("Cannot craeate consensus: %v", err)
}
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)
stks := staking.StakingTransactions{}
@ -90,10 +89,9 @@ func TestVerifyNewBlock(t *testing.T) {
if err != nil {
t.Fatalf("newhost failure: %v", err)
}
engine := chain.NewEngine()
chainconfig := nodeconfig.GetShardConfig(shard.BeaconChainShardID).GetNetworkType().ChainConfig()
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(
quorum.SuperMajorityVote, shard.BeaconChainShardID,
@ -112,7 +110,7 @@ func TestVerifyNewBlock(t *testing.T) {
archiveMode := make(map[uint32]bool)
archiveMode[0] = true
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)
stks := staking.StakingTransactions{}
@ -146,10 +144,9 @@ func TestVerifyVRF(t *testing.T) {
if err != nil {
t.Fatalf("newhost failure: %v", err)
}
engine := chain.NewEngine()
chainconfig := nodeconfig.GetShardConfig(shard.BeaconChainShardID).GetNetworkType().ChainConfig()
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)
if err != nil {
@ -168,7 +165,7 @@ func TestVerifyVRF(t *testing.T) {
archiveMode := make(map[uint32]bool)
archiveMode[0] = true
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)
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().Config().VRFEpoch = big.NewInt(0)
if err := node.Blockchain().Engine().VerifyVRF(
if err := chain.Engine().VerifyVRF(
node.Blockchain(), block.Header(),
); err != nil {
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/types"
"github.com/harmony-one/harmony/crypto/bls"
"github.com/harmony-one/harmony/internal/chain"
nodeconfig "github.com/harmony-one/harmony/internal/configs/node"
"github.com/harmony-one/harmony/internal/registry"
"github.com/harmony-one/harmony/internal/shardchain"
@ -35,10 +34,9 @@ func TestFinalizeNewBlockAsync(t *testing.T) {
t.Fatalf("newhost failure: %v", err)
}
var testDBFactory = &shardchain.MemDBFactory{}
engine := chain.NewEngine()
chainconfig := nodeconfig.GetShardConfig(shard.BeaconChainShardID).GetNetworkType().ChainConfig()
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)
require.NoError(t, err)
@ -53,7 +51,7 @@ func TestFinalizeNewBlockAsync(t *testing.T) {
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()

@ -8,7 +8,6 @@ import (
"github.com/harmony-one/harmony/consensus/quorum"
"github.com/harmony-one/harmony/core"
"github.com/harmony-one/harmony/crypto/bls"
"github.com/harmony-one/harmony/internal/chain"
nodeconfig "github.com/harmony-one/harmony/internal/configs/node"
"github.com/harmony-one/harmony/internal/registry"
"github.com/harmony-one/harmony/internal/shardchain"
@ -34,13 +33,12 @@ func TestNewNode(t *testing.T) {
if err != nil {
t.Fatalf("newhost failure: %v", err)
}
engine := chain.NewEngine()
decider := quorum.NewDecider(
quorum.SuperMajorityVote, shard.BeaconChainShardID,
)
chainconfig := nodeconfig.GetShardConfig(shard.BeaconChainShardID).GetNetworkType().ChainConfig()
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)
if err != nil {
@ -54,7 +52,7 @@ func TestNewNode(t *testing.T) {
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 {
t.Error("Consensus is not initialized for the node")
}

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

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

@ -23,6 +23,7 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/harmony-one/harmony/core"
"github.com/harmony-one/harmony/internal/chain"
"github.com/harmony-one/harmony/block"
blockfactory "github.com/harmony-one/harmony/block/factory"
@ -49,7 +50,6 @@ type BlockGen struct {
receipts []*types.Receipt
uncles []*block.Header
config *params.ChainConfig
engine consensus_engine.Engine
}
// 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.
func GenerateChain(
config *params.ChainConfig, parent *types.Block,
engine consensus_engine.Engine, db ethdb.Database,
db ethdb.Database,
n int,
gen func(int, *BlockGen),
) ([]*types.Block, []types.Receipts) {
@ -185,18 +185,17 @@ func GenerateChain(
statedb: statedb,
config: config,
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
if gen != nil {
gen(i, b)
}
if b.engine != nil {
if true {
// 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 },
)
if err != nil {
@ -228,7 +227,7 @@ func GenerateChain(
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
if parent.Time() == nil {
time = big.NewInt(10)

@ -94,7 +94,7 @@ func fundFaucetContract(chain core.BlockChain) {
fmt.Println("--------- Funding addresses for Faucet Contract Call ---------")
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))
dataEnc = common.FromHex(FaucetContractBinary)
ftx, _ := types.SignTx(
@ -206,7 +206,7 @@ func playFaucetContract(chain core.BlockChain) {
func main() {
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())
backend := &testWorkerBackend{
@ -223,7 +223,7 @@ func main() {
//// Generate a small n-block chain and an uncle block for it
n := 3
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.SetShardID(0)
gen.AddTx(pendingTxs[i].(*types.Transaction))

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

Loading…
Cancel
Save