diff --git a/lib/ae_mdw/sync/server.ex b/lib/ae_mdw/sync/server.ex index 748d6cbf4..3cd9d5570 100644 --- a/lib/ae_mdw/sync/server.ex +++ b/lib/ae_mdw/sync/server.ex @@ -491,22 +491,31 @@ defmodule AeMdw.Sync.Server do |> List.flatten() |> maybe_add_accounts_balance_mutations() - {{height, _mbi}, _block, _mutations} = List.last(blocks_mutations) - Log.info("[sync_mem] exec until height=#{height}") + # An empty batch (no blocks to apply - e.g. a resume/extension check that + # turns out to have nothing new past the already-synced height) is a + # legitimate no-op, not an error - List.last/1 would return nil and crash + # the match below if this weren't guarded. + case List.last(blocks_mutations) do + nil -> + state + + {{height, _mbi}, _block, _mutations} -> + Log.info("[sync_mem] exec until height=#{height}") + + {ts, new_state} = + :timer.tc(fn -> + all_mutations = + Enum.map(blocks_mutations, fn {_height, _block, mutations} -> mutations end) - {ts, new_state} = - :timer.tc(fn -> - all_mutations = - Enum.map(blocks_mutations, fn {_height, _block, mutations} -> mutations end) + State.commit_mem(state, all_mutations) + end) - State.commit_mem(state, all_mutations) - end) + :ok = profile_sync("sync_mem", height, ts, blocks_mutations, gens_in_batch) - :ok = profile_sync("sync_mem", height, ts, blocks_mutations, gens_in_batch) + broadcast_blocks(gens_mutations) - broadcast_blocks(gens_mutations) - - new_state + new_state + end end defp spawn_task(fun) do