Skip to content

Commit

Permalink
feat: remove goerli networks
Browse files Browse the repository at this point in the history
  • Loading branch information
xJonathanLEI committed Apr 15, 2024
1 parent ae0d626 commit 3ef7b56
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 56 deletions.
5 changes: 2 additions & 3 deletions book/src/providers.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ There are two ways to specify a JSON-RPC provider, either [directly](#using-an-r
> ℹ️ **Note**
>
> When no provider option is supplied, Starkli falls back to using the `goerli` network. If the network is not already defined, a [free RPC vendor](#free-rpc-vendors) is used.
> When no provider option is supplied, Starkli falls back to using the `sepolia` network. If the network is not already defined, a [free RPC vendor](#free-rpc-vendors) is used.
>
> You're advised against relying on the fallback to use the `goerli` network, as the default network might change over time. Therefore, a warning is shown each time the fallback is used.
> You're advised against relying on the fallback to use the `sepolia` network, as the default network might change over time. Therefore, a warning is shown each time the fallback is used.
## Using an RPC URL directly
Expand Down Expand Up @@ -88,7 +88,6 @@ Historically, the now-deprecated-and-removed sequencer gateway provider allowed
The following 3 networks are eligible for free RPC vendors:

- `mainnet`
- `goerli`
- `sepolia`

When using these networks, **and when the network is not already defined in the active profile**, a free vendor will be randomly chosen from below:
Expand Down
2 changes: 1 addition & 1 deletion book/src/tutorials/starkli-101.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ In this tutorial, you will be guided from scratch to deploy contracts on the Sta

> ℹ️ **Note**
>
> To make it easier to get started, this tutorial skips the step of choosing a provider and uses the `goerli` network fallback with [free RPC vendor](../providers.md#free-rpc-vendors), but relying on the network fallback is discouraged in practice.
> To make it easier to get started, this tutorial skips the step of choosing a provider and uses the `sepolia` network fallback with [free RPC vendor](../providers.md#free-rpc-vendors), but relying on the network fallback is discouraged in practice.
>
> Make sure to visit the [providers](../providers.md) page to learn more once you finish the tutorial.
Expand Down
8 changes: 3 additions & 5 deletions src/casm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,9 @@ impl CasmArgs {
match network {
Some(network) => {
let auto_version = match network {
Network::Goerli
| Network::Sepolia
| Network::GoerliIntegration
| Network::SepoliaIntegration
| Network::Mainnet => CompilerVersion::V2_6_2,
Network::Sepolia | Network::SepoliaIntegration | Network::Mainnet => {
CompilerVersion::V2_6_2
}
};

eprintln!(
Expand Down
14 changes: 0 additions & 14 deletions src/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ use crate::provider::ExtendedProvider;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Network {
Mainnet,
Goerli,
Sepolia,
GoerliIntegration,
SepoliaIntegration,
}

Expand All @@ -29,10 +27,7 @@ impl FromStr for Network {
fn from_str(s: &str) -> Result<Self> {
match s {
"mainnet" | "alpha-mainnet" => Ok(Self::Mainnet),
"goerli" | "goerli1" | "goerli-1" | "alpha-goerli" | "alpha-goerli1"
| "alpha-goerli-1" => Ok(Self::Goerli),
"sepolia" | "alpha-sepolia" | "sepolia-testnet" => Ok(Self::Sepolia),
"goerli-integration" | "integration" => Ok(Self::GoerliIntegration),
"sepolia-integration" => Ok(Self::SepoliaIntegration),
_ => Err(anyhow::anyhow!("unknown network: {}", s)),
}
Expand All @@ -43,9 +38,7 @@ impl Display for Network {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Mainnet => write!(f, "mainnet"),
Self::Goerli => write!(f, "goerli"),
Self::Sepolia => write!(f, "sepolia"),
Self::GoerliIntegration => write!(f, "goerli-integration"),
Self::SepoliaIntegration => write!(f, "sepolia-integration"),
}
}
Expand All @@ -56,16 +49,9 @@ impl Display for Network {
impl NetworkSource for ExtendedProvider {
async fn get_network(&self) -> Result<Option<Network>> {
let chain_id = self.chain_id().await?;
let is_integration = self.is_integration();

Ok(if chain_id == starknet::core::chain_id::MAINNET {
Some(Network::Mainnet)
} else if chain_id == starknet::core::chain_id::TESTNET {
if is_integration {
Some(Network::GoerliIntegration)
} else {
Some(Network::Goerli)
}
} else if chain_id == short_string!("SN_SEPOLIA") {
Some(Network::Sepolia)
} else if chain_id == short_string!("SN_INTEGRATION_SEPOLIA") {
Expand Down
37 changes: 4 additions & 33 deletions src/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ use crate::{
};

const CHAIN_ID_MAINNET: FieldElement = short_string!("SN_MAIN");
const CHAIN_ID_GOERLI: FieldElement = short_string!("SN_GOERLI");
const CHAIN_ID_SEPOLIA: FieldElement = short_string!("SN_SEPOLIA");

#[derive(Debug, Clone, Parser)]
Expand All @@ -36,16 +35,8 @@ pub struct ProviderArgs {
network: Option<String>,
}

/// This type was created because integration network has the same chain ID as `goerli`. We would
/// otherwise has no way of telling them apart. We could generally just ignore this, but it would
/// actually cause issues when deciding what Sierra compiler version to use depending on network, so
/// we still need this.
///
/// Now the type also internally stores the RPC version of the endpoint, which is useful for showing
/// warnings whens using methods that contain breaking changes between versions.
pub struct ExtendedProvider {
provider: AnyProvider,
is_integration: bool,
rpc_version: OnceCell<String>,
}

Expand All @@ -54,7 +45,6 @@ impl ProviderArgs {
Ok(match (self.rpc, self.network) {
(Some(rpc), None) => ExtendedProvider::new(
AnyProvider::JsonRpcHttp(JsonRpcClient::new(HttpTransport::new(rpc))),
false,
None,
),
(Some(rpc), Some(_)) => {
Expand All @@ -68,7 +58,6 @@ impl ProviderArgs {

ExtendedProvider::new(
AnyProvider::JsonRpcHttp(JsonRpcClient::new(HttpTransport::new(rpc))),
false,
None,
)
}
Expand All @@ -77,12 +66,12 @@ impl ProviderArgs {
eprintln!(
"{}",
"WARNING: you're using neither --rpc (STARKNET_RPC) nor --network \
(STARKNET_NETWORK). The `goerli` network is used by default. See \
(STARKNET_NETWORK). The `sepolia` network is used by default. See \
https://book.starkli.rs/providers for more details."
.bright_magenta()
);

Self::resolve_network("goerli")?
Self::resolve_network("sepolia")?
}
})
}
Expand Down Expand Up @@ -168,14 +157,6 @@ impl ProviderArgs {
&builtin_network,
)),
},
Network::Goerli => crate::profile::Network {
name: Some("Starknet Goerli Testnet".into()),
chain_id: CHAIN_ID_GOERLI,
is_integration: false,
provider: NetworkProvider::Free(choose_vendor(
&builtin_network,
)),
},
Network::Sepolia => crate::profile::Network {
name: Some("Starknet Sepolia Testnet".into()),
chain_id: CHAIN_ID_SEPOLIA,
Expand All @@ -184,7 +165,7 @@ impl ProviderArgs {
&builtin_network,
)),
},
Network::GoerliIntegration | Network::SepoliaIntegration => {
Network::SepoliaIntegration => {
anyhow::bail!(
"network {} cannot be used without being configured",
network
Expand Down Expand Up @@ -221,8 +202,6 @@ impl ProviderArgs {
FreeProviderVendor::Blast => {
if matched_network.chain_id == CHAIN_ID_MAINNET {
Some("https://starknet-mainnet.public.blastapi.io/rpc/v0_6")
} else if matched_network.chain_id == CHAIN_ID_GOERLI {
Some("https://starknet-testnet.public.blastapi.io/rpc/v0_6")
} else if matched_network.chain_id == CHAIN_ID_SEPOLIA {
Some("https://starknet-sepolia.public.blastapi.io/rpc/v0_6")
} else {
Expand All @@ -232,8 +211,6 @@ impl ProviderArgs {
FreeProviderVendor::Nethermind => {
if matched_network.chain_id == CHAIN_ID_MAINNET {
Some("https://free-rpc.nethermind.io/mainnet-juno/rpc/v0_6")
} else if matched_network.chain_id == CHAIN_ID_GOERLI {
Some("https://free-rpc.nethermind.io/goerli-juno/rpc/v0_6")
} else if matched_network.chain_id == CHAIN_ID_SEPOLIA {
Some("https://free-rpc.nethermind.io/sepolia-juno/rpc/v0_6")
} else {
Expand Down Expand Up @@ -267,7 +244,6 @@ impl ProviderArgs {

let provider = ExtendedProvider::new(
AnyProvider::JsonRpcHttp(JsonRpcClient::new(HttpTransport::new(rpc_url))),
matched_network.is_integration,
rpc_version,
);

Expand All @@ -280,10 +256,9 @@ impl ProviderArgs {
}

impl ExtendedProvider {
pub fn new(provider: AnyProvider, is_integration: bool, rpc_version: Option<String>) -> Self {
pub fn new(provider: AnyProvider, rpc_version: Option<String>) -> Self {
Self {
provider,
is_integration,
rpc_version: match rpc_version {
Some(rpc_version) => OnceCell::from(rpc_version),
None => OnceCell::new(),
Expand All @@ -294,10 +269,6 @@ impl ExtendedProvider {
pub fn is_rpc(&self) -> bool {
matches!(self.provider, AnyProvider::JsonRpcHttp(_))
}

pub fn is_integration(&self) -> bool {
self.is_integration
}
}

#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
Expand Down

0 comments on commit 3ef7b56

Please sign in to comment.