Skip to content

Commit

Permalink
fix: Fix de(activate) validator equality
Browse files Browse the repository at this point in the history
  • Loading branch information
OnedgeLee committed Nov 14, 2024
1 parent e7b4bd5 commit 5d4a9d6
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 14 deletions.
14 changes: 8 additions & 6 deletions Lib9c/Action/ValidatorDelegation/UpdateValidators.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
24 changes: 16 additions & 8 deletions Lib9c/ValidatorDelegation/ValidatorDelegatee.cs
Original file line number Diff line number Diff line change
Expand Up @@ -202,21 +202,29 @@ 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()
{
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)
Expand Down

0 comments on commit 5d4a9d6

Please sign in to comment.