Skip to content
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

Conversation

hunjixin
Copy link
Contributor

@hunjixin hunjixin commented Sep 1, 2023

@codecov-commenter
Copy link

codecov-commenter commented Sep 1, 2023

Codecov Report

Merging #1398 (b5cc6ad) into master (8076305) will decrease coverage by 0.08%.
The diff coverage is 82.75%.

Additional details and impacted files

Impacted file tree graph

@@            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     
Files Changed Coverage Δ
actors/miner/src/lib.rs 84.69% <78.26%> (-0.05%) ⬇️
actors/miner/src/monies.rs 99.43% <100.00%> (+<0.01%) ⬆️
actors/miner/src/state.rs 80.97% <100.00%> (-0.05%) ⬇️
actors/power/src/lib.rs 84.04% <100.00%> (-0.72%) ⬇️
runtime/src/runtime/policy.rs 98.38% <100.00%> (+0.01%) ⬆️

... and 6 files with indirect coverage changes

@hunjixin hunjixin requested review from anorth, alexytsu and ZenGround0 and removed request for alexytsu September 1, 2023 05:05
Copy link
Member

@anorth anorth left a 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"));
Copy link
Member

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

Copy link
Contributor Author

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

Comment on lines +252 to +258
.map_err(|e| {
actor_error!(
illegal_state,
"failed to lock new miner deposit in vesting table: {}",
e
)
})?;
Copy link
Member

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)
Copy link
Member

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?

Copy link
Contributor Author

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()
Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

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();
Copy link
Member

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) ?

Copy link
Contributor Author

@hunjixin hunjixin Oct 10, 2023

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();
Copy link
Member

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());
Copy link
Member

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.

Copy link
Contributor Author

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,
Copy link
Member

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.

@tediou5
Copy link

tediou5 commented Mar 28, 2024

I've finished a new implementation, please close this pr, thanks
@anorth
FIP-0077

@anorth
Copy link
Member

anorth commented Apr 4, 2024

Closing as requested

@anorth anorth closed this Apr 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants