-
Notifications
You must be signed in to change notification settings - Fork 124
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
[refactor] Remove errors from subaccounts keeper functions that don't return errors #678
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -283,19 +283,13 @@ func (k Keeper) UpdateSubaccounts( | |
} | ||
|
||
// Apply the updates to perpetual positions. | ||
success, err = UpdatePerpetualPositions( | ||
UpdatePerpetualPositions( | ||
settledUpdates, | ||
perpIdToFundingIndex, | ||
) | ||
if !success || err != nil { | ||
return success, successPerUpdate, err | ||
} | ||
|
||
// Apply the updates to asset positions. | ||
success, err = UpdateAssetPositions(settledUpdates) | ||
if !success || err != nil { | ||
return success, successPerUpdate, err | ||
} | ||
UpdateAssetPositions(settledUpdates) | ||
|
||
// Apply all updates, including a subaccount update event in the Indexer block message | ||
// per update and emit a cometbft event for each settled funding payment. | ||
|
@@ -433,10 +427,7 @@ func (k Keeper) getSettledSubaccount( | |
// division result always rounds towards negative infinity. | ||
totalNetSettlementPpm.Div(totalNetSettlementPpm, lib.BigIntOneMillion()), | ||
) | ||
err = newSubaccount.SetUsdcAssetPosition(newUsdcPosition) | ||
if err != nil { | ||
return types.Subaccount{}, nil, err | ||
} | ||
newSubaccount.SetUsdcAssetPosition(newUsdcPosition) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The - newSubaccount.SetUsdcAssetPosition(newUsdcPosition)
+ err = newSubaccount.SetUsdcAssetPosition(newUsdcPosition)
+ if err != nil {
+ return types.Subaccount{}, nil, err
+ } |
||
return newSubaccount, fundingPayments, nil | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -104,9 +104,6 @@ func getUpdatedPerpetualPositions( | |
func UpdatePerpetualPositions( | ||
settledUpdates []settledUpdate, | ||
perpIdToFundingIndex map[uint32]dtypes.SerializableInt, | ||
) ( | ||
success bool, | ||
err error, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This function doesn't return an error anymore, so removed it. |
||
) { | ||
// Apply the updates. | ||
for i, u := range settledUpdates { | ||
|
@@ -164,16 +161,12 @@ func UpdatePerpetualPositions( | |
|
||
settledUpdates[i].SettledSubaccount.PerpetualPositions = perpetualPositions | ||
} | ||
return true, nil | ||
} | ||
|
||
// For each settledUpdate in settledUpdates, updates its SettledSubaccount.AssetPositions | ||
// to reflect settledUpdate.AssetUpdates. | ||
func UpdateAssetPositions( | ||
settledUpdates []settledUpdate, | ||
) ( | ||
success bool, | ||
err error, | ||
) { | ||
// Apply the updates. | ||
for i, u := range settledUpdates { | ||
|
@@ -226,5 +219,4 @@ func UpdateAssetPositions( | |
|
||
settledUpdates[i].SettledSubaccount.AssetPositions = assetPositions | ||
} | ||
return true, nil | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -73,26 +73,25 @@ func (m *Subaccount) GetUsdcPosition() *big.Int { | |
} | ||
|
||
// SetUsdcAssetPosition sets the balance of the USDC asset position to `newUsdcPosition`. | ||
// If the absolute value of `newUsdcPosition` cannot be represented in a uint64, | ||
// an error is returned. | ||
func (m *Subaccount) SetUsdcAssetPosition(newUsdcPosition *big.Int) error { | ||
if m != nil { | ||
usdcAssetPosition := m.getUsdcAssetPosition() | ||
if newUsdcPosition == nil || newUsdcPosition.Sign() == 0 { | ||
if usdcAssetPosition != nil { | ||
m.AssetPositions = m.AssetPositions[1:] | ||
} | ||
} else { | ||
if usdcAssetPosition == nil { | ||
usdcAssetPosition = &AssetPosition{ | ||
AssetId: assettypes.AssetUsdc.Id, | ||
} | ||
m.AssetPositions = append([]*AssetPosition{usdcAssetPosition}, m.AssetPositions...) | ||
func (m *Subaccount) SetUsdcAssetPosition(newUsdcPosition *big.Int) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This function also doesn't return an error anymore, so removed it + refactored it to early return. Let me know if anyone would prefer I remove the refactor logic to early return. This function has good test coverage though so I felt like the change is safe. |
||
if m == nil { | ||
return | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we panic / error log if this ever happens? It doesn't seem like this function should silently fail if called with a nil pointer. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this was meant to be a convenience method for tests only. I don't think there is a reason to use this instead of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
} | ||
|
||
usdcAssetPosition := m.getUsdcAssetPosition() | ||
if newUsdcPosition == nil || newUsdcPosition.Sign() == 0 { | ||
lucas-dydx marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if usdcAssetPosition != nil { | ||
m.AssetPositions = m.AssetPositions[1:] | ||
} | ||
} else { | ||
if usdcAssetPosition == nil { | ||
usdcAssetPosition = &AssetPosition{ | ||
AssetId: assettypes.AssetUsdc.Id, | ||
} | ||
usdcAssetPosition.Quantums = dtypes.NewIntFromBigInt(newUsdcPosition) | ||
m.AssetPositions = append([]*AssetPosition{usdcAssetPosition}, m.AssetPositions...) | ||
} | ||
usdcAssetPosition.Quantums = dtypes.NewIntFromBigInt(newUsdcPosition) | ||
} | ||
return nil | ||
} | ||
|
||
func (m *Subaccount) getUsdcAssetPosition() *AssetPosition { | ||
|
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.
The error handling has been removed from the
UpdatePerpetualPositions
andUpdateAssetPositions
functions. This could potentially lead to silent failures if these functions encounter an error. Consider adding error handling back in to ensure that any issues are properly caught and handled.