Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

R4R: Minor changes on slashing logs and gov Querier #2259

Merged
merged 7 commits into from
Sep 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions x/gov/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 mean 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
Expand Down Expand Up @@ -143,7 +149,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 {
Expand All @@ -154,7 +160,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()))
}

Expand Down
31 changes: 21 additions & 10 deletions x/gov/queryable.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,33 @@ import (
abci "github.com/tendermint/tendermint/abci/types"
)

// query endpoints supported by the governance Querier
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")
Expand Down
24 changes: 16 additions & 8 deletions x/stake/keeper/slash.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand All @@ -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():
Expand Down Expand Up @@ -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
Expand All @@ -127,17 +127,25 @@ 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))
// TODO Return event(s), blocked on https://github.com/tendermint/tendermint/pull/1803
return
}

// 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))
// TODO Return event(s), blocked on https://github.com/tendermint/tendermint/pull/1803
return
}
Expand All @@ -146,7 +154,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
Expand Down