Txn -> Transaction

pull/7584/head
POA 1 year ago
parent 8b70c29bac
commit 126c59a30d
  1. 4
      apps/block_scout_web/lib/block_scout_web/chain.ex
  2. 12
      apps/explorer/lib/explorer/chain.ex
  3. 24
      apps/explorer/lib/explorer/chain/import/runner/zkevm_batch_transactions.ex
  4. 26
      apps/explorer/lib/explorer/chain/import/runner/zkevm_lifecycle_transactions.ex
  5. 26
      apps/explorer/lib/explorer/chain/import/runner/zkevm_transaction_batches.ex
  6. 6
      apps/explorer/lib/explorer/chain/import/stage/block_referencing.ex
  7. 6
      apps/explorer/lib/explorer/chain/transaction.ex
  8. 8
      apps/explorer/lib/explorer/chain/zkevm_batch_transaction.ex
  9. 8
      apps/explorer/lib/explorer/chain/zkevm_lifecycle_transaction.ex
  10. 21
      apps/explorer/lib/explorer/chain/zkevm_transaction_batch.ex
  11. 20
      apps/indexer/lib/indexer/fetcher/zkevm_transaction_batch.ex
  12. 4
      apps/indexer/lib/indexer/supervisor.ex

@ -35,7 +35,7 @@ defmodule BlockScoutWeb.Chain do
Transaction.StateChange,
Wei,
Withdrawal,
ZkevmTxnBatch
ZkevmTransactionBatch
}
alias Explorer.PagingOptions
@ -535,7 +535,7 @@ defmodule BlockScoutWeb.Chain do
%{"index" => index}
end
defp paging_params(%ZkevmTxnBatch{number: number}) do
defp paging_params(%ZkevmTransactionBatch{number: number}) do
%{"number" => number}
end

@ -65,8 +65,8 @@ defmodule Explorer.Chain do
Transaction,
Wei,
Withdrawal,
ZkevmBatchTxn,
ZkevmTxnBatch
ZkevmBatchTransaction,
ZkevmTransactionBatch
}
alias Explorer.Chain.Block.{EmissionReward, Reward}
@ -6396,7 +6396,7 @@ defmodule Explorer.Chain do
def zkevm_batch(number, options \\ [])
def zkevm_batch(:latest, options) when is_list(options) do
ZkevmTxnBatch
ZkevmTransactionBatch
|> order_by(desc: :number)
|> limit(1)
|> select_repo(options).one()
@ -6409,7 +6409,7 @@ defmodule Explorer.Chain do
def zkevm_batch(number, options) when is_list(options) do
necessity_by_association = Keyword.get(options, :necessity_by_association, %{})
ZkevmTxnBatch
ZkevmTransactionBatch
|> where(number: ^number)
|> join_associations(necessity_by_association)
|> select_repo(options).one()
@ -6442,7 +6442,7 @@ defmodule Explorer.Chain do
necessity_by_association = Keyword.get(options, :necessity_by_association, %{})
base_query =
from(tb in ZkevmTxnBatch,
from(tb in ZkevmTransactionBatch,
order_by: [desc: tb.number]
)
@ -6465,7 +6465,7 @@ defmodule Explorer.Chain do
end
def zkevm_batch_transactions(batch_number, options \\ []) do
query = from(bts in ZkevmBatchTxn, where: bts.batch_number == ^batch_number)
query = from(bts in ZkevmBatchTransaction, where: bts.batch_number == ^batch_number)
select_repo(options).all(query)
end

@ -1,12 +1,12 @@
defmodule Explorer.Chain.Import.Runner.ZkevmBatchTxns do
defmodule Explorer.Chain.Import.Runner.ZkevmBatchTransactions do
@moduledoc """
Bulk imports `t:Explorer.Chain.ZkevmBatchTxn.t/0`.
Bulk imports `t:Explorer.Chain.ZkevmBatchTransaction.t/0`.
"""
require Ecto.Query
alias Ecto.{Changeset, Multi, Repo}
alias Explorer.Chain.{Import, ZkevmBatchTxn}
alias Explorer.Chain.{Import, ZkevmBatchTransaction}
alias Explorer.Prometheus.Instrumenter
@behaviour Import.Runner
@ -14,13 +14,13 @@ defmodule Explorer.Chain.Import.Runner.ZkevmBatchTxns do
# milliseconds
@timeout 60_000
@type imported :: [ZkevmBatchTxn.t()]
@type imported :: [ZkevmBatchTransaction.t()]
@impl Import.Runner
def ecto_schema_module, do: ZkevmBatchTxn
def ecto_schema_module, do: ZkevmBatchTransaction
@impl Import.Runner
def option_key, do: :zkevm_batch_txns
def option_key, do: :zkevm_batch_transactions
@impl Import.Runner
def imported_table_row do
@ -39,12 +39,12 @@ defmodule Explorer.Chain.Import.Runner.ZkevmBatchTxns do
|> Map.put_new(:timeout, @timeout)
|> Map.put(:timestamps, timestamps)
Multi.run(multi, :insert_zkevm_batch_txns, fn repo, _ ->
Multi.run(multi, :insert_zkevm_batch_transactions, fn repo, _ ->
Instrumenter.block_import_stage_runner(
fn -> insert(repo, changes_list, insert_options) end,
:block_referencing,
:zkevm_batch_txns,
:zkevm_batch_txns
:zkevm_batch_transactions,
:zkevm_batch_transactions
)
end)
end
@ -53,17 +53,17 @@ defmodule Explorer.Chain.Import.Runner.ZkevmBatchTxns do
def timeout, do: @timeout
@spec insert(Repo.t(), [map()], %{required(:timeout) => timeout(), required(:timestamps) => Import.timestamps()}) ::
{:ok, [ZkevmBatchTxn.t()]}
{:ok, [ZkevmBatchTransaction.t()]}
| {:error, [Changeset.t()]}
def insert(repo, changes_list, %{timeout: timeout, timestamps: timestamps} = _options) when is_list(changes_list) do
# Enforce ZkevmBatchTxn ShareLocks order (see docs: sharelock.md)
# Enforce ZkevmBatchTransaction ShareLocks order (see docs: sharelock.md)
ordered_changes_list = Enum.sort_by(changes_list, & &1.hash)
{:ok, inserted} =
Import.insert_changes_list(
repo,
ordered_changes_list,
for: ZkevmBatchTxn,
for: ZkevmBatchTransaction,
returning: true,
timeout: timeout,
timestamps: timestamps,

@ -1,12 +1,12 @@
defmodule Explorer.Chain.Import.Runner.ZkevmLifecycleTxns do
defmodule Explorer.Chain.Import.Runner.ZkevmLifecycleTransactions do
@moduledoc """
Bulk imports `t:Explorer.Chain.ZkevmLifecycleTxn.t/0`.
Bulk imports `t:Explorer.Chain.ZkevmLifecycleTransaction.t/0`.
"""
require Ecto.Query
alias Ecto.{Changeset, Multi, Repo}
alias Explorer.Chain.{Import, ZkevmLifecycleTxn}
alias Explorer.Chain.{Import, ZkevmLifecycleTransaction}
alias Explorer.Prometheus.Instrumenter
import Ecto.Query, only: [from: 2]
@ -16,13 +16,13 @@ defmodule Explorer.Chain.Import.Runner.ZkevmLifecycleTxns do
# milliseconds
@timeout 60_000
@type imported :: [ZkevmLifecycleTxn.t()]
@type imported :: [ZkevmLifecycleTransaction.t()]
@impl Import.Runner
def ecto_schema_module, do: ZkevmLifecycleTxn
def ecto_schema_module, do: ZkevmLifecycleTransaction
@impl Import.Runner
def option_key, do: :zkevm_lifecycle_txns
def option_key, do: :zkevm_lifecycle_transactions
@impl Import.Runner
def imported_table_row do
@ -41,12 +41,12 @@ defmodule Explorer.Chain.Import.Runner.ZkevmLifecycleTxns do
|> Map.put_new(:timeout, @timeout)
|> Map.put(:timestamps, timestamps)
Multi.run(multi, :insert_zkevm_lifecycle_txns, fn repo, _ ->
Multi.run(multi, :insert_zkevm_lifecycle_transactions, fn repo, _ ->
Instrumenter.block_import_stage_runner(
fn -> insert(repo, changes_list, insert_options) end,
:block_referencing,
:zkevm_lifecycle_txns,
:zkevm_lifecycle_txns
:zkevm_lifecycle_transactions,
:zkevm_lifecycle_transactions
)
end)
end
@ -55,19 +55,19 @@ defmodule Explorer.Chain.Import.Runner.ZkevmLifecycleTxns do
def timeout, do: @timeout
@spec insert(Repo.t(), [map()], %{required(:timeout) => timeout(), required(:timestamps) => Import.timestamps()}) ::
{:ok, [ZkevmLifecycleTxn.t()]}
{:ok, [ZkevmLifecycleTransaction.t()]}
| {:error, [Changeset.t()]}
def insert(repo, changes_list, %{timeout: timeout, timestamps: timestamps} = options) when is_list(changes_list) do
on_conflict = Map.get_lazy(options, :on_conflict, &default_on_conflict/0)
# Enforce ZkevmLifecycleTxn ShareLocks order (see docs: sharelock.md)
# Enforce ZkevmLifecycleTransaction ShareLocks order (see docs: sharelock.md)
ordered_changes_list = Enum.sort_by(changes_list, & &1.id)
{:ok, inserted} =
Import.insert_changes_list(
repo,
ordered_changes_list,
for: ZkevmLifecycleTxn,
for: ZkevmLifecycleTransaction,
returning: true,
timeout: timeout,
timestamps: timestamps,
@ -80,7 +80,7 @@ defmodule Explorer.Chain.Import.Runner.ZkevmLifecycleTxns do
defp default_on_conflict do
from(
tx in ZkevmLifecycleTxn,
tx in ZkevmLifecycleTransaction,
update: [
set: [
# don't update `id` as it is a primary key

@ -1,12 +1,12 @@
defmodule Explorer.Chain.Import.Runner.ZkevmTxnBatches do
defmodule Explorer.Chain.Import.Runner.ZkevmTransactionBatches do
@moduledoc """
Bulk imports `t:Explorer.Chain.ZkevmTxnBatch.t/0`.
Bulk imports `t:Explorer.Chain.ZkevmTransactionBatch.t/0`.
"""
require Ecto.Query
alias Ecto.{Changeset, Multi, Repo}
alias Explorer.Chain.{Import, ZkevmTxnBatch}
alias Explorer.Chain.{Import, ZkevmTransactionBatch}
alias Explorer.Prometheus.Instrumenter
import Ecto.Query, only: [from: 2]
@ -16,13 +16,13 @@ defmodule Explorer.Chain.Import.Runner.ZkevmTxnBatches do
# milliseconds
@timeout 60_000
@type imported :: [ZkevmTxnBatch.t()]
@type imported :: [ZkevmTransactionBatch.t()]
@impl Import.Runner
def ecto_schema_module, do: ZkevmTxnBatch
def ecto_schema_module, do: ZkevmTransactionBatch
@impl Import.Runner
def option_key, do: :zkevm_txn_batches
def option_key, do: :zkevm_transaction_batches
@impl Import.Runner
def imported_table_row do
@ -41,12 +41,12 @@ defmodule Explorer.Chain.Import.Runner.ZkevmTxnBatches do
|> Map.put_new(:timeout, @timeout)
|> Map.put(:timestamps, timestamps)
Multi.run(multi, :insert_zkevm_txn_batches, fn repo, _ ->
Multi.run(multi, :insert_zkevm_transaction_batches, fn repo, _ ->
Instrumenter.block_import_stage_runner(
fn -> insert(repo, changes_list, insert_options) end,
:block_referencing,
:zkevm_txn_batches,
:zkevm_txn_batches
:zkevm_transaction_batches,
:zkevm_transaction_batches
)
end)
end
@ -55,19 +55,19 @@ defmodule Explorer.Chain.Import.Runner.ZkevmTxnBatches do
def timeout, do: @timeout
@spec insert(Repo.t(), [map()], %{required(:timeout) => timeout(), required(:timestamps) => Import.timestamps()}) ::
{:ok, [ZkevmTxnBatch.t()]}
{:ok, [ZkevmTransactionBatch.t()]}
| {:error, [Changeset.t()]}
def insert(repo, changes_list, %{timeout: timeout, timestamps: timestamps} = options) when is_list(changes_list) do
on_conflict = Map.get_lazy(options, :on_conflict, &default_on_conflict/0)
# Enforce ZkevmTxnBatch ShareLocks order (see docs: sharelock.md)
# Enforce ZkevmTransactionBatch ShareLocks order (see docs: sharelock.md)
ordered_changes_list = Enum.sort_by(changes_list, & &1.number)
{:ok, inserted} =
Import.insert_changes_list(
repo,
ordered_changes_list,
for: ZkevmTxnBatch,
for: ZkevmTransactionBatch,
returning: true,
timeout: timeout,
timestamps: timestamps,
@ -80,7 +80,7 @@ defmodule Explorer.Chain.Import.Runner.ZkevmTxnBatches do
defp default_on_conflict do
from(
tb in ZkevmTxnBatch,
tb in ZkevmTransactionBatch,
update: [
set: [
# don't update `number` as it is a primary key and used for the conflict target

@ -33,9 +33,9 @@ defmodule Explorer.Chain.Import.Stage.BlockReferencing do
"polygon_zkevm" ->
@default_runners ++
[
Runner.ZkevmLifecycleTxns,
Runner.ZkevmTxnBatches,
Runner.ZkevmBatchTxns
Runner.ZkevmLifecycleTransactions,
Runner.ZkevmTransactionBatches,
Runner.ZkevmBatchTransactions
]
_ -> @default_runners
end

@ -28,7 +28,7 @@ defmodule Explorer.Chain.Transaction do
Transaction,
TransactionAction,
Wei,
ZkevmBatchTxn
ZkevmBatchTransaction
}
alias Explorer.Chain.Transaction.{Fork, Status}
@ -276,8 +276,8 @@ defmodule Explorer.Chain.Transaction do
has_many(:uncles, through: [:forks, :uncle])
has_one(:zkevm_batch_txn, ZkevmBatchTxn, foreign_key: :hash)
has_one(:zkevm_batch, through: [:zkevm_batch_txn, :batch])
has_one(:zkevm_batch_transaction, ZkevmBatchTransaction, foreign_key: :hash)
has_one(:zkevm_batch, through: [:zkevm_batch_transaction, :batch])
has_one(:zkevm_sequence_txn, through: [:zkevm_batch, :sequence_transaction])
has_one(:zkevm_verify_txn, through: [:zkevm_batch, :verify_transaction])

@ -1,22 +1,22 @@
defmodule Explorer.Chain.ZkevmBatchTxn do
defmodule Explorer.Chain.ZkevmBatchTransaction do
@moduledoc "Models a list of transactions related to a batch for zkEVM."
use Explorer.Schema
alias Explorer.Chain.{Hash, Transaction, ZkevmTxnBatch}
alias Explorer.Chain.{Hash, Transaction, ZkevmTransactionBatch}
@required_attrs ~w(batch_number hash)a
@type t :: %__MODULE__{
batch_number: non_neg_integer(),
batch: %Ecto.Association.NotLoaded{} | ZkevmTxnBatch.t() | nil,
batch: %Ecto.Association.NotLoaded{} | ZkevmTransactionBatch.t() | nil,
hash: Hash.t(),
l2_transaction: %Ecto.Association.NotLoaded{} | Transaction.t() | nil
}
@primary_key false
schema "zkevm_batch_l2_transactions" do
belongs_to(:batch, ZkevmTxnBatch, foreign_key: :batch_number, references: :number, type: :integer)
belongs_to(:batch, ZkevmTransactionBatch, foreign_key: :batch_number, references: :number, type: :integer)
belongs_to(:l2_transaction, Transaction, foreign_key: :hash, primary_key: true, references: :hash, type: Hash.Full)
timestamps()

@ -1,9 +1,9 @@
defmodule Explorer.Chain.ZkevmLifecycleTxn do
defmodule Explorer.Chain.ZkevmLifecycleTransaction do
@moduledoc "Models an L1 lifecycle transaction for zkEVM."
use Explorer.Schema
alias Explorer.Chain.{Hash, ZkevmTxnBatch}
alias Explorer.Chain.{Hash, ZkevmTransactionBatch}
@required_attrs ~w(id hash is_verify)a
@ -17,8 +17,8 @@ defmodule Explorer.Chain.ZkevmLifecycleTxn do
field(:hash, Hash.Full)
field(:is_verify, :boolean)
has_many(:sequenced_batches, ZkevmTxnBatch, foreign_key: :sequence_id)
has_many(:verified_batches, ZkevmTxnBatch, foreign_key: :verify_id)
has_many(:sequenced_batches, ZkevmTransactionBatch, foreign_key: :sequence_id)
has_many(:verified_batches, ZkevmTransactionBatch, foreign_key: :verify_id)
timestamps()
end

@ -1,9 +1,9 @@
defmodule Explorer.Chain.ZkevmTxnBatch do
defmodule Explorer.Chain.ZkevmTransactionBatch do
@moduledoc "Models a batch of transactions for zkEVM."
use Explorer.Schema
alias Explorer.Chain.{Hash, ZkevmBatchTxn, ZkevmLifecycleTxn}
alias Explorer.Chain.{Hash, ZkevmBatchTransaction, ZkevmLifecycleTransaction}
@optional_attrs ~w(sequence_id verify_id)a
@ -17,10 +17,10 @@ defmodule Explorer.Chain.ZkevmTxnBatch do
acc_input_hash: Hash.t(),
state_root: Hash.t(),
sequence_id: non_neg_integer() | nil,
sequence_transaction: %Ecto.Association.NotLoaded{} | ZkevmLifecycleTxn.t() | nil,
sequence_transaction: %Ecto.Association.NotLoaded{} | ZkevmLifecycleTransaction.t() | nil,
verify_id: non_neg_integer() | nil,
verify_transaction: %Ecto.Association.NotLoaded{} | ZkevmLifecycleTxn.t() | nil,
l2_transactions: %Ecto.Association.NotLoaded{} | [ZkevmBatchTxn.t()]
verify_transaction: %Ecto.Association.NotLoaded{} | ZkevmLifecycleTransaction.t() | nil,
l2_transactions: %Ecto.Association.NotLoaded{} | [ZkevmBatchTransaction.t()]
}
@primary_key {:number, :integer, autogenerate: false}
@ -31,10 +31,15 @@ defmodule Explorer.Chain.ZkevmTxnBatch do
field(:acc_input_hash, Hash.Full)
field(:state_root, Hash.Full)
belongs_to(:sequence_transaction, ZkevmLifecycleTxn, foreign_key: :sequence_id, references: :id, type: :integer)
belongs_to(:verify_transaction, ZkevmLifecycleTxn, foreign_key: :verify_id, references: :id, type: :integer)
belongs_to(:sequence_transaction, ZkevmLifecycleTransaction,
foreign_key: :sequence_id,
references: :id,
type: :integer
)
has_many(:l2_transactions, ZkevmBatchTxn, foreign_key: :batch_number)
belongs_to(:verify_transaction, ZkevmLifecycleTransaction, foreign_key: :verify_id, references: :id, type: :integer)
has_many(:l2_transactions, ZkevmBatchTransaction, foreign_key: :batch_number)
timestamps()
end

@ -1,4 +1,4 @@
defmodule Indexer.Fetcher.ZkevmTxnBatch do
defmodule Indexer.Fetcher.ZkevmTransactionBatch do
@moduledoc """
Fills zkevm_transaction_batches DB table.
"""
@ -13,7 +13,7 @@ defmodule Indexer.Fetcher.ZkevmTxnBatch do
import EthereumJSONRPC, only: [integer_to_quantity: 1, json_rpc: 2, quantity_to_integer: 1]
alias Explorer.{Chain, Repo}
alias Explorer.Chain.{ZkevmLifecycleTxn, ZkevmTxnBatch}
alias Explorer.Chain.{ZkevmLifecycleTransaction, ZkevmTransactionBatch}
@zero_hash "0000000000000000000000000000000000000000000000000000000000000000"
@ -34,9 +34,9 @@ defmodule Indexer.Fetcher.ZkevmTxnBatch do
@impl GenServer
def init(args) do
Logger.metadata(fetcher: :zkevm_txn_batches)
Logger.metadata(fetcher: :zkevm_transaction_batches)
config = Application.get_all_env(:indexer)[Indexer.Fetcher.ZkevmTxnBatch]
config = Application.get_all_env(:indexer)[Indexer.Fetcher.ZkevmTransactionBatch]
chunk_size = config[:chunk_size]
recheck_interval = config[:recheck_interval]
@ -113,7 +113,7 @@ defmodule Indexer.Fetcher.ZkevmTxnBatch do
defp get_last_verified_batch_number do
query =
from(tb in ZkevmTxnBatch,
from(tb in ZkevmTransactionBatch,
select: tb.number,
where: not is_nil(tb.verify_id),
order_by: [desc: tb.number],
@ -127,7 +127,7 @@ defmodule Indexer.Fetcher.ZkevmTxnBatch do
defp get_next_id do
query =
from(lt in ZkevmLifecycleTxn,
from(lt in ZkevmLifecycleTransaction,
select: lt.id,
order_by: [desc: lt.id],
limit: 1
@ -228,7 +228,7 @@ defmodule Indexer.Fetcher.ZkevmTxnBatch do
query =
from(
lt in ZkevmLifecycleTxn,
lt in ZkevmLifecycleTransaction,
select: {lt.hash, lt.id},
where: lt.hash in ^l1_tx_hashes
)
@ -287,9 +287,9 @@ defmodule Indexer.Fetcher.ZkevmTxnBatch do
{:ok, _} =
Chain.import(%{
zkevm_lifecycle_txns: %{params: l1_txs_to_import},
zkevm_txn_batches: %{params: batches_to_import},
zkevm_batch_txns: %{params: l2_txs_to_import},
zkevm_lifecycle_transactions: %{params: l1_txs_to_import},
zkevm_transaction_batches: %{params: batches_to_import},
zkevm_batch_transactions: %{params: l2_txs_to_import},
timeout: :infinity
})
end

@ -35,7 +35,7 @@ defmodule Indexer.Supervisor do
TransactionAction,
UncleBlock,
Withdrawal,
ZkevmTxnBatch
ZkevmTransactionBatch
}
alias Indexer.Temporary.{
@ -133,7 +133,7 @@ defmodule Indexer.Supervisor do
{Indexer.Fetcher.PolygonEdge.Withdrawal.Supervisor,
[[memory_monitor: memory_monitor, json_rpc_named_arguments: json_rpc_named_arguments]]},
{Indexer.Fetcher.PolygonEdge.WithdrawalExit.Supervisor, [[memory_monitor: memory_monitor]]},
configure(ZkevmTxnBatch.Supervisor, [
configure(ZkevmTransactionBatch.Supervisor, [
[json_rpc_named_arguments: json_rpc_named_arguments, memory_monitor: memory_monitor]
]),

Loading…
Cancel
Save