Skip to content

Commit

Permalink
Revert "fix: fix some issues in challenge module (#453)" (#460)
Browse files Browse the repository at this point in the history
This reverts commit c6029ee.
  • Loading branch information
unclezoro authored Sep 6, 2023
1 parent 9fd4c68 commit 9a9d0d5
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 38 deletions.
64 changes: 29 additions & 35 deletions x/challenge/keeper/msg_server_attest.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ import (
storagetypes "github.com/bnb-chain/greenfield/x/storage/types"
)

// one_gb_bytes stands for the total bytes in 1gb
const one_gb_bytes = 1024 * 1024 * 1024

// Attest handles user's request for attesting a challenge.
// The attestation can include a valid challenge or is only for heartbeat purpose.
// If the challenge is valid, the related storage provider will be slashed.
Expand Down Expand Up @@ -148,8 +145,8 @@ func (k msgServer) Attest(goCtx context.Context, msg *types.MsgAttest) (*types.M
func (k msgServer) calculateSlashAmount(ctx sdk.Context, objectSize uint64) sdkmath.Int {
params := k.GetParams(ctx)
sizeRate := params.SlashAmountSizeRate
objectSizeInGB := sdk.NewDecFromBigInt(new(big.Int).SetUint64(objectSize)).QuoRoundUp(sdk.NewDec(one_gb_bytes))
slashAmount := objectSizeInGB.Mul(sizeRate).Mul(sdk.NewDec(1e18)).TruncateInt()
objectSizeInGB := sdk.NewDecFromBigInt(new(big.Int).SetUint64(objectSize)).QuoRoundUp(sdk.NewDec(1073741824))
slashAmount := objectSizeInGB.MulMut(sizeRate).MulMut(sdk.NewDec(1e18)).TruncateInt()

min := params.SlashAmountMin
if slashAmount.LT(min) {
Expand Down Expand Up @@ -198,40 +195,37 @@ func (k msgServer) calculateSlashRewards(ctx sdk.Context, total sdkmath.Int, cha
func (k msgServer) doSlashAndRewards(ctx sdk.Context, challengeId uint64, voteResult types.VoteResult, slashAmount sdkmath.Int,
spID uint32, submitter, challenger sdk.AccAddress, validators []string) error {

challengerReward, eachValidatorReward, submitterReward := sdkmath.ZeroInt(), sdkmath.ZeroInt(), sdkmath.ZeroInt()

if !slashAmount.IsZero() {

challengerReward, eachValidatorReward, submitterReward = k.calculateSlashRewards(ctx, slashAmount,
challenger, int64(len(validators)))
challengerReward, eachValidatorReward, submitterReward := k.calculateSlashRewards(ctx, slashAmount,
challenger, int64(len(validators)))

denom := k.SpKeeper.DepositDenomForSP(ctx)
rewards := make([]sptypes.RewardInfo, 0)
if !challenger.Equals(sdk.AccAddress{}) {
rewards = append(rewards, sptypes.RewardInfo{
Address: challenger.String(),
Amount: sdk.Coin{
Denom: denom,
Amount: challengerReward,
},
})
}
for _, val := range validators {
rewards = append(rewards, sptypes.RewardInfo{
Address: val,
Amount: sdk.Coin{
Denom: denom,
Amount: eachValidatorReward,
},
})
}
denom := k.SpKeeper.DepositDenomForSP(ctx)
rewards := make([]sptypes.RewardInfo, 0)
if !challenger.Equals(sdk.AccAddress{}) {
rewards = append(rewards, sptypes.RewardInfo{
Address: submitter.String(),
Address: challenger.String(),
Amount: sdk.Coin{
Denom: denom,
Amount: submitterReward,
}})

Amount: challengerReward,
},
})
}
for _, val := range validators {
rewards = append(rewards, sptypes.RewardInfo{
Address: val,
Amount: sdk.Coin{
Denom: denom,
Amount: eachValidatorReward,
},
})
}
rewards = append(rewards, sptypes.RewardInfo{
Address: submitter.String(),
Amount: sdk.Coin{
Denom: denom,
Amount: submitterReward,
}})

if challengerReward.IsPositive() || eachValidatorReward.IsPositive() || submitterReward.IsPositive() {
err := k.SpKeeper.Slash(ctx, spID, rewards)
if err != nil {
return err
Expand Down
3 changes: 0 additions & 3 deletions x/challenge/keeper/msg_server_submit.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@ func (k msgServer) Submit(goCtx context.Context, msg *types.MsgSubmit) (*types.M
if objectInfo.ObjectStatus != storagetypes.OBJECT_STATUS_SEALED {
return nil, types.ErrInvalidObjectStatus
}
if objectInfo.PayloadSize == 0 {
return nil, errors.Wrap(types.ErrInvalidSegmentIndex, "the object is empty, no segment")
}

// check whether the sp stores the object info, generate redundancy index
stored := false
Expand Down

0 comments on commit 9a9d0d5

Please sign in to comment.