From bf64039395b6c7b59bab6e274a386d5c5f05a0e4 Mon Sep 17 00:00:00 2001 From: root Date: Mon, 24 Aug 2026 14:21:06 +0000 Subject: [PATCH] fix: update BlockHash to canonical hash in GetLogs and GetFilterLogs --- eth/filters/api.go | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/eth/filters/api.go b/eth/filters/api.go index aef9adba103f..b98a582a9992 100644 --- a/eth/filters/api.go +++ b/eth/filters/api.go @@ -72,7 +72,6 @@ func NewPublicFilterAPI(backend Backend, lightMode bool) *PublicFilterAPI { filters: make(map[rpc.ID]*filter), } go api.timeoutLoop() - return api } @@ -141,7 +140,6 @@ func (api *PublicFilterAPI) NewPendingTransactions(ctx context.Context) (*rpc.Su if !supported { return &rpc.Subscription{}, rpc.ErrNotificationsUnsupported } - rpcSub := notifier.CreateSubscription() go func() { @@ -206,7 +204,6 @@ func (api *PublicFilterAPI) NewHeads(ctx context.Context) (*rpc.Subscription, er if !supported { return &rpc.Subscription{}, rpc.ErrNotificationsUnsupported } - rpcSub := notifier.CreateSubscription() go func() { @@ -248,7 +245,6 @@ func (api *PublicFilterAPI) Logs(ctx context.Context, crit FilterCriteria) (*rpc } go func() { - for { select { case logs := <-matchedLogs: @@ -336,11 +332,14 @@ func (api *PublicFilterAPI) GetLogs(ctx context.Context, crit FilterCriteria) ([ } // Create and run the filter to get all the logs filter := New(api.backend, crit.FromBlock.Int64(), crit.ToBlock.Int64(), crit.Addresses, crit.Topics) - logs, err := filter.Logs(ctx) if err != nil { return nil, err } + for _, log := range logs { + // update BlockHash to fix #1 + log.BlockHash = core.GetCanonicalHash(api.chainDb, log.BlockNumber) + } return returnLogs(logs), err } @@ -357,7 +356,6 @@ func (api *PublicFilterAPI) UninstallFilter(id rpc.ID) bool { if found { f.s.Unsubscribe() } - return found } @@ -369,11 +367,9 @@ func (api *PublicFilterAPI) GetFilterLogs(ctx context.Context, id rpc.ID) ([]*ty api.filtersMu.Lock() f, found := api.filters[id] api.filtersMu.Unlock() - if !found || f.typ != LogsSubscription { return nil, fmt.Errorf("filter not found") } - begin := rpc.LatestBlockNumber.Int64() if f.crit.FromBlock != nil { begin = f.crit.FromBlock.Int64() @@ -384,11 +380,14 @@ func (api *PublicFilterAPI) GetFilterLogs(ctx context.Context, id rpc.ID) ([]*ty } // Create and run the filter to get all the logs filter := New(api.backend, begin, end, f.crit.Addresses, f.crit.Topics) - logs, err := filter.Logs(ctx) if err != nil { return nil, err } + for _, log := range logs { + // update BlockHash to fix #1 + log.BlockHash = core.GetCanonicalHash(api.chainDb, log.BlockNumber) + } return returnLogs(logs), nil } @@ -426,7 +425,6 @@ func (api *PublicFilterAPI) GetFilterChanges(id rpc.ID) (interface{}, error) { return returnLogs(logs), nil } } - return []interface{}{}, fmt.Errorf("filter not found") } @@ -465,13 +463,11 @@ func (args *FilterCriteria) UnmarshalJSON(data []byte) error { if raw.From != nil { args.FromBlock = big.NewInt(raw.From.Int64()) } - if raw.ToBlock != nil { args.ToBlock = big.NewInt(raw.ToBlock.Int64()) } args.Addresses = []common.Address{} - if raw.Addresses != nil { // raw.Address can contain a single address or an array of addresses switch rawAddr := raw.Addresses.(type) { @@ -506,7 +502,6 @@ func (args *FilterCriteria) UnmarshalJSON(data []byte) error { switch topic := t.(type) { case nil: // ignore topic when matching logs - case string: // match specific topic top, err := decodeTopic(topic) @@ -514,7 +509,6 @@ func (args *FilterCriteria) UnmarshalJSON(data []byte) error { return err } args.Topics[i] = []common.Hash{top} - case []interface{}: // or case e.g. [null, "topic0", "topic1"] for _, rawTopic := range topic { @@ -541,9 +535,11 @@ func (args *FilterCriteria) UnmarshalJSON(data []byte) error { return nil } + func hasXDCPrefix(str string) bool { return len(str) >= 3 && (str[0] == 'x' || str[0] == 'X') && (str[1] == 'd' || str[1] == 'D') && (str[2] == 'c' || str[2] == 'C') } + func decodeAddress(s string) (common.Address, error) { if hasXDCPrefix(s) { s = "0x" + s[3:] @@ -561,4 +557,4 @@ func decodeTopic(s string) (common.Hash, error) { err = fmt.Errorf("hex has invalid length %d after decoding", len(b)) } return common.BytesToHash(b), err -} +} \ No newline at end of file