anton-rs / kona

A suite of `no_std` components for the OP Stack state transition function and L2 chain derivation.
https://anton-rs.github.io/kona
MIT License
125 stars 33 forks source link

fix(derive): Refactor Inline Constants to Lazy Initialization #99

Closed refcell closed 6 months ago

refcell commented 6 months ago

Description

In https://github.com/ethereum-optimism/kona/pull/92/files#diff-7174eed32936e964edfad6916051e033114fafa6e5b7e0d53fe60b4718a05c60, ecotone variables were inlined into the transaction building. This ticket is to refactor these variables and use once_cell to lazily declare the variables as public global variables.

This might look something like the following.

+ use once_cell::sync::Lazy;

+ static DEPLOY_L1_BLOCK_SOURCE: Lazy<UpgradeDepositSource> = Lazy::new(|| {
+    UpgradeDepositSource { intent: String::from("Ecotone: L1 Block Deployment") }
+ });

+ static DEPLOY_GAS_PRICE_ORACLE_SOURCE: Lazy<UpgradeDepositSource> = Lazy::new(|| {
+    UpgradeDepositSource { intent: String::from("Ecotone: Gas Price Oracle Deployment") }
+ });

+ static UPDATE_L1_BLOCK_PROXY_SOURCE: Lazy<UpgradeDepositSource> = Lazy::new(|| {
+    UpgradeDepositSource { intent: String::from("Ecotone: L1 Block Proxy Update") }
+ });

+ static UPDATE_GAS_PRICE_ORACLE_SOURCE: Lazy<UpgradeDepositSource> = Lazy::new(|| {
+    UpgradeDepositSource { intent: String::from("Ecotone: Gas Price Oracle Proxy Update") }
+ });

+ static ENABLE_ECOTONE_SOURCE: Lazy<UpgradeDepositSource> = Lazy::new(|| {
+    UpgradeDepositSource { intent: String::from("Ecotone: Gas Price Oracle Set Ecotone") };
+ });

+ static BEACON_ROOOTS_SOURCE: Lazy<UpgradeDepositSource> = Lazy::new(|| {
+    UpgradeDepositSource { intent: String::from("Ecotone: beacon block roots contract deployment") }
+ });

impl EcotoneTransactionBuilder {
    /// Constructs the Ecotone network upgrade transactions.
    pub fn build_txs() -> anyhow::Result<Vec<RawTransaction>> {
        let mut txs = vec![];

-       let deploy_l1_block_source =
-           UpgradeDepositSource { intent: String::from("Ecotone: L1 Block Deployment") };

-        let deploy_gas_price_oracle_source =
-           UpgradeDepositSource { intent: String::from("Ecotone: Gas Price Oracle Deployment") };

-        let update_l1_block_proxy_source =
-            UpgradeDepositSource { intent: String::from("Ecotone: L1 Block Proxy Update") };

-        let update_gas_price_oracle_source =
-            UpgradeDepositSource { intent: String::from("Ecotone: Gas Price Oracle Proxy Update") };

-        let enable_ecotone_source =
-            UpgradeDepositSource { intent: String::from("Ecotone: Gas Price Oracle Set Ecotone") };

-        let beacon_roots_source = UpgradeDepositSource {
-            intent: String::from("Ecotone: beacon block roots contract deployment"),
-        };

        ...
    }
}
clabby commented 6 months ago

Closed by #92