Skip to content

Commit

Permalink
Merge branch 'yuji/pgf-ibc' (#2243)
Browse files Browse the repository at this point in the history
* origin/yuji/pgf-ibc:
  fix to add the height in IBC event
  add new e2e
  add changelog
  add E2E test
  fix for 0.28.0
  add ibc
  pgf over ibc
  • Loading branch information
tzemanovic committed Jan 9, 2024
2 parents 1431ede + e9433e3 commit c5ba273
Show file tree
Hide file tree
Showing 15 changed files with 699 additions and 128 deletions.
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))
1 change: 1 addition & 0 deletions .github/workflows/scripts/e2e.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"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
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
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) => {
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

0 comments on commit c5ba273

Please sign in to comment.