Skip to content

Commit

Permalink
Return penalty to staker if target chain has already progressed
Browse files Browse the repository at this point in the history
  • Loading branch information
hobofan committed Jan 14, 2019
1 parent 4871cbc commit 3957841
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions contracts/gateway/EIP20Gateway.sol
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,50 @@ contract EIP20Gateway is GatewayBase {
bytes32(0),
true
);
// Return revert penalty to staker if message is already progressed
// and can't be reverted anymore.
tryReturnPenaltyToStaker(
_messageHash,
staker_,
messageBox.outbox[_messageHash], // old message status
MessageBus.MessageStatus(_messageStatus) // new message status
);
}

/**
* @notice Return the revert penalty to the staker. Only valid for
* a message transition from DeclaredRevocation -> Progressed.
*
* @dev Should only be called from progressStakeWithProof. This function
* exists to avoid a stack too deep error.
*
* @param _messageHash Message hash.
* @param _staker Staker address.
* @param _oldMessageStatus Message status before progressing.
* @param _newMessageStatus Message status after progressing.
*/
function tryReturnPenaltyToStaker(
bytes32 _messageHash,
address _staker,
MessageBus.MessageStatus _oldMessageStatus,
MessageBus.MessageStatus _newMessageStatus
)
private
{
if (_oldMessageStatus != MessageBus.MessageStatus.DeclaredRevocation) {
return;
}
if (_newMessageStatus != MessageBus.MessageStatus.Progressed) {
return;
}

// Penalty charged to staker for revert stake.
uint256 penalty = stakes[_messageHash].bounty
.mul(REVOCATION_PENALTY)
.div(100);

// transfer the penalty amount
require(baseToken.transfer(_staker, penalty));
}

/**
Expand Down

0 comments on commit 3957841

Please sign in to comment.