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

Revert "fix: fix some issues in challenge module (#453)" #460

Merged
merged 1 commit into from
Sep 6, 2023
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
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
Loading