diff --git a/Lib9c/Action/ValidatorDelegation/UpdateValidators.cs b/Lib9c/Action/ValidatorDelegation/UpdateValidators.cs index 89b1d9c0c8..fb1c87075b 100644 --- a/Lib9c/Action/ValidatorDelegation/UpdateValidators.cs +++ b/Lib9c/Action/ValidatorDelegation/UpdateValidators.cs @@ -32,25 +32,27 @@ public override IWorld Execute(IActionContext context) var repository = new ValidatorRepository(world, context); var validators = repository.GetValidatorList().ActiveSet(); - foreach (var deactivated in prevValidators.Except(validators)) + foreach (var deactivated in prevValidators.Select(v => v.OperatorAddress) + .Except(validators.Select(v => v.OperatorAddress))) { - var validatorDelegatee = repository.GetValidatorDelegatee(deactivated.OperatorAddress); + var validatorDelegatee = repository.GetValidatorDelegatee(deactivated); validatorDelegatee.Deactivate(); repository.SetValidatorDelegatee(validatorDelegatee); var guildRepository = new GuildRepository(repository.World, repository.ActionContext); - var validatorDelegateeForGuildParticipant = guildRepository.GetGuildDelegatee(deactivated.OperatorAddress); + var validatorDelegateeForGuildParticipant = guildRepository.GetGuildDelegatee(deactivated); validatorDelegateeForGuildParticipant.Deactivate(); guildRepository.SetGuildDelgatee(validatorDelegateeForGuildParticipant); repository.UpdateWorld(guildRepository.World); } - foreach (var activated in validators.Except(prevValidators)) + foreach (var activated in validators.Select(v => v.OperatorAddress) + .Except(prevValidators.Select(v => v.OperatorAddress))) { - var validatorDelegatee = repository.GetValidatorDelegatee(activated.OperatorAddress); + var validatorDelegatee = repository.GetValidatorDelegatee(activated); validatorDelegatee.Activate(); repository.SetValidatorDelegatee(validatorDelegatee); var guildRepository = new GuildRepository(repository.World, repository.ActionContext); - var validatorDelegateeForGuildParticipant = guildRepository.GetGuildDelegatee(activated.OperatorAddress); + var validatorDelegateeForGuildParticipant = guildRepository.GetGuildDelegatee(activated); validatorDelegateeForGuildParticipant.Activate(); guildRepository.SetGuildDelgatee(validatorDelegateeForGuildParticipant); repository.UpdateWorld(guildRepository.World); diff --git a/Lib9c/ValidatorDelegation/ValidatorDelegatee.cs b/Lib9c/ValidatorDelegation/ValidatorDelegatee.cs index fd350c5800..c3fa0d537b 100644 --- a/Lib9c/ValidatorDelegation/ValidatorDelegatee.cs +++ b/Lib9c/ValidatorDelegation/ValidatorDelegatee.cs @@ -202,10 +202,14 @@ public void Activate() ValidatorRepository repository = (ValidatorRepository)Repository; IsActive = true; Metadata.DelegationPoolAddress = ActiveDelegationPoolAddress; - repository.TransferAsset( - InactiveDelegationPoolAddress, - ActiveDelegationPoolAddress, - TotalDelegated); + + if (TotalDelegated.Sign > 0) + { + repository.TransferAsset( + InactiveDelegationPoolAddress, + ActiveDelegationPoolAddress, + TotalDelegated); + } } public void Deactivate() @@ -213,10 +217,14 @@ public void Deactivate() ValidatorRepository repository = (ValidatorRepository)Repository; IsActive = false; Metadata.DelegationPoolAddress = InactiveDelegationPoolAddress; - repository.TransferAsset( - ActiveDelegationPoolAddress, - InactiveDelegationPoolAddress, - TotalDelegated); + + if (TotalDelegated.Sign > 0) + { + repository.TransferAsset( + ActiveDelegationPoolAddress, + InactiveDelegationPoolAddress, + TotalDelegated); + } } public void OnDelegationChanged(object? sender, long height)