-
Notifications
You must be signed in to change notification settings - Fork 80
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
feat: add miner deposit #1398
feat: add miner deposit #1398
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
|
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.
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.
@@ -188,6 +188,10 @@ impl Actor { | |||
.collect::<Result<_, _>>()?; | |||
|
|||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Insufficient funds is probably a better error code
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, 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use the newer .with_context_code
form here.
@@ -288,6 +288,11 @@ pub fn locked_reward_from_reward(reward: TokenAmount) -> (TokenAmount, &'static | |||
(lock_amount, &REWARD_VESTING_SPEC) | |||
} | |||
|
|||
/// 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is the deposit a parameter here if it's just passed straight back out?
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you are right removing this will cause problems with the circulation calculations.
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 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm, check_state_invariants behavior need change.
builtin-actors/actors/miner/src/testing.rs
Line 306 in b81da94
if state.continue_deadline_cron() { |
assert_eq!(expected, h.get_locked_funds(&rt)); | ||
} | ||
|
||
#[test] | ||
fn funds_vest() { | ||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just too much test to fix, this is a quick fix
@@ -175,7 +175,8 @@ fn insufficient_funds_for_batch_precommit_in_combination_of_fee_debt_and_network | |||
#[test] | |||
fn enough_funds_for_fee_debt_and_network_fee_but_not_for_pcd() { | |||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
@@ -129,7 +129,7 @@ impl Actor { | |||
}, | |||
)?; | |||
st.miner_count += 1; | |||
|
|||
st.add_pledge_total(rt.policy().new_miner_deposit.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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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