Skip to content

Commit

Permalink
fix: do not fetch history if there is no history in poll_blocks() (#1744
Browse files Browse the repository at this point in the history
)

Co-authored-by: El De-dog-lo <[email protected]>
  • Loading branch information
mikeshultz and fubuloubu authored Nov 22, 2023
1 parent 6dc6d4a commit caab108
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/ape/managers/chain.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,9 +287,10 @@ def poll_blocks(
# Get number of last block with the necessary amount of confirmations.
block = None

if start_block is not None:
head_minus_confirms = self.height - required_confirmations
if start_block is not None and start_block <= head_minus_confirms:
# Front-load historical blocks.
for block in self.range(start_block, self.height - required_confirmations + 1):
for block in self.range(start_block, head_minus_confirms + 1):
yield block

if block:
Expand Down
19 changes: 19 additions & 0 deletions tests/functional/test_block_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,3 +147,22 @@ def test_poll_blocks_timeout(
with pytest.raises(ChainError, match=r"Timed out waiting for new block \(time_waited=1.\d+\)."):
with PollDaemon("blocks", poller, lambda x: None, lambda: False):
time.sleep(1.5)


def test_poll_blocks_future(chain_that_mined_5, eth_tester_provider, owner, PollDaemon):
blocks: Queue = Queue(maxsize=3)
poller = chain_that_mined_5.blocks.poll_blocks(
start_block=chain_that_mined_5.blocks.head.number + 1
)

with PollDaemon("blocks", poller, blocks.put, blocks.full):
# Sleep first to ensure listening before mining.
time.sleep(1)
eth_tester_provider.mine(3)

assert blocks.full()
first = blocks.get().number
second = blocks.get().number
third = blocks.get().number
assert first == second - 1
assert second == third - 1

0 comments on commit caab108

Please sign in to comment.