|
|
|
@ -49,8 +49,6 @@ 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" |
|
|
|
@ -192,6 +190,7 @@ 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 |
|
|
|
@ -205,9 +204,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, |
|
|
|
|
vmConfig vm.Config, options Options, |
|
|
|
|
engine consensus_engine.Engine, vmConfig vm.Config, options Options, |
|
|
|
|
) (*BlockChainImpl, error) { |
|
|
|
|
return newBlockChainWithOptions(db, stateCache, beaconChain, cacheConfig, chainConfig, vmConfig, options) |
|
|
|
|
return newBlockChainWithOptions(db, stateCache, beaconChain, cacheConfig, chainConfig, engine, vmConfig, options) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// NewBlockChain returns a fully initialised block chain using information
|
|
|
|
@ -215,15 +214,15 @@ func NewBlockChainWithOptions( |
|
|
|
|
// Processor.
|
|
|
|
|
func NewBlockChain( |
|
|
|
|
db ethdb.Database, stateCache state.Database, beaconChain BlockChain, cacheConfig *CacheConfig, chainConfig *params.ChainConfig, |
|
|
|
|
vmConfig vm.Config, |
|
|
|
|
engine consensus_engine.Engine, vmConfig vm.Config, |
|
|
|
|
) (*BlockChainImpl, error) { |
|
|
|
|
return newBlockChainWithOptions(db, stateCache, beaconChain, cacheConfig, chainConfig, vmConfig, Options{}) |
|
|
|
|
return newBlockChainWithOptions(db, stateCache, beaconChain, cacheConfig, chainConfig, engine, vmConfig, Options{}) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func newBlockChainWithOptions( |
|
|
|
|
db ethdb.Database, stateCache state.Database, beaconChain BlockChain, |
|
|
|
|
cacheConfig *CacheConfig, chainConfig *params.ChainConfig, |
|
|
|
|
vmConfig vm.Config, options Options) (*BlockChainImpl, error) { |
|
|
|
|
engine consensus_engine.Engine, vmConfig vm.Config, options Options) (*BlockChainImpl, error) { |
|
|
|
|
|
|
|
|
|
bodyCache, _ := lru.New(bodyCacheLimit) |
|
|
|
|
bodyRLPCache, _ := lru.New(bodyCacheLimit) |
|
|
|
@ -267,6 +266,7 @@ func newBlockChainWithOptions( |
|
|
|
|
blockAccumulatorCache: blockAccumulatorCache, |
|
|
|
|
leaderPubKeyFromCoinbase: leaderPubKeyFromCoinbase, |
|
|
|
|
blockchainPruner: newBlockchainPruner(db), |
|
|
|
|
engine: engine, |
|
|
|
|
vmConfig: vmConfig, |
|
|
|
|
badBlocks: badBlocks, |
|
|
|
|
pendingSlashes: slash.Records{}, |
|
|
|
@ -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 := chain.Engine() |
|
|
|
|
engine := blockchain.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 := chain.Engine().VerifyVRF( |
|
|
|
|
if err := bc.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 := chain.Engine().VerifyShardState(bc, beaconChain, block.Header()) |
|
|
|
|
err := bc.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 := chain2.Engine().VerifyHeaders(bc, headers, seals) |
|
|
|
|
abort, results := bc.Engine().VerifyHeaders(bc, headers, seals) |
|
|
|
|
verifyHeadersResults = results |
|
|
|
|
defer close(abort) |
|
|
|
|
} |
|
|
|
@ -2045,6 +2045,8 @@ 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)) |
|
|
|
|
} |
|
|
|
|