diff options
author | Felföldi Zsolt <zsfelfoldi@gmail.com> | 2018-06-12 21:52:54 +0800 |
---|---|---|
committer | Péter Szilágyi <peterke@gmail.com> | 2018-06-12 21:52:54 +0800 |
commit | 049f5b357200406c01f7bf2d2e2936d1d28a319b (patch) | |
tree | ef73043730c3d77359b9163ab6cbb2f053e5cf86 /light/lightchain.go | |
parent | 0255951587ef0eada5d162f3404bc481f70a2ce2 (diff) | |
download | dexon-049f5b357200406c01f7bf2d2e2936d1d28a319b.tar.gz dexon-049f5b357200406c01f7bf2d2e2936d1d28a319b.tar.zst dexon-049f5b357200406c01f7bf2d2e2936d1d28a319b.zip |
core, eth, les: more efficient hash-based header chain retrieval (#16946)
Diffstat (limited to 'light/lightchain.go')
-rw-r--r-- | light/lightchain.go | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/light/lightchain.go b/light/lightchain.go index 9d0a4e4f7..30b9bd89a 100644 --- a/light/lightchain.go +++ b/light/lightchain.go @@ -433,6 +433,18 @@ func (self *LightChain) GetBlockHashesFromHash(hash common.Hash, max uint64) []c return self.hc.GetBlockHashesFromHash(hash, max) } +// GetAncestor retrieves the Nth ancestor of a given block. It assumes that either the given block or +// a close ancestor of it is canonical. maxNonCanonical points to a downwards counter limiting the +// number of blocks to be individually checked before we reach the canonical chain. +// +// Note: ancestor == 0 returns the same block, 1 returns its parent and so on. +func (bc *LightChain) GetAncestor(hash common.Hash, number, ancestor uint64, maxNonCanonical *uint64) (common.Hash, uint64) { + bc.chainmu.Lock() + defer bc.chainmu.Unlock() + + return bc.hc.GetAncestor(hash, number, ancestor, maxNonCanonical) +} + // GetHeaderByNumber retrieves a block header from the database by number, // caching it (associated with its hash) if found. func (self *LightChain) GetHeaderByNumber(number uint64) *types.Header { |