Skip to content

Commit

Permalink
refactor name of function
Browse files Browse the repository at this point in the history
  • Loading branch information
yutianwu committed Jan 9, 2023
1 parent e4c61b7 commit b1706a8
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 11 deletions.
6 changes: 3 additions & 3 deletions x/oracle/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func (k Keeper) IsValidatorInturn(ctx sdk.Context, validators []stakingtypes.Val
}

if validatorIndex < 0 {
return false, sdkerrors.Wrapf(types.ErrNotValidator, fmt.Sprintf("sender is not validator"))
return false, sdkerrors.Wrapf(types.ErrNotRelayer, fmt.Sprintf("sender(%s) is not a relayer", claim.FromAddress))
}

// check inturn validator index
Expand All @@ -105,8 +105,8 @@ func (k Keeper) IsValidatorInturn(ctx sdk.Context, validators []stakingtypes.Val
return uint64(validatorIndex) == (inturnValidatorIndex+backoffIndex)%uint64(len(validators)), nil
}

// ProcessClaim checks the bls signature
func (k Keeper) ProcessClaim(ctx sdk.Context, claim *types.MsgClaim) error {
// CheckClaim checks the bls signature
func (k Keeper) CheckClaim(ctx sdk.Context, claim *types.MsgClaim) error {
historicalInfo, ok := k.StakingKeeper.GetHistoricalInfo(ctx, ctx.BlockHeight())
if !ok {
return sdkerrors.Wrapf(types.ErrValidatorSet, fmt.Sprintf("get historical validators failed"))
Expand Down
10 changes: 5 additions & 5 deletions x/oracle/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,12 @@ func (s *TestSuite) TestProcessClaim() {
msgClaim.AggSignature = blsSig

s.ctx = s.ctx.WithBlockTime(time.Unix(int64(msgClaim.Timestamp), 0))
err := s.app.OracleKeeper.ProcessClaim(s.ctx, &msgClaim)
err := s.app.OracleKeeper.CheckClaim(s.ctx, &msgClaim)
s.Require().Nil(err, "error should be nil")

// not in turn
s.ctx = s.ctx.WithBlockTime(time.Unix(int64(msgClaim.Timestamp)+6, 0))
err = s.app.OracleKeeper.ProcessClaim(s.ctx, &msgClaim)
err = s.app.OracleKeeper.CheckClaim(s.ctx, &msgClaim)
s.Require().NotNil(err, "error should not be nil")
s.Require().Contains(err.Error(), "validator is not in turn")

Expand All @@ -121,7 +121,7 @@ func (s *TestSuite) TestProcessClaim() {
}
msgClaim.VoteAddressSet = wrongValBitSet.Bytes()
s.ctx = s.ctx.WithBlockTime(time.Unix(int64(msgClaim.Timestamp), 0))
err = s.app.OracleKeeper.ProcessClaim(s.ctx, &msgClaim)
err = s.app.OracleKeeper.CheckClaim(s.ctx, &msgClaim)
s.Require().NotNil(err, "error should not be nil")
s.Require().Contains(err.Error(), "number of validator set is larger than validators")

Expand All @@ -131,7 +131,7 @@ func (s *TestSuite) TestProcessClaim() {
wrongValBitSet.Set(uint(validatorMap[newValidators[1].RelayerAddress]))
msgClaim.VoteAddressSet = wrongValBitSet.Bytes()
s.ctx = s.ctx.WithBlockTime(time.Unix(int64(msgClaim.Timestamp), 0))
err = s.app.OracleKeeper.ProcessClaim(s.ctx, &msgClaim)
err = s.app.OracleKeeper.CheckClaim(s.ctx, &msgClaim)
s.Require().NotNil(err, "error should not be nil")
s.Require().Contains(err.Error(), "not enough validators voted")

Expand All @@ -140,7 +140,7 @@ func (s *TestSuite) TestProcessClaim() {
msgClaim.AggSignature = bytes.Repeat([]byte{2}, 96)

s.ctx = s.ctx.WithBlockTime(time.Unix(int64(msgClaim.Timestamp), 0))
err = s.app.OracleKeeper.ProcessClaim(s.ctx, &msgClaim)
err = s.app.OracleKeeper.CheckClaim(s.ctx, &msgClaim)
s.Require().NotNil(err, "error should not be nil")
s.Require().Contains(err.Error(), "BLS signature converts failed")
}
Expand Down
5 changes: 3 additions & 2 deletions x/oracle/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,11 @@ func (k msgServer) Claim(goCtx context.Context, req *types.MsgClaim) (*types.Msg

sequence := k.oracleKeeper.CrossChainKeeper.GetReceiveSequence(ctx, sdk.ChainID(req.SrcChainId), types.RelayPackagesChannelId)
if sequence != req.Sequence {
return nil, sdkerrors.Wrapf(types.ErrInvalidReceiveSequence, fmt.Sprintf("current sequence of channel %d is %d", types.RelayPackagesChannelId, sequence))
logger.Error("wrong sequence")
//return nil, sdkerrors.Wrapf(types.ErrInvalidReceiveSequence, fmt.Sprintf("current sequence of channel %d is %d", types.RelayPackagesChannelId, sequence))
}

err := k.oracleKeeper.ProcessClaim(ctx, req)
err := k.oracleKeeper.CheckClaim(ctx, req)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion x/oracle/types/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ var (
ErrBlsPubKey = sdkerrors.Register(ModuleName, 9, "public key is invalid")
ErrBlsVotesNotEnough = sdkerrors.Register(ModuleName, 10, "bls votes is not enough")
ErrInvalidBlsSignature = sdkerrors.Register(ModuleName, 11, "bls signature is invalid")
ErrNotValidator = sdkerrors.Register(ModuleName, 12, "sender is not validator")
ErrNotRelayer = sdkerrors.Register(ModuleName, 12, "sender is not a relayer")
ErrValidatorNotInTurn = sdkerrors.Register(ModuleName, 13, "validator is not in turn")
ErrInvalidDestChainId = sdkerrors.Register(ModuleName, 14, "dest chain id is invalid")
ErrInvalidSrcChainId = sdkerrors.Register(ModuleName, 15, "src chain id is invalid")
Expand Down

0 comments on commit b1706a8

Please sign in to comment.