mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-23 21:26:42 +00:00
core: don't process blocks if they're already present in the database
This commit is contained in:
parent
f6367548e4
commit
d4fd6a6101
4 changed files with 16 additions and 3 deletions
|
|
@ -20,6 +20,7 @@ package common
|
|||
type Database interface {
|
||||
Put(key []byte, value []byte) error
|
||||
Get(key []byte) ([]byte, error)
|
||||
Has(key []byte) bool
|
||||
Delete(key []byte) error
|
||||
Close()
|
||||
Flush() error
|
||||
|
|
|
|||
|
|
@ -364,9 +364,7 @@ func (bc *ChainManager) HasBlock(hash common.Hash) bool {
|
|||
if bc.cache.Contains(hash) {
|
||||
return true
|
||||
}
|
||||
|
||||
data, _ := bc.chainDb.Get(append(blockHashPre, hash[:]...))
|
||||
return len(data) != 0
|
||||
return bc.chainDb.Has(append(blockHashPre, hash[:]...))
|
||||
}
|
||||
|
||||
func (self *ChainManager) GetBlockHashesFromHash(hash common.Hash, max uint64) (chain []common.Hash) {
|
||||
|
|
@ -560,6 +558,10 @@ func (self *ChainManager) InsertChain(chain types.Blocks) (int, error) {
|
|||
glog.V(logger.Debug).Infoln("Premature abort during chain processing")
|
||||
break
|
||||
}
|
||||
if self.HasBlock(block.Hash()) {
|
||||
stats.ignored++
|
||||
continue
|
||||
}
|
||||
|
||||
bstart := time.Now()
|
||||
// Wait for block i's nonce to be verified before processing
|
||||
|
|
|
|||
|
|
@ -138,6 +138,11 @@ func (self *LDBDatabase) Delete(key []byte) error {
|
|||
return self.db.Delete(key, nil)
|
||||
}
|
||||
|
||||
func (self *LDBDatabase) Has(key []byte) bool {
|
||||
b, _ := self.db.Has(key, nil)
|
||||
return b
|
||||
}
|
||||
|
||||
func (self *LDBDatabase) NewIterator() iterator.Iterator {
|
||||
return self.db.NewIterator(nil, nil)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -57,6 +57,11 @@ func (db *MemDatabase) GetKeys() []*common.Key {
|
|||
}
|
||||
*/
|
||||
|
||||
func (db *MemDatabase) Has(key []byte) bool {
|
||||
_, ok := db.db[string(key)]
|
||||
return ok
|
||||
}
|
||||
|
||||
func (db *MemDatabase) Delete(key []byte) error {
|
||||
delete(db.db, string(key))
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue