Skip to content

Commit

Permalink
fix: Anvil block timestamp (#7686)
Browse files Browse the repository at this point in the history
Anvil uses the time of the forked block as its timestamp as its
baseline. Subsequent blocks have a timestamp equal to that baseline plus
the time that passed since the fork was created.

To fix it, we set the next block timestamp manually to the current date
and immediately trigger a block mine.
  • Loading branch information
spalladino authored Jul 30, 2024
1 parent 11f3885 commit dc8ad6e
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions iac/mainnet-fork/scripts/run_nginx_anvil.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ mkdir -p /data
echo "Waiting for ethereum host at $ETHEREUM_HOST..."
while ! curl -s $ETHEREUM_HOST >/dev/null; do sleep 1; done

# Fix anvil's fork timestamp
./foundry/bin/cast rpc --rpc-url="$ETHEREUM_HOST" evm_setNextBlockTimestamp $(date +%s | xargs printf '0x%x') > /dev/null
./foundry/bin/cast rpc --rpc-url="$ETHEREUM_HOST" evm_mine > /dev/null

echo "Starting nginx..."
nginx &
wait

0 comments on commit dc8ad6e

Please sign in to comment.