From 98a1b0517168597500c04e09afee1e30039108a0 Mon Sep 17 00:00:00 2001 From: hero5512 Date: Tue, 10 Jan 2023 22:34:08 -0500 Subject: [PATCH] fix get_logs error (#1423) --- core/store/ledgerstore/block_store.go | 6 +++++- http/ethrpc/filters/filter.go | 9 +++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/core/store/ledgerstore/block_store.go b/core/store/ledgerstore/block_store.go index 0a83a8b71..653d85029 100644 --- a/core/store/ledgerstore/block_store.go +++ b/core/store/ledgerstore/block_store.go @@ -579,7 +579,7 @@ func (this *BlockStore) LoadBloomBits() error { initStart := (curBlockHeight + 4095) / 4096 if curBlockHeight < config.GetAddDecimalsHeight() { - initStart = config.GetAddDecimalsHeight() / 4096 * 4096 + initStart = MinFilterStart() } start, err := GetOrSetFilterStart(this.store, initStart) @@ -602,3 +602,7 @@ func (this *BlockStore) LoadBloomBits() error { } return nil } + +func MinFilterStart() uint32 { + return config.GetAddDecimalsHeight() / 4096 * 4096 +} diff --git a/http/ethrpc/filters/filter.go b/http/ethrpc/filters/filter.go index 6a3035f1b..994860404 100644 --- a/http/ethrpc/filters/filter.go +++ b/http/ethrpc/filters/filter.go @@ -29,6 +29,7 @@ import ( "github.com/ethereum/go-ethereum/eth/filters" common2 "github.com/ontio/ontology/common" common4 "github.com/ontio/ontology/core/store/common" + "github.com/ontio/ontology/core/store/ledgerstore" "github.com/ontio/ontology/core/types" "github.com/ontio/ontology/http/base/actor" utils2 "github.com/ontio/ontology/http/ethrpc/utils" @@ -142,6 +143,14 @@ func (f *Filter) Logs(ctx context.Context) ([]*ethtypes.Log, error) { } start := actor.GetFilterStart() + minFilterStart := ledgerstore.MinFilterStart() + if f.criteria.ToBlock.Int64() < int64(minFilterStart) { + return nil, nil + } + + if f.criteria.FromBlock.Int64() < int64(minFilterStart) { + f.criteria.FromBlock = big.NewInt(int64(minFilterStart)) + } if f.criteria.FromBlock.Int64() < int64(start) || f.criteria.ToBlock.Int64() < int64(start) {