mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-15 17:30:44 +00:00
eth/filters: fix for eth_getLogs failing with tag (#25922)
This commit is contained in:
parent
98c67ab2d9
commit
c241fc3574
3 changed files with 59 additions and 14 deletions
|
|
@ -895,11 +895,32 @@ type filterBackend struct {
|
||||||
func (fb *filterBackend) ChainDb() ethdb.Database { return fb.db }
|
func (fb *filterBackend) ChainDb() ethdb.Database { return fb.db }
|
||||||
func (fb *filterBackend) EventMux() *event.TypeMux { panic("not supported") }
|
func (fb *filterBackend) EventMux() *event.TypeMux { panic("not supported") }
|
||||||
|
|
||||||
func (fb *filterBackend) HeaderByNumber(ctx context.Context, block rpc.BlockNumber) (*types.Header, error) {
|
func (fb *filterBackend) HeaderByNumber(ctx context.Context, number rpc.BlockNumber) (*types.Header, error) {
|
||||||
if block == rpc.LatestBlockNumber {
|
switch number {
|
||||||
|
case rpc.PendingBlockNumber:
|
||||||
|
if block := fb.backend.pendingBlock; block != nil {
|
||||||
|
return block.Header(), nil
|
||||||
|
}
|
||||||
|
return nil, nil
|
||||||
|
case rpc.LatestBlockNumber:
|
||||||
return fb.bc.CurrentHeader(), nil
|
return fb.bc.CurrentHeader(), nil
|
||||||
|
case rpc.CommittedBlockNumber:
|
||||||
|
if fb.bc.Config().XDPoS == nil {
|
||||||
|
return nil, errors.New("only XDPoS v2 supports committed block lookup")
|
||||||
|
}
|
||||||
|
current := fb.bc.CurrentBlock().Header()
|
||||||
|
if fb.bc.Config().XDPoS.BlockConsensusVersion(
|
||||||
|
current.Number,
|
||||||
|
current.Extra,
|
||||||
|
XDPoS.ExtraFieldCheck,
|
||||||
|
) == params.ConsensusEngineVersion2 {
|
||||||
|
confirmedHash := fb.bc.Engine().(*XDPoS.XDPoS).EngineV2.GetLatestCommittedBlockInfo().Hash
|
||||||
|
return fb.bc.GetHeaderByHash(confirmedHash), nil
|
||||||
|
}
|
||||||
|
return nil, errors.New("only XDPoS v2 can lookup committed block")
|
||||||
|
default:
|
||||||
|
return fb.bc.GetHeaderByNumber(uint64(number.Int64())), nil
|
||||||
}
|
}
|
||||||
return fb.bc.GetHeaderByNumber(uint64(block.Int64())), nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fb *filterBackend) HeaderByHash(ctx context.Context, hash common.Hash) (*types.Header, error) {
|
func (fb *filterBackend) HeaderByHash(ctx context.Context, hash common.Hash) (*types.Header, error) {
|
||||||
|
|
|
||||||
|
|
@ -119,20 +119,39 @@ func (f *Filter) Logs(ctx context.Context) ([]*types.Log, error) {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
var (
|
var (
|
||||||
head = header.Number.Uint64()
|
err error
|
||||||
end = uint64(f.end)
|
head = header.Number.Int64()
|
||||||
pending = f.end == rpc.PendingBlockNumber.Int64()
|
pending = f.end == rpc.PendingBlockNumber.Int64()
|
||||||
)
|
)
|
||||||
if f.begin == rpc.LatestBlockNumber.Int64() {
|
resolveSpecial := func(number int64) (int64, error) {
|
||||||
f.begin = int64(head)
|
var hdr *types.Header
|
||||||
|
switch number {
|
||||||
|
case rpc.LatestBlockNumber.Int64():
|
||||||
|
return head, nil
|
||||||
|
case rpc.PendingBlockNumber.Int64():
|
||||||
|
// we should return head here since we've already captured
|
||||||
|
// that we need to get the pending logs in the pending boolean above
|
||||||
|
return head, nil
|
||||||
|
case rpc.CommittedBlockNumber.Int64():
|
||||||
|
hdr, _ = f.sys.backend.HeaderByNumber(ctx, rpc.CommittedBlockNumber)
|
||||||
|
if hdr == nil {
|
||||||
|
return 0, errors.New("committed header not found")
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
return number, nil
|
||||||
|
}
|
||||||
|
return hdr.Number.Int64(), nil
|
||||||
}
|
}
|
||||||
if f.end == rpc.LatestBlockNumber.Int64() || f.end == rpc.PendingBlockNumber.Int64() {
|
if f.begin, err = resolveSpecial(f.begin); err != nil {
|
||||||
end = head
|
return nil, err
|
||||||
|
}
|
||||||
|
if f.end, err = resolveSpecial(f.end); err != nil {
|
||||||
|
return nil, err
|
||||||
}
|
}
|
||||||
// Gather all indexed logs, and finish with non indexed ones
|
// Gather all indexed logs, and finish with non indexed ones
|
||||||
var (
|
var (
|
||||||
logs []*types.Log
|
logs []*types.Log
|
||||||
err error
|
end = uint64(f.end)
|
||||||
size, sections = f.sys.backend.BloomStatus()
|
size, sections = f.sys.backend.BloomStatus()
|
||||||
)
|
)
|
||||||
if indexed := sections * size; indexed > uint64(f.begin) {
|
if indexed := sections * size; indexed > uint64(f.begin) {
|
||||||
|
|
|
||||||
|
|
@ -57,16 +57,21 @@ func (b *testBackend) ChainDb() ethdb.Database {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *testBackend) HeaderByNumber(ctx context.Context, blockNr rpc.BlockNumber) (*types.Header, error) {
|
func (b *testBackend) HeaderByNumber(ctx context.Context, blockNr rpc.BlockNumber) (*types.Header, error) {
|
||||||
var hash common.Hash
|
var (
|
||||||
var num uint64
|
hash common.Hash
|
||||||
if blockNr == rpc.LatestBlockNumber {
|
num uint64
|
||||||
|
)
|
||||||
|
switch blockNr {
|
||||||
|
case rpc.LatestBlockNumber:
|
||||||
hash = rawdb.ReadHeadBlockHash(b.db)
|
hash = rawdb.ReadHeadBlockHash(b.db)
|
||||||
number := rawdb.ReadHeaderNumber(b.db, hash)
|
number := rawdb.ReadHeaderNumber(b.db, hash)
|
||||||
if number == nil {
|
if number == nil {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
num = *number
|
num = *number
|
||||||
} else {
|
case rpc.CommittedBlockNumber:
|
||||||
|
return nil, nil
|
||||||
|
default:
|
||||||
num = uint64(blockNr)
|
num = uint64(blockNr)
|
||||||
hash = rawdb.ReadCanonicalHash(b.db, num)
|
hash = rawdb.ReadCanonicalHash(b.db, num)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue