Revert "Removed engine dependency." (#4392)

* Revert "Fix tests."

This reverts commit 597ba2d6f1.

* Revert "Network type."

This reverts commit 5e1878aedc.

* Revert "Clean up code."

This reverts commit 15885f4c9b.

* Revert "Fix possible panic."

This reverts commit 1a70d5eb66.

* Revert "Removed engine dependency."

This reverts commit 8c2ff803f7.
pull/4376/head
Casey Gardiner 2 years ago committed by GitHub
parent 597ba2d6f1
commit fa84def721
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  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. 8
      cmd/harmony/main.go
  8. 2
      consensus/engine/consensus_engine.go
  9. 7
      consensus/engine/errors.go
  10. 2
      consensus/validator.go
  11. 16
      core/block_validator.go
  12. 6
      core/blockchain_impl.go
  13. 7
      core/epochchain.go
  14. 4
      core/epochchain_test.go
  15. 4
      core/evm.go
  16. 5
      core/evm_test.go
  17. 9
      core/genesis_initializer.go
  18. 10
      core/headerchain.go
  19. 18
      core/state_processor.go
  20. 6
      core/tx_pool_test.go
  21. 7
      hmy/tracer.go
  22. 10
      internal/chain/engine.go
  23. 7
      internal/shardchain/dbinit.go
  24. 24
      internal/shardchain/shardchains.go
  25. 4
      node/node.go
  26. 3
      node/node_cross_link.go
  27. 20
      node/node_handler_test.go
  28. 7
      node/node_newblock_test.go
  29. 7
      node/node_test.go
  30. 24
      node/worker/worker.go
  31. 12
      node/worker/worker_test.go
  32. 13
      test/chain/chain/chain_makers.go
  33. 4
      test/chain/main.go
  34. 2
      test/chain/reward/main.go

@ -880,12 +880,12 @@ func (ss *StateSync) UpdateBlockAndStatus(block *types.Block, bc core.BlockChain
}
startTime := time.Now()
if err := chain.Engine().VerifyHeaderSignature(bc, block.Header(), sig, bitmap); err != nil {
if err := bc.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 := chain.Engine().VerifyHeader(bc, block.Header(), verifySeal)
err := bc.Engine().VerifyHeader(bc, block.Header(), verifySeal)
if err == engine.ErrUnknownAncestor {
return err
} else if err != nil {

@ -27,6 +27,7 @@ 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 := chain.Engine().VerifyHeaderSignature(bc, block.Header(), sigBytes, bitmap); err != nil {
if err := bc.Engine().VerifyHeaderSignature(bc, block.Header(), sigBytes, bitmap); err != nil {
return &sigVerifyErr{err}
}
if err := chain.Engine().VerifyHeader(bc, block.Header(), true); err != nil {
if err := bc.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 := chain.Engine().VerifyHeaderSignature(bc, block.Header(), sig, bitmap); err != nil {
if err := bc.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 := chain.Engine().VerifyHeaderSignature(bc, block.Header(), sig, bitmap); err != nil {
if err := bc.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 := chain.Engine().VerifyHeader(bc, block.Header(), verifySeal)
err := bc.Engine().VerifyHeader(bc, block.Header(), verifySeal)
if err == engine.ErrUnknownAncestor {
return err
} else if err != nil {

@ -153,11 +153,6 @@ 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,6 +16,7 @@ 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"
@ -700,8 +701,11 @@ 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{}, nodeConfig.GetNetworkType(),
&hc, chainDBFactory, &core.GenesisInitializer{NetworkType: nodeConfig.GetNetworkType()}, engine, &chainConfig,
)
for shardID, archival := range nodeConfig.ArchiveModes() {
if archival {
@ -736,7 +740,7 @@ func setupConsensusAndNode(hc harmonyconfig.HarmonyConfig, nodeConfig *nodeconfi
os.Exit(1)
}
currentNode := node.New(myHost, currentConsensus, collection, blacklist, allowedTxs, localAccounts, nodeConfig.ArchiveModes(), &hc, registry)
currentNode := node.New(myHost, currentConsensus, engine, collection, blacklist, allowedTxs, localAccounts, nodeConfig.ArchiveModes(), &hc, registry)
if hc.Legacy != nil && hc.Legacy.TPBroadcastInvalidTxn != nil {
currentNode.BroadcastInvalidTx = *hc.Legacy.TPBroadcastInvalidTxn

@ -79,7 +79,7 @@ type Engine interface {
// via the VerifySeal method.
VerifyHeader(chain ChainReader, header *block.Header, seal bool) error
// VerifyHeaderSignature similar to VerifyHeader, which is only for verifying the block headers of one's own chain, this verification
// Similiar to VerifyHeader, which is only for verifying the block headers of one's own chain, this verification
// is used for verifying "incoming" block header against commit signature and bitmap sent from the other chain cross-shard via libp2p.
// i.e. this header verification api is more flexible since the caller specifies which commit signature and bitmap to use
// for verifying the block header, which is necessary for cross-shard block header verification. Example of such is cross-shard transaction.

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

@ -26,8 +26,6 @@ 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 +40,16 @@ import (
//
// BlockValidator implements validator.
type BlockValidator struct {
config *params.ChainConfig // Chain configuration options
bc BlockChain // Canonical blockchain
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) *BlockValidator {
func NewBlockValidator(config *params.ChainConfig, blockchain BlockChain, engine consensus_engine.Engine) *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 chain.Engine().VerifyHeader(v.bc, h, true)
return v.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 chain2.Engine().VerifyHeaders(v.bc, headers, seals)
return v.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 chain.Engine().VerifyHeaderSignature(v.bc, cxp.Header, commitSig, cxp.CommitBitmap)
return v.engine.VerifyHeaderSignature(v.bc, cxp.Header, commitSig, cxp.CommitBitmap)
}

@ -275,7 +275,7 @@ func newBlockChainWithOptions(
}
var err error
bc.hc, err = NewHeaderChain(db, chainConfig, bc.getProcInterrupt)
bc.hc, err = NewHeaderChain(db, chainConfig, engine, bc.getProcInterrupt)
if err != nil {
return nil, err
}
@ -294,8 +294,8 @@ func newBlockChainWithOptions(
beaconChain = bc
}
bc.SetValidator(NewBlockValidator(chainConfig, bc))
bc.SetProcessor(NewStateProcessor(chainConfig, bc, beaconChain))
bc.SetValidator(NewBlockValidator(chainConfig, bc, engine))
bc.SetProcessor(NewStateProcessor(chainConfig, bc, beaconChain, engine))
// Take ownership of this particular state
go bc.update()

@ -9,6 +9,7 @@ import (
"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"
@ -28,6 +29,7 @@ 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
@ -44,7 +46,7 @@ func cache(size int) *lru.Cache {
}
func NewEpochChain(db ethdb.Database, chainConfig *params.ChainConfig,
vmConfig vm.Config) (*EpochChain, error) {
engine consensus_engine.Engine, vmConfig vm.Config) (*EpochChain, error) {
hash := rawdb.ReadCanonicalHash(db, 0)
genesisBlock := rawdb.ReadBlock(db, hash, 0)
@ -58,6 +60,7 @@ 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),
@ -240,7 +243,7 @@ func (bc *EpochChain) Config() *params.ChainConfig {
}
func (bc *EpochChain) Engine() engine.Engine {
return chain.Engine()
return bc.engine
}
func (bc *EpochChain) ReadShardState(epoch *big.Int) (*shard.State, error) {

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

@ -26,6 +26,7 @@ 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"
@ -38,6 +39,9 @@ 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,7 @@ import (
"github.com/harmony-one/harmony/core/vm"
"github.com/harmony-one/harmony/crypto/bls"
"github.com/harmony-one/harmony/crypto/hash"
"github.com/harmony-one/harmony/internal/chain"
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,11 +41,12 @@ 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, chain.Engine(), vm.Config{})
chain, _ := NewBlockChain(database, state.NewDatabase(database), nil, nil, gspec.Config, engine, vm.Config{})
db, _ := chain.StateAt(genesis.Root())
// make a fake block header (use epoch 1 so that locked tokens can be tested)

@ -13,10 +13,11 @@ import (
// GenesisInitializer is a shardchain.DBInitializer adapter.
type GenesisInitializer struct {
NetworkType nodeconfig.NetworkType
}
// InitChainDB sets up a new genesis block in the database for the given shard.
func (gi *GenesisInitializer) InitChainDB(db ethdb.Database, networkType nodeconfig.NetworkType, shardID uint32) error {
func (gi *GenesisInitializer) InitChainDB(db ethdb.Database, shardID uint32) error {
shardState, _ := committee.WithStakingEnabled.Compute(
big.NewInt(GenesisEpoch), nil,
)
@ -33,14 +34,14 @@ func (gi *GenesisInitializer) InitChainDB(db ethdb.Database, networkType nodecon
}
shardState = &shard.State{Shards: []shard.Committee{*subComm}}
}
gi.setupGenesisBlock(db, shardID, shardState, networkType)
gi.setupGenesisBlock(db, shardID, shardState)
return nil
}
// SetupGenesisBlock sets up a genesis blockchain.
func (gi *GenesisInitializer) setupGenesisBlock(db ethdb.Database, shardID uint32, myShardState *shard.State, networkType nodeconfig.NetworkType) {
func (gi *GenesisInitializer) setupGenesisBlock(db ethdb.Database, shardID uint32, myShardState *shard.State) {
utils.Logger().Info().Interface("shardID", shardID).Msg("setting up a brand new chain database")
gspec := NewGenesisSpec(networkType, shardID)
gspec := NewGenesisSpec(gi.NetworkType, shardID)
gspec.ShardStateHash = myShardState.Hash()
gspec.ShardState = *myShardState.DeepCopy()
// Store genesis block into db.

@ -32,6 +32,7 @@ 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"
@ -65,7 +66,8 @@ type HeaderChain struct {
procInterrupt func() bool
rand *mrand.Rand
rand *mrand.Rand
engine consensus_engine.Engine
}
// NewHeaderChain creates a new HeaderChain structure.
@ -73,7 +75,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, procInterrupt func() bool) (*HeaderChain, error) {
func NewHeaderChain(chainDb ethdb.Database, config *params.ChainConfig, engine consensus_engine.Engine, procInterrupt func() bool) (*HeaderChain, error) {
headerCache, _ := lru.New(headerCacheLimit)
tdCache, _ := lru.New(tdCacheLimit)
numberCache, _ := lru.New(numberCacheLimit)
@ -94,6 +96,7 @@ func NewHeaderChain(chainDb ethdb.Database, config *params.ChainConfig, procInte
canonicalCache: canonicalHash,
procInterrupt: procInterrupt,
rand: mrand.New(mrand.NewSource(seed.Int64())),
engine: engine,
}
hc.genesisHeader = hc.GetHeaderByNumber(0)
@ -545,6 +548,9 @@ 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"
@ -50,13 +50,14 @@ const (
//
// StateProcessor implements Processor.
type StateProcessor struct {
config *params.ChainConfig // Chain configuration options
bc BlockChain // Canonical blockchain
beacon BlockChain // Beacon chain
resultCache *lru.Cache // Cache for result after a certain block is processed
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
}
// ProcessorResult structure is cached, and each individual element is returned
// this structure is cached, and each individual element is returned
type ProcessorResult struct {
Receipts types.Receipts
CxReceipts types.CXReceipts
@ -69,7 +70,7 @@ type ProcessorResult struct {
// NewStateProcessor initialises a new StateProcessor.
func NewStateProcessor(
config *params.ChainConfig, bc BlockChain, beacon BlockChain,
config *params.ChainConfig, bc BlockChain, beacon BlockChain, engine consensus_engine.Engine,
) *StateProcessor {
if bc == nil {
panic("bc is nil")
@ -82,6 +83,7 @@ func NewStateProcessor(
config: config,
bc: bc,
beacon: beacon,
engine: engine,
resultCache: resultCache,
}
}
@ -193,7 +195,7 @@ func (p *StateProcessor) Process(
// Block processing don't need to block on reward computation as in block proposal
sigsReady <- true
}()
_, payout, err := chain.Engine().Finalize(
_, payout, err := p.engine.Finalize(
p.bc,
p.beacon,
header, statedb, block.Transactions(),

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

@ -39,7 +39,6 @@ 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"
)
@ -348,7 +347,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 := chain.Engine().VerifyHeader(hmy.BlockChain, block.Header(), true); err != nil {
if err := hmy.BlockChain.Engine().VerifyHeader(hmy.BlockChain, block.Header(), true); err != nil {
return nil, err
}
parent := hmy.BlockChain.GetBlock(block.ParentHash(), block.NumberU64()-1)
@ -423,7 +422,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 := chain.Engine().VerifyHeader(hmy.BlockChain, block.Header(), true); err != nil {
if err := hmy.BlockChain.Engine().VerifyHeader(hmy.BlockChain, block.Header(), true); err != nil {
return nil, err
}
parent := hmy.BlockChain.GetBlock(block.ParentHash(), block.NumberU64()-1)
@ -524,7 +523,7 @@ func (hmy *Harmony) standardTraceBlockToFile(ctx context.Context, block *types.B
}
}
// Create the parent state database
if err := chain.Engine().VerifyHeader(hmy.BlockChain, block.Header(), true); err != nil {
if err := hmy.BlockChain.Engine().VerifyHeader(hmy.BlockChain, block.Header(), true); err != nil {
return nil, err
}
parent := hmy.BlockChain.GetBlock(block.ParentHash(), block.NumberU64()-1)

@ -6,7 +6,6 @@ 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"
@ -17,6 +16,7 @@ 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,10 +45,8 @@ type engineImpl struct {
verifiedSigCache *lru.Cache // verifiedSigKey -> struct{}{}
}
var internal engine.Engine = NewEngine()
// NewEngine creates Engine with some cache
func NewEngine() engine.Engine {
func NewEngine() *engineImpl {
sigCache, _ := lru.New(verifiedSigCache)
epochCtxCache, _ := lru.New(epochCtxCache)
return &engineImpl{
@ -57,10 +55,6 @@ func NewEngine() engine.Engine {
}
}
func Engine() engine.Engine {
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 {

@ -1,11 +1,8 @@
package shardchain
import (
"github.com/ethereum/go-ethereum/ethdb"
nodeconfig "github.com/harmony-one/harmony/internal/configs/node"
)
import "github.com/ethereum/go-ethereum/ethdb"
// DBInitializer initializes a newly created chain database.
type DBInitializer interface {
InitChainDB(db ethdb.Database, networkType nodeconfig.NetworkType, shardID uint32) error
InitChainDB(db ethdb.Database, shardID uint32) error
}

@ -6,18 +6,18 @@ import (
"time"
"github.com/harmony-one/harmony/core/state"
"github.com/harmony-one/harmony/internal/chain"
harmonyconfig "github.com/harmony-one/harmony/internal/configs/harmony"
nodeconfig "github.com/harmony-one/harmony/internal/configs/node"
"github.com/harmony-one/harmony/internal/shardchain/tikv_manage"
"github.com/harmony-one/harmony/shard"
"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"
"github.com/harmony-one/harmony/internal/params"
"github.com/harmony-one/harmony/internal/utils"
"github.com/pkg/errors"
)
@ -40,10 +40,11 @@ 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
networkType nodeconfig.NetworkType
chainConfig *params.ChainConfig
harmonyconfig *harmonyconfig.HarmonyConfig
}
@ -55,16 +56,17 @@ type CollectionImpl struct {
// the factory is brand new (empty).
func NewCollection(
harmonyconfig *harmonyconfig.HarmonyConfig,
dbFactory DBFactory, dbInit DBInitializer,
network nodeconfig.NetworkType,
dbFactory DBFactory, dbInit DBInitializer, engine engine.Engine,
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),
networkType: network,
chainConfig: chainConfig,
}
}
@ -93,7 +95,7 @@ func (sc *CollectionImpl) ShardChain(shardID uint32, options ...core.Options) (c
utils.Logger().Info().
Uint32("shardID", shardID).
Msg("initializing a new chain database")
if err := sc.dbInit.InitChainDB(db, sc.networkType, shardID); err != nil {
if err := sc.dbInit.InitChainDB(db, shardID); err != nil {
return nil, errors.Wrapf(err, "cannot initialize a new chain database")
}
}
@ -114,7 +116,7 @@ func (sc *CollectionImpl) ShardChain(shardID uint32, options ...core.Options) (c
}
}
chainConfig := sc.networkType.ChainConfig()
chainConfig := *sc.chainConfig
if shardID == shard.BeaconChainShardID {
// For beacon chain inside a shard chain, need to reset the eth chainID to shard 0's eth chainID in the config
@ -126,7 +128,7 @@ func (sc *CollectionImpl) ShardChain(shardID uint32, options ...core.Options) (c
}
var bc core.BlockChain
if opts.EpochChain {
bc, err = core.NewEpochChain(db, &chainConfig, vm.Config{})
bc, err = core.NewEpochChain(db, &chainConfig, sc.engine, vm.Config{})
} else {
stateCache, err := initStateCache(db, sc, shardID)
if err != nil {
@ -134,7 +136,7 @@ func (sc *CollectionImpl) ShardChain(shardID uint32, options ...core.Options) (c
}
if shardID == shard.BeaconChainShardID {
bc, err = core.NewBlockChainWithOptions(
db, stateCache, bc, cacheConfig, &chainConfig, chain.Engine(), vm.Config{}, opts,
db, stateCache, bc, cacheConfig, &chainConfig, sc.engine, vm.Config{}, opts,
)
} else {
beacon, ok := sc.pool[shard.BeaconChainShardID]
@ -143,7 +145,7 @@ func (sc *CollectionImpl) ShardChain(shardID uint32, options ...core.Options) (c
}
bc, err = core.NewBlockChainWithOptions(
db, stateCache, beacon, cacheConfig, &chainConfig, chain.Engine(), vm.Config{}, opts,
db, stateCache, beacon, cacheConfig, &chainConfig, sc.engine, vm.Config{}, opts,
)
}
}

@ -12,6 +12,7 @@ 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"
@ -1014,6 +1015,7 @@ 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,
@ -1108,7 +1110,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)
node.Worker = worker.New(node.Blockchain().Config(), blockchain, beaconChain, engine)
node.deciderCache, _ = lru.New(16)
node.committeeCache, _ = lru.New(16)

@ -8,7 +8,6 @@ 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"
@ -180,7 +179,7 @@ func (node *Node) VerifyCrossLink(cl types.CrossLink) error {
if cl.ShardID() >= instance.NumShards() {
return errors.New("[VerifyCrossLink] ShardID should less than NumShards")
}
engine := chain.Engine()
engine := node.Blockchain().Engine()
if err := engine.VerifyCrossLink(node.Blockchain(), cl); err != nil {
return errors.Wrap(err, "[VerifyCrossLink]")

@ -33,8 +33,10 @@ 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{}, nodeconfig.GetShardConfig(shard.BeaconChainShardID).GetNetworkType(),
nil, testDBFactory, &core.GenesisInitializer{NetworkType: nodeconfig.GetShardConfig(shard.BeaconChainShardID).GetNetworkType()}, engine, &chainconfig,
)
decider := quorum.NewDecider(
quorum.SuperMajorityVote, shard.BeaconChainShardID,
@ -51,7 +53,7 @@ func TestAddNewBlock(t *testing.T) {
t.Fatalf("Cannot craeate consensus: %v", err)
}
nodeconfig.SetNetworkType(nodeconfig.Devnet)
node := New(host, consensus, collection, nil, nil, nil, nil, nil, reg)
node := New(host, consensus, engine, collection, nil, nil, nil, nil, nil, reg)
txs := make(map[common.Address]types.Transactions)
stks := staking.StakingTransactions{}
@ -88,8 +90,10 @@ 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{}, nodeconfig.GetShardConfig(shard.BeaconChainShardID).GetNetworkType(),
nil, testDBFactory, &core.GenesisInitializer{NetworkType: nodeconfig.GetShardConfig(shard.BeaconChainShardID).GetNetworkType()}, engine, &chainconfig,
)
decider := quorum.NewDecider(
quorum.SuperMajorityVote, shard.BeaconChainShardID,
@ -108,7 +112,7 @@ func TestVerifyNewBlock(t *testing.T) {
archiveMode := make(map[uint32]bool)
archiveMode[0] = true
archiveMode[1] = false
node := New(host, consensus, collection, nil, nil, nil, archiveMode, nil, reg)
node := New(host, consensus, engine, collection, nil, nil, nil, archiveMode, nil, reg)
txs := make(map[common.Address]types.Transactions)
stks := staking.StakingTransactions{}
@ -142,8 +146,10 @@ 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{}, nodeconfig.GetShardConfig(shard.BeaconChainShardID).GetNetworkType(),
nil, testDBFactory, &core.GenesisInitializer{NetworkType: nodeconfig.GetShardConfig(shard.BeaconChainShardID).GetNetworkType()}, engine, &chainconfig,
)
blockchain, err := collection.ShardChain(shard.BeaconChainShardID)
if err != nil {
@ -162,7 +168,7 @@ func TestVerifyVRF(t *testing.T) {
archiveMode := make(map[uint32]bool)
archiveMode[0] = true
archiveMode[1] = false
node := New(host, consensus, collection, nil, nil, nil, archiveMode, nil, reg)
node := New(host, consensus, engine, collection, nil, nil, nil, archiveMode, nil, reg)
txs := make(map[common.Address]types.Transactions)
stks := staking.StakingTransactions{}
@ -199,7 +205,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 := chain.Engine().VerifyVRF(
if err := node.Blockchain().Engine().VerifyVRF(
node.Blockchain(), block.Header(),
); err != nil {
t.Error("New vrf is not verified successfully:", err)

@ -10,6 +10,7 @@ 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"
@ -34,8 +35,10 @@ 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{}, nodeconfig.GetShardConfig(shard.BeaconChainShardID).GetNetworkType(),
nil, testDBFactory, &core.GenesisInitializer{NetworkType: nodeconfig.GetShardConfig(shard.BeaconChainShardID).GetNetworkType()}, engine, &chainconfig,
)
blockchain, err := collection.ShardChain(shard.BeaconChainShardID)
require.NoError(t, err)
@ -50,7 +53,7 @@ func TestFinalizeNewBlockAsync(t *testing.T) {
t.Fatalf("Cannot craeate consensus: %v", err)
}
node := New(host, consensus, collection, nil, nil, nil, nil, nil, registry.New().SetBlockchain(blockchain))
node := New(host, consensus, engine, collection, nil, nil, nil, nil, nil, registry.New().SetBlockchain(blockchain))
node.Worker.UpdateCurrent()

@ -8,6 +8,7 @@ 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"
@ -33,11 +34,13 @@ 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{}, nodeconfig.GetShardConfig(shard.BeaconChainShardID).GetNetworkType(),
nil, testDBFactory, &core.GenesisInitializer{NetworkType: nodeconfig.GetShardConfig(shard.BeaconChainShardID).GetNetworkType()}, engine, &chainconfig,
)
blockchain, err := collection.ShardChain(shard.BeaconChainShardID)
if err != nil {
@ -51,7 +54,7 @@ func TestNewNode(t *testing.T) {
t.Fatalf("Cannot craeate consensus: %v", err)
}
node := New(host, consensus, collection, nil, nil, nil, nil, nil, reg)
node := New(host, consensus, engine, collection, nil, nil, nil, nil, nil, reg)
if node.Consensus == nil {
t.Error("Consensus is not initialized for the node")
}

@ -8,7 +8,6 @@ import (
"time"
"github.com/harmony-one/harmony/consensus/reward"
"github.com/harmony-one/harmony/internal/chain"
"github.com/harmony-one/harmony/consensus"
@ -20,6 +19,7 @@ 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,6 +59,7 @@ 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
}
@ -311,7 +312,7 @@ func (w *Worker) UpdateCurrent() error {
Time(big.NewInt(timestamp)).
ShardID(w.chain.ShardID()).
Header()
return w.makeCurrent(parent.Header(), header)
return w.makeCurrent(parent, header)
}
// GetCurrentHeader returns the current header to propose
@ -320,7 +321,7 @@ func (w *Worker) GetCurrentHeader() *block.Header {
}
// makeCurrent creates a new environment for the current cycle.
func (w *Worker) makeCurrent(parent *block.Header, header *block.Header) error {
func (w *Worker) makeCurrent(parent *types.Block, header *block.Header) error {
state, err := w.chain.StateAt(parent.Root())
if err != nil {
return err
@ -380,6 +381,16 @@ func (w *Worker) GetCurrentReceipts() []*types.Receipt {
return w.current.receipts
}
// OutgoingReceipts get the receipts generated starting from the last state.
func (w *Worker) OutgoingReceipts() []*types.CXReceipt {
return w.current.outcxs
}
// IncomingReceipts get incoming receipts in destination shard that is received from source shard
func (w *Worker) IncomingReceipts() []*types.CXReceiptsProof {
return w.current.incxs
}
// CollectVerifiedSlashes sets w.current.slashes only to those that
// past verification
func (w *Worker) CollectVerifiedSlashes() error {
@ -547,7 +558,7 @@ func (w *Worker) FinalizeNewBlock(
}
}()
block, payout, err := chain.Engine().Finalize(
block, payout, err := w.engine.Finalize(
w.chain,
w.beacon,
copyHeader, state, w.current.txs, w.current.receipts,
@ -563,13 +574,14 @@ func (w *Worker) FinalizeNewBlock(
// New create a new worker object.
func New(
config *params.ChainConfig, chain core.BlockChain, beacon core.BlockChain,
config *params.ChainConfig, chain core.BlockChain, beacon core.BlockChain, engine consensus_engine.Engine,
) *Worker {
worker := &Worker{
config: config,
factory: blockfactory.NewFactory(config),
chain: chain,
beacon: beacon,
engine: engine,
}
worker.gasFloor = 80000000
worker.gasCeil = 120000000
@ -586,7 +598,7 @@ func New(
Time(big.NewInt(timestamp)).
ShardID(worker.chain.ShardID()).
Header()
worker.makeCurrent(parent.Header(), header)
worker.makeCurrent(parent, header)
return worker
}

@ -6,7 +6,6 @@ import (
"testing"
"github.com/harmony-one/harmony/core/state"
"github.com/harmony-one/harmony/internal/chain"
"github.com/ethereum/go-ethereum/core/rawdb"
@ -17,6 +16,7 @@ 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,17 +40,18 @@ 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, chain.Engine(), vm.Config{})
chain, err := core.NewBlockChain(database, state.NewDatabase(database), &core.BlockChainImpl{}, nil, gspec.Config, engine, vm.Config{})
if err != nil {
t.Error(err)
}
// Create a new worker
worker := New(params.TestChainConfig, chain, nil)
worker := New(params.TestChainConfig, chain, nil, engine)
if worker.GetCurrentState().GetBalance(crypto.PubkeyToAddress(testBankKey.PublicKey)).Cmp(testBankFunds) != 0 {
t.Error("Worker state is not setup correctly")
@ -67,13 +68,14 @@ 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, chain.Engine(), vm.Config{})
chain, _ := core.NewBlockChain(database, state.NewDatabase(database), nil, nil, gspec.Config, engine, vm.Config{})
// Create a new worker
worker := New(params.TestChainConfig, chain, nil)
worker := New(params.TestChainConfig, chain, nil, engine)
// Generate a test tx
baseNonce := worker.GetCurrentState().GetNonce(crypto.PubkeyToAddress(testBankKey.PublicKey))

@ -23,7 +23,6 @@ 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"
@ -50,6 +49,7 @@ 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,
db ethdb.Database,
engine consensus_engine.Engine, db ethdb.Database,
n int,
gen func(int, *BlockGen),
) ([]*types.Block, []types.Receipts) {
@ -185,17 +185,18 @@ func GenerateChain(
statedb: statedb,
config: config,
factory: factory,
engine: engine,
}
b.header = makeHeader(chainreader, parent, statedb, factory)
b.header = makeHeader(chainreader, parent, statedb, b.engine, factory)
// Execute any user modifications to the block
if gen != nil {
gen(i, b)
}
if true {
if b.engine != nil {
// Finalize and seal the block
block, _, err := chain.Engine().Finalize(
block, _, err := b.engine.Finalize(
chainreader, nil, b.header, statedb, b.txs, b.receipts, nil, nil, nil, nil, nil, func() uint64 { return 0 },
)
if err != nil {
@ -227,7 +228,7 @@ func GenerateChain(
return blocks, receipts
}
func makeHeader(chain consensus_engine.ChainReader, parent *types.Block, state *state.DB, factory blockfactory.Factory) *block.Header {
func makeHeader(chain consensus_engine.ChainReader, parent *types.Block, state *state.DB, engine consensus_engine.Engine, 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)
contractworker = pkgworker.New(params.TestChainConfig, chain, nil, chain.Engine())
nonce = contractworker.GetCurrentState().GetNonce(crypto.PubkeyToAddress(FaucetPriKey.PublicKey))
dataEnc = common.FromHex(FaucetContractBinary)
ftx, _ := types.SignTx(
@ -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, database, n, func(i int, gen *chain2.BlockGen) {
blocks, _ := chain2.GenerateChain(chainConfig, genesis, chain.Engine(), database, n, func(i int, gen *chain2.BlockGen) {
gen.SetCoinbase(FaucetAddress)
gen.SetShardID(0)
gen.AddTx(pendingTxs[i].(*types.Transaction))

@ -7,7 +7,6 @@ import (
"time"
"github.com/ethereum/go-ethereum/core/rawdb"
"github.com/harmony-one/harmony/internal/chain"
msg_pb "github.com/harmony-one/harmony/api/proto/message"
"github.com/harmony-one/harmony/crypto/bls"
@ -23,6 +22,7 @@ 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"

Loading…
Cancel
Save