diff --git a/Lib9c/Action/ValidatorDelegation/AllocateGuildReward.cs b/Lib9c/Action/ValidatorDelegation/AllocateGuildReward.cs index 77b9974086..3ea088d11a 100644 --- a/Lib9c/Action/ValidatorDelegation/AllocateGuildReward.cs +++ b/Lib9c/Action/ValidatorDelegation/AllocateGuildReward.cs @@ -11,6 +11,7 @@ using Libplanet.Types.Blocks; using Lib9c; using Nekoyume.Action.Guild.Migration.LegacyModels; +using Serilog; namespace Nekoyume.Action.ValidatorDelegation { @@ -29,16 +30,23 @@ public override void LoadPlainValue(IValue plainValue) public override IWorld Execute(IActionContext context) { var world = context.PreviousState; + Log.Information( + "[AllocateGuildReward] Start block #{BlockIndex}", + context.BlockIndex); if (world.GetDelegationMigrationHeight() is not { } migrationHeight || context.BlockIndex < migrationHeight) { + Log.Information("[AllocateGuildReward] Skipped (migration height not reached)"); return world; } + Log.Information("[AllocateGuildReward] Creating ValidatorRepository..."); var repository = new ValidatorRepository(world, context); + Log.Information("[AllocateGuildReward] ValidatorRepository created"); var rewardCurrency = Currencies.Mead; var proposerInfo = repository.GetProposerInfo(); + Log.Information("[AllocateGuildReward] ProposerInfo retrieved"); if (context.LastCommit is BlockCommit lastCommit) { @@ -47,21 +55,31 @@ public override IWorld Execute(IActionContext context) (total, next) => total + (next.ValidatorPower ?? BigInteger.Zero)); + Log.Information( + "[AllocateGuildReward] DistributeProposerReward start, votes={VoteCount}, power={Power}", + lastCommit.Votes.Count(), + validatorSetPower); DistributeProposerReward( repository, rewardCurrency, proposerInfo, validatorSetPower, lastCommit.Votes); + Log.Information("[AllocateGuildReward] DistributeProposerReward done"); + Log.Information("[AllocateGuildReward] DistributeValidatorReward start"); DistributeValidatorReward( repository, rewardCurrency, validatorSetPower, lastCommit.Votes); + Log.Information("[AllocateGuildReward] DistributeValidatorReward done"); } var communityFund = repository.GetBalance(Addresses.RewardPool, rewardCurrency); + Log.Information( + "[AllocateGuildReward] CommunityFund={CommunityFund}", + communityFund); if (communityFund.Sign > 0) { @@ -71,6 +89,7 @@ public override IWorld Execute(IActionContext context) communityFund); } + Log.Information("[AllocateGuildReward] Complete block #{BlockIndex}", context.BlockIndex); return repository.World; } @@ -140,14 +159,17 @@ FungibleAssetValue rewardToAllocate if (rewardToAllocate.Sign <= 0) { + Log.Information("[AllocateGuildReward.DistributeValidatorReward] No reward to allocate"); return; } if (validatorSetPower == BigInteger.Zero) { + Log.Information("[AllocateGuildReward.DistributeValidatorReward] ValidatorSetPower is zero"); return; } + int index = 0; foreach (Vote vote in lastVotes) { if (vote.Flag == VoteFlag.Null || vote.Flag == VoteFlag.Unknown) @@ -155,9 +177,17 @@ FungibleAssetValue rewardToAllocate continue; } + var validatorAddress = vote.ValidatorPublicKey.Address; + Log.Information( + "[AllocateGuildReward.DistributeValidatorReward] Processing validator {Index} {Address}", + index, validatorAddress); + if (!repository.TryGetDelegatee( - vote.ValidatorPublicKey.Address, out var validatorDelegatee)) + validatorAddress, out var validatorDelegatee)) { + Log.Information( + "[AllocateGuildReward.DistributeValidatorReward] Delegatee not found for {Address}", + validatorAddress); continue; } @@ -167,12 +197,19 @@ FungibleAssetValue rewardToAllocate continue; } + Log.Information( + "[AllocateGuildReward.DistributeValidatorReward] AllocateReward for {Address}, power={Power}", + validatorAddress, validatorPower); validatorDelegatee.AllocateReward( rewardToAllocate, validatorPower, validatorSetPower, Addresses.RewardPool, blockHeight); + Log.Information( + "[AllocateGuildReward.DistributeValidatorReward] AllocateReward done for {Address}", + validatorAddress); + index++; } } } diff --git a/Lib9c/Action/ValidatorDelegation/AllocateReward.cs b/Lib9c/Action/ValidatorDelegation/AllocateReward.cs index 186fed4546..e056ae318b 100644 --- a/Lib9c/Action/ValidatorDelegation/AllocateReward.cs +++ b/Lib9c/Action/ValidatorDelegation/AllocateReward.cs @@ -13,6 +13,7 @@ using Nekoyume.ValidatorDelegation; using Nekoyume.Module.ValidatorDelegation; using Nekoyume.Action.Guild.Migration.LegacyModels; +using Serilog; namespace Nekoyume.Action.ValidatorDelegation { @@ -31,15 +32,19 @@ public override void LoadPlainValue(IValue plainValue) public override IWorld Execute(IActionContext context) { var world = context.PreviousState; + Log.Information("[AllocateReward] Start block #{BlockIndex}", context.BlockIndex); if (world.GetDelegationMigrationHeight() is not { } migrationHeight || context.BlockIndex < migrationHeight) { + Log.Information("[AllocateReward] Skipped (migration height not reached)"); return world; } var rewardCurrency = world.GetGoldCurrency(); + Log.Information("[AllocateReward] Creating GuildRepository..."); var repository = new GuildRepository(world, context); + Log.Information("[AllocateReward] GuildRepository created"); if (context.LastCommit is BlockCommit lastCommit) { @@ -48,11 +53,20 @@ public override IWorld Execute(IActionContext context) (total, next) => total + (next.ValidatorPower ?? BigInteger.Zero)); + Log.Information("[AllocateReward] DistributeValidator start"); DistributeValidator(repository, rewardCurrency, validatorSetPower, lastCommit.Votes); + Log.Information("[AllocateReward] DistributeValidator done"); + + Log.Information("[AllocateReward] DistributeGuild start"); var validatorRepository = new ValidatorRepository(repository.World, context); DistributeGuild(validatorRepository, rewardCurrency, validatorSetPower, lastCommit.Votes); + Log.Information("[AllocateReward] DistributeGuild done, UpdateWorld..."); repository.UpdateWorld(validatorRepository.World); + Log.Information("[AllocateReward] UpdateWorld done"); + + Log.Information("[AllocateReward] DistributeGuildParticipant start"); DistributeGuildParticipant(repository, rewardCurrency, validatorSetPower, lastCommit.Votes); + Log.Information("[AllocateReward] DistributeGuildParticipant done"); } var communityFund = repository.GetBalance(Addresses.RewardPool, rewardCurrency); @@ -65,6 +79,7 @@ public override IWorld Execute(IActionContext context) communityFund); } + Log.Information("[AllocateReward] Complete block #{BlockIndex}", context.BlockIndex); return repository.World; } diff --git a/Lib9c/Action/ValidatorDelegation/SlashValidator.cs b/Lib9c/Action/ValidatorDelegation/SlashValidator.cs index f130ddd0f6..6102396e9f 100644 --- a/Lib9c/Action/ValidatorDelegation/SlashValidator.cs +++ b/Lib9c/Action/ValidatorDelegation/SlashValidator.cs @@ -10,6 +10,7 @@ using Nekoyume.Model.Guild; using Nekoyume.Module.ValidatorDelegation; using Nekoyume.ValidatorDelegation; +using Serilog; namespace Nekoyume.Action.ValidatorDelegation { @@ -34,6 +35,7 @@ public override void LoadPlainValue(IValue plainValue) public override IWorld Execute(IActionContext context) { var world = context.PreviousState; + Log.Information("[SlashValidator] Start block #{BlockIndex}", context.BlockIndex); if (world.GetDelegationMigrationHeight() is null) { @@ -48,12 +50,19 @@ public override IWorld Execute(IActionContext context) .Select(vote => vote.ValidatorPublicKey), context.BlockIndex); repository.SetAbstainHistory(abstainHistory); + Log.Information( + "[SlashValidator] AbstainsToSlash count={Count}", + abstainsToSlash.Count()); foreach (var abstain in abstainsToSlash) { + Log.Information( + "[SlashValidator] Slashing abstainer {Address}", + abstain.Address); var validatorDelegatee = repository.GetDelegatee(abstain.Address); if (validatorDelegatee.Jailed) { + Log.Information("[SlashValidator] Already jailed, skip {Address}", abstain.Address); continue; } @@ -65,13 +74,20 @@ public override IWorld Execute(IActionContext context) guildDelegatee.Slash(LivenessSlashFactor, context.BlockIndex, context.BlockIndex); guildDelegatee.Jail(context.BlockIndex + AbstainJailTime); repository.UpdateWorld(guildRepository.World); + Log.Information("[SlashValidator] Slashed and jailed {Address}", abstain.Address); } + Log.Information( + "[SlashValidator] Processing evidence, count={Count}", + context.Evidence.Count()); foreach (var evidence in context.Evidence) { switch (evidence) { case DuplicateVoteEvidence e: + Log.Information( + "[SlashValidator] DuplicateVoteEvidence target={Address}, height={Height}", + e.TargetAddress, e.Height); if (e.Height > context.BlockIndex) { throw new Exception("Evidence height is greater than block index."); @@ -86,12 +102,14 @@ public override IWorld Execute(IActionContext context) guildDelegatee.Slash(DuplicateVoteSlashFactor, e.Height, context.BlockIndex); guildDelegatee.Tombstone(); repository.UpdateWorld(guildRepository.World); + Log.Information("[SlashValidator] DuplicateVote slashed {Address}", e.TargetAddress); break; default: break; } } + Log.Information("[SlashValidator] Complete block #{BlockIndex}", context.BlockIndex); return repository.World; } }