Skip to content
This repository has been archived by the owner on Mar 28, 2023. It is now read-only.

Liquidation-entry refactor #573

Merged
merged 7 commits into from
Apr 16, 2020
Merged

Liquidation-entry refactor #573

merged 7 commits into from
Apr 16, 2020

Conversation

NicholasDotSol
Copy link
Contributor

@NicholasDotSol NicholasDotSol commented Apr 10, 2020

  • startSignerFraudLiquidatoin and StartSignerAbortLiquidation have been consolidated to a single startLiquidation method. a boolean is passed to differentiate between abort and fraud.

  • if coming from redemption, always setLiquidated and make the signer bonds redeemer-withdrawable. Check the deposit state directly rather than relying on redeemerAddress being set to determine if we're coming from the liquidation flow.

closes: #553

draft untill:

NicholasDotSol added 4 commits April 10, 2020 08:24
startSignerFraudLiquidatoin and StartSignerAbortLiquidation
have been consolidated to a single
`startLiquidation` method
a boolean is passed to  differentiate between abort and fraud
if coming from redemption, always setLiquidated and make signer
bonds redeemer-withdrawable
This was only used to check if we're coming from a redemption flow.
We now use `inRedemption` to check if we're coming from redemption flow.
reclaim some more state by zeroing out redeemerAddress
@NicholasDotSol NicholasDotSol changed the title Liquidation refactor Liquidation-entry refactor Apr 10, 2020
/// @param _d Deposit storage pointer.
function startSignerFraudLiquidation(DepositUtils.Deposit storage _d) internal {
_d.logStartedLiquidation(true);
/// @notice Starts signer liquidation due to abort, undercollateralization, or fraud
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about something like “Starts signer liquidation by seizing signer bonds. If the deposit is currently being redeemed, the redeemer receives the full bond value; otherwise, a falling price auction begins to buy 1 TBTC in exchange for a portion of the seized bonds; see purchaseSignerBondsAtAuction.”

Since this is internal, I think the whole thing can be @dev.

Copy link
Contributor

@Shadowfiend Shadowfiend left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left a few remarks. This is looking solid though.

_d.logStartedLiquidation(true);
/// @notice Starts signer liquidation due to abort, undercollateralization, or fraud
/// @dev Liquidation is done by auction.
/// @param _wasFraud Boolean checking liquidation cause. True if fraud, false otherwise.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this could be more clearly stated as “True if liquidation is being started due to fraud, false if for any other reason.”

_d.setLiquidated();
_d.enableWithdrawal(_d.redeemerAddress, _seized);
_d.logLiquidated();
// Reclaim used state for gas savings
_d.redemptionTeardown();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can still do this once alongside the bond seizure, right? redemptionTeardown doesn't change the deposit state, so the _d.inRedemption() check should still work.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

redemptionTeardown() zeroes out redeemerAddress
This is new, I just added it to claim more state back.

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 just saw comment below...

_d.redeemerOutputScript = "";
_d.initialRedemptionFee = 0;
_d.withdrawalRequestTime = 0;
_d.lastRequestedDigest = bytes32(0);
_d.redeemerAddress = address(0);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This affects my sinister plan above. I kind of like keeping the redeemer address as part of the final state of a deposit though… It means a closed deposit knows its original lot size, its final owner, and its redeemer. Feels clean somehow? Though I realize this may make the final tx cheaper 🤔

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It also feels like cleaning this up could inadvertently break some stuff that isn't worth spending time on fixing…

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'd rather save the gas than have a redeemer value in storage.

It also feels like cleaning this up could inadvertently break some stuff that isn't worth spending time on fixing…

when we reclaim this state we are always wrapping up. as long as the state is reclaimed after its last use there should be no problem

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're also assuming the gas saved will be saved, since there's a limit to how much gets refunded via state release. The transactions that do this aren't super expensive.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's a fair point, but we're definitely not reaching the cap for functions like provideRedemptionProof. We'll surely see the refund there

NicholasDotSol added 2 commits April 15, 2020 07:04
Clarify what's happening with the liquidation,
as wella s the boolean parameter
@NicholasDotSol NicholasDotSol marked this pull request as ready for review April 15, 2020 12:23
if redeemerAddress is stored locally so it is not lost after
redemptionTeardown, a shared call to redemptionTeardown() is enough for
fraud and non-fraud startLiquidation paths.
Copy link
Contributor

@Shadowfiend Shadowfiend left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, let's do this thing.

@Shadowfiend Shadowfiend merged commit e50c0ee into master Apr 16, 2020
@Shadowfiend Shadowfiend deleted the liquidation-refactor branch April 16, 2020 16:41
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Investigate cleaner way of identifying signer fraud liquidation redemption origin
2 participants