diff options
author | Péter Szilágyi <peterke@gmail.com> | 2018-11-16 22:34:30 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-11-16 22:34:30 +0800 |
commit | 91c66d47effed704e3f5e6be8b44474b722c3c45 (patch) | |
tree | 33b8721bd8001e80b8250f4a783babf0b5110a68 /core | |
parent | 68be45e5f89a5bde33376a8e103c133392f18516 (diff) | |
parent | accc0fab4f407eaeab428127bd5395a28f371f9f (diff) | |
download | go-tangerine-91c66d47effed704e3f5e6be8b44474b722c3c45.tar go-tangerine-91c66d47effed704e3f5e6be8b44474b722c3c45.tar.gz go-tangerine-91c66d47effed704e3f5e6be8b44474b722c3c45.tar.bz2 go-tangerine-91c66d47effed704e3f5e6be8b44474b722c3c45.tar.lz go-tangerine-91c66d47effed704e3f5e6be8b44474b722c3c45.tar.xz go-tangerine-91c66d47effed704e3f5e6be8b44474b722c3c45.tar.zst go-tangerine-91c66d47effed704e3f5e6be8b44474b722c3c45.zip |
Merge pull request #18085 from holiman/downloader_span
downloader: different sync strategy
Diffstat (limited to 'core')
-rw-r--r-- | core/blockchain.go | 13 | ||||
-rw-r--r-- | core/rawdb/accessors_chain.go | 9 |
2 files changed, 20 insertions, 2 deletions
diff --git a/core/blockchain.go b/core/blockchain.go index 22f130ce6..d173b2de2 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -561,6 +561,17 @@ func (bc *BlockChain) HasBlock(hash common.Hash, number uint64) bool { return rawdb.HasBody(bc.db, hash, number) } +// HasFastBlock checks if a fast block is fully present in the database or not. +func (bc *BlockChain) HasFastBlock(hash common.Hash, number uint64) bool { + if !bc.HasBlock(hash, number) { + return false + } + if bc.receiptsCache.Contains(hash) { + return true + } + return rawdb.HasReceipts(bc.db, hash, number) +} + // HasState checks if state trie is fully present in the database or not. func (bc *BlockChain) HasState(hash common.Hash) bool { _, err := bc.stateCache.OpenTrie(hash) @@ -618,12 +629,10 @@ func (bc *BlockChain) GetReceiptsByHash(hash common.Hash) types.Receipts { if receipts, ok := bc.receiptsCache.Get(hash); ok { return receipts.(types.Receipts) } - number := rawdb.ReadHeaderNumber(bc.db, hash) if number == nil { return nil } - receipts := rawdb.ReadReceipts(bc.db, hash, *number) bc.receiptsCache.Add(hash, receipts) return receipts diff --git a/core/rawdb/accessors_chain.go b/core/rawdb/accessors_chain.go index 6660e17de..491a125c6 100644 --- a/core/rawdb/accessors_chain.go +++ b/core/rawdb/accessors_chain.go @@ -271,6 +271,15 @@ func DeleteTd(db DatabaseDeleter, hash common.Hash, number uint64) { } } +// HasReceipts verifies the existence of all the transaction receipts belonging +// to a block. +func HasReceipts(db DatabaseReader, hash common.Hash, number uint64) bool { + if has, err := db.Has(blockReceiptsKey(number, hash)); !has || err != nil { + return false + } + return true +} + // ReadReceipts retrieves all the transaction receipts belonging to a block. func ReadReceipts(db DatabaseReader, hash common.Hash, number uint64) types.Receipts { // Retrieve the flattened receipt slice |