mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-27 15:16:43 +00:00
fix filter conditions
This commit is contained in:
parent
cf647a821f
commit
f51fcaeebd
4 changed files with 25 additions and 7 deletions
|
|
@ -342,7 +342,6 @@ func (api *FilterAPI) GetLogs(ctx context.Context, crit FilterCriteria) ([]*type
|
|||
}
|
||||
var filter *Filter
|
||||
if crit.BlockHash != nil {
|
||||
// TODO: return pruned history error here where it would apply
|
||||
// Block filter requested, construct a single-shot filter
|
||||
filter = api.sys.NewBlockFilter(*crit.BlockHash, crit.Addresses, crit.Topics)
|
||||
} else {
|
||||
|
|
@ -355,10 +354,11 @@ func (api *FilterAPI) GetLogs(ctx context.Context, crit FilterCriteria) ([]*type
|
|||
if crit.ToBlock != nil {
|
||||
end = crit.ToBlock.Int64()
|
||||
}
|
||||
// Block numbers below 0 are special cases.
|
||||
if begin > 0 && end > 0 && begin > end {
|
||||
return nil, errInvalidBlockRange
|
||||
}
|
||||
if begin < int64(api.events.backend.HistoryPruningCutoff()) {
|
||||
if begin > 0 && begin < int64(api.events.backend.HistoryPruningCutoff()) {
|
||||
return nil, &prunedHistoryError{}
|
||||
}
|
||||
// Construct the range filter
|
||||
|
|
|
|||
|
|
@ -86,6 +86,9 @@ func (f *Filter) Logs(ctx context.Context) ([]*types.Log, error) {
|
|||
if header == nil {
|
||||
return nil, errors.New("unknown block")
|
||||
}
|
||||
if header.Number.Uint64() < f.sys.backend.HistoryPruningCutoff() {
|
||||
return nil, &prunedHistoryError{}
|
||||
}
|
||||
return f.blockLogs(ctx, header)
|
||||
}
|
||||
|
||||
|
|
@ -114,12 +117,20 @@ func (f *Filter) Logs(ctx context.Context) ([]*types.Log, error) {
|
|||
return 0, errors.New("safe header not found")
|
||||
}
|
||||
return hdr.Number.Uint64(), nil
|
||||
case rpc.EarliestBlockNumber.Int64():
|
||||
earliest := f.sys.backend.HistoryPruningCutoff()
|
||||
hdr, _ := f.sys.backend.HeaderByNumber(ctx, rpc.BlockNumber(earliest))
|
||||
if hdr == nil {
|
||||
return 0, errors.New("earliest header not found")
|
||||
}
|
||||
return hdr.Number.Uint64(), nil
|
||||
default:
|
||||
if number < 0 {
|
||||
return 0, errors.New("negative block number")
|
||||
}
|
||||
return uint64(number), nil
|
||||
}
|
||||
}
|
||||
|
||||
// range query need to resolve the special begin/end block number
|
||||
begin, err := resolveSpecial(f.begin)
|
||||
|
|
|
|||
|
|
@ -310,6 +310,14 @@ func (es *EventSystem) SubscribeLogs(crit ethereum.FilterQuery, logs chan []*typ
|
|||
return nil, errPendingLogsUnsupported
|
||||
}
|
||||
|
||||
if from == rpc.EarliestBlockNumber {
|
||||
from = rpc.BlockNumber(es.backend.HistoryPruningCutoff())
|
||||
}
|
||||
// Queries beyond the pruning cutoff are not supported.
|
||||
if uint64(from) < es.backend.HistoryPruningCutoff() {
|
||||
return nil, &prunedHistoryError{}
|
||||
}
|
||||
|
||||
// only interested in new mined logs
|
||||
if from == rpc.LatestBlockNumber && to == rpc.LatestBlockNumber {
|
||||
return es.subscribeLogs(crit, logs), nil
|
||||
|
|
|
|||
|
|
@ -1369,7 +1369,6 @@ func (api *TransactionAPI) GetRawTransactionByHash(ctx context.Context, hash com
|
|||
|
||||
// GetTransactionReceipt returns the transaction receipt for the given transaction hash.
|
||||
func (api *TransactionAPI) GetTransactionReceipt(ctx context.Context, hash common.Hash) (map[string]interface{}, error) {
|
||||
// TODO(s1na): transaction lookup should be pruned as well.
|
||||
found, tx, blockHash, blockNumber, index, err := api.b.GetTransaction(ctx, hash)
|
||||
if err != nil {
|
||||
return nil, NewTxIndexingError() // transaction is not fully indexed
|
||||
|
|
|
|||
Loading…
Reference in a new issue