mirror of
				https://github.com/0glabs/0g-chain.git
				synced 2025-10-31 14:47:29 +00:00 
			
		
		
		
	Cache redundant calculation in cdp RepayPrinciple (#569)
* fix exhibit 29 and remove redundant calcuation * use better naming (totalPrincipal instead of totalDebt) and add comment for future maintainers
This commit is contained in:
		
							parent
							
								
									0ddae8609e
								
							
						
					
					
						commit
						3e63356c58
					
				| @ -85,8 +85,11 @@ func (k Keeper) RepayPrincipal(ctx sdk.Context, owner sdk.AccAddress, denom stri | ||||
| 		return err | ||||
| 	} | ||||
| 
 | ||||
| 	// Note: assumes cdp.Principal and cdp.AccumulatedFees don't change during calculations
 | ||||
| 	totalPrincipal := cdp.Principal.Add(cdp.AccumulatedFees) | ||||
| 
 | ||||
| 	// calculate fee and principal payment
 | ||||
| 	feePayment, principalPayment := k.calculatePayment(ctx, cdp.Principal.Add(cdp.AccumulatedFees), cdp.AccumulatedFees, payment) | ||||
| 	feePayment, principalPayment := k.calculatePayment(ctx, totalPrincipal, cdp.AccumulatedFees, payment) | ||||
| 
 | ||||
| 	err = k.validatePrincipalPayment(ctx, cdp, principalPayment) | ||||
| 	if err != nil { | ||||
| @ -131,7 +134,7 @@ func (k Keeper) RepayPrincipal(ctx sdk.Context, owner sdk.AccAddress, denom stri | ||||
| 	) | ||||
| 
 | ||||
| 	// remove the old collateral:debt ratio index
 | ||||
| 	oldCollateralToDebtRatio := k.CalculateCollateralToDebtRatio(ctx, cdp.Collateral, cdp.Principal.Add(cdp.AccumulatedFees)) | ||||
| 	oldCollateralToDebtRatio := k.CalculateCollateralToDebtRatio(ctx, cdp.Collateral, totalPrincipal) | ||||
| 	k.RemoveCdpCollateralRatioIndex(ctx, denom, cdp.ID, oldCollateralToDebtRatio) | ||||
| 
 | ||||
| 	// update cdp state
 | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 Nick DeLuca
						Nick DeLuca