diff options
author | BJ4 <bojie@dexon.org> | 2018-11-09 12:08:17 +0800 |
---|---|---|
committer | Wei-Ning Huang <w@dexon.org> | 2019-03-12 12:19:09 +0800 |
commit | f28fece79933816d1eed57b758d211760639cb58 (patch) | |
tree | 307c7be454e9a9be95076cda49bfaab7be308406 /core/blockchain.go | |
parent | dbdc956478df94d63af69c28a17e63ecae1235aa (diff) | |
download | dexon-f28fece79933816d1eed57b758d211760639cb58.tar dexon-f28fece79933816d1eed57b758d211760639cb58.tar.gz dexon-f28fece79933816d1eed57b758d211760639cb58.tar.bz2 dexon-f28fece79933816d1eed57b758d211760639cb58.tar.lz dexon-f28fece79933816d1eed57b758d211760639cb58.tar.xz dexon-f28fece79933816d1eed57b758d211760639cb58.tar.zst dexon-f28fece79933816d1eed57b758d211760639cb58.zip |
app: fix core test
Diffstat (limited to 'core/blockchain.go')
-rw-r--r-- | core/blockchain.go | 78 |
1 files changed, 77 insertions, 1 deletions
diff --git a/core/blockchain.go b/core/blockchain.go index 7b0fcd23c..0949c7cc2 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -203,7 +203,83 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, chainConfig *par addressCounter: make(map[uint32]map[common.Address]uint64), chainLastHeight: make(map[uint32]uint64), } - bc.SetValidator(NewDexonBlockValidator(chainConfig, bc, engine)) + bc.SetValidator(NewBlockValidator(chainConfig, bc, engine)) + bc.SetProcessor(NewStateProcessor(chainConfig, bc, engine)) + + var err error + bc.hc, err = NewHeaderChain(db, chainConfig, engine, bc.getProcInterrupt) + if err != nil { + return nil, err + } + bc.genesisBlock = bc.GetBlockByNumber(0) + if bc.genesisBlock == nil { + return nil, ErrNoGenesis + } + if err := bc.loadLastState(); err != nil { + return nil, err + } + // Check the current state of the block hashes and make sure that we do not have any of the bad blocks in our chain + for hash := range BadHashes { + if header := bc.GetHeaderByHash(hash); header != nil { + // get the canonical block corresponding to the offending header's number + headerByNumber := bc.GetHeaderByNumber(header.Number.Uint64()) + // make sure the headerByNumber (if present) is in our current canonical chain + if headerByNumber != nil && headerByNumber.Hash() == header.Hash() { + log.Error("Found bad hash, rewinding chain", "number", header.Number, "hash", header.ParentHash) + bc.SetHead(header.Number.Uint64() - 1) + log.Error("Chain rewind was successful, resuming normal operation") + } + } + } + + // Set genesis round height mapping. + bc.roundHeightMap.Store(0, 0) + + // Take ownership of this particular state + go bc.update() + return bc, nil +} + +func NewBlockChainWithDexonValidator(db ethdb.Database, cacheConfig *CacheConfig, chainConfig *params.ChainConfig, engine consensus.Engine, vmConfig vm.Config, shouldPreserve func(block *types.Block) bool) (*BlockChain, error) { + if cacheConfig == nil { + cacheConfig = &CacheConfig{ + TrieNodeLimit: 256 * 1024 * 1024, + TrieTimeLimit: 5 * time.Minute, + } + } + bodyCache, _ := lru.New(bodyCacheLimit) + bodyRLPCache, _ := lru.New(bodyCacheLimit) + receiptsCache, _ := lru.New(receiptsCacheLimit) + blockCache, _ := lru.New(blockCacheLimit) + futureBlocks, _ := lru.New(maxFutureBlocks) + badBlocks, _ := lru.New(badBlockLimit) + + bc := &BlockChain{ + chainConfig: chainConfig, + cacheConfig: cacheConfig, + db: db, + triegc: prque.New(nil), + stateCache: state.NewDatabase(db), + quit: make(chan struct{}), + bodyCache: bodyCache, + bodyRLPCache: bodyRLPCache, + receiptsCache: receiptsCache, + blockCache: blockCache, + futureBlocks: futureBlocks, + engine: engine, + vmConfig: vmConfig, + badBlocks: badBlocks, + pendingBlocks: make(map[uint64]struct { + block *types.Block + receipts types.Receipts + }), + confirmedBlocks: make(map[uint32]map[coreCommon.Hash]*blockInfo), + addressNonce: make(map[uint32]map[common.Address]uint64), + addressCost: make(map[uint32]map[common.Address]*big.Int), + addressCounter: make(map[uint32]map[common.Address]uint64), + chainLastHeight: make(map[uint32]uint64), + } + bc.SetValidator(NewBlockValidator(chainConfig, bc, engine)) bc.SetProcessor(NewStateProcessor(chainConfig, bc, engine)) var err error |