Skip to content
This repository has been archived by the owner on Oct 4, 2024. It is now read-only.

Add Sepolia network #408

Merged
merged 5 commits into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 .env.example
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
export DB_TYPE= # set to postgresql if you want to use postgresql, empty otherwise (sqlite).
export DISABLE_MAINNET_SYNC=true # Set to true if you want to disable mainnet sync
export DISABLE_TESTNET_SYNC=true # Set to true if you want to disable testnet sync
export DISABLE_SEPOLIA_SYNC=true # Set to true if you want to disable sepolia sync
export RPC_API_HOST=<YOUR_RPC_API_HOST> # Set to your mainnet rpc api host, is will be used in the explorer as "Mainnet"
export TESTNET_RPC_API_HOST=<YOUR_TESTNET_RPC_API_HOST> # Set to your testnet rpc api host, is will be used in the explorer as "Testnet"
export SEPOLIA_RPC_API_HOST=<YOUR_SEPOLIA_RPC_API_HOST> # Set to your sepolia rpc api host, is will be used in the explorer as "Sepolia"
export DB_NAME=<DB_NAME> # set DB creds
export DB_USER=<DB_USER>
export DB_PASS=<DB_PASS>
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ jobs:
env:
RPC_API_HOST: ${{ secrets.RPC_API_HOST }}
TESTNET_RPC_API_HOST: ${{ secrets.TESTNET_RPC_API_HOST }}
SEPOLIA_RPC_API_HOST: ${{ secrets.SEPOLIA_RPC_API_HOST }}
name: Build and test
runs-on: ubuntu-latest
services:
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/deploy-production.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ jobs:
PHX_SERVER: ${{ vars.PHX_SERVER }}
RPC_API_HOST: ${{ secrets.RPC_API_HOST }}
TESTNET_RPC_API_HOST: ${{ secrets.TESTNET_RPC_API_HOST }}
SEPOLIA_RPC_API_HOST: ${{ secrets.SEPOLIA_RPC_API_HOST }}
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_REGION: ${{ vars.AWS_REGION }}
Expand All @@ -67,6 +68,7 @@ jobs:
SENTRY_DSN: ${{ secrets.SENTRY_DSN }}
ENABLE_MAINNET_SYNC: "true"
ENABLE_TESTNET_SYNC: "true"
ENABLE_SEPOLIA_SYNC: "true"
ENABLE_GATEWAY_DATA: "true"
run: |
ansible-playbook -i ansible/inventory.yaml ansible/playbooks/deployment.yaml
2 changes: 2 additions & 0 deletions .github/workflows/deploy-testing.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ jobs:
PHX_SERVER: ${{ vars.PHX_SERVER }}
RPC_API_HOST: ${{ secrets.RPC_API_HOST }}
TESTNET_RPC_API_HOST: ${{ secrets.TESTNET_RPC_API_HOST }}
SEPOLIA_RPC_API_HOST: ${{ secrets.SEPOLIA_RPC_API_HOST }}
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_REGION: ${{ vars.AWS_REGION }}
Expand All @@ -64,6 +65,7 @@ jobs:
ANSIBLE_STDOUT_CALLBACK: "yaml"
ENABLE_MAINNET_SYNC: "true"
ENABLE_TESTNET_SYNC: "true"
ENABLE_SEPOLIA_SYNC: "true"
ENABLE_GATEWAY_DATA: "true"
NEWRELIC_KEY: ${{ secrets.NEWRELIC_KEY }}
NEWRELIC_APP_NAME: ${{ vars.NEWRELIC_APP_NAME }}
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ Set the following environment variables:
```bash
export RPC_API_HOST=your_rpc_hostname
export TESTNET_RPC_API_HOST=testnet_rpc_hostname
export SEPOLIA_RPC_API_HOST=sepolia_rpc_hostname
```

### RPC with Juno
Expand Down Expand Up @@ -100,6 +101,7 @@ The synchronization process is activated by default, you can turn it off by conf
```bash
export DISABLE_MAINNET_SYNC=true
export DISABLE_TESTNET_SYNC=true
export DISABLE_SEPOLIA_SYNC=true
```

It's worth noting that you have the flexibility to select which networks you want to synchronize by adjusting these environment variables.
Expand Down
4 changes: 4 additions & 0 deletions ansible/playbooks/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
MIX_ENV: prod
RPC_API_HOST: "{{ lookup('ansible.builtin.env', 'RPC_API_HOST') }}"
TESTNET_RPC_API_HOST: "{{ lookup('ansible.builtin.env', 'TESTNET_RPC_API_HOST') }}"
SEPOLIA_RPC_API_HOST: "{{ lookup('ansible.builtin.env', 'SEPOLIA_RPC_API_HOST') }}"
DB_TYPE: "{{ lookup('ansible.builtin.env', 'DB_TYPE') }}"
DATABASE_URL: "{{ lookup('ansible.builtin.env', 'DATABASE_URL') }}"
NEWRELIC_KEY:
Expand All @@ -51,6 +52,7 @@
SENTRY_DSN: "{{ lookup('ansible.builtin.env', 'SENTRY_DSN') }}"
ENABLE_MAINNET_SYNC: "{{ lookup('ansible.builtin.env', 'ENABLE_MAINNET_SYNC') }}"
ENABLE_TESTNET_SYNC: "{{ lookup('ansible.builtin.env', 'ENABLE_TESTNET_SYNC') }}"
ENABLE_SEPOLIA_SYNC: "{{ lookup('ansible.builtin.env', 'ENABLE_SEPOLIA_SYNC') }}"
ENABLE_GATEWAY_DATA: "{{ lookup('ansible.builtin.env', 'ENABLE_GATEWAY_DATA') }}"
args:
chdir: "/home/{{ lookup('ansible.builtin.env', 'TS_USER') }}/tmp/stark_compass_explorer"
Expand Down Expand Up @@ -80,6 +82,7 @@
database_url: "{{ lookup('ansible.builtin.env', 'DATABASE_URL') }}"
rpc_api_host: "{{ lookup('ansible.builtin.env', 'RPC_API_HOST') }}"
testnet_rpc_api_host: "{{ lookup('ansible.builtin.env', 'TESTNET_RPC_API_HOST') }}"
sepolia_rpc_api_host: "{{ lookup('ansible.builtin.env', 'SEPOLIA_RPC_API_HOST') }}"
aws_access_key_id: "{{ lookup('ansible.builtin.env', 'AWS_ACCESS_KEY_ID') }}"
aws_secret_access_key: "{{ lookup('ansible.builtin.env', 'AWS_SECRET_ACCESS_KEY') }}"
aws_region: "{{ lookup('ansible.builtin.env', 'AWS_REGION') }}"
Expand All @@ -90,6 +93,7 @@
sentry_dsn: "{{ lookup('ansible.builtin.env', 'SENTRY_DSN') }}"
enable_mainnet_sync: "{{ lookup('ansible.builtin.env', 'ENABLE_MAINNET_SYNC') }}"
enable_testnet_sync: "{{ lookup('ansible.builtin.env', 'ENABLE_TESTNET_SYNC') }}"
enable_sepolia_sync: "{{ lookup('ansible.builtin.env', 'ENABLE_SEPOLIA_SYNC') }}"
enable_gateway_data: "{{ lookup('ansible.builtin.env', 'ENABLE_GATEWAY_DATA') }}"

- name: Create user systemd directory
Expand Down
2 changes: 2 additions & 0 deletions ansible/playbooks/templates/.env.j2
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ DB_TYPE={{ db_type }}
DATABASE_URL={{ database_url }}
RPC_API_HOST={{ rpc_api_host }}
TESTNET_RPC_API_HOST={{ testnet_rpc_api_host }}
SEPOLIA_RPC_API_HOST={{ sepolia_rpc_api_host }}
AWS_ACCESS_KEY_ID={{ aws_access_key_id }}
AWS_SECRET_ACCESS_KEY={{ aws_secret_access_key }}
AWS_REGION={{ aws_region }}
Expand All @@ -16,3 +17,4 @@ SENTRY_DSN={{ sentry_dsn }}
SENTRY_ENV={{ sentry_env }}
ENABLE_MAINNET_SYNC={{ enable_mainnet_sync }}
ENABLE_TESTNET_SYNC={{ enable_testnet_sync }}
ENABLE_SEPOLIA_SYNC={{ enable_sepolia_sync }}
2 changes: 1 addition & 1 deletion config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ config :esbuild,
]

config :starknet_explorer,
allowed_networks: [:mainnet, :testnet]
allowed_networks: [:mainnet, :testnet, :sepolia]

# Import environment specific config. This must remain at the bottom
# of this file so it overrides the configuration defined above.
Expand Down
9 changes: 8 additions & 1 deletion config/runtime.exs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,16 @@ testnet_rpc_host =
environment variable for testnet is missing.
"""

sepolia_rpc_host =
System.get_env("SEPOLIA_RPC_API_HOST") ||
raise """
environment variable for sepolia is missing.
"""

config :starknet_explorer,
rpc_host: rpc_host,
testnet_host: testnet_rpc_host
testnet_host: testnet_rpc_host,
sepolia_host: sepolia_rpc_host

config :starknet_explorer, rpc_host: rpc_host

Expand Down
2 changes: 1 addition & 1 deletion lib/cache_request_warmer.ex
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ defmodule StarknetExplorer.Cache.BlockWarmer do
def interval, do: @interval

def execute(%{network: network})
when network in [:mainnet, :testnet] do
when network in [:mainnet, :testnet, :sepolia] do
Logger.debug("Warming cache for #{network}")
# Try/Rescue is not really an elixir/erlang thing to do, but
# I think this is the most simple way to do this, since
Expand Down
16 changes: 15 additions & 1 deletion lib/starknet_explorer/application.ex
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,20 @@ defmodule StarknetExplorer.Application do
]
end

sepolia_state_sync =
if System.get_env("DISABLE_SEPOLIA_SYNC") == "true" do
[]
else
# Start the State Sync System server for sepolia.
[
Supervisor.child_spec(
{StarknetExplorer.Blockchain.StateSyncSystem,
[network: :sepolia, name: :sepolia_state_sync]},
id: :sepolia_state_sync
)
]
end

children =
[
# Start the Telemetry supervisor
Expand All @@ -50,7 +64,7 @@ defmodule StarknetExplorer.Application do
# Start a worker by calling: StarknetExplorer.Worker.start_link(arg)
# {StarknetExplorer.Worker, arg}
StarknetExplorer.IndexCache
] ++ testnet_state_sync ++ mainnet_state_sync
] ++ sepolia_state_sync ++ testnet_state_sync ++ mainnet_state_sync

# See https://hexdocs.pm/elixir/Supervisor.html
# for other strategies and supported options
Expand Down
2 changes: 1 addition & 1 deletion lib/starknet_explorer/block/block.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ defmodule StarknetExplorer.Block do
alias StarknetExplorerWeb.Utils
alias StarknetExplorer.TransactionReceipt, as: Receipt
require Logger
@networks [:mainnet, :testnet]
@networks [:mainnet, :testnet, :sepolia]
@cast_fields [
:number,
:status,
Expand Down
4 changes: 3 additions & 1 deletion lib/starknet_explorer/cache.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ defmodule StarknetExplorer.IndexCache do
def start_link(_) do
blocks_mainnet = StarknetExplorer.Data.many_blocks_with_txs("mainnet")
blocks_testnet = StarknetExplorer.Data.many_blocks_with_txs("testnet")
blocks_sepolia = StarknetExplorer.Data.many_blocks_with_txs("sepolia")

Agent.start_link(
fn ->
%{
"mainnet" => blocks_mainnet,
"testnet" => blocks_testnet
"testnet" => blocks_testnet,
"sepolia" => blocks_sepolia
}
end,
name: __MODULE__
Expand Down
2 changes: 1 addition & 1 deletion lib/starknet_explorer/class.ex
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ defmodule StarknetExplorer.Class do
]
}

@networks [:mainnet, :testnet]
@networks [:mainnet, :testnet, :sepolia]

@fields [
:declared_by_address,
Expand Down
2 changes: 1 addition & 1 deletion lib/starknet_explorer/contract.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ defmodule StarknetExplorer.Contract do
import Ecto.Query
alias StarknetExplorer.Repo

@networks [:mainnet, :testnet]
@networks [:mainnet, :testnet, :sepolia]
@fields [
:address,
:deployed_by_address,
Expand Down
2 changes: 1 addition & 1 deletion lib/starknet_explorer/events.ex
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ defmodule StarknetExplorer.Events do
field :data, {:array, :string}
field :index_in_block, :integer
field :transaction_hash, :string
field :network, Ecto.Enum, values: [:mainnet, :testnet]
field :network, Ecto.Enum, values: [:mainnet, :testnet, :sepolia]
timestamps()
end

Expand Down
2 changes: 1 addition & 1 deletion lib/starknet_explorer/message.ex
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ defmodule StarknetExplorer.Message do
:l1_to_l2_cancelled_on_l1
]

field :network, Ecto.Enum, values: [:mainnet, :testnet]
field :network, Ecto.Enum, values: [:mainnet, :testnet, :sepolia]
# belongs_to :transaction, Transaction, foreign_key: :transaction_hash, references: :hash
timestamps()
end
Expand Down
2 changes: 1 addition & 1 deletion lib/starknet_explorer/transaction.ex
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ defmodule StarknetExplorer.Transaction do
@deploy_account_tx_fields ++
[:network, :nonce]

@networks [:mainnet, :testnet]
@networks [:mainnet, :testnet, :sepolia]

@primary_key {:hash, :string, []}
schema "transactions" do
Expand Down
2 changes: 1 addition & 1 deletion lib/starknet_explorer/transaction_receipt.ex
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ defmodule StarknetExplorer.TransactionReceipt do
# :contract_address
# ]

@networks [:mainnet, :testnet]
@networks [:mainnet, :testnet, :sepolia]

@fields @invoke_tx_receipt_fields ++
@l1_receipt_handler ++
Expand Down
8 changes: 8 additions & 0 deletions lib/starknet_explorer_web/components/layouts/root.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,14 @@
<span>Testnet</span>
</a>
</div>
<div class="w-full py-2 hover:bg-brand">
<a class="option relative pl-10" href="/sepolia">
<span class="animate-ping bg-green-500 rounded-full w-2 h-2"></span>
<span class="absolute top-1/2 left-5 transform -translate-x-1/2 -translate-y-1/2 opacity-50 bg-green-500 rounded-full w-2 h-2">
</span>
<span>Sepolia</span>
</a>
</div>
</div>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion lib/starknet_explorer_web/live/common_assigns.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ defmodule StarknetExplorerWeb.Live.CommonAssigns do
def on_mount(:network, params, _session, socket) do
socket =
case Map.get(params, "network") do
network when network in ["testnet"] ->
network when network in ["testnet", "sepolia"] ->
network =
network
|> String.to_existing_atom()
Expand Down
5 changes: 5 additions & 0 deletions lib/starknet_explorer_web/live/utils.ex
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ defmodule StarknetExplorerWeb.Utils do
# This case is for mainnet
def network_path(:mainnet), do: "/"
def network_path(:testnet), do: "/testnet/"
def network_path(:sepolia), do: "/sepolia/"

def network_path(:mainnet, remaining_path) do
"/#{remaining_path}"
Expand All @@ -173,6 +174,10 @@ defmodule StarknetExplorerWeb.Utils do
"/testnet/#{remaining_path}"
end

def network_path(:sepolia, remaining_path) do
"/sepolia/#{remaining_path}"
end

def format_version(<<"0x", hex_val::binary>>), do: "Cairo " <> hex_val
def format_version(nil), do: "-"
def format_version(version), do: version
Expand Down
7 changes: 4 additions & 3 deletions lib/starknet_rpc.ex
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ defmodule StarknetExplorer.Rpc do
network
)

defp send_request(method, args, network) when network in [:mainnet, :testnet] do
defp send_request(method, args, network) when network in [:mainnet, :testnet, :sepolia] do
payload = build_payload(method, args)

case cache_lookup(method, args, network) do
Expand All @@ -107,7 +107,7 @@ defmodule StarknetExplorer.Rpc do
end

defp send_request_no_cache(method, args, network)
when network in [:mainnet, :testnet] do
when network in [:mainnet, :testnet, :sepolia] do
payload = build_payload(method, args)
host = fetch_rpc_host(network)
{:ok, rsp} = post(host, payload)
Expand All @@ -116,6 +116,7 @@ defmodule StarknetExplorer.Rpc do

defp fetch_rpc_host(:mainnet), do: Application.fetch_env!(:starknet_explorer, :rpc_host)
defp fetch_rpc_host(:testnet), do: Application.fetch_env!(:starknet_explorer, :testnet_host)
defp fetch_rpc_host(:sepolia), do: Application.fetch_env!(:starknet_explorer, :sepolia_host)

defp build_payload(method, params) do
%{
Expand Down Expand Up @@ -151,7 +152,7 @@ defmodule StarknetExplorer.Rpc do

defp do_cache_lookup(cache_type, key, network)
when cache_type in [:block_cache, :tx_cache, :request_cache] and
network in [:mainnet, :testnet] do
network in [:mainnet, :testnet, :sepolia] do
cache_name = :"#{network}_#{cache_type}"

case Cachex.get(cache_name, key) do
Expand Down
Loading