diff options
author | BJ4 <bojie@dexon.org> | 2018-11-09 12:08:17 +0800 |
---|---|---|
committer | Wei-Ning Huang <w@dexon.org> | 2019-04-09 21:32:53 +0800 |
commit | 07da8c75d1a8f9557f73eff4d6cb74e4047ea7b8 (patch) | |
tree | e045d29c9b1b9cd074a51ba8ef9eebe9a7e8c15e /core/blockchain.go | |
parent | 39ccaa58fd25cac9d2f85823f2ea56cd65cb06b7 (diff) | |
download | dexon-07da8c75d1a8f9557f73eff4d6cb74e4047ea7b8.tar dexon-07da8c75d1a8f9557f73eff4d6cb74e4047ea7b8.tar.gz dexon-07da8c75d1a8f9557f73eff4d6cb74e4047ea7b8.tar.bz2 dexon-07da8c75d1a8f9557f73eff4d6cb74e4047ea7b8.tar.lz dexon-07da8c75d1a8f9557f73eff4d6cb74e4047ea7b8.tar.xz dexon-07da8c75d1a8f9557f73eff4d6cb74e4047ea7b8.tar.zst dexon-07da8c75d1a8f9557f73eff4d6cb74e4047ea7b8.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 c44d2633a..79e0b2a02 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 |