Skip to content

Commit e5b3f80

Browse files
avilagaston9uri-99
andauthored
fix(explorer): fetch_batch_data_pointer in explorer reads the entire response body without any limitation (#1198)
Co-authored-by: Urix <[email protected]>
1 parent 5143a3e commit e5b3f80

File tree

12 files changed

+175
-63
lines changed

12 files changed

+175
-63
lines changed

explorer/.env.dev

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,5 @@ DEBUG_ERRORS=true
2020

2121
# Operator version tracker API
2222
TRACKER_API_URL=http://localhost:3030
23+
24+
MAX_BATCH_SIZE=268435456 # 256 MiB

explorer/lib/explorer/contract_managers/aligned_layer_service_manager.ex

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,8 @@ defmodule AlignedLayerServiceManager do
136136
proof_hashes: nil,
137137
fee_per_proof: BatcherPaymentServiceManager.get_fee_per_proof(%{merkle_root: created_batch.batchMerkleRoot}),
138138
sender_address: Utils.string_to_bytes32(created_batch.senderAddress),
139-
max_aggregator_fee: created_batch.maxAggregatorFee
139+
max_aggregator_fee: created_batch.maxAggregatorFee,
140+
is_valid: true # set to false later if a process determines it is invalid
140141
}
141142
end
142143

@@ -166,7 +167,8 @@ defmodule AlignedLayerServiceManager do
166167
fee_per_proof: unverified_batch.fee_per_proof,
167168
proof_hashes: nil,
168169
sender_address: unverified_batch.sender_address,
169-
max_aggregator_fee: unverified_batch.max_aggregator_fee
170+
max_aggregator_fee: unverified_batch.max_aggregator_fee,
171+
is_valid: true # set to false later if a process determines it is invalid
170172
}
171173
end
172174
end

explorer/lib/explorer/models/batch_structs.ex

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ defmodule BatchDB do
3232
:proof_hashes,
3333
:fee_per_proof,
3434
:sender_address,
35-
:max_aggregator_fee
35+
:max_aggregator_fee,
36+
:is_valid
3637
]
3738
defstruct [
3839
:merkle_root,
@@ -48,6 +49,7 @@ defmodule BatchDB do
4849
:proof_hashes,
4950
:fee_per_proof,
5051
:sender_address,
51-
:max_aggregator_fee
52+
:max_aggregator_fee,
53+
:is_valid
5254
]
5355
end

explorer/lib/explorer/models/batches.ex

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,16 @@ defmodule Batches do
1818
field :fee_per_proof, :integer
1919
field :sender_address, :binary
2020
field :max_aggregator_fee, :decimal
21+
field :is_valid, :boolean, default: true
2122

2223
timestamps()
2324
end
2425

2526
@doc false
2627
def changeset(new_batch, updates) do
2728
new_batch
28-
|> cast(updates, [:merkle_root, :amount_of_proofs, :is_verified, :submission_block_number, :submission_transaction_hash, :submission_timestamp, :response_block_number, :response_transaction_hash, :response_timestamp, :data_pointer, :fee_per_proof, :sender_address, :max_aggregator_fee])
29-
|> validate_required([:merkle_root, :amount_of_proofs, :is_verified, :submission_block_number, :submission_transaction_hash, :fee_per_proof, :sender_address])
29+
|> cast(updates, [:merkle_root, :amount_of_proofs, :is_verified, :submission_block_number, :submission_transaction_hash, :submission_timestamp, :response_block_number, :response_transaction_hash, :response_timestamp, :data_pointer, :fee_per_proof, :sender_address, :max_aggregator_fee, :is_valid])
30+
|> validate_required([:merkle_root, :amount_of_proofs, :is_verified, :submission_block_number, :submission_transaction_hash, :fee_per_proof, :sender_address, :is_valid])
3031
|> validate_format(:merkle_root, ~r/0x[a-fA-F0-9]{64}/)
3132
|> unique_constraint(:merkle_root)
3233
|> validate_number(:amount_of_proofs, greater_than: 0)
@@ -37,6 +38,7 @@ defmodule Batches do
3738
|> validate_format(:response_transaction_hash, ~r/0x[a-fA-F0-9]{64}/)
3839
|> validate_number(:max_aggregator_fee, greater_than: 0)
3940
|> validate_number(:fee_per_proof, greater_than_or_equal_to: 0)
41+
|> validate_inclusion(:is_valid, [true, false])
4042
end
4143

4244
def cast_to_batches(%BatchDB{} = batch_db) do
@@ -53,7 +55,8 @@ defmodule Batches do
5355
data_pointer: batch_db.data_pointer,
5456
fee_per_proof: batch_db.fee_per_proof,
5557
sender_address: batch_db.sender_address,
56-
max_aggregator_fee: batch_db.max_aggregator_fee
58+
max_aggregator_fee: batch_db.max_aggregator_fee,
59+
is_valid: batch_db.is_valid
5760
}
5861
end
5962

@@ -113,7 +116,7 @@ defmodule Batches do
113116
threshold_datetime = DateTime.utc_now() |> DateTime.add(-43200, :second) # 12 hours ago
114117

115118
query = from(b in Batches,
116-
where: b.is_verified == false and b.submission_timestamp > ^threshold_datetime,
119+
where: b.is_valid == true and b.is_verified == false and b.submission_timestamp > ^threshold_datetime,
117120
select: b)
118121

119122
Explorer.Repo.all(query)
@@ -193,5 +196,4 @@ defmodule Batches do
193196
end
194197
end
195198
end
196-
197199
end

explorer/lib/explorer/periodically.ex

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ defmodule Explorer.Periodically do
4545

4646
run_every_n_iterations = 8
4747
new_count = rem(count + 1, run_every_n_iterations)
48+
4849
if new_count == 0 do
4950
Task.start(&process_unverified_batches/0)
5051
end
@@ -79,25 +80,19 @@ defmodule Explorer.Periodically do
7980
{:ok, lock} ->
8081
"Processing batch: #{batch.merkle_root}" |> Logger.debug()
8182

82-
{batch_changeset, proofs} =
83-
batch
84-
|> Utils.extract_info_from_data_pointer()
85-
|> Batches.generate_changesets()
86-
87-
Batches.insert_or_update(batch_changeset, proofs)
88-
|> case do
89-
{:ok, _} ->
90-
PubSub.broadcast(Explorer.PubSub, "update_views", %{
91-
eth_usd:
92-
case EthConverter.get_eth_price_usd() do
93-
{:ok, eth_usd_price} -> eth_usd_price
94-
{:error, _error} -> :empty
95-
end
96-
})
97-
98-
{:error, error} ->
99-
Logger.error("Some error in DB operation, not broadcasting update_views: #{inspect(error)}")
100-
83+
with {:ok, updated_batch} <- Utils.process_batch(batch),
84+
{batch_changeset, proofs} <- Batches.generate_changesets(updated_batch),
85+
{:ok, _} <- Batches.insert_or_update(batch_changeset, proofs) do
86+
PubSub.broadcast(Explorer.PubSub, "update_views", %{
87+
eth_usd:
88+
case EthConverter.get_eth_price_usd() do
89+
{:ok, eth_usd_price} -> eth_usd_price
90+
{:error, _error} -> :empty
91+
end
92+
})
93+
else
94+
{:error, reason} ->
95+
Logger.error("Error processing batch #{batch.merkle_root}. Error: #{inspect(reason)}")
10196
# no changes in DB
10297
nil ->
10398
nil

explorer/lib/explorer_web/components/core_components.ex

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -417,15 +417,15 @@ defmodule ExplorerWeb.CoreComponents do
417417
end
418418

419419
@doc """
420-
Renders a dynamic badge compoent.
420+
Renders a dynamic badge component.
421421
"""
422422
attr :class, :string, default: nil
423423
attr :status, :boolean, default: true
424-
attr :falsy_text, :string, default: "Pending"
425-
attr :truthy_text, :string, default: "Verified"
424+
attr :falsy_text, :string
425+
attr :truthy_text, :string
426426
slot :inner_block, default: nil
427427

428-
def dynamic_badge(assigns) do
428+
def dynamic_badge_boolean(assigns) do
429429
~H"""
430430
<.badge
431431
variant={
@@ -449,6 +449,39 @@ defmodule ExplorerWeb.CoreComponents do
449449
"""
450450
end
451451

452+
@doc """
453+
Renders a dynamic badge component for the batcher.
454+
"""
455+
attr :class, :string, default: nil
456+
attr :status, :atom
457+
slot :inner_block, default: nil
458+
459+
def dynamic_badge_for_batcher(assigns) do
460+
~H"""
461+
<.badge
462+
variant={
463+
case @status do
464+
:invalid -> "destructive"
465+
:verified -> "accent"
466+
:pending -> "foreground"
467+
end
468+
}
469+
class={
470+
classes([
471+
@class
472+
])
473+
}
474+
>
475+
<%= case @status do
476+
:invalid -> "Invalid"
477+
:verified -> "Verified"
478+
:pending -> "Pending"
479+
end %>
480+
<%= render_slot(@inner_block) %>
481+
</.badge>
482+
"""
483+
end
484+
452485
@doc """
453486
Renders an input with label and error messages.
454487

explorer/lib/explorer_web/live/pages/batch/index.html.heex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
<h3>
2626
Status:
2727
</h3>
28-
<.dynamic_badge class="w-fit" status={@current_batch.is_verified} />
28+
<.dynamic_badge_for_batcher class="w-fit" status={Helpers.get_batch_status(@current_batch)} />
2929
</div>
3030
<div>
3131
<h3>

explorer/lib/explorer_web/live/pages/batches/index.html.heex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
</.link>
1515
</:col>
1616
<:col :let={batch} label="Status">
17-
<.dynamic_badge status={batch.is_verified} />
17+
<.dynamic_badge_for_batcher status={Helpers.get_batch_status(batch)} />
1818
</:col>
1919
<:col :let={batch} label="Age">
2020
<span class="md:px-0" title={batch.submission_timestamp}>

explorer/lib/explorer_web/live/pages/operators/index.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ defmodule ExplorerWeb.Operators.Index do
8383
<%= operator.total_stake |> EthConverter.wei_to_eth(2) |> Helpers.format_number() %> ETH
8484
</:col>
8585
<:col :let={operator} label="Status">
86-
<.dynamic_badge status={operator.is_active} truthy_text="Active" falsy_text="Inactive" />
86+
<.dynamic_badge_boolean status={operator.is_active} truthy_text="Active" falsy_text="Inactive" />
8787
</:col>
8888
</.table>
8989
<% else %>

0 commit comments

Comments
 (0)