Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(explorer): set a max_batch_size to the explorer #1202

Closed
wants to merge 38 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
9713716
fix: add request_timeout to explorer
avilagaston9 Oct 8, 2024
ba51f1c
refactor: replace the value with a constant
avilagaston9 Oct 8, 2024
9e10697
refactor: handle error
avilagaston9 Oct 8, 2024
ae13563
fix: adding missing changes
avilagaston9 Oct 8, 2024
6f6405a
refactor: fixing formatting issues
avilagaston9 Oct 8, 2024
62c2fa5
refactor: improve error msg
avilagaston9 Oct 8, 2024
d2519f0
refactor: change constant to env
avilagaston9 Oct 8, 2024
951eb28
fix: env variable
avilagaston9 Oct 8, 2024
44552b3
refactor: improve error handling
avilagaston9 Oct 8, 2024
01c5b27
test: add exploit test
avilagaston9 Oct 8, 2024
3bbd2a6
refactor: improve lgos
avilagaston9 Oct 8, 2024
88aaca7
refactor: add comment
avilagaston9 Oct 8, 2024
e54d15b
refactor: error message
uri-99 Oct 9, 2024
f2f3fcd
refactor: better error handling
uri-99 Oct 9, 2024
a8066b2
Merge branch '1016-fixexplorer-fetch_batch_data_pointer-in-explorer-r…
entropidelic Oct 9, 2024
a8afa27
Merge branch '1016-fixexplorer-fetch_batch_data_pointer-in-explorer-r…
uri-99 Oct 9, 2024
0004e82
Merge branch 'test-max-batch-size-limit-explorer' of https://github.c…
uri-99 Oct 9, 2024
e69bc14
Update explorer/lib/explorer_web/live/utils.ex
uri-99 Oct 9, 2024
3875037
fix: calculate_proof_hashes
uri-99 Oct 9, 2024
5cee221
refactor: check content lenght in the headers
avilagaston9 Oct 9, 2024
9c5ef15
fix: set invalid proof hashes to 0
avilagaston9 Oct 9, 2024
8ab0e93
fix: use a binary zero
avilagaston9 Oct 9, 2024
13838a2
Merge branch '1016-fixexplorer-fetch_batch_data_pointer-in-explorer-r…
avilagaston9 Oct 9, 2024
0466b3b
fix: set a default content length
avilagaston9 Oct 9, 2024
a735611
feat(explorer): add is_valid field to batches
avilagaston9 Oct 10, 2024
abf078e
fix: change is_verified to is_valid
avilagaston9 Oct 10, 2024
48c61df
fix: set true as a default for is_valid field
avilagaston9 Oct 10, 2024
f6d3cea
feat: add is valid status to frontend
avilagaston9 Oct 10, 2024
bcc9a52
fix: convert content-length to integer
avilagaston9 Oct 10, 2024
9cbc0ef
Merge branch '1016-fixexplorer-fetch_batch_data_pointer-in-explorer-r…
avilagaston9 Oct 10, 2024
824fd46
fix: set a default content length
avilagaston9 Oct 9, 2024
00a8494
fix: convert content-length to integer
avilagaston9 Oct 10, 2024
3aa7533
Merge branch 'mark-invalid-batches' into test-max-batch-size-limit-ex…
avilagaston9 Oct 10, 2024
6534a09
refactor: improve error handling
avilagaston9 Oct 12, 2024
35fe886
fix: error handling
avilagaston9 Oct 12, 2024
c8c957d
Merge branch 'mark-invalid-batches' into test-max-batch-size-limit-ex…
avilagaston9 Oct 14, 2024
0fa48b8
fix: handle errors properly
avilagaston9 Oct 14, 2024
1e15eab
Merge branch 'mark-invalid-batches' into test-max-batch-size-limit-ex…
avilagaston9 Oct 14, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions explorer/.env.dev
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,5 @@ DEBUG_ERRORS=true

# Operator version tracker API
TRACKER_API_URL=http://localhost:3030

MAX_BATCH_SIZE=268435456 # 256 MiB
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,8 @@ defmodule AlignedLayerServiceManager do
proof_hashes: nil,
fee_per_proof: BatcherPaymentServiceManager.get_fee_per_proof(%{merkle_root: created_batch.batchMerkleRoot}),
sender_address: Utils.string_to_bytes32(created_batch.senderAddress),
max_aggregator_fee: created_batch.maxAggregatorFee
max_aggregator_fee: created_batch.maxAggregatorFee,
is_valid: true
}
end

Expand Down Expand Up @@ -166,7 +167,8 @@ defmodule AlignedLayerServiceManager do
fee_per_proof: unverified_batch.fee_per_proof,
proof_hashes: nil,
sender_address: unverified_batch.sender_address,
max_aggregator_fee: unverified_batch.max_aggregator_fee
max_aggregator_fee: unverified_batch.max_aggregator_fee,
is_valid: true
}
end
end
Expand Down
6 changes: 4 additions & 2 deletions explorer/lib/explorer/models/batch_structs.ex
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ defmodule BatchDB do
:proof_hashes,
:fee_per_proof,
:sender_address,
:max_aggregator_fee
:max_aggregator_fee,
:is_valid
]
defstruct [
:merkle_root,
Expand All @@ -48,6 +49,7 @@ defmodule BatchDB do
:proof_hashes,
:fee_per_proof,
:sender_address,
:max_aggregator_fee
:max_aggregator_fee,
:is_valid
]
end
12 changes: 7 additions & 5 deletions explorer/lib/explorer/models/batches.ex
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,16 @@ defmodule Batches do
field :fee_per_proof, :integer
field :sender_address, :binary
field :max_aggregator_fee, :decimal
field :is_valid, :boolean, default: true

timestamps()
end

@doc false
def changeset(new_batch, updates) do
new_batch
|> 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])
|> validate_required([:merkle_root, :amount_of_proofs, :is_verified, :submission_block_number, :submission_transaction_hash, :fee_per_proof, :sender_address])
|> 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])
|> validate_required([:merkle_root, :amount_of_proofs, :is_verified, :submission_block_number, :submission_transaction_hash, :fee_per_proof, :sender_address, :is_valid])
|> validate_format(:merkle_root, ~r/0x[a-fA-F0-9]{64}/)
|> unique_constraint(:merkle_root)
|> validate_number(:amount_of_proofs, greater_than: 0)
Expand All @@ -37,6 +38,7 @@ defmodule Batches do
|> validate_format(:response_transaction_hash, ~r/0x[a-fA-F0-9]{64}/)
|> validate_number(:max_aggregator_fee, greater_than: 0)
|> validate_number(:fee_per_proof, greater_than_or_equal_to: 0)
|> validate_inclusion(:is_valid, [true, false])
end

def cast_to_batches(%BatchDB{} = batch_db) do
Expand All @@ -53,7 +55,8 @@ defmodule Batches do
data_pointer: batch_db.data_pointer,
fee_per_proof: batch_db.fee_per_proof,
sender_address: batch_db.sender_address,
max_aggregator_fee: batch_db.max_aggregator_fee
max_aggregator_fee: batch_db.max_aggregator_fee,
is_valid: batch_db.is_valid
}
end

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

query = from(b in Batches,
where: b.is_verified == false and b.submission_timestamp > ^threshold_datetime,
where: b.is_valid == true and b.is_verified == false and b.submission_timestamp > ^threshold_datetime,
select: b)

Explorer.Repo.all(query)
Expand Down Expand Up @@ -193,5 +196,4 @@ defmodule Batches do
end
end
end

end
33 changes: 14 additions & 19 deletions explorer/lib/explorer/periodically.ex
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ defmodule Explorer.Periodically do

run_every_n_iterations = 8
new_count = rem(count + 1, run_every_n_iterations)

if new_count == 0 do
Task.start(&process_unverified_batches/0)
end
Expand Down Expand Up @@ -79,25 +80,19 @@ defmodule Explorer.Periodically do
{:ok, lock} ->
"Processing batch: #{batch.merkle_root}" |> Logger.debug()

{batch_changeset, proofs} =
batch
|> Utils.extract_info_from_data_pointer()
|> Batches.generate_changesets()

Batches.insert_or_update(batch_changeset, proofs)
|> case do
{:ok, _} ->
PubSub.broadcast(Explorer.PubSub, "update_views", %{
eth_usd:
case EthConverter.get_eth_price_usd() do
{:ok, eth_usd_price} -> eth_usd_price
{:error, _error} -> :empty
end
})

{:error, error} ->
Logger.error("Some error in DB operation, not broadcasting update_views: #{inspect(error)}")

with {:ok, updated_batch} <- Utils.process_batch(batch),
{batch_changeset, proofs} <- Batches.generate_changesets(updated_batch),
{:ok, _} <- Batches.insert_or_update(batch_changeset, proofs) do
PubSub.broadcast(Explorer.PubSub, "update_views", %{
eth_usd:
case EthConverter.get_eth_price_usd() do
{:ok, eth_usd_price} -> eth_usd_price
{:error, _error} -> :empty
end
})
else
{:error, reason} ->
Logger.error("Error processing batch #{batch.merkle_root}. Error: #{inspect(reason)}")
# no changes in DB
nil ->
nil
Expand Down
41 changes: 37 additions & 4 deletions explorer/lib/explorer_web/components/core_components.ex
Original file line number Diff line number Diff line change
Expand Up @@ -417,15 +417,15 @@ defmodule ExplorerWeb.CoreComponents do
end

@doc """
Renders a dynamic badge compoent.
Renders a dynamic badge component.
"""
attr :class, :string, default: nil
attr :status, :boolean, default: true
attr :falsy_text, :string, default: "Pending"
attr :truthy_text, :string, default: "Verified"
attr :falsy_text, :string
attr :truthy_text, :string
slot :inner_block, default: nil

def dynamic_badge(assigns) do
def dynamic_badge_boolean(assigns) do
~H"""
<.badge
variant={
Expand All @@ -449,6 +449,39 @@ defmodule ExplorerWeb.CoreComponents do
"""
end

@doc """
Renders a dynamic badge component for the batcher.
"""
attr :class, :string, default: nil
attr :status, :atom
slot :inner_block, default: nil

def dynamic_badge_for_batcher(assigns) do
~H"""
<.badge
variant={
case @status do
:invalid -> "destructive"
:verified -> "accent"
:pending -> "foreground"
end
}
class={
classes([
@class
])
}
>
<%= case @status do
:invalid -> "Invalid"
:verified -> "Verified"
:pending -> "Pending"
end %>
<%= render_slot(@inner_block) %>
</.badge>
"""
end

@doc """
Renders an input with label and error messages.

Expand Down
2 changes: 1 addition & 1 deletion explorer/lib/explorer_web/live/pages/batch/index.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<h3>
Status:
</h3>
<.dynamic_badge class="w-fit" status={@current_batch.is_verified} />
<.dynamic_badge_for_batcher class="w-fit" status={Helpers.get_batch_status(@current_batch)} />
</div>
<div>
<h3>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
</.link>
</:col>
<:col :let={batch} label="Status">
<.dynamic_badge status={batch.is_verified} />
<.dynamic_badge_for_batcher status={Helpers.get_batch_status(batch)} />
</:col>
<:col :let={batch} label="Age">
<span class="md:px-0" title={batch.submission_timestamp}>
Expand Down
2 changes: 1 addition & 1 deletion explorer/lib/explorer_web/live/pages/operators/index.ex
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ defmodule ExplorerWeb.Operators.Index do
<%= operator.total_stake |> EthConverter.wei_to_eth(2) |> Helpers.format_number() %> ETH
</:col>
<:col :let={operator} label="Status">
<.dynamic_badge status={operator.is_active} truthy_text="Active" falsy_text="Inactive" />
<.dynamic_badge_boolean status={operator.is_active} truthy_text="Active" falsy_text="Inactive" />
</:col>
</.table>
<% else %>
Expand Down
Loading
Loading