From aba655913edd49ef8de8c39f9819b0896fe063af Mon Sep 17 00:00:00 2001 From: Roshan Date: Fri, 12 Jan 2024 11:26:14 +0800 Subject: [PATCH 1/2] fix: add `isAutoUndelegate` for auto `DistributeUndelegatedSynPackage` --- contracts/Staking.sol | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/contracts/Staking.sol b/contracts/Staking.sol index 63468cf2..6d775775 100644 --- a/contracts/Staking.sol +++ b/contracts/Staking.sol @@ -620,6 +620,7 @@ contract Staking is IStaking, System, IParamSubscriber, IApplication { address recipient; address validator; uint256 amount; + bool isAutoUndelegate; while (iter.hasNext()) { if (idx == 0) { recipient = address(uint160(iter.next().toAddress())); @@ -628,6 +629,8 @@ contract Staking is IStaking, System, IParamSubscriber, IApplication { } else if (idx == 2) { amount = uint256(iter.next().toUint()); success = true; + } else if (idx == 3) { + isAutoUndelegate = iter.next().toBoolean(); } else { break; } @@ -643,6 +646,11 @@ contract Staking is IStaking, System, IParamSubscriber, IApplication { pendingUndelegateTime[recipient][validator] = 0; undelegated[recipient] = undelegated[recipient].add(amount); + if (isAutoUndelegate) { + delegated[recipient] = delegated[recipient].sub(amount); + delegatedOfValidator[recipient][validator] = delegatedOfValidator[recipient][validator].sub(amount); + } + emit undelegatedReceived(recipient, validator, amount); return (CODE_OK, new bytes(0)); } From 7f2222ebb8c34d737ecd823ecfde8d85e797a88b Mon Sep 17 00:00:00 2001 From: Roshan Date: Fri, 12 Jan 2024 11:57:39 +0800 Subject: [PATCH 2/2] add annotation --- contracts/Staking.sol | 2 ++ 1 file changed, 2 insertions(+) diff --git a/contracts/Staking.sol b/contracts/Staking.sol index 6d775775..4f0d133e 100644 --- a/contracts/Staking.sol +++ b/contracts/Staking.sol @@ -646,6 +646,8 @@ contract Staking is IStaking, System, IParamSubscriber, IApplication { pendingUndelegateTime[recipient][validator] = 0; undelegated[recipient] = undelegated[recipient].add(amount); + // this is to address the issue that the contract state will not being updated + // when the Beacon Chain system undelegate all the funds after second sunset upgrade if (isAutoUndelegate) { delegated[recipient] = delegated[recipient].sub(amount); delegatedOfValidator[recipient][validator] = delegatedOfValidator[recipient][validator].sub(amount);