From 19cf663eb1baba96cb678a314e2b426cb16758d2 Mon Sep 17 00:00:00 2001 From: Federico Kunze Date: Fri, 7 Sep 2018 12:51:37 +0200 Subject: [PATCH 1/5] Minor changes logs and gov querier --- x/gov/handler.go | 6 +++--- x/gov/queryable.go | 31 +++++++++++++++++++++---------- x/stake/keeper/slash.go | 4 ++-- 3 files changed, 26 insertions(+), 15 deletions(-) diff --git a/x/gov/handler.go b/x/gov/handler.go index 59e47a14ec2e..660134c1f4e9 100644 --- a/x/gov/handler.go +++ b/x/gov/handler.go @@ -114,7 +114,7 @@ func EndBlocker(ctx sdk.Context, keeper Keeper) (resTags sdk.Tags) { resTags.AppendTag(tags.Action, tags.ActionProposalDropped) resTags.AppendTag(tags.ProposalID, proposalIDBytes) - logger.Info(fmt.Sprintf("Proposal %d - \"%s\" - didn't mean minimum deposit (had only %s), deleted", + logger.Info(fmt.Sprintf("Proposal %d (%s) didn't meet minimum deposit (had only %s). Deleted", inactiveProposal.GetProposalID(), inactiveProposal.GetTitle(), inactiveProposal.GetTotalDeposit())) } @@ -143,7 +143,7 @@ func EndBlocker(ctx sdk.Context, keeper Keeper) (resTags sdk.Tags) { activeProposal.SetTallyResult(tallyResults) keeper.SetProposal(ctx, activeProposal) - logger.Info(fmt.Sprintf("Proposal %d - \"%s\" - tallied, passed: %v", + logger.Info(fmt.Sprintf("Proposal %d (%s) tallied. Passed: %v", activeProposal.GetProposalID(), activeProposal.GetTitle(), passes)) for _, valAddr := range nonVotingVals { @@ -154,7 +154,7 @@ func EndBlocker(ctx sdk.Context, keeper Keeper) (resTags sdk.Tags) { val.GetPower().RoundInt64(), keeper.GetTallyingProcedure(ctx).GovernancePenalty) - logger.Info(fmt.Sprintf("Validator %s failed to vote on proposal %d, slashing", + logger.Info(fmt.Sprintf("Validator %s failed to vote on proposal %d. Slashing", val.GetOperator(), activeProposal.GetProposalID())) } diff --git a/x/gov/queryable.go b/x/gov/queryable.go index 090b9a91455a..45c219bd4c18 100644 --- a/x/gov/queryable.go +++ b/x/gov/queryable.go @@ -8,22 +8,33 @@ import ( abci "github.com/tendermint/tendermint/abci/types" ) +// nolint +const ( + QueryProposals = "proposals" + QueryProposal = "proposal" + QueryDeposits = "deposits" + QueryDeposit = "deposit" + QueryVotes = "votes" + QueryVote = "vote" + QueryTally = "tally" +) + func NewQuerier(keeper Keeper) sdk.Querier { return func(ctx sdk.Context, path []string, req abci.RequestQuery) (res []byte, err sdk.Error) { switch path[0] { - case "proposal": + case QueryProposals: + return queryProposals(ctx, path[1:], req, keeper) + case QueryProposal: return queryProposal(ctx, path[1:], req, keeper) - case "deposit": - return queryDeposit(ctx, path[1:], req, keeper) - case "vote": - return queryVote(ctx, path[1:], req, keeper) - case "deposits": + case QueryDeposits: return queryDeposits(ctx, path[1:], req, keeper) - case "votes": + case QueryDeposit: + return queryDeposit(ctx, path[1:], req, keeper) + case QueryVotes: return queryVotes(ctx, path[1:], req, keeper) - case "proposals": - return queryProposals(ctx, path[1:], req, keeper) - case "tally": + case QueryVote: + return queryVote(ctx, path[1:], req, keeper) + case QueryTally: return queryTally(ctx, path[1:], req, keeper) default: return nil, sdk.ErrUnknownRequest("unknown gov query endpoint") diff --git a/x/stake/keeper/slash.go b/x/stake/keeper/slash.go index e077accb7113..b5c2e6efbea2 100644 --- a/x/stake/keeper/slash.go +++ b/x/stake/keeper/slash.go @@ -117,8 +117,8 @@ func (k Keeper) Slash(ctx sdk.Context, pubkey crypto.PubKey, infractionHeight in // Log that a slash occurred! logger.Info(fmt.Sprintf( - "Validator %s slashed by slashFactor %s, burned %v tokens", - pubkey.Address(), slashFactor.String(), tokensToBurn)) + "Validator %s slashed by slash factor of %s, burned %v tokens", + validator.GetOperator(), slashFactor.String(), tokensToBurn)) // TODO Return event(s), blocked on https://github.com/tendermint/tendermint/pull/1803 return From bf36cb47298b22321266c95cf454378021208393 Mon Sep 17 00:00:00 2001 From: Federico Kunze Date: Fri, 7 Sep 2018 17:18:40 +0200 Subject: [PATCH 2/5] Address Aleks comments --- x/gov/handler.go | 8 ++++---- x/stake/keeper/slash.go | 12 ++++++------ 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/x/gov/handler.go b/x/gov/handler.go index 660134c1f4e9..7e48649462b6 100644 --- a/x/gov/handler.go +++ b/x/gov/handler.go @@ -114,8 +114,8 @@ func EndBlocker(ctx sdk.Context, keeper Keeper) (resTags sdk.Tags) { resTags.AppendTag(tags.Action, tags.ActionProposalDropped) resTags.AppendTag(tags.ProposalID, proposalIDBytes) - logger.Info(fmt.Sprintf("Proposal %d (%s) didn't meet minimum deposit (had only %s). Deleted", - inactiveProposal.GetProposalID(), inactiveProposal.GetTitle(), inactiveProposal.GetTotalDeposit())) + logger.Info(fmt.Sprintf("proposal %d (%s) didn't meet minimum deposit of %v steak (had only %s steak); deleted", + inactiveProposal.GetProposalID(), inactiveProposal.GetTitle(), keeper.GetDepositProcedure(ctx).MinDeposit.AmountOf("steak"), inactiveProposal.GetTotalDeposit().AmountOf("steak"))) } // Check if earliest Active Proposal ended voting period yet @@ -143,7 +143,7 @@ func EndBlocker(ctx sdk.Context, keeper Keeper) (resTags sdk.Tags) { activeProposal.SetTallyResult(tallyResults) keeper.SetProposal(ctx, activeProposal) - logger.Info(fmt.Sprintf("Proposal %d (%s) tallied. Passed: %v", + logger.Info(fmt.Sprintf("proposal %d (%s) tallied; passed: %v", activeProposal.GetProposalID(), activeProposal.GetTitle(), passes)) for _, valAddr := range nonVotingVals { @@ -154,7 +154,7 @@ func EndBlocker(ctx sdk.Context, keeper Keeper) (resTags sdk.Tags) { val.GetPower().RoundInt64(), keeper.GetTallyingProcedure(ctx).GovernancePenalty) - logger.Info(fmt.Sprintf("Validator %s failed to vote on proposal %d. Slashing", + logger.Info(fmt.Sprintf("validator %s failed to vote on proposal %d; slashing", val.GetOperator(), activeProposal.GetProposalID())) } diff --git a/x/stake/keeper/slash.go b/x/stake/keeper/slash.go index b5c2e6efbea2..ffe016959811 100644 --- a/x/stake/keeper/slash.go +++ b/x/stake/keeper/slash.go @@ -50,7 +50,7 @@ func (k Keeper) Slash(ctx sdk.Context, pubkey crypto.PubKey, infractionHeight in // should not be slashing unbonded if validator.IsUnbonded(ctx) { - panic(fmt.Sprintf("should not be slashing unbonded validator: %v", validator)) + panic(fmt.Sprintf("should not be slashing unbonded validator: %s", validator.GetOperator())) } operatorAddress := validator.GetOperator() @@ -72,7 +72,7 @@ func (k Keeper) Slash(ctx sdk.Context, pubkey crypto.PubKey, infractionHeight in // Special-case slash at current height for efficiency - we don't need to look through unbonding delegations or redelegations logger.Info(fmt.Sprintf( - "Slashing at current height %d, not scanning unbonding delegations & redelegations", + "slashing at current height %d, not scanning unbonding delegations & redelegations", infractionHeight)) case infractionHeight < ctx.BlockHeight(): @@ -117,7 +117,7 @@ func (k Keeper) Slash(ctx sdk.Context, pubkey crypto.PubKey, infractionHeight in // Log that a slash occurred! logger.Info(fmt.Sprintf( - "Validator %s slashed by slash factor of %s, burned %v tokens", + "validator %s slashed by slash factor of %s; burned %v tokens", validator.GetOperator(), slashFactor.String(), tokensToBurn)) // TODO Return event(s), blocked on https://github.com/tendermint/tendermint/pull/1803 @@ -128,7 +128,7 @@ func (k Keeper) Slash(ctx sdk.Context, pubkey crypto.PubKey, infractionHeight in func (k Keeper) Jail(ctx sdk.Context, pubkey crypto.PubKey) { k.setJailed(ctx, pubkey, true) logger := ctx.Logger().With("module", "x/stake") - logger.Info(fmt.Sprintf("Validator %s jailed", pubkey.Address())) + logger.Info(fmt.Sprintf("validator %s jailed", pubkey.Address())) // TODO Return event(s), blocked on https://github.com/tendermint/tendermint/pull/1803 return } @@ -137,7 +137,7 @@ func (k Keeper) Jail(ctx sdk.Context, pubkey crypto.PubKey) { func (k Keeper) Unjail(ctx sdk.Context, pubkey crypto.PubKey) { k.setJailed(ctx, pubkey, false) logger := ctx.Logger().With("module", "x/stake") - logger.Info(fmt.Sprintf("Validator %s unjailed", pubkey.Address())) + logger.Info(fmt.Sprintf("validator %s unjailed", pubkey.Address())) // TODO Return event(s), blocked on https://github.com/tendermint/tendermint/pull/1803 return } @@ -146,7 +146,7 @@ func (k Keeper) Unjail(ctx sdk.Context, pubkey crypto.PubKey) { func (k Keeper) setJailed(ctx sdk.Context, pubkey crypto.PubKey, isJailed bool) { validator, found := k.GetValidatorByPubKey(ctx, pubkey) if !found { - panic(fmt.Errorf("Validator with pubkey %s not found, cannot set jailed to %v", pubkey, isJailed)) + panic(fmt.Errorf("validator with pubkey %s not found, cannot set jailed to %v", pubkey, isJailed)) } validator.Jailed = isJailed k.UpdateValidator(ctx, validator) // update validator, possibly unbonding or bonding it From aba504b6c547de5e81ebd53e815c7c34bb67870f Mon Sep 17 00:00:00 2001 From: Federico Kunze Date: Fri, 7 Sep 2018 17:26:46 +0200 Subject: [PATCH 3/5] Updated (un)jail logs --- x/stake/keeper/slash.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/x/stake/keeper/slash.go b/x/stake/keeper/slash.go index ffe016959811..f4a171df198b 100644 --- a/x/stake/keeper/slash.go +++ b/x/stake/keeper/slash.go @@ -127,8 +127,12 @@ func (k Keeper) Slash(ctx sdk.Context, pubkey crypto.PubKey, infractionHeight in // jail a validator func (k Keeper) Jail(ctx sdk.Context, pubkey crypto.PubKey) { k.setJailed(ctx, pubkey, true) + validatorAddr, err := sdk.ValAddressFromHex(pubkey.Address().String()) + if err != nil { + panic(err.Error()) + } logger := ctx.Logger().With("module", "x/stake") - logger.Info(fmt.Sprintf("validator %s jailed", pubkey.Address())) + logger.Info(fmt.Sprintf("validator %s jailed", validatorAddr.String())) // TODO Return event(s), blocked on https://github.com/tendermint/tendermint/pull/1803 return } @@ -136,8 +140,12 @@ func (k Keeper) Jail(ctx sdk.Context, pubkey crypto.PubKey) { // unjail a validator func (k Keeper) Unjail(ctx sdk.Context, pubkey crypto.PubKey) { k.setJailed(ctx, pubkey, false) + validatorAddr, err := sdk.ValAddressFromHex(pubkey.Address().String()) + if err != nil { + panic(err.Error()) + } logger := ctx.Logger().With("module", "x/stake") - logger.Info(fmt.Sprintf("validator %s unjailed", pubkey.Address())) + logger.Info(fmt.Sprintf("validator %s unjailed", validatorAddr.String())) // TODO Return event(s), blocked on https://github.com/tendermint/tendermint/pull/1803 return } From 881a9f22cd8f4a9e51e5e1780e048f886a414f4a Mon Sep 17 00:00:00 2001 From: Federico Kunze Date: Sun, 9 Sep 2018 19:49:14 +0200 Subject: [PATCH 4/5] Update logs --- x/gov/handler.go | 10 ++++++++-- x/stake/keeper/slash.go | 6 +++--- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/x/gov/handler.go b/x/gov/handler.go index 7e48649462b6..0bfd42083e0f 100644 --- a/x/gov/handler.go +++ b/x/gov/handler.go @@ -114,8 +114,14 @@ func EndBlocker(ctx sdk.Context, keeper Keeper) (resTags sdk.Tags) { resTags.AppendTag(tags.Action, tags.ActionProposalDropped) resTags.AppendTag(tags.ProposalID, proposalIDBytes) - logger.Info(fmt.Sprintf("proposal %d (%s) didn't meet minimum deposit of %v steak (had only %s steak); deleted", - inactiveProposal.GetProposalID(), inactiveProposal.GetTitle(), keeper.GetDepositProcedure(ctx).MinDeposit.AmountOf("steak"), inactiveProposal.GetTotalDeposit().AmountOf("steak"))) + logger.Info( + fmt.Sprintf("proposal %d (%s) didn't meet minimum deposit of %v steak (had only %s steak); deleted", + inactiveProposal.GetProposalID(), + inactiveProposal.GetTitle(), + keeper.GetDepositProcedure(ctx).MinDeposit.AmountOf("steak"), + inactiveProposal.GetTotalDeposit().AmountOf("steak"), + ), + ) } // Check if earliest Active Proposal ended voting period yet diff --git a/x/stake/keeper/slash.go b/x/stake/keeper/slash.go index f4a171df198b..fe75f421dae3 100644 --- a/x/stake/keeper/slash.go +++ b/x/stake/keeper/slash.go @@ -28,7 +28,7 @@ func (k Keeper) Slash(ctx sdk.Context, pubkey crypto.PubKey, infractionHeight in logger := ctx.Logger().With("module", "x/stake") if slashFactor.LT(sdk.ZeroDec()) { - panic(fmt.Errorf("attempted to slash with a negative slashFactor: %v", slashFactor)) + panic(fmt.Errorf("attempted to slash with a negative slash factor: %v", slashFactor)) } // Amount of slashing = slash slashFactor * power at time of infraction @@ -132,7 +132,7 @@ func (k Keeper) Jail(ctx sdk.Context, pubkey crypto.PubKey) { panic(err.Error()) } logger := ctx.Logger().With("module", "x/stake") - logger.Info(fmt.Sprintf("validator %s jailed", validatorAddr.String())) + logger.Info(fmt.Sprintf("validator %s jailed", validatorAddr)) // TODO Return event(s), blocked on https://github.com/tendermint/tendermint/pull/1803 return } @@ -145,7 +145,7 @@ func (k Keeper) Unjail(ctx sdk.Context, pubkey crypto.PubKey) { panic(err.Error()) } logger := ctx.Logger().With("module", "x/stake") - logger.Info(fmt.Sprintf("validator %s unjailed", validatorAddr.String())) + logger.Info(fmt.Sprintf("validator %s unjailed", validatorAddr)) // TODO Return event(s), blocked on https://github.com/tendermint/tendermint/pull/1803 return } From 8233bb76b0f00432f28bd46885dcd312ed209e1a Mon Sep 17 00:00:00 2001 From: Federico Kunze Date: Tue, 11 Sep 2018 16:10:17 +0200 Subject: [PATCH 5/5] Add comment to querier constants --- x/gov/queryable.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/gov/queryable.go b/x/gov/queryable.go index 45c219bd4c18..6aa0c9884a44 100644 --- a/x/gov/queryable.go +++ b/x/gov/queryable.go @@ -8,7 +8,7 @@ import ( abci "github.com/tendermint/tendermint/abci/types" ) -// nolint +// query endpoints supported by the governance Querier const ( QueryProposals = "proposals" QueryProposal = "proposal"