Skip to content
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

fix: transfer BNB back to tokenHub when _doMigration failed #523

Merged
merged 2 commits into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions contracts/BC_fusion/StakeHub.sol
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,8 @@ contract StakeHub is System, Initializable, Protectable {
MIGRATE_SUCCESS,
CLAIM_FUND_FAILED,
VALIDATOR_NOT_EXISTED,
VALIDATOR_JAILED
VALIDATOR_JAILED,
INVALID_DELEGATOR
}

struct Validator {
Expand Down Expand Up @@ -274,7 +275,7 @@ contract StakeHub is System, Initializable, Protectable {
function handleSynPackage(
uint8,
bytes calldata msgBytes
) external onlyCrossChainContract enableReceivingFund returns (bytes memory) {
) external onlyCrossChainContract whenNotPaused enableReceivingFund returns (bytes memory) {
(StakeMigrationPackage memory migrationPkg, bool decodeSuccess) = _decodeMigrationSynPackage(msgBytes);
if (!decodeSuccess) revert InvalidSynPackage();

Expand All @@ -299,6 +300,8 @@ contract StakeHub is System, Initializable, Protectable {
if (respCode == StakeMigrationRespCode.MIGRATE_SUCCESS) {
return new bytes(0);
} else {
(bool success,) = TOKEN_HUB_ADDR.call{ value: address(this).balance }("");
if (!success) revert TransferFailed();
emit MigrateFailed(migrationPkg.operatorAddress, migrationPkg.delegator, migrationPkg.amount, respCode);
return msgBytes;
}
Expand Down Expand Up @@ -1030,13 +1033,9 @@ contract StakeHub is System, Initializable, Protectable {
return (migrationPackage, success);
}

function _doMigration(StakeMigrationPackage memory migrationPkg)
internal
whenNotPaused
returns (StakeMigrationRespCode)
{
function _doMigration(StakeMigrationPackage memory migrationPkg) internal returns (StakeMigrationRespCode) {
if (blackList[migrationPkg.delegator] || migrationPkg.delegator == address(0)) {
revert InBlackList();
return StakeMigrationRespCode.INVALID_DELEGATOR;
}

if (!_validatorSet.contains(migrationPkg.operatorAddress)) {
Expand Down
1 change: 1 addition & 0 deletions test/StakeHub.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,7 @@ contract StakeHubTest is Deployer {
emit MigrateFailed(delegator, delegator, delegation, StakeMigrationRespCode.VALIDATOR_NOT_EXISTED);
vm.prank(address(crossChain));
stakeHub.handleSynPackage(BC_FUSION_CHANNELID, elements.encodeList());
assertEq(address(stakeHub).balance, 0, "StakeHub balance should be 0");

// failed for claim fund failed
elements[0] = validator.encodeAddress();
Expand Down
Loading