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

gov refactor #2506

Merged
merged 17 commits into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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 .changelog/unreleased/improvements/2506-refactor-gov.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Refactored governance crate dependencies.
([\#2506](https://github.com/anoma/namada/pull/2506))
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/governance/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ testing = ["proptest"]
namada_core = { path = "../core" }
namada_macros = {path = "../macros"}
namada_parameters = {path = "../parameters"}
namada_state = {path = "../state"}
namada_storage = {path = "../storage"}
namada_trans_token = {path = "../trans_token"}

borsh.workspace = true
Expand Down
4 changes: 2 additions & 2 deletions crates/governance/src/parameters.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use namada_core::borsh::{BorshDeserialize, BorshSerialize};
use namada_core::token;
use namada_state::{StorageRead, StorageResult, StorageWrite};
use namada_storage::{Result, StorageRead, StorageWrite};

use super::storage::keys as goverance_storage;

Expand Down Expand Up @@ -46,7 +46,7 @@ impl Default for GovernanceParameters {

impl GovernanceParameters {
/// Initialize governance parameters into storage
pub fn init_storage<S>(&self, storage: &mut S) -> StorageResult<()>
pub fn init_storage<S>(&self, storage: &mut S) -> Result<()>
where
S: StorageRead + StorageWrite,
{
Expand Down
20 changes: 6 additions & 14 deletions crates/governance/src/pgf/inflation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,21 @@
use namada_core::address::Address;
use namada_core::token;
use namada_parameters::storage as params_storage;
use namada_state::{
DBIter, StorageHasher, StorageRead, StorageResult, WlStorage, DB,
};
use namada_storage::{Result, StorageRead, StorageWrite};
use namada_trans_token::credit_tokens;
use namada_trans_token::storage_key::minted_balance_key;

use crate::pgf::storage::{get_parameters, get_payments, get_stewards};
use crate::storage::proposal::{PGFIbcTarget, PGFTarget};

/// Apply the PGF inflation.
pub fn apply_inflation<D, H, F>(
storage: &mut WlStorage<D, H>,
pub fn apply_inflation<S, F>(
storage: &mut S,
transfer_over_ibc: F,
) -> StorageResult<()>
) -> Result<()>
where
D: DB + for<'iter> DBIter<'iter> + Sync + 'static,
H: StorageHasher + Sync + 'static,
F: Fn(
&mut WlStorage<D, H>,
&Address,
&Address,
&PGFIbcTarget,
) -> StorageResult<()>,
S: StorageWrite + StorageRead,
F: Fn(&mut S, &Address, &Address, &PGFIbcTarget) -> Result<()>,
{
let pgf_parameters = get_parameters(storage)?;
let staking_token = storage.get_native_token()?;
Expand Down
4 changes: 2 additions & 2 deletions crates/governance/src/pgf/parameters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::collections::BTreeSet;
use namada_core::address::Address;
use namada_core::borsh::{BorshDeserialize, BorshSerialize};
use namada_core::dec::Dec;
use namada_state::{StorageRead, StorageResult, StorageWrite};
use namada_storage::{Result, StorageRead, StorageWrite};
use serde::{Deserialize, Serialize};

use super::storage::keys as pgf_storage;
Expand Down Expand Up @@ -44,7 +44,7 @@ impl Default for PgfParameters {

impl PgfParameters {
/// Initialize governance parameters into storage
pub fn init_storage<S>(&self, storage: &mut S) -> StorageResult<()>
pub fn init_storage<S>(&self, storage: &mut S) -> Result<()>
where
S: StorageRead + StorageWrite,
{
Expand Down
2 changes: 1 addition & 1 deletion crates/governance/src/pgf/storage/keys.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use namada_core::address::Address;
use namada_core::storage::{DbKeySeg, Key, KeySeg};
use namada_macros::StorageKeys;
use namada_state::collections::{lazy_map, LazyCollection, LazyMap};
use namada_storage::collections::{lazy_map, LazyCollection, LazyMap};

use crate::pgf::storage::steward::StewardDetail;
use crate::pgf::ADDRESS;
Expand Down
19 changes: 8 additions & 11 deletions crates/governance/src/pgf/storage/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@

use namada_core::address::Address;
use namada_core::dec::Dec;
use namada_state::{StorageRead, StorageResult, StorageWrite};
use namada_storage::{Result, StorageRead, StorageWrite};

use crate::pgf::parameters::PgfParameters;
use crate::pgf::storage::keys as pgf_keys;
use crate::pgf::storage::steward::StewardDetail;
use crate::storage::proposal::StoragePgfFunding;

/// Query the current pgf steward set
pub fn get_stewards<S>(storage: &S) -> StorageResult<Vec<StewardDetail>>
pub fn get_stewards<S>(storage: &S) -> Result<Vec<StewardDetail>>
where
S: StorageRead,
{
Expand All @@ -36,26 +36,23 @@
pub fn get_steward<S>(
storage: &S,
address: &Address,
) -> StorageResult<Option<StewardDetail>>
) -> Result<Option<StewardDetail>>

Check warning on line 39 in crates/governance/src/pgf/storage/mod.rs

View check run for this annotation

Codecov / codecov/patch

crates/governance/src/pgf/storage/mod.rs#L39

Added line #L39 was not covered by tests
where
S: StorageRead,
{
pgf_keys::stewards_handle().get(storage, address)
}

/// Check if an address is a steward
pub fn is_steward<S>(storage: &S, address: &Address) -> StorageResult<bool>
pub fn is_steward<S>(storage: &S, address: &Address) -> Result<bool>
where
S: StorageRead,
{
pgf_keys::stewards_handle().contains(storage, address)
}

/// Remove a steward
pub fn remove_steward<S>(
storage: &mut S,
address: &Address,
) -> StorageResult<()>
pub fn remove_steward<S>(storage: &mut S, address: &Address) -> Result<()>
where
S: StorageRead + StorageWrite,
{
Expand All @@ -65,7 +62,7 @@
}

/// Query the current pgf continous payments
pub fn get_payments<S>(storage: &S) -> StorageResult<Vec<StoragePgfFunding>>
pub fn get_payments<S>(storage: &S) -> Result<Vec<StoragePgfFunding>>
where
S: StorageRead,
{
Expand All @@ -81,7 +78,7 @@
}

/// Query the pgf parameters
pub fn get_parameters<S>(storage: &S) -> StorageResult<PgfParameters>
pub fn get_parameters<S>(storage: &S) -> Result<PgfParameters>
where
S: StorageRead,
{
Expand All @@ -108,7 +105,7 @@
storage: &mut S,
address: Address,
reward_distribution: HashMap<Address, Dec>,
) -> StorageResult<()>
) -> Result<()>
where
S: StorageRead + StorageWrite,
{
Expand Down
39 changes: 14 additions & 25 deletions crates/governance/src/storage/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@
use namada_core::address::Address;
use namada_core::borsh::BorshDeserialize;
use namada_core::storage::Epoch;
use namada_state::{
iter_prefix, StorageError, StorageRead, StorageResult, StorageWrite,
};
use namada_storage::{iter_prefix, Error, Result, StorageRead, StorageWrite};
use namada_trans_token as token;

use crate::parameters::GovernanceParameters;
Expand All @@ -32,7 +30,7 @@
data: InitProposalData,
content: Vec<u8>,
code: Option<Vec<u8>>,
) -> StorageResult<()>
) -> Result<()>
where
S: StorageRead + StorageWrite,
{
Expand All @@ -57,7 +55,7 @@
governance_keys::get_proposal_code_key(proposal_id);
let proposal_code = code
.clone()
.ok_or(StorageError::new_const("Missing proposal code"))?;
.ok_or(Error::new_const("Missing proposal code"))?;

Check warning on line 58 in crates/governance/src/storage/mod.rs

View check run for this annotation

Codecov / codecov/patch

crates/governance/src/storage/mod.rs#L58

Added line #L58 was not covered by tests
storage.write_bytes(&proposal_code_key, proposal_code)?
}
_ => storage.write(&proposal_type_key, data.r#type.clone())?,
Expand All @@ -78,7 +76,7 @@
let proposal_code_key =
governance_keys::get_proposal_code_key(proposal_id);
let proposal_code =
code.ok_or(StorageError::new_const("Missing proposal code"))?;
code.ok_or(Error::new_const("Missing proposal code"))?;

Check warning on line 79 in crates/governance/src/storage/mod.rs

View check run for this annotation

Codecov / codecov/patch

crates/governance/src/storage/mod.rs#L79

Added line #L79 was not covered by tests
storage.write_bytes(&proposal_code_key, proposal_code)?;
}

Expand Down Expand Up @@ -109,10 +107,7 @@
}

/// A proposal vote transaction.
pub fn vote_proposal<S>(
storage: &mut S,
data: VoteProposalData,
) -> StorageResult<()>
pub fn vote_proposal<S>(storage: &mut S, data: VoteProposalData) -> Result<()>
where
S: StorageRead + StorageWrite,
{
Expand All @@ -132,7 +127,7 @@
storage: &mut S,
proposal_id: u64,
proposal_result: ProposalResult,
) -> StorageResult<()>
) -> Result<()>
where
S: StorageRead + StorageWrite,
{
Expand All @@ -145,7 +140,7 @@
pub fn get_proposal_by_id<S>(
storage: &S,
id: u64,
) -> StorageResult<Option<StorageProposal>>
) -> Result<Option<StorageProposal>>

Check warning on line 143 in crates/governance/src/storage/mod.rs

View check run for this annotation

Codecov / codecov/patch

crates/governance/src/storage/mod.rs#L143

Added line #L143 was not covered by tests
where
S: StorageRead,
{
Expand Down Expand Up @@ -178,10 +173,7 @@
}

/// Query all the votes for a proposal_id
pub fn get_proposal_votes<S>(
storage: &S,
proposal_id: u64,
) -> StorageResult<Vec<Vote>>
pub fn get_proposal_votes<S>(storage: &S, proposal_id: u64) -> Result<Vec<Vote>>
where
S: StorageRead,
{
Expand Down Expand Up @@ -216,10 +208,7 @@
}

/// Check if an accepted proposal is being executed
pub fn is_proposal_accepted<S>(
storage: &S,
tx_data: &[u8],
) -> StorageResult<bool>
pub fn is_proposal_accepted<S>(storage: &S, tx_data: &[u8]) -> Result<bool>
where
S: StorageRead,
{
Expand All @@ -237,7 +226,7 @@
pub fn get_proposal_code<S>(
storage: &S,
proposal_id: u64,
) -> StorageResult<Option<Vec<u8>>>
) -> Result<Option<Vec<u8>>>

Check warning on line 229 in crates/governance/src/storage/mod.rs

View check run for this annotation

Codecov / codecov/patch

crates/governance/src/storage/mod.rs#L229

Added line #L229 was not covered by tests
where
S: StorageRead,
{
Expand All @@ -249,7 +238,7 @@
pub fn get_proposal_author<S>(
storage: &S,
proposal_id: u64,
) -> StorageResult<Option<Address>>
) -> Result<Option<Address>>

Check warning on line 241 in crates/governance/src/storage/mod.rs

View check run for this annotation

Codecov / codecov/patch

crates/governance/src/storage/mod.rs#L241

Added line #L241 was not covered by tests
where
S: StorageRead,
{
Expand All @@ -258,7 +247,7 @@
}

/// Get governance parameters
pub fn get_parameters<S>(storage: &S) -> StorageResult<GovernanceParameters>
pub fn get_parameters<S>(storage: &S) -> Result<GovernanceParameters>

Check warning on line 250 in crates/governance/src/storage/mod.rs

View check run for this annotation

Codecov / codecov/patch

crates/governance/src/storage/mod.rs#L250

Added line #L250 was not covered by tests
where
S: StorageRead,
{
Expand Down Expand Up @@ -295,7 +284,7 @@
}

/// Get governance "max_proposal_period" parameter
pub fn get_max_proposal_period<S>(storage: &S) -> StorageResult<u64>
pub fn get_max_proposal_period<S>(storage: &S) -> Result<u64>
where
S: StorageRead,
{
Expand All @@ -309,7 +298,7 @@
pub fn get_proposal_result<S>(
storage: &S,
proposal_id: u64,
) -> StorageResult<Option<ProposalResult>>
) -> Result<Option<ProposalResult>>

Check warning on line 301 in crates/governance/src/storage/mod.rs

View check run for this annotation

Codecov / codecov/patch

crates/governance/src/storage/mod.rs#L301

Added line #L301 was not covered by tests
where
S: StorageRead,
{
Expand Down
2 changes: 1 addition & 1 deletion wasm/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion wasm_for_tests/wasm_source/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading