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