-
Notifications
You must be signed in to change notification settings - Fork 17
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
Hardening overrule proposals with additional checks #NTRN-325 #32
Conversation
…istry # Conflicts: # artifacts/checksums.txt # artifacts/checksums_intermediate.txt # artifacts/cwd_core.wasm # artifacts/cwd_pre_propose_overrule.wasm # artifacts/cwd_pre_propose_single.wasm # artifacts/cwd_proposal_single.wasm # artifacts/cwd_subdao_core.wasm # artifacts/cwd_subdao_pre_propose_single.wasm # artifacts/cwd_subdao_proposal_single.wasm # artifacts/cwd_subdao_timelock_single.wasm
|
||
let mut start_after: Option<SubDao> = None; | ||
|
||
// unfortunately, there is no way to get the total subdao number so we do infinite loop here |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i would consider adding another state value to the main dao with the counter of currently registered proposals. you can then query for this value to avoid the weirdness below
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do you mean add a query to check is the subdao exist?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think @oopcode means the query for a number of listed subdaos. So there would be not an "infinite" loop with checking "does it returns something, if not then we probably reached the end of the list" but just loop through the predicted number of items.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, it makes perfect sense, but my point was, if we are modifying main dao query interface, we can create a more helpful query for this especially case
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did what @swelf19 proposed because it makes things much cleaner
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Minor issues found only
if proposal_modules.is_empty() { | ||
return Err(PreProposeOverruleError::SubdaoMisconfigured {}); | ||
} | ||
|
||
let prop_policy: ProposalCreationPolicy = deps.querier.query_wasm_smart( | ||
proposal_modules.first().unwrap().address.clone(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe it's easy to refactor these lines without unwrap()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
like
proposal_modules
.first()
.ok_or(PreProposeOverruleError::Std(
cosmwasm_std::StdError::GenericErr {
msg: "No modules or smth".to_string(),
},
))?
.address
.clone()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
if subdao_list.is_empty() { | ||
return Ok(false); | ||
} | ||
|
||
start_after = Some(subdao_list.last().unwrap().clone()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The same about unwrap
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code doesn't exists anymore fortunately
|
||
if !is_proposal_timelocked( | ||
&deps, | ||
&Addr::unchecked(timelock_contract_addr.clone()), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
timelock_contract_addr is an Addr type, you no need to wrap it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
|
||
if subdao_list | ||
.into_iter() | ||
.any(|subdao| subdao.addr == subdao_core.clone().into_string()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addr implements PartialEq for String, you can just dereference &Addr subdao.addr == *subdao_core
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
if !is_proposal_timelocked( | ||
&deps, | ||
&Addr::unchecked(timelock_contract_addr.clone()), | ||
proposal_id, | ||
)? { | ||
return Err(PreProposeOverruleError::ProposalWrongState {}); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if !is_proposal_timelocked( | |
&deps, | |
&Addr::unchecked(timelock_contract_addr.clone()), | |
proposal_id, | |
)? { | |
return Err(PreProposeOverruleError::ProposalWrongState {}); | |
} | |
if !is_proposal_timelocked(&deps, &timelock_contract_addr, proposal_id)? { | |
return Err(PreProposeOverruleError::ProposalWrongState {}); | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
timelock_contract: &String, | ||
) -> Result<Addr, PreProposeOverruleError> { | ||
let timelock_config: TimelockTypes::Config = deps.querier.query_wasm_smart( | ||
timelock_contract.to_string(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
already &String
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed the argument type to Addr for consistency reasons
@@ -12,4 +12,16 @@ pub enum PreProposeOverruleError { | |||
|
|||
#[error("Base pre propose messages aren't supported.")] | |||
MessageUnsupported {}, | |||
|
|||
#[error("Subdao is wrongly configured.")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
misconfigured?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
#[error("Subdao is wrongly configured.")] | ||
SubdaoMisconfigured {}, | ||
|
||
#[error("Subdao isn't in the list.")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove the full stop
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
Important notice: after making fixes according to review comments, the mysterious error with "Invalid relocation" on my m1 mac disappeared 🤷♂️ will see if it will appear again |
The changes made in this PR:
Genesis changes: neutron-org/neutron#201
Integration tests: neutron-org/neutron-integration-tests#131