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

Remove native VP ADDR associated type #1724

Closed
sug0 opened this issue Jul 14, 2023 · 3 comments · Fixed by #1725
Closed

Remove native VP ADDR associated type #1724

sug0 opened this issue Jul 14, 2023 · 3 comments · Fixed by #1725

Comments

@sug0
Copy link
Contributor

sug0 commented Jul 14, 2023

The ADDR associated type in native VPs never gets used for anything useful. #1718 and #1693 introduce internal addresses containing data. Since there is no reasonable default to instantiate this data with, we should remove the ADDR type altogether from the native VP interface.

@sug0
Copy link
Contributor Author

sug0 commented Jul 14, 2023

The patch is quite simple:

diff --git a/shared/src/ledger/ibc/vp/mod.rs b/shared/src/ledger/ibc/vp/mod.rs
index 619e484ba..5a29ebfe3 100644
--- a/shared/src/ledger/ibc/vp/mod.rs
+++ b/shared/src/ledger/ibc/vp/mod.rs
@@ -14,7 +14,7 @@ use namada_core::ledger::ibc::{
 use namada_core::ledger::storage::write_log::StorageModification;
 use namada_core::ledger::storage::{self as ledger_storage, StorageHasher};
 use namada_core::proto::Tx;
-use namada_core::types::address::{Address, InternalAddress};
+use namada_core::types::address::Address;
 use namada_core::types::storage::Key;
 use namada_proof_of_stake::read_pos_params;
 use thiserror::Error;
@@ -65,8 +65,6 @@ where
 {
     type Error = Error;
 
-    const ADDR: InternalAddress = InternalAddress::Ibc;
-
     fn validate_tx(
         &self,
         tx_data: &Tx,
@@ -307,8 +305,8 @@ mod tests {
     };
     use super::{get_dummy_header, *};
     use crate::core::ledger::storage::testing::TestWlStorage;
-    use crate::core::types::address::nam;
     use crate::core::types::address::testing::established_address_1;
+    use crate::core::types::address::{nam, InternalAddress};
     use crate::core::types::storage::Epoch;
     use crate::ibc::applications::transfer::acknowledgement::TokenTransferAcknowledgement;
     use crate::ibc::applications::transfer::coin::PrefixedCoin;
diff --git a/shared/src/ledger/native_vp/ethereum_bridge/bridge_pool_vp.rs b/shared/src/ledger/native_vp/ethereum_bridge/bridge_pool_vp.rs
index 6b04aa843..f7a62090b 100644
--- a/shared/src/ledger/native_vp/ethereum_bridge/bridge_pool_vp.rs
+++ b/shared/src/ledger/native_vp/ethereum_bridge/bridge_pool_vp.rs
@@ -243,8 +243,6 @@ where
 {
     type Error = Error;
 
-    const ADDR: InternalAddress = InternalAddress::EthBridgePool;
-
     fn validate_tx(
         &self,
         tx: &Tx,
diff --git a/shared/src/ledger/native_vp/ethereum_bridge/vp.rs b/shared/src/ledger/native_vp/ethereum_bridge/vp.rs
index 1280e1943..8b944862e 100644
--- a/shared/src/ledger/native_vp/ethereum_bridge/vp.rs
+++ b/shared/src/ledger/native_vp/ethereum_bridge/vp.rs
@@ -9,7 +9,7 @@ use namada_core::ledger::eth_bridge::storage::{
 };
 use namada_core::ledger::storage::traits::StorageHasher;
 use namada_core::ledger::{eth_bridge, storage as ledger_storage};
-use namada_core::types::address::{Address, InternalAddress};
+use namada_core::types::address::Address;
 use namada_core::types::storage::Key;
 use namada_core::types::token::{balance_key, Amount, Change};
 
@@ -109,8 +109,6 @@ where
 {
     type Error = Error;
 
-    const ADDR: InternalAddress = eth_bridge::INTERNAL_ADDRESS;
-
     /// Validate that a wasm transaction is permitted to change keys under this
     /// account.
     ///
diff --git a/shared/src/ledger/native_vp/governance/mod.rs b/shared/src/ledger/native_vp/governance/mod.rs
index 7d9323f25..d41242a47 100644
--- a/shared/src/ledger/native_vp/governance/mod.rs
+++ b/shared/src/ledger/native_vp/governance/mod.rs
@@ -16,7 +16,7 @@ use crate::ledger::native_vp::{Ctx, NativeVp};
 use crate::ledger::storage_api::StorageRead;
 use crate::ledger::{native_vp, pos};
 use crate::proto::Tx;
-use crate::types::address::{Address, InternalAddress};
+use crate::types::address::Address;
 use crate::types::storage::{Epoch, Key};
 use crate::types::token;
 use crate::vm::WasmCacheAccess;
@@ -50,8 +50,6 @@ where
 {
     type Error = Error;
 
-    const ADDR: InternalAddress = InternalAddress::Governance;
-
     fn validate_tx(
         &self,
         tx_data: &Tx,
diff --git a/shared/src/ledger/native_vp/mod.rs b/shared/src/ledger/native_vp/mod.rs
index c7d58f056..ed34545f1 100644
--- a/shared/src/ledger/native_vp/mod.rs
+++ b/shared/src/ledger/native_vp/mod.rs
@@ -22,7 +22,7 @@ use crate::ledger::storage;
 use crate::ledger::storage::write_log::WriteLog;
 use crate::ledger::storage::{Storage, StorageHasher};
 use crate::proto::Tx;
-use crate::types::address::{Address, InternalAddress};
+use crate::types::address::Address;
 use crate::types::hash::Hash;
 use crate::types::storage::{
     BlockHash, BlockHeight, Epoch, Header, Key, TxIndex,
@@ -37,9 +37,6 @@ pub type Error = storage_api::Error;
 
 /// A native VP module should implement its validation logic using this trait.
 pub trait NativeVp {
-    /// The address of this VP
-    const ADDR: InternalAddress;
-
     /// Error type for the methods' results.
     type Error: std::error::Error;
 
diff --git a/shared/src/ledger/native_vp/multitoken.rs b/shared/src/ledger/native_vp/multitoken.rs
index 94e4e7091..87bf2ca7d 100644
--- a/shared/src/ledger/native_vp/multitoken.rs
+++ b/shared/src/ledger/native_vp/multitoken.rs
@@ -45,8 +45,6 @@ where
 {
     type Error = Error;
 
-    const ADDR: InternalAddress = InternalAddress::Multitoken;
-
     fn validate_tx(
         &self,
         _tx: &Tx,
diff --git a/shared/src/ledger/native_vp/parameters.rs b/shared/src/ledger/native_vp/parameters.rs
index d367c1669..bb1db0ab3 100644
--- a/shared/src/ledger/native_vp/parameters.rs
+++ b/shared/src/ledger/native_vp/parameters.rs
@@ -4,7 +4,7 @@ use std::collections::BTreeSet;
 
 use namada_core::ledger::storage;
 use namada_core::proto::Tx;
-use namada_core::types::address::{Address, InternalAddress};
+use namada_core::types::address::Address;
 use namada_core::types::storage::Key;
 use thiserror::Error;
 
@@ -41,8 +41,6 @@ where
 {
     type Error = Error;
 
-    const ADDR: InternalAddress = InternalAddress::Parameters;
-
     fn validate_tx(
         &self,
         tx_data: &Tx,
diff --git a/shared/src/ledger/native_vp/replay_protection.rs b/shared/src/ledger/native_vp/replay_protection.rs
index 9b300e376..a2a2a66f3 100644
--- a/shared/src/ledger/native_vp/replay_protection.rs
+++ b/shared/src/ledger/native_vp/replay_protection.rs
@@ -3,7 +3,7 @@
 use std::collections::BTreeSet;
 
 use namada_core::ledger::storage;
-use namada_core::types::address::{Address, InternalAddress};
+use namada_core::types::address::Address;
 use namada_core::types::storage::Key;
 use thiserror::Error;
 
@@ -40,8 +40,6 @@ where
 {
     type Error = Error;
 
-    const ADDR: InternalAddress = InternalAddress::ReplayProtection;
-
     fn validate_tx(
         &self,
         _tx_data: &Tx,
diff --git a/shared/src/ledger/native_vp/slash_fund.rs b/shared/src/ledger/native_vp/slash_fund.rs
index bed71d3bd..8f2ab5440 100644
--- a/shared/src/ledger/native_vp/slash_fund.rs
+++ b/shared/src/ledger/native_vp/slash_fund.rs
@@ -11,7 +11,7 @@ use crate::ledger::native_vp::{self, governance, Ctx, NativeVp};
 use crate::ledger::storage::{self as ledger_storage, StorageHasher};
 use crate::ledger::storage_api::StorageRead;
 use crate::proto::Tx;
-use crate::types::address::{Address, InternalAddress};
+use crate::types::address::Address;
 use crate::types::storage::Key;
 use crate::types::token;
 use crate::vm::WasmCacheAccess;
@@ -45,8 +45,6 @@ where
 {
     type Error = Error;
 
-    const ADDR: InternalAddress = InternalAddress::SlashFund;
-
     fn validate_tx(
         &self,
         tx_data: &Tx,
diff --git a/shared/src/ledger/pos/vp.rs b/shared/src/ledger/pos/vp.rs
index dda349702..18085c5c5 100644
--- a/shared/src/ledger/pos/vp.rs
+++ b/shared/src/ledger/pos/vp.rs
@@ -89,8 +89,6 @@ where
 {
     type Error = Error;
 
-    const ADDR: InternalAddress = InternalAddress::PoS;
-
     fn validate_tx(
         &self,
         tx_data: &Tx,
@@ -101,7 +99,7 @@ where
         // use validation::DataUpdate::{self, *};
         // use validation::ValidatorUpdate::*;
 
-        let addr = Address::Internal(Self::ADDR);
+        let addr = Address::Internal(InternalAddress::PoS);
         // let mut changes: Vec<DataUpdate> = vec![];
         let _current_epoch = self.ctx.pre().get_block_epoch()?;
 

@sug0
Copy link
Contributor Author

sug0 commented Jul 14, 2023

cc @tzemanovic

@tzemanovic
Copy link
Member

sounds good to me!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants