glifio / glif

Apache License 2.0
8 stars 4 forks source link

invalid 100% faulty sector error #142

Closed Schwartz10 closed 2 months ago

Schwartz10 commented 6 months ago

If you have an Agent that is attempting to borrow, it seems that the error message when they try to borrow too much is wrong - it shows invalid faulty sectors

heres an agent with faulty sectors now 0xEC5527D5E04A6B2641ec15E89f43AED22098f7ba

if you simulate a borrow call that fails, the cli shows faulty sector error, when it should show the right error

jimpick commented 6 months ago

Here's what glif agent info shows:

$ glif agent info

BASIC INFO

Agent 0x Addr                         0xEC5527D5E04A6B2641ec15E89f43AED22098f7ba    
Agent f4 Addr                         f410f5rkspvpajjvsmqpmcxuj6q5o2iqjr552tky7uey  
Agent f0 Addr                         f03005567                                     
Agent GLIF ID                         113                                           
Agent Owner                           0xfF000000000000000000000000000000002ddc6e    
Agent Operator                        0x0439f8219c7f60e17A4072526D0231A19a760F97    
Agent ADO Requester                   0x0439f8219c7f60e17A4072526D0231A19a760F97    
Agent Miners                          5                                             
Version                               1 ✅                                           

ECON INFO

Borrow now                            66485.222867057 FIL   
Max borrow                            349573.187153627 FIL  

Liquidation value                     204471.340335711 FIL  
Recovery rate                         85.090%                       

Total borrowed                        67404.221944927 FIL  
You current owe                       2.067909206 FIL      
Current borrow APR                    15.000%              
Your weekly payment                   193.902556280 FIL    
Quota                                 2500000.000 FIL      

Liquid FIL                            293.39308330 FIL                
Total FIL                             242190.81552174 FIL             
Equity                                174786.59357681 FIL             
Expected weekly earnings              1540.64566633 FIL               
Debt-to-liquidation-value (LTV)       32.965% (must stay below 80%)   
Debt-to-equity (DTE)                  38.564% (must stay below 200%)  
Debt-to-income (DTI)                  12.586% (must stay below 25%)   

HEALTH

Status unhealthy 🔴
WARNING: Your Agent has one or more miners with faulty sectors - recover your sectors as soon as possible
Faulty sector ratio: 1.73%
Faulty sector ratio limit: 0.1%

Agent's administrator                 0x0000000000000000000000000000000000000000  
Agent in default                      false                                       
jimpick commented 6 months ago

Actual faulty sectors:

$ glif agent miners list
Agent's miners:
Miner f01937995 - 69639.193583501 FIL
Miner f01947770 - 68849.504112456 FIL
Miner f03019624 - 56433.622946257 FIL
Miner f03024798 - 44670.467621938 FIL
Miner f03045966 - 2307.611302863 FIL

Total balance: 241900.399567016
$ for m in f01937995 f01947770 f03019624 f03024798 f03045966; do echo $m $(./lotus-shed miner faults $m | sed -E 's/(faulty sectors:|no faults)//' | wc -w); done
f01937995 0
f01947770 0
f03019624 4393
f03024798 5440
f03045966 1334
jimpick commented 6 months ago

I can't test a borrow with that agent because I don't have the requester key.

But if I try borrowing a ridiculous amount with agent 112 (mine):

$ glif agent borrow 1000000
Borrowing 1e+06 FIL from the infinity-pool into agent 0x4180644623721523Db0D20E1158e2FCbC5b297C3
\2024/04/11 18:51:51 Agent fault ratio is above the limit: 100% (limit is 0.1%). Recover your sectors to complete the action

So I can reproduce.

jimpick commented 6 months ago

The message is coming via the ADO, which uses go-pools to compute the agent data with the new funds added to the available balance.

There is a comment:

        } else if (new(big.Int).Div(numerator, data.CollateralValue)).Cmp(constants.MAX_LTV) > 0 {
        // if the LTV (loan to liquidation value) is greater than the max LTV, we report faulty sectors in order to trigger a liquidation
        // this is a bit of a workaround until the liquidation value buffer is built-in to the contracts directly
        data.FaultySectors = aggMinerStats.LiveSectors
    }

This workaround is intentionally reporting all sectors as faulty to prevent the borrow. It is confusing because this is being reported on the command line, and the user doesn't know about the workaround.

https://github.com/glifio/go-pools/blob/0eeb3b4e1498024d0d0bd46ead2f9e9bbebcff85/econ/econ.go#L58