Skip to content

Commit

Permalink
Revert "Return errors instead of panic (cosmos#3782)" (cosmos#4054)
Browse files Browse the repository at this point in the history
This reverts commit 985aae5.
  • Loading branch information
rigelrozanski authored Apr 5, 2019
1 parent 055d219 commit cec3065
Show file tree
Hide file tree
Showing 28 changed files with 135 additions and 296 deletions.
1 change: 0 additions & 1 deletion .pending/breaking/sdk/3782-Return-errors-i

This file was deleted.

12 changes: 2 additions & 10 deletions baseapp/baseapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,6 @@ func (app *BaseApp) validateHeight(req abci.RequestBeginBlock) error {

// BeginBlock implements the ABCI application interface.
func (app *BaseApp) BeginBlock(req abci.RequestBeginBlock) (res abci.ResponseBeginBlock) {
var err error
if app.cms.TracingEnabled() {
app.cms.SetTracingContext(sdk.TraceContext(
map[string]interface{}{"blockHeight": req.Header.Height},
Expand Down Expand Up @@ -573,10 +572,7 @@ func (app *BaseApp) BeginBlock(req abci.RequestBeginBlock) (res abci.ResponseBeg
app.deliverState.ctx = app.deliverState.ctx.WithBlockGasMeter(gasMeter)

if app.beginBlocker != nil {
res, err = app.beginBlocker(app.deliverState.ctx, req)
if err != nil {
panic(err)
}
res = app.beginBlocker(app.deliverState.ctx, req)
}

// set the signed validators for addition to context in deliverTx
Expand Down Expand Up @@ -878,16 +874,12 @@ func (app *BaseApp) runTx(mode runTxMode, txBytes []byte, tx sdk.Tx) (result sdk

// EndBlock implements the ABCI interface.
func (app *BaseApp) EndBlock(req abci.RequestEndBlock) (res abci.ResponseEndBlock) {
var err error
if app.deliverState.ms.TracingEnabled() {
app.deliverState.ms = app.deliverState.ms.SetTracingContext(nil).(sdk.CacheMultiStore)
}

if app.endBlocker != nil {
res, err = app.endBlocker(app.deliverState.ctx, req)
if err != nil {
panic(err)
}
res = app.endBlocker(app.deliverState.ctx, req)
}

return
Expand Down
33 changes: 12 additions & 21 deletions cmd/gaia/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,39 +216,30 @@ func MakeCodec() *codec.Codec {
}

// application updates every end block
func (app *GaiaApp) BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock) (resp abci.ResponseBeginBlock, err error) {
func (app *GaiaApp) BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock) abci.ResponseBeginBlock {
// mint new tokens for the previous block
err = mint.BeginBlocker(ctx, app.mintKeeper)
if err != nil {
return resp, err
}
mint.BeginBlocker(ctx, app.mintKeeper)

// distribute rewards for the previous block
err = distr.BeginBlocker(ctx, req, app.distrKeeper)
if err != nil {
return resp, err
}
distr.BeginBlocker(ctx, req, app.distrKeeper)

// slash anyone who double signed.
// NOTE: This should happen after distr.BeginBlocker so that
// there is nothing left over in the validator fee pool,
// so as to keep the CanWithdrawInvariant invariant.
// TODO: This should really happen at EndBlocker.
resp.Tags, err = slashing.BeginBlocker(ctx, req, app.slashingKeeper)
return resp, err
tags := slashing.BeginBlocker(ctx, req, app.slashingKeeper)

return abci.ResponseBeginBlock{
Tags: tags.ToKVPairs(),
}
}

// application updates every end block
// nolint: unparam
func (app *GaiaApp) EndBlocker(ctx sdk.Context, req abci.RequestEndBlock) (abci.ResponseEndBlock, error) {
tags, err := gov.EndBlocker(ctx, app.govKeeper)
if err != nil {
return abci.ResponseEndBlock{}, err
}
validatorUpdates, endBlockerTags, err := staking.EndBlocker(ctx, app.stakingKeeper)
if err != nil {
return abci.ResponseEndBlock{}, err
}
func (app *GaiaApp) EndBlocker(ctx sdk.Context, req abci.RequestEndBlock) abci.ResponseEndBlock {
tags := gov.EndBlocker(ctx, app.govKeeper)
validatorUpdates, endBlockerTags := staking.EndBlocker(ctx, app.stakingKeeper)
tags = append(tags, endBlockerTags...)

if app.assertInvariantsBlockly {
Expand All @@ -258,7 +249,7 @@ func (app *GaiaApp) EndBlocker(ctx sdk.Context, req abci.RequestEndBlock) (abci.
return abci.ResponseEndBlock{
ValidatorUpdates: validatorUpdates,
Tags: tags,
}, nil
}
}

// initialize store from a genesis state
Expand Down
6 changes: 1 addition & 5 deletions cmd/gaia/app/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,12 @@ func (app *GaiaApp) ExportAppStateAndValidators(forZeroHeight bool, jailWhiteLis
}
app.accountKeeper.IterateAccounts(ctx, appendAccount)

mintGenesisState, err := mint.ExportGenesis(ctx, app.mintKeeper)
if err != nil {
return nil, nil, err
}
genState := NewGenesisState(
accounts,
auth.ExportGenesis(ctx, app.accountKeeper, app.feeCollectionKeeper),
bank.ExportGenesis(ctx, app.bankKeeper),
staking.ExportGenesis(ctx, app.stakingKeeper),
mintGenesisState,
mint.ExportGenesis(ctx, app.mintKeeper),
distr.ExportGenesis(ctx, app.distrKeeper),
gov.ExportGenesis(ctx, app.govKeeper),
crisis.ExportGenesis(ctx, app.crisisKeeper),
Expand Down
18 changes: 9 additions & 9 deletions cmd/gaia/cmd/gaiadebug/hack.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,23 +218,23 @@ func MakeCodec() *codec.Codec {
}

// application updates every end block
func (app *GaiaApp) BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock) (resp abci.ResponseBeginBlock, err error) {
resp.Tags, err = slashing.BeginBlocker(ctx, req, app.slashingKeeper)
return resp, err
func (app *GaiaApp) BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock) abci.ResponseBeginBlock {
tags := slashing.BeginBlocker(ctx, req, app.slashingKeeper)

return abci.ResponseBeginBlock{
Tags: tags.ToKVPairs(),
}
}

// application updates every end block
// nolint: unparam
func (app *GaiaApp) EndBlocker(ctx sdk.Context, req abci.RequestEndBlock) (abci.ResponseEndBlock, error) {
validatorUpdates, tags, err := staking.EndBlocker(ctx, app.stakingKeeper)
if err != nil {
return abci.ResponseEndBlock{}, err
}
func (app *GaiaApp) EndBlocker(ctx sdk.Context, req abci.RequestEndBlock) abci.ResponseEndBlock {
validatorUpdates, tags := staking.EndBlocker(ctx, app.stakingKeeper)

return abci.ResponseEndBlock{
ValidatorUpdates: validatorUpdates,
Tags: tags,
}, nil
}
}

// custom logic for gaia initialization
Expand Down
4 changes: 2 additions & 2 deletions types/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import abci "github.com/tendermint/tendermint/abci/types"
type InitChainer func(ctx Context, req abci.RequestInitChain) abci.ResponseInitChain

// run code before the transactions in a block
type BeginBlocker func(ctx Context, req abci.RequestBeginBlock) (abci.ResponseBeginBlock, error)
type BeginBlocker func(ctx Context, req abci.RequestBeginBlock) abci.ResponseBeginBlock

// run code after the transactions in a block and return updates to the validator set
type EndBlocker func(ctx Context, req abci.RequestEndBlock) (abci.ResponseEndBlock, error)
type EndBlocker func(ctx Context, req abci.RequestEndBlock) abci.ResponseEndBlock

// respond to p2p filtering queries from Tendermint
type PeerFilter func(info string) abci.ResponseQuery
7 changes: 1 addition & 6 deletions x/bank/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,12 +168,7 @@ func (keeper BaseSendKeeper) GetSendEnabled(ctx sdk.Context) bool {

// SetSendEnabled sets the send enabled
func (keeper BaseSendKeeper) SetSendEnabled(ctx sdk.Context, enabled bool) {
err := keeper.paramSpace.Set(ctx, ParamStoreKeySendEnabled, &enabled)
if err != nil {
// TODO: return error - needs rewrite interfaces
// and handle error on the caller side
// check PR #3782
}
keeper.paramSpace.Set(ctx, ParamStoreKeySendEnabled, &enabled)
}

var _ ViewKeeper = (*BaseViewKeeper)(nil)
Expand Down
12 changes: 2 additions & 10 deletions x/crisis/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,11 @@ func ParamKeyTable() params.KeyTable {

// GetConstantFee get's the constant fee from the paramSpace
func (k Keeper) GetConstantFee(ctx sdk.Context) (constantFee sdk.Coin) {
if err := k.paramSpace.Get(ctx, ParamStoreKeyConstantFee, &constantFee); err != nil {
// TODO: return error - needs rewrite interfaces
// and handle error on the caller side
// check PR #3782
}
k.paramSpace.Get(ctx, ParamStoreKeyConstantFee, &constantFee)
return
}

// GetConstantFee set's the constant fee in the paramSpace
func (k Keeper) SetConstantFee(ctx sdk.Context, constantFee sdk.Coin) {
if err := k.paramSpace.Set(ctx, ParamStoreKeyConstantFee, constantFee); err != nil {
// TODO: return error - needs rewrite interfaces
// and handle error on the caller side
// check PR #3782
}
k.paramSpace.Set(ctx, ParamStoreKeyConstantFee, constantFee)
}
4 changes: 2 additions & 2 deletions x/distribution/abci_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
)

// set the proposer for determining distribution during endblock
func BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock, k keeper.Keeper) error {
func BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock, k keeper.Keeper) {

// determine the total power signing the block
var previousTotalPower, sumPreviousPrecommitPower int64
Expand All @@ -29,5 +29,5 @@ func BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock, k keeper.Keeper)
// record the proposer for when we payout on the next block
consAddr := sdk.ConsAddress(req.Header.ProposerAddress)
k.SetPreviousProposerConsAddr(ctx, consAddr)
return nil

}
4 changes: 2 additions & 2 deletions x/gov/endblocker.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
)

// Called every block, process inflation, update validator set
func EndBlocker(ctx sdk.Context, keeper Keeper) (sdk.Tags, error) {
func EndBlocker(ctx sdk.Context, keeper Keeper) sdk.Tags {
logger := ctx.Logger().With("module", "x/gov")
resTags := sdk.NewTags()

Expand Down Expand Up @@ -78,5 +78,5 @@ func EndBlocker(ctx sdk.Context, keeper Keeper) (sdk.Tags, error) {
resTags = resTags.AppendTag(tags.ProposalResult, tagValue)
}

return resTags, nil
return resTags
}
42 changes: 6 additions & 36 deletions x/gov/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,64 +261,34 @@ func (keeper Keeper) activateVotingPeriod(ctx sdk.Context, proposal Proposal) {
// Returns the current DepositParams from the global param store
func (keeper Keeper) GetDepositParams(ctx sdk.Context) DepositParams {
var depositParams DepositParams
err := keeper.paramSpace.Get(ctx, ParamStoreKeyDepositParams, &depositParams)
if err != nil {
// TODO: return error - needs rewrite interfaces
// and handle error on the caller side
// check PR #3782
}
keeper.paramSpace.Get(ctx, ParamStoreKeyDepositParams, &depositParams)
return depositParams
}

// Returns the current VotingParams from the global param store
func (keeper Keeper) GetVotingParams(ctx sdk.Context) VotingParams {
var votingParams VotingParams
err := keeper.paramSpace.Get(ctx, ParamStoreKeyVotingParams, &votingParams)
if err != nil {
// TODO: return error - needs rewrite interfaces
// and handle error on the caller side
// check PR #3782
}
keeper.paramSpace.Get(ctx, ParamStoreKeyVotingParams, &votingParams)
return votingParams
}

// Returns the current TallyParam from the global param store
func (keeper Keeper) GetTallyParams(ctx sdk.Context) TallyParams {
var tallyParams TallyParams
err := keeper.paramSpace.Get(ctx, ParamStoreKeyTallyParams, &tallyParams)
if err != nil {
// TODO: return error - needs rewrite interfaces
// and handle error on the caller side
// check PR #3782
}
keeper.paramSpace.Get(ctx, ParamStoreKeyTallyParams, &tallyParams)
return tallyParams
}

func (keeper Keeper) setDepositParams(ctx sdk.Context, depositParams DepositParams) {
err := keeper.paramSpace.Set(ctx, ParamStoreKeyDepositParams, &depositParams)
if err != nil {
// TODO: return error - needs rewrite interfaces
// and handle error on the caller side
// check PR #3782
}
keeper.paramSpace.Set(ctx, ParamStoreKeyDepositParams, &depositParams)
}

func (keeper Keeper) setVotingParams(ctx sdk.Context, votingParams VotingParams) {
err := keeper.paramSpace.Set(ctx, ParamStoreKeyVotingParams, &votingParams)
if err != nil {
// TODO: return error - needs rewrite interfaces
// and handle error on the caller side
// check PR #3782
}
keeper.paramSpace.Set(ctx, ParamStoreKeyVotingParams, &votingParams)
}

func (keeper Keeper) setTallyParams(ctx sdk.Context, tallyParams TallyParams) {
err := keeper.paramSpace.Set(ctx, ParamStoreKeyTallyParams, &tallyParams)
if err != nil {
// TODO: return error - needs rewrite interfaces
// and handle error on the caller side
// check PR #3782
}
keeper.paramSpace.Set(ctx, ParamStoreKeyTallyParams, &tallyParams)
}

// Votes
Expand Down
6 changes: 3 additions & 3 deletions x/gov/test_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ func getMockApp(t *testing.T, numGenAccs int, genState GenesisState, genAccs []a

// gov and staking endblocker
func getEndBlocker(keeper Keeper) sdk.EndBlocker {
return func(ctx sdk.Context, req abci.RequestEndBlock) (abci.ResponseEndBlock, error) {
tags, err := EndBlocker(ctx, keeper)
return func(ctx sdk.Context, req abci.RequestEndBlock) abci.ResponseEndBlock {
tags := EndBlocker(ctx, keeper)
return abci.ResponseEndBlock{
Tags: tags,
}, err
}
}
}

Expand Down
13 changes: 3 additions & 10 deletions x/mint/abci_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,11 @@ import (
)

// Inflate every block, update inflation parameters once per hour
func BeginBlocker(ctx sdk.Context, k Keeper) error {
func BeginBlocker(ctx sdk.Context, k Keeper) {

// fetch stored minter & params
minter, err := k.GetMinter(ctx)
if err != nil {
return err
}
params, err := k.GetParams(ctx)
if err != nil {
return err
}
minter := k.GetMinter(ctx)
params := k.GetParams(ctx)

// recalculate inflation rate
totalSupply := k.sk.TotalTokens(ctx)
Expand All @@ -28,6 +22,5 @@ func BeginBlocker(ctx sdk.Context, k Keeper) error {
mintedCoin := minter.BlockProvision(params)
k.fck.AddCollectedFees(ctx, sdk.Coins{mintedCoin})
k.sk.InflateSupply(ctx, mintedCoin.Amount)
return nil

}
24 changes: 7 additions & 17 deletions x/mint/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,25 +29,15 @@ func DefaultGenesisState() GenesisState {
// new mint genesis
func InitGenesis(ctx sdk.Context, keeper Keeper, data GenesisState) {
keeper.SetMinter(ctx, data.Minter)
if err := keeper.SetParams(ctx, data.Params); err != nil {
// TODO: return error - needs rewrite interfaces
// and handle error on the caller side
// check PR #3782
}
keeper.SetParams(ctx, data.Params)
}

// ExportGenesis returns a GenesisState for a given context and keeper. The
// GenesisState will contain the pool, and validator/delegator distribution info's
func ExportGenesis(ctx sdk.Context, keeper Keeper) (GenesisState, error) {
minter, err := keeper.GetMinter(ctx)
if err != nil {
return GenesisState{}, err
}
params, err := keeper.GetParams(ctx)
if err != nil {
return GenesisState{}, err
}
return NewGenesisState(minter, params), nil
// ExportGenesis returns a GenesisState for a given context and keeper.
func ExportGenesis(ctx sdk.Context, keeper Keeper) GenesisState {

minter := keeper.GetMinter(ctx)
params := keeper.GetParams(ctx)
return NewGenesisState(minter, params)
}

// ValidateGenesis validates the provided genesis state to ensure the
Expand Down
Loading

0 comments on commit cec3065

Please sign in to comment.