Conversation
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## master #1398 +/- ##
==========================================
- Coverage 91.06% 90.99% -0.08%
==========================================
Files 145 145
Lines 27397 27420 +23
==========================================
+ Hits 24950 24951 +1
- Misses 2447 2469 +22
|
anorth
left a comment
There was a problem hiding this comment.
As discussed in the FIP, I think the deposit amount must be a function, not a constant. This will increase the impact this change has on test code, so I suggest we resolve things at the specification level before applying that impact to the code here.
|
|
||
| let policy = rt.policy(); | ||
| if rt.current_balance() < policy.new_miner_deposit { | ||
| return Err(actor_error!(illegal_argument, "not enough miner deposit")); |
There was a problem hiding this comment.
Insufficient funds is probably a better error code
There was a problem hiding this comment.
yes, but this may exit two case:
case1: value in message is not enough for new miner deposit
case2: the from address dont have enough funds to deposit this error return before exec create miner.
so i think argument error should be resonable
| .map_err(|e| { | ||
| actor_error!( | ||
| illegal_state, | ||
| "failed to lock new miner deposit in vesting table: {}", | ||
| e | ||
| ) | ||
| })?; |
There was a problem hiding this comment.
Please use the newer .with_context_code form here.
|
|
||
| /// Lock amount of deposit of creating new miner | ||
| pub fn locked_new_miner_deposit(deposit: TokenAmount) -> (TokenAmount, &'static VestSpec) { | ||
| (deposit, &REWARD_VESTING_SPEC) |
There was a problem hiding this comment.
Why is the deposit a parameter here if it's just passed straight back out?
There was a problem hiding this comment.
just copy a copy code from locked_reward_from_reward. In fact, I do tend to use a certain ratio of sector collateral as new miners deposit.
| !self.pre_commit_deposits.is_zero() | ||
| || !self.initial_pledge.is_zero() | ||
| || !self.locked_funds.is_zero() | ||
| !self.pre_commit_deposits.is_zero() || !self.initial_pledge.is_zero() |
There was a problem hiding this comment.
I don't think this change is reasonable. A miner needs to keep vesting if they have locked funds - we can't tell how they reached this state.
There was a problem hiding this comment.
you are right removing this will cause problems with the circulation calculations.
There was a problem hiding this comment.
i have a progessing version without this code, but there are too much test case to fix. and had time to handle this since I quit my job recently.
There was a problem hiding this comment.
hmm, check_state_invariants behavior need change.
builtin-actors/actors/miner/src/testing.rs
Line 306 in b81da94
| let h = ActorHarness::new(PERIOD_OFFSET); | ||
| let rt = h.new_runtime(); | ||
| let mut rt = h.new_runtime(); | ||
| rt.policy.new_miner_deposit = TokenAmount::zero(); |
There was a problem hiding this comment.
I think it's a problem that this test is touched at all, and that an unrealistic value is used for the deposit. Can you explain why (in code comments) ?
There was a problem hiding this comment.
just too much test to fix, this is a quick fix
| let actor = ActorHarness::new(*PERIOD_OFFSET); | ||
| let rt = actor.new_runtime(); | ||
| let mut rt = actor.new_runtime(); | ||
| rt.policy.new_miner_deposit = TokenAmount::default(); |
There was a problem hiding this comment.
Why setting this unrealistic amount? Tests need to be updated to use a real deposit.
Also default is a rather opaque way of saying zero. Please use zero() everywhere so it's more obvious that this is not a default value, but a fake one.
| )?; | ||
| st.miner_count += 1; | ||
|
|
||
| st.add_pledge_total(rt.policy().new_miner_deposit.clone()); |
There was a problem hiding this comment.
This code is a long way from the other code that it has to stay in sync with. This has a high chance of introducing an error over time. Instead, I think the miner should notify the power actor of the locked tokens the same way it does for every other locking: by invoking the update pledge method. We might need to re-arrange this method to ensure the state is ready for the re-entrant call and will not be overwritten.
There was a problem hiding this comment.
It was initially intended to be written this way, but the current method doesn't support it. The behavior of the existing method had to be modified.
fn update_pledge_total(
rt: &impl Runtime,
params: UpdatePledgeTotalParams,
) -> Result<(), ActorError> {
rt.validate_immediate_caller_type(std::iter::once(&Type::Miner))?;
rt.transaction(|st: &mut State, rt| {
st.validate_miner_has_claim(rt.store(), &rt.message().caller())?;
st.add_pledge_total(params.pledge_delta);
if st.total_pledge_collateral.is_negative() { // NOTICE need allow negative value in this line
return Err(actor_error!(
illegal_state,
"negative total pledge collateral {}",
st.total_pledge_collateral
));
}
Ok(())
})
}| Expect::power_update_pledge( | ||
| id_addr.id().unwrap(), | ||
| Some(TokenAmount::from_atto(BigInt::from_signed_bytes_be(&[ | ||
| 255, 17, 91, 207, 234, 13, 8, 99, 78, |
There was a problem hiding this comment.
This is completely opaque to me. Please use de/serialization code to produce this value so we can see where it comes from.
|
Closing as requested |
|
fip filecoin-project/FIPs#796
disccussion filecoin-project/FIPs#780