diff --git a/crates/governance/src/finalize_block.rs b/crates/governance/src/finalize_block.rs index be5990c85b2..e947e735e9e 100644 --- a/crates/governance/src/finalize_block.rs +++ b/crates/governance/src/finalize_block.rs @@ -1,6 +1,8 @@ //! Governance logic applied on an end of a block. +use std::borrow::Cow; use std::collections::BTreeSet; +use std::fmt::Display; use std::str::FromStr; use borsh::BorshDeserialize; @@ -41,7 +43,7 @@ pub fn finalize_block( is_new_epoch: bool, dispatch_tx: FnTx, transfer_over_ibc: FnIbcTransfer, -) -> Result<()> +) -> Result> where S: StateRead + State, Token: token::Read + token::Write + token::Events, @@ -50,7 +52,7 @@ where FnIbcTransfer: Fn(&mut S, &Address, &Address, &PGFIbcTarget) -> Result<()>, { if is_new_epoch { - load_and_execute_governance_proposals::< + let result = load_and_execute_governance_proposals::< S, Token, PoS, @@ -67,8 +69,12 @@ where dispatch_tx, transfer_over_ibc, )?; + if result.passed.is_empty() && result.rejected.is_empty() { + return Ok(None); + } + return Ok(Some(result)); } - Ok(()) + Ok(None) } /// Count of passed and rejected proposals. @@ -78,6 +84,36 @@ pub struct ProposalsResult { rejected: Vec, } +impl Display for ProposalsResult { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!( + f, + "{}{}", + if self.passed.is_empty() { + Cow::Owned(format!("Passed IDs: {}. ", fmt_ids(&self.passed))) + } else { + Cow::Borrowed("") + }, + if self.rejected.is_empty() { + Cow::Owned(format!( + "Rejected IDs: {}.", + fmt_ids(&self.rejected) + )) + } else { + Cow::Borrowed("") + } + ) + } +} + +fn fmt_ids(ids: &[u64]) -> String { + itertools::intersperse( + ids.iter().map(|s| Cow::Owned(s.to_string())), + Cow::Borrowed(", "), + ) + .collect::() +} + fn load_and_execute_governance_proposals< S, Token, diff --git a/crates/node/src/shell/finalize_block.rs b/crates/node/src/shell/finalize_block.rs index 23c20ea543f..d4564a5344a 100644 --- a/crates/node/src/shell/finalize_block.rs +++ b/crates/node/src/shell/finalize_block.rs @@ -98,7 +98,11 @@ where // Sub-system updates: // - Governance - applied first in case a proposal changes any of the // other syb-systems - gov_finalize_block(self, emit_events, current_epoch, new_epoch)?; + if let Some(proposals_result) = + gov_finalize_block(self, emit_events, current_epoch, new_epoch)? + { + tracing::info!("Governance proposals result: {proposals_result}"); + } // - Token token_finalize_block(&mut self.state, emit_events, is_masp_new_epoch)?; // - PoS @@ -1134,7 +1138,7 @@ fn gov_finalize_block( emit_events: &mut Vec, current_epoch: Epoch, is_new_epoch: bool, -) -> Result<()> +) -> Result> where D: DB + for<'iter> DBIter<'iter> + Sync, H: StorageHasher + Sync,