diff --git a/x/opchild/genesis.go b/x/opchild/genesis.go index 66049892..34afba37 100644 --- a/x/opchild/genesis.go +++ b/x/opchild/genesis.go @@ -18,7 +18,7 @@ func WriteValidators(ctx context.Context, keeper *keeper.Keeper) (vals []tmtypes if err != nil { return true, err } - tmPk, err := cryptocodec.ToTmPubKeyInterface(pk) + tmPk, err := cryptocodec.ToCmtPubKeyInterface(pk) if err != nil { return true, err } diff --git a/x/opchild/keeper/genesis.go b/x/opchild/keeper/genesis.go index 0b2e6017..159e6d94 100644 --- a/x/opchild/keeper/genesis.go +++ b/x/opchild/keeper/genesis.go @@ -30,7 +30,9 @@ func (k Keeper) InitGenesis(ctx context.Context, data *types.GenesisState) (res } for _, validator := range data.Validators { - k.SetValidator(ctx, validator) + if err := k.SetValidator(ctx, validator); err != nil { + panic(err) + } // Manually set indices for the first time if err := k.SetValidatorByConsAddr(ctx, validator); err != nil { @@ -46,7 +48,10 @@ func (k Keeper) InitGenesis(ctx context.Context, data *types.GenesisState) (res panic(err) } - k.SetLastValidatorPower(ctx, valAddr, lv.Power) + if err := k.SetLastValidatorPower(ctx, valAddr, lv.Power); err != nil { + panic(err) + } + validator, found := k.GetValidator(ctx, valAddr) if !found { @@ -67,10 +72,14 @@ func (k Keeper) InitGenesis(ctx context.Context, data *types.GenesisState) (res } for _, finalizedL1Sequence := range data.FinalizedL1Sequences { - k.RecordFinalizedL1Sequence(ctx, finalizedL1Sequence) + if err := k.RecordFinalizedL1Sequence(ctx, finalizedL1Sequence); err != nil { + panic(err) + } } - k.SetNextL2Sequence(ctx, data.NextL2Sequence) + if err := k.SetNextL2Sequence(ctx, data.NextL2Sequence); err != nil { + panic(err) + } return res } diff --git a/x/opchild/keeper/historical_info.go b/x/opchild/keeper/historical_info.go index a1b398bf..7c11a369 100644 --- a/x/opchild/keeper/historical_info.go +++ b/x/opchild/keeper/historical_info.go @@ -55,7 +55,9 @@ func (k Keeper) TrackHistoricalInfo(ctx context.Context) error { if err != nil { return err } else if found { - k.DeleteHistoricalInfo(ctx, i) + if err := k.DeleteHistoricalInfo(ctx, i); err != nil { + return err + } } else { break } diff --git a/x/opchild/keeper/msg_server.go b/x/opchild/keeper/msg_server.go index 1824db80..d40e0e89 100644 --- a/x/opchild/keeper/msg_server.go +++ b/x/opchild/keeper/msg_server.go @@ -188,7 +188,9 @@ func (ms MsgServer) AddValidator(ctx context.Context, req *types.MsgAddValidator return nil, err } - ms.SetValidator(ctx, validator) + if err := ms.SetValidator(ctx, validator); err != nil { + return nil, err + } if err = ms.SetValidatorByConsAddr(ctx, validator); err != nil { return nil, err } @@ -227,7 +229,9 @@ func (ms MsgServer) RemoveValidator(ctx context.Context, req *types.MsgRemoveVal // set validator consensus power `0`, // then `val_state_change` will execute `k.RemoveValidator`. - ms.Keeper.SetValidator(ctx, val) + if err := ms.Keeper.SetValidator(ctx, val); err != nil { + return nil, err + } sdkCtx.EventManager().EmitEvents(sdk.Events{ sdk.NewEvent( @@ -323,7 +327,9 @@ func (ms MsgServer) FinalizeTokenDeposit(ctx context.Context, req *types.MsgFina return nil, err } - ms.RecordFinalizedL1Sequence(ctx, req.Sequence) + if err := ms.RecordFinalizedL1Sequence(ctx, req.Sequence); err != nil { + return nil, err + } event := sdk.NewEvent( types.EventTypeFinalizeTokenDeposit, diff --git a/x/opchild/keeper/val_state_change.go b/x/opchild/keeper/val_state_change.go index 49d07865..0b3b47a1 100644 --- a/x/opchild/keeper/val_state_change.go +++ b/x/opchild/keeper/val_state_change.go @@ -57,7 +57,9 @@ func (k Keeper) ApplyAndReturnValidatorSetUpdates(ctx context.Context) ([]abci.V if !found || oldPower != newPower { updates = append(updates, validator.ABCIValidatorUpdate()) - k.SetLastValidatorPower(ctx, valAddr, newPower) + if err := k.SetLastValidatorPower(ctx, valAddr, newPower); err != nil { + return nil, err + } } delete(last, validator.GetOperator()) @@ -75,8 +77,14 @@ func (k Keeper) ApplyAndReturnValidatorSetUpdates(ctx context.Context) ([]abci.V return nil, err } - k.RemoveValidator(ctx, valAddr) - k.DeleteLastValidatorPower(ctx, valAddr) + if err := k.RemoveValidator(ctx, valAddr); err != nil { + return nil, err + } + + if err := k.DeleteLastValidatorPower(ctx, valAddr); err != nil { + return nil, err + } + updates = append(updates, validator.ABCIValidatorUpdateZero()) } @@ -91,12 +99,12 @@ type validatorsByAddr map[string]int64 func (k Keeper) getLastValidatorsByAddr(ctx context.Context) (validatorsByAddr, error) { last := make(validatorsByAddr) - k.IterateLastValidators(ctx, func(validator types.ValidatorI, power int64) (stop bool, err error) { + err := k.IterateLastValidators(ctx, func(validator types.ValidatorI, power int64) (stop bool, err error) { last[validator.GetOperator()] = power return false, nil }) - return last, nil + return last, err } // given a map of remaining validators to previous bonded power diff --git a/x/opchild/keeper/validator.go b/x/opchild/keeper/validator.go index 9b79f248..57ea496a 100644 --- a/x/opchild/keeper/validator.go +++ b/x/opchild/keeper/validator.go @@ -94,23 +94,23 @@ func (k Keeper) RemoveValidator(ctx context.Context, address sdk.ValAddress) err // get the set of all validators with no limits, used during genesis dump func (k Keeper) GetAllValidators(ctx context.Context) (validators []types.Validator, err error) { - k.Validators.Walk(ctx, nil, func(key []byte, validator types.Validator) (stop bool, err error) { + err = k.Validators.Walk(ctx, nil, func(key []byte, validator types.Validator) (stop bool, err error) { validators = append(validators, validator) return false, nil }) - return validators, nil + return validators, err } // return a given amount of all the validators func (k Keeper) GetValidators(ctx context.Context, maxRetrieve uint32) (validators []types.Validator, err error) { validators = make([]types.Validator, 0, maxRetrieve) - k.Validators.Walk(ctx, nil, func(key []byte, validator types.Validator) (stop bool, err error) { + err = k.Validators.Walk(ctx, nil, func(key []byte, validator types.Validator) (stop bool, err error) { validators = append(validators, validator) return len(validators) == int(maxRetrieve), nil }) - return validators, nil + return validators, err } // Last Validator Index @@ -154,7 +154,7 @@ func (k Keeper) GetLastValidators(ctx context.Context) (validators []types.Valid validators = make([]types.Validator, 0, maxValidators) - k.IterateLastValidatorPowers(ctx, func(operator []byte, power int64) (stop bool, err error) { + err = k.IterateLastValidatorPowers(ctx, func(operator []byte, power int64) (stop bool, err error) { validators = append(validators, k.mustGetValidator(ctx, operator)) // sanity check @@ -165,5 +165,5 @@ func (k Keeper) GetLastValidators(ctx context.Context) (validators []types.Valid return false, nil }) - return validators, nil + return validators, err } diff --git a/x/opchild/types/validator.go b/x/opchild/types/validator.go index ff965267..48e7787d 100644 --- a/x/opchild/types/validator.go +++ b/x/opchild/types/validator.go @@ -6,7 +6,7 @@ import ( "strings" abci "github.com/cometbft/cometbft/abci/types" - tmprotocrypto "github.com/cometbft/cometbft/proto/tendermint/crypto" + cmtprotocrypto "github.com/cometbft/cometbft/proto/tendermint/crypto" "sigs.k8s.io/yaml" "cosmossdk.io/core/address" @@ -227,16 +227,16 @@ func (v Validator) ConsPubKey() (cryptotypes.PubKey, error) { return pk, nil } -// TmConsPublicKey casts Validator.ConsensusPubkey to tmprotocrypto.PubKey. -func (v Validator) TmConsPublicKey() (tmprotocrypto.PublicKey, error) { +// TmConsPublicKey casts Validator.ConsensusPubkey to cmtprotocrypto.PubKey. +func (v Validator) TmConsPublicKey() (cmtprotocrypto.PublicKey, error) { pk, err := v.ConsPubKey() if err != nil { - return tmprotocrypto.PublicKey{}, err + return cmtprotocrypto.PublicKey{}, err } - tmPk, err := cryptocodec.ToTmProtoPublicKey(pk) + tmPk, err := cryptocodec.ToCmtProtoPublicKey(pk) if err != nil { - return tmprotocrypto.PublicKey{}, err + return cmtprotocrypto.PublicKey{}, err } return tmPk, nil diff --git a/x/ophost/keeper/genesis.go b/x/ophost/keeper/genesis.go index a5cb3d1f..85cfaf69 100644 --- a/x/ophost/keeper/genesis.go +++ b/x/ophost/keeper/genesis.go @@ -21,7 +21,9 @@ func (k Keeper) InitGenesis(ctx sdk.Context, data *types.GenesisState) { panic(err) } - k.SetNextL1Sequence(ctx, bridgeId, bridge.NextL1Sequence) + if err := k.SetNextL1Sequence(ctx, bridgeId, bridge.NextL1Sequence); err != nil { + panic(err) + } for _, proposal := range bridge.Proposals { if err := k.SetOutputProposal(ctx, bridgeId, proposal.OutputIndex, proposal.OutputProposal); err != nil { @@ -29,20 +31,28 @@ func (k Keeper) InitGenesis(ctx sdk.Context, data *types.GenesisState) { } } - k.SetNextOutputIndex(ctx, bridgeId, bridge.NextOutputIndex) + if err := k.SetNextOutputIndex(ctx, bridgeId, bridge.NextOutputIndex); err != nil { + panic(err) + } for _, provenWithdrawal := range bridge.ProvenWithdrawals { withdrawalHash := [32]byte{} copy(withdrawalHash[:], provenWithdrawal) - k.RecordProvenWithdrawal(ctx, bridgeId, withdrawalHash) + if err := k.RecordProvenWithdrawal(ctx, bridgeId, withdrawalHash); err != nil { + panic(err) + } } for _, tokenPair := range bridge.TokenPairs { - k.SetTokenPair(ctx, bridgeId, tokenPair.L2Denom, tokenPair.L1Denom) + if err := k.SetTokenPair(ctx, bridgeId, tokenPair.L2Denom, tokenPair.L1Denom); err != nil { + panic(err) + } } } - k.SetNextBridgeId(ctx, data.NextBridgeId) + if err := k.SetNextBridgeId(ctx, data.NextBridgeId); err != nil { + panic(err) + } } // ExportGenesis returns a GenesisState for a given context and keeper. The @@ -51,7 +61,7 @@ func (k Keeper) InitGenesis(ctx sdk.Context, data *types.GenesisState) { func (k Keeper) ExportGenesis(ctx sdk.Context) *types.GenesisState { var bridges []types.Bridge - k.IterateBridgeConfig(ctx, func(bridgeId uint64, bridgeConfig types.BridgeConfig) (stop bool, err error) { + err := k.IterateBridgeConfig(ctx, func(bridgeId uint64, bridgeConfig types.BridgeConfig) (stop bool, err error) { nextL1Sequence, err := k.GetNextL1Sequence(ctx, bridgeId) if err != nil { return true, err @@ -102,6 +112,9 @@ func (k Keeper) ExportGenesis(ctx sdk.Context) *types.GenesisState { return false, nil }) + if err != nil { + panic(err) + } nextBridgeId, err := k.GetNextBridgeId(ctx) if err != nil { diff --git a/x/ophost/keeper/msg_server.go b/x/ophost/keeper/msg_server.go index 59cea8b5..c3cee9a1 100644 --- a/x/ophost/keeper/msg_server.go +++ b/x/ophost/keeper/msg_server.go @@ -171,7 +171,9 @@ func (ms MsgServer) DeleteOutput(ctx context.Context, req *types.MsgDeleteOutput } // delete output proposal - ms.DeleteOutputProposal(ctx, bridgeId, outputIndex) + if err := ms.DeleteOutputProposal(ctx, bridgeId, outputIndex); err != nil { + return nil, err + } sdk.UnwrapSDKContext(ctx).EventManager().EmitEvent(sdk.NewEvent( types.EventTypeDeleteOutput, @@ -211,7 +213,9 @@ func (ms MsgServer) InitiateTokenDeposit(ctx context.Context, req *types.MsgInit if ok, err := ms.HasTokenPair(ctx, bridgeId, l2Denom); err != nil { return nil, err } else if !ok { - ms.SetTokenPair(ctx, bridgeId, l2Denom, coin.Denom) + if err := ms.SetTokenPair(ctx, bridgeId, l2Denom, coin.Denom); err != nil { + return nil, err + } } // emit events for bridge executor @@ -314,7 +318,9 @@ func (ms MsgServer) FinalizeTokenWithdrawal(ctx context.Context, req *types.MsgF return nil, types.ErrFailedToVerifyWithdrawal.Wrap("invalid storage root proofs") } - ms.RecordProvenWithdrawal(ctx, bridgeId, withdrawalHash) + if err := ms.RecordProvenWithdrawal(ctx, bridgeId, withdrawalHash); err != nil { + return nil, err + } } // transfer asset to a user from the bridge account diff --git a/x/ophost/keeper/msg_server_test.go b/x/ophost/keeper/msg_server_test.go index bfa5f2d2..8e389ae7 100644 --- a/x/ophost/keeper/msg_server_test.go +++ b/x/ophost/keeper/msg_server_test.go @@ -225,7 +225,7 @@ func Test_UpdateProposal(t *testing.T) { // current proposer signer msg = types.NewMsgUpdateProposer(addrs[1], 1, addrs[2]) - _, err = ms.UpdateProposer(sdk.WrapSDKContext(ctx), msg) + _, err = ms.UpdateProposer(ctx, msg) require.NoError(t, err) _config, err = ms.GetBridgeConfig(ctx, 1) require.NoError(t, err) @@ -270,7 +270,7 @@ func Test_UpdateChallenger(t *testing.T) { // current challenger msg = types.NewMsgUpdateChallenger(addrs[2], 1, addrs[3]) - _, err = ms.UpdateChallenger(sdk.WrapSDKContext(ctx), msg) + _, err = ms.UpdateChallenger(ctx, msg) require.NoError(t, err) _config, err = ms.GetBridgeConfig(ctx, 1) require.NoError(t, err) diff --git a/x/ophost/keeper/querier_test.go b/x/ophost/keeper/querier_test.go index 4b6ca35b..117b36e0 100644 --- a/x/ophost/keeper/querier_test.go +++ b/x/ophost/keeper/querier_test.go @@ -6,8 +6,6 @@ import ( "github.com/stretchr/testify/require" - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/initia-labs/OPinit/x/ophost/keeper" "github.com/initia-labs/OPinit/x/ophost/types" ) @@ -26,7 +24,7 @@ func Test_QueryBridge(t *testing.T) { require.NoError(t, err) q := keeper.NewQuerier(input.OPHostKeeper) - res, err := q.Bridge(sdk.WrapSDKContext(ctx), &types.QueryBridgeRequest{ + res, err := q.Bridge(ctx, &types.QueryBridgeRequest{ BridgeId: 1, }) @@ -60,7 +58,7 @@ func Test_QueryBridges(t *testing.T) { require.NoError(t, input.OPHostKeeper.SetBridgeConfig(ctx, 2, config2)) q := keeper.NewQuerier(input.OPHostKeeper) - res, err := q.Bridges(sdk.WrapSDKContext(ctx), &types.QueryBridgesRequest{}) + res, err := q.Bridges(ctx, &types.QueryBridgesRequest{}) require.NoError(t, err) require.Equal(t, []types.QueryBridgeResponse{ @@ -85,14 +83,14 @@ func Test_QueryTokenPair(t *testing.T) { input.OPHostKeeper.SetTokenPair(ctx, 1, pair.L2Denom, pair.L1Denom) q := keeper.NewQuerier(input.OPHostKeeper) - res, err := q.TokenPairByL1Denom(sdk.WrapSDKContext(ctx), &types.QueryTokenPairByL1DenomRequest{ + res, err := q.TokenPairByL1Denom(ctx, &types.QueryTokenPairByL1DenomRequest{ BridgeId: 1, L1Denom: pair.L1Denom, }) require.NoError(t, err) require.Equal(t, pair, res.TokenPair) - res2, err := q.TokenPairByL2Denom(sdk.WrapSDKContext(ctx), &types.QueryTokenPairByL2DenomRequest{ + res2, err := q.TokenPairByL2Denom(ctx, &types.QueryTokenPairByL2DenomRequest{ BridgeId: 1, L2Denom: pair.L2Denom, }) @@ -114,7 +112,7 @@ func Test_QueryTokenPairs(t *testing.T) { input.OPHostKeeper.SetTokenPair(ctx, 1, pair2.L2Denom, pair2.L1Denom) q := keeper.NewQuerier(input.OPHostKeeper) - res, err := q.TokenPairs(sdk.WrapSDKContext(ctx), &types.QueryTokenPairsRequest{ + res, err := q.TokenPairs(ctx, &types.QueryTokenPairsRequest{ BridgeId: 1, }) @@ -134,7 +132,7 @@ func Test_QueryOutputProposal(t *testing.T) { require.NoError(t, input.OPHostKeeper.SetOutputProposal(ctx, 1, 1, output)) q := keeper.NewQuerier(input.OPHostKeeper) - res, err := q.OutputProposal(sdk.WrapSDKContext(ctx), &types.QueryOutputProposalRequest{ + res, err := q.OutputProposal(ctx, &types.QueryOutputProposalRequest{ BridgeId: 1, OutputIndex: 1, }) @@ -158,7 +156,7 @@ func Test_QueryOutputProposals(t *testing.T) { require.NoError(t, input.OPHostKeeper.SetOutputProposal(ctx, 1, 2, output2)) q := keeper.NewQuerier(input.OPHostKeeper) - res, err := q.OutputProposals(sdk.WrapSDKContext(ctx), &types.QueryOutputProposalsRequest{ + res, err := q.OutputProposals(ctx, &types.QueryOutputProposalsRequest{ BridgeId: 1, })