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

PGF over IBC #2243

Merged
merged 18 commits into from
Jan 13, 2024
1 change: 1 addition & 0 deletions .changelog/unreleased/features/1395-pgf-ibc.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- PGF over IBC ([\#1395](https://github.com/anoma/namada/issues/1395))
2 changes: 2 additions & 0 deletions .changelog/unreleased/testing/773-ibc-e2e-hermes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Add IBC E2E test with Hermes
([\#773](https://github.com/anoma/namada/issues/773))
4 changes: 3 additions & 1 deletion .github/workflows/scripts/e2e.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{
"e2e::eth_bridge_tests::everything": 4,
"e2e::ibc_tests::run_ledger_ibc": 155,
"e2e::ibc_tests::run_ledger_ibc_with_hermes": 130,
"e2e::ibc_tests::pgf_over_ibc_with_hermes": 240,
"e2e::eth_bridge_tests::test_add_to_bridge_pool": 10,
"e2e::ledger_tests::double_signing_gets_slashed": 12,
"e2e::ledger_tests::invalid_transactions": 13,
Expand Down Expand Up @@ -32,4 +34,4 @@
"e2e::wallet_tests::wallet_encrypted_key_cmds": 1,
"e2e::wallet_tests::wallet_encrypted_key_cmds_env_var": 1,
"e2e::wallet_tests::wallet_unencrypted_key_cmds": 1
}
}
4 changes: 2 additions & 2 deletions .github/workflows/scripts/schedule-e2e.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
NIGHTLY_VERSION = open("rust-nightly-version", "r").read().strip()

E2E_FILE = ".github/workflows/scripts/e2e.json"
CARGO_TEST_COMMAND = "cargo +{} test {} -- --test-threads=1 --nocapture"
CARGO_TEST_COMMAND = "cargo +{} test {} -- --test-threads=1 --nocapture --exact"

MACHINES = [{'tasks': [], 'time': [], 'total_time': 0} for _ in range(N_OF_MACHINES)]

Expand Down Expand Up @@ -73,4 +73,4 @@ def find_freer_machine():
print(" Run locally with: {}".format(test_command))

if has_failures:
exit(1)
exit(1)
4 changes: 2 additions & 2 deletions apps/src/lib/client/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1304,8 +1304,8 @@ pub async fn query_pgf(context: &impl Namada, _args: args::QueryPgf) {
context.io(),
"{:4}- {} for {}",
"",
funding.detail.target,
funding.detail.amount.to_string_native()
funding.detail.target(),
funding.detail.amount().to_string_native()
);
}
}
Expand Down
15 changes: 13 additions & 2 deletions apps/src/lib/node/ledger/shell/finalize_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ where
// Invariant: Process slashes before inflation as they may affect
// the rewards in the current epoch.
self.process_slashes();
self.apply_inflation(current_epoch)?;
self.apply_inflation(current_epoch, &mut response)?;
}

// Consensus set liveness check
Expand Down Expand Up @@ -659,7 +659,11 @@ where
/// account, then update the reward products of the validators. This is
/// executed while finalizing the first block of a new epoch and is applied
/// with respect to the previous epoch.
fn apply_inflation(&mut self, current_epoch: Epoch) -> Result<()> {
fn apply_inflation(
&mut self,
current_epoch: Epoch,
response: &mut shim::response::FinalizeBlock,
) -> Result<()> {
let last_epoch = current_epoch.prev();

// Get the number of blocks in the last epoch
Expand All @@ -682,6 +686,13 @@ where

// Pgf inflation
pgf_inflation::apply_inflation(&mut self.wl_storage)?;
for ibc_event in self.wl_storage.write_log_mut().take_ibc_events() {
let mut event = Event::from(ibc_event.clone());
// Add the height for IBC event query
let height = self.wl_storage.storage.get_last_block_height() + 1;
event["height"] = height.to_string();
response.events.push(event);
}

Ok(())
}
Expand Down
65 changes: 43 additions & 22 deletions apps/src/lib/node/ledger/shell/governance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::collections::HashMap;

use namada::core::ledger::governance::storage::keys as gov_storage;
use namada::core::ledger::governance::storage::proposal::{
AddRemove, PGFAction, ProposalType, StoragePgfFunding,
AddRemove, PGFAction, PGFTarget, ProposalType, StoragePgfFunding,
};
use namada::core::ledger::governance::utils::{
compute_proposal_result, ProposalVotes, TallyResult, TallyType, TallyVote,
Expand All @@ -18,7 +18,7 @@ use namada::ledger::pos::BondId;
use namada::ledger::protocol;
use namada::ledger::storage::types::encode;
use namada::ledger::storage::{DBIter, StorageHasher, DB};
use namada::ledger::storage_api::{pgf, token, StorageWrite};
use namada::ledger::storage_api::{ibc, pgf, token, StorageWrite};
use namada::proof_of_stake::bond_amount;
use namada::proof_of_stake::parameters::PosParams;
use namada::proof_of_stake::storage::read_total_stake;
Expand Down Expand Up @@ -136,6 +136,20 @@ where
id
);

for ibc_event in
grarco marked this conversation as resolved.
Show resolved Hide resolved
shell.wl_storage.write_log_mut().take_ibc_events()
{
let mut event = Event::from(ibc_event.clone());
// Add the height for IBC event query
let height = shell
.wl_storage
.storage
.get_last_block_height()
+ 1;
event["height"] = height.to_string();
response.events.push(event);
}

ProposalEvent::pgf_payments_proposal_event(id, result)
.into()
}
Expand Down Expand Up @@ -341,64 +355,71 @@ where
Ok(true)
}

fn execute_pgf_payment_proposal<S>(
storage: &mut S,
fn execute_pgf_payment_proposal<D, H>(
storage: &mut WlStorage<D, H>,
token: &Address,
payments: Vec<PGFAction>,
proposal_id: u64,
) -> Result<bool>
where
S: StorageRead + StorageWrite,
D: DB + for<'iter> DBIter<'iter> + Sync + 'static,
H: StorageHasher + Sync + 'static,
{
for payment in payments {
match payment {
PGFAction::Continuous(action) => match action {
AddRemove::Add(target) => {
pgf_storage::fundings_handle().insert(
storage,
target.target.clone(),
target.target().clone(),
StoragePgfFunding::new(target.clone(), proposal_id),
)?;
tracing::info!(
"Execute ContinousPgf from proposal id {}: set {} to \
{}.",
proposal_id,
target.amount.to_string_native(),
target.target
target.amount().to_string_native(),
target.target()
);
}
AddRemove::Remove(target) => {
pgf_storage::fundings_handle()
.remove(storage, &target.target)?;
.remove(storage, &target.target())?;
tracing::info!(
"Execute ContinousPgf from proposal id {}: set {} to \
{}.",
proposal_id,
target.amount.to_string_native(),
target.target
target.amount().to_string_native(),
target.target()
);
}
},
PGFAction::Retro(target) => {
match token::transfer(
storage,
token,
&ADDRESS,
&target.target,
target.amount,
) {
let result = match &target {
PGFTarget::Internal(target) => token::transfer(
storage,
token,
&ADDRESS,
&target.target,
target.amount,
),
PGFTarget::Ibc(target) => {
grarco marked this conversation as resolved.
Show resolved Hide resolved
ibc::transfer_over_ibc(storage, token, &ADDRESS, target)
}
};
match result {
Ok(()) => tracing::info!(
"Execute RetroPgf from proposal id {}: sent {} to {}.",
proposal_id,
target.amount.to_string_native(),
target.target
target.amount().to_string_native(),
target.target()
),
Err(e) => tracing::warn!(
"Error in RetroPgf transfer from proposal id {}, \
amount {} to {}: {}",
proposal_id,
target.amount.to_string_native(),
target.target,
target.amount().to_string_native(),
target.target(),
e
),
}
Expand Down
20 changes: 5 additions & 15 deletions core/src/ledger/governance/cli/onchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use super::validation::{
ProposalValidation,
};
use crate::ledger::governance::parameters::GovernanceParameters;
use crate::ledger::governance::storage::proposal::PGFTarget;
use crate::ledger::storage_api::token;
use crate::types::address::Address;
use crate::types::storage::Epoch;
Expand Down Expand Up @@ -277,9 +278,9 @@ impl PgfAction {
)]
pub struct PgfFunding {
/// Pgf continuous funding
pub continuous: Vec<PgfFundingTarget>,
pub continuous: Vec<PGFTarget>,
/// pgf retro fundings
pub retro: Vec<PgfFundingTarget>,
pub retro: Vec<PGFTarget>,
}

/// Pgf continous funding
Expand All @@ -288,7 +289,7 @@ pub struct PgfFunding {
)]
pub struct PgfContinous {
/// Pgf target
pub target: PgfFundingTarget,
pub target: PGFTarget,
/// Pgf action
pub action: PgfAction,
}
Expand All @@ -299,18 +300,7 @@ pub struct PgfContinous {
)]
pub struct PgfRetro {
/// Pgf retro target
pub target: PgfFundingTarget,
}

/// Pgf Target
#[derive(
Debug, Clone, BorshSerialize, BorshDeserialize, Serialize, Deserialize,
)]
pub struct PgfFundingTarget {
/// Target amount
pub amount: token::Amount,
/// Target address
pub address: Address,
pub target: PGFTarget,
}

/// Represent an proposal vote
Expand Down
Loading
Loading