@@ -11,7 +11,6 @@ use crate::{
11
11
reassemble_governance_proto, split_governance_proto, HeapGovernanceData , XdrConversionRate ,
12
12
} ,
13
13
migrations:: maybe_run_migrations,
14
- network_economics:: InheritFrom ,
15
14
neuron:: { DissolveStateAndAge , Neuron , NeuronBuilder , Visibility } ,
16
15
neuron_data_validation:: { NeuronDataValidationSummary , NeuronDataValidator } ,
17
16
neuron_store:: {
@@ -4356,8 +4355,7 @@ impl Governance {
4356
4355
}
4357
4356
}
4358
4357
Action :: ManageNetworkEconomics ( network_economics) => {
4359
- self . perform_manage_network_economics ( network_economics) ;
4360
- self . set_proposal_execution_status ( pid, Ok ( ( ) ) ) ;
4358
+ self . perform_manage_network_economics ( pid, network_economics) ;
4361
4359
}
4362
4360
// A motion is not executed, just recorded for posterity.
4363
4361
Action :: Motion ( _) => {
@@ -4522,20 +4520,40 @@ impl Governance {
4522
4520
) ;
4523
4521
}
4524
4522
4525
- fn perform_manage_network_economics ( & mut self , new_network_economics : NetworkEconomics ) {
4526
- let Some ( original_network_economics) = & self . heap_data . economics else {
4527
- // This wouldn't happen in production, but if it does, we try to do
4528
- // the best we can, because doing nothing seems more catastrophic.
4529
- println ! (
4530
- "{}ERROR: NetworkEconomics was not set. Setting to proposed NetworkEconomics:\n {:#?}" ,
4531
- LOG_PREFIX , new_network_economics,
4532
- ) ;
4533
- self . heap_data . economics = Some ( new_network_economics) ;
4534
- return ;
4535
- } ;
4523
+ fn perform_manage_network_economics (
4524
+ & mut self ,
4525
+ proposal_id : u64 ,
4526
+ proposed_network_economics : NetworkEconomics ,
4527
+ ) {
4528
+ let result = self . perform_manage_network_economics_impl ( proposed_network_economics) ;
4529
+ self . set_proposal_execution_status ( proposal_id, result) ;
4530
+ }
4531
+
4532
+ /// Only call this from perform_manage_network_economics.
4533
+ fn perform_manage_network_economics_impl (
4534
+ & mut self ,
4535
+ proposed_network_economics : NetworkEconomics ,
4536
+ ) -> Result < ( ) , GovernanceError > {
4537
+ let new_network_economics = self
4538
+ . economics ( )
4539
+ . apply_changes_and_validate ( & proposed_network_economics)
4540
+ . map_err ( |defects| {
4541
+ GovernanceError :: new_with_message (
4542
+ ErrorType :: InvalidProposal ,
4543
+ format ! (
4544
+ "The resulting NetworkEconomics is invalid for the following reason(s):\
4545
+ \n - {}",
4546
+ defects. join( "\n - " ) ,
4547
+ ) ,
4548
+ )
4549
+ } ) ?;
4536
4550
4537
- self . heap_data . economics =
4538
- Some ( new_network_economics. inherit_from ( original_network_economics) ) ;
4551
+ println ! (
4552
+ "{}INFO: Committing new NetworkEconomics:\n {:#?}" ,
4553
+ LOG_PREFIX , new_network_economics,
4554
+ ) ;
4555
+ self . heap_data . economics = Some ( new_network_economics) ;
4556
+ Ok ( ( ) )
4539
4557
}
4540
4558
4541
4559
async fn perform_install_code ( & mut self , proposal_id : u64 , install_code : InstallCode ) {
@@ -4883,6 +4901,45 @@ impl Governance {
4883
4901
Ok ( ( ) )
4884
4902
}
4885
4903
4904
+ /// This verifies the following:
4905
+ ///
4906
+ /// 1. When the changes are applied, the resulting NetworkEconomics is
4907
+ /// valid. See NetworkEconomics::validate.
4908
+ ///
4909
+ /// Since self.heap_data.economics can be different when a proposal is
4910
+ /// executed (compared to when it is created), this should be performed both
4911
+ /// at proposal creation time AND execution time.
4912
+ ///
4913
+ /// Note that it is not considered "invalid" when the "modified" result is
4914
+ /// the same as the original (i.e. setting F to V even though the current
4915
+ /// value of F is ALREADY V). This is because such a proposal is not
4916
+ /// actually harmful to the system; just maybe confusing to users.
4917
+ fn validate_manage_network_economics (
4918
+ & self ,
4919
+ // (Note that this is the value associated with ManageNetworkEconomics,
4920
+ // not the resulting NetworkEconomics.)
4921
+ proposed_network_economics : & NetworkEconomics ,
4922
+ ) -> Result < ( ) , GovernanceError > {
4923
+ // It maybe does not make sense to be able to set transaction_fee_e8s
4924
+ // via proposal. What we probably want instead is to fetch this value
4925
+ // from ledger.
4926
+
4927
+ self . economics ( )
4928
+ . apply_changes_and_validate ( proposed_network_economics)
4929
+ . map_err ( |defects| {
4930
+ let message = format ! (
4931
+ "The resulting settings would not be valid for the \
4932
+ following reason(s):\n \
4933
+ - {}",
4934
+ defects. join( "\n - " ) ,
4935
+ ) ;
4936
+
4937
+ GovernanceError :: new_with_message ( ErrorType :: InvalidProposal , message)
4938
+ } ) ?;
4939
+
4940
+ Ok ( ( ) )
4941
+ }
4942
+
4886
4943
pub ( crate ) fn economics ( & self ) -> & NetworkEconomics {
4887
4944
self . heap_data
4888
4945
. economics
@@ -4960,8 +5017,11 @@ impl Governance {
4960
5017
Action :: ManageNeuron ( manage_neuron) => {
4961
5018
self . validate_manage_neuron_proposal ( manage_neuron)
4962
5019
}
4963
- Action :: ManageNetworkEconomics ( _)
4964
- | Action :: ApproveGenesisKyc ( _)
5020
+ Action :: ManageNetworkEconomics ( network_economics) => {
5021
+ self . validate_manage_network_economics ( network_economics)
5022
+ }
5023
+
5024
+ Action :: ApproveGenesisKyc ( _)
4965
5025
| Action :: AddOrRemoveNodeProvider ( _)
4966
5026
| Action :: RewardNodeProvider ( _)
4967
5027
| Action :: RewardNodeProviders ( _)
0 commit comments