mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-23 13:16:42 +00:00
stricter range validation
Signed-off-by: jsvisa <delweng@gmail.com>
This commit is contained in:
parent
69a14cb0ae
commit
6419fa7f38
1 changed files with 12 additions and 24 deletions
|
|
@ -39,7 +39,7 @@ var (
|
||||||
errFilterNotFound = errors.New("filter not found")
|
errFilterNotFound = errors.New("filter not found")
|
||||||
errConnectDropped = errors.New("connection dropped")
|
errConnectDropped = errors.New("connection dropped")
|
||||||
errInvalidToBlock = errors.New("log subscription does not support history block range")
|
errInvalidToBlock = errors.New("log subscription does not support history block range")
|
||||||
errInvalidFromBlock = errors.New("invalid from block")
|
errInvalidFromBlock = errors.New("from block can be only a number, or \"safe\", or \"finalized\"")
|
||||||
)
|
)
|
||||||
|
|
||||||
// filter is a helper struct that holds meta information over the filter type
|
// filter is a helper struct that holds meta information over the filter type
|
||||||
|
|
@ -267,33 +267,22 @@ func (api *FilterAPI) Logs(ctx context.Context, crit FilterCriteria) (*rpc.Subsc
|
||||||
return rpcSub, err
|
return rpcSub, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// logs is the inner implmention of logs filter
|
// logs is the inner implementation of logs filtering.
|
||||||
// from: nil, to: nil -> only live
|
// from: nil, to: nil -> only live mode.
|
||||||
// from: blockNum | safe | finalized, to: nil -> historical from from and then toggle live
|
// from: blockNum | safe | finalized, to: nil -> historical beginning at `from` to head, then live mode.
|
||||||
// every other case should fail with an error
|
// Every other case should fail with an error.
|
||||||
func (api *FilterAPI) logs(ctx context.Context, notifier notifier, rpcSub *rpc.Subscription, crit FilterCriteria) error {
|
func (api *FilterAPI) logs(ctx context.Context, notifier notifier, rpcSub *rpc.Subscription, crit FilterCriteria) error {
|
||||||
var from, to rpc.BlockNumber
|
if crit.ToBlock != nil {
|
||||||
if crit.FromBlock == nil {
|
|
||||||
from = rpc.LatestBlockNumber
|
|
||||||
} else {
|
|
||||||
from = rpc.BlockNumber(crit.FromBlock.Int64())
|
|
||||||
}
|
|
||||||
if crit.ToBlock == nil {
|
|
||||||
to = rpc.LatestBlockNumber
|
|
||||||
} else {
|
|
||||||
to = rpc.BlockNumber(crit.ToBlock.Int64())
|
|
||||||
}
|
|
||||||
|
|
||||||
if to != rpc.LatestBlockNumber && to != rpc.PendingBlockNumber {
|
|
||||||
return errInvalidToBlock
|
return errInvalidToBlock
|
||||||
}
|
}
|
||||||
|
if crit.FromBlock == nil {
|
||||||
// do live filter only
|
|
||||||
if from == rpc.LatestBlockNumber || from == rpc.PendingBlockNumber {
|
|
||||||
return api.liveLogs(ctx, notifier, rpcSub, crit)
|
return api.liveLogs(ctx, notifier, rpcSub, crit)
|
||||||
}
|
}
|
||||||
|
from := rpc.BlockNumber(crit.FromBlock.Int64())
|
||||||
if from == rpc.SafeBlockNumber || from == rpc.FinalizedBlockNumber {
|
switch from {
|
||||||
|
case rpc.LatestBlockNumber, rpc.PendingBlockNumber:
|
||||||
|
return errInvalidFromBlock
|
||||||
|
case rpc.SafeBlockNumber, rpc.FinalizedBlockNumber:
|
||||||
header, err := api.sys.backend.HeaderByNumber(ctx, from)
|
header, err := api.sys.backend.HeaderByNumber(ctx, from)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
@ -303,7 +292,6 @@ func (api *FilterAPI) logs(ctx context.Context, notifier notifier, rpcSub *rpc.S
|
||||||
if from < 0 {
|
if from < 0 {
|
||||||
return errInvalidFromBlock
|
return errInvalidFromBlock
|
||||||
}
|
}
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
// do historical sync first
|
// do historical sync first
|
||||||
_, err := api.histLogs(ctx, notifier, rpcSub, int64(from), crit)
|
_, err := api.histLogs(ctx, notifier, rpcSub, int64(from), crit)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue