diff --git a/libethereum/ClientBase.cpp b/libethereum/ClientBase.cpp index fb81c2592..9ac9d9647 100644 --- a/libethereum/ClientBase.cpp +++ b/libethereum/ClientBase.cpp @@ -185,7 +185,7 @@ LocalisedLogEntries ClientBase::logs(LogFilter const& _f) const tie(blocks, ancestor, ancestorIndex) = bc().treeRoute(_f.earliest(), _f.latest(), false); for (size_t i = 0; i < ancestorIndex; i++) - appendLogsFromBlock(_f, blocks[i], BlockPolarity::Dead, ret); + prependLogsFromBlock(_f, blocks[i], BlockPolarity::Dead, ret); // cause end is our earliest block, let's compare it with our ancestor // if ancestor is smaller let's move our end to it @@ -195,11 +195,11 @@ LocalisedLogEntries ClientBase::logs(LogFilter const& _f) const // -> g // 3a -> 2a -> 1a // - // if earliest is at 1a and latest is a 3b, coverting them to numbers - // will give us pair (1, 3) - // and we want to get all logs from g (ancestor) to 3 - // so we have to move 1a to g - end = min(end, (unsigned)numberFromHash(ancestor)); + // if earliest is at 2a and latest is a 3b, coverting them to numbers + // will give us pair (2, 3) + // and we want to get all logs from 1 (ancestor + 1) to 3 + // so we have to move 2a to g + 1 + end = min(end, (unsigned)numberFromHash(ancestor) + 1); // Handle blocks from main chain set matchingBlocks; @@ -213,12 +213,13 @@ LocalisedLogEntries ClientBase::logs(LogFilter const& _f) const matchingBlocks.insert(i); for (auto n: matchingBlocks) - appendLogsFromBlock(_f, bc().numberHash(n), BlockPolarity::Live, ret); + prependLogsFromBlock(_f, bc().numberHash(n), BlockPolarity::Live, ret); + reverse(ret.begin(), ret.end()); return ret; } -void ClientBase::appendLogsFromBlock(LogFilter const& _f, h256 const& _blockHash, BlockPolarity _polarity, LocalisedLogEntries& io_logs) const +void ClientBase::prependLogsFromBlock(LogFilter const& _f, h256 const& _blockHash, BlockPolarity _polarity, LocalisedLogEntries& io_logs) const { auto receipts = bc().receipts(_blockHash).receipts; for (size_t i = 0; i < receipts.size(); i++) diff --git a/libethereum/ClientBase.h b/libethereum/ClientBase.h index 9e513124a..2b762c0b4 100644 --- a/libethereum/ClientBase.h +++ b/libethereum/ClientBase.h @@ -104,7 +104,7 @@ public: virtual LocalisedLogEntries logs(unsigned _watchId) const override; virtual LocalisedLogEntries logs(LogFilter const& _filter) const override; - virtual void appendLogsFromBlock(LogFilter const& _filter, h256 const& _blockHash, BlockPolarity _polarity, LocalisedLogEntries& io_logs) const; + virtual void prependLogsFromBlock(LogFilter const& _filter, h256 const& _blockHash, BlockPolarity _polarity, LocalisedLogEntries& io_logs) const; /// Install, uninstall and query watches. virtual unsigned installWatch(LogFilter const& _filter, Reaping _r = Reaping::Automatic) override;