Skip to content

Commit

Permalink
feat: refine payment and update default parameter (#297)
Browse files Browse the repository at this point in the history
  • Loading branch information
forcodedancing committed Jun 26, 2023
1 parent 9c1e3bd commit 5d3de69
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 15 deletions.
6 changes: 3 additions & 3 deletions x/sp/types/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ import (

// SP params default values
const (
// Dafault deposit denom
// Default deposit denom
DefaultDepositDenom = "BNB"
)

var (
// DefaultMinDeposit defines the minimum deposit amount for all storage provider
DefaultMinDeposit = math.NewIntFromBigInt(new(big.Int).Mul(big.NewInt(10000), big.NewInt(1e18)))
// DefaultSecondarySpStorePriceRatio is 65%
DefaultSecondarySpStorePriceRatio = sdk.NewDecFromIntWithPrec(sdk.NewInt(65), 2)
// DefaultSecondarySpStorePriceRatio is 12%
DefaultSecondarySpStorePriceRatio = sdk.NewDecFromIntWithPrec(sdk.NewInt(12), 2)
)

var (
Expand Down
13 changes: 8 additions & 5 deletions x/storage/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -472,10 +472,13 @@ func (k Keeper) CreateObject(
return sdkmath.ZeroUint(), errors.Wrapf(types.ErrInvalidApproval, "The approval of sp is expired.")
}

err := k.VerifySPAndSignature(ctx, sdk.MustAccAddressFromHex(bucketInfo.PrimarySpAddress), opts.ApprovalMsgBytes,
opts.PrimarySpApproval.Sig)
if err != nil {
return sdkmath.ZeroUint(), err
var err error
if !ctx.IsCheckTx() { // no signature verification for simulation
err = k.VerifySPAndSignature(ctx, sdk.MustAccAddressFromHex(bucketInfo.PrimarySpAddress), opts.ApprovalMsgBytes,
opts.PrimarySpApproval.Sig)
if err != nil {
return sdkmath.ZeroUint(), err
}
}

objectKey := types.GetObjectKey(bucketName, objectName)
Expand Down Expand Up @@ -530,7 +533,7 @@ func (k Keeper) CreateObject(
store.Set(objectKey, sequence.EncodeSequence(objectInfo.Id))
store.Set(types.GetObjectByIDKey(objectInfo.Id), obz)

if err := ctx.EventManager().EmitTypedEvents(&types.EventCreateObject{
if err = ctx.EventManager().EmitTypedEvents(&types.EventCreateObject{
Creator: operator.String(),
Owner: objectInfo.Owner,
BucketName: bucketInfo.BucketName,
Expand Down
3 changes: 2 additions & 1 deletion x/storage/keeper/payment.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,8 @@ func (k Keeper) GetObjectLockFee(ctx sdk.Context, primarySpAddress string, price
if err != nil {
return amount, fmt.Errorf("get charge size error: %w", err)
}
rate := price.PrimaryStorePrice.Add(price.SecondaryStorePrice.MulInt64(storagetypes.SecondarySPNum)).MulInt(sdkmath.NewIntFromUint64(chargeSize)).TruncateInt()
secondarySPNum := int64(k.GetExpectSecondarySPNumForECObject(ctx))
rate := price.PrimaryStorePrice.Add(price.SecondaryStorePrice.MulInt64(secondarySPNum)).MulInt(sdkmath.NewIntFromUint64(chargeSize)).TruncateInt()
versionedParams, err := k.paymentKeeper.GetVersionedParamsWithTs(ctx, priceTime)
if err != nil {
return amount, fmt.Errorf("get versioned reserve time error: %w", err)
Expand Down
6 changes: 0 additions & 6 deletions x/storage/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,6 @@ import (
sdkmath "cosmossdk.io/math"
)

const (
SecondarySPNum = 6
// MinChargeSize is the minimum size to charge for a storage object
MinChargeSize = 1024
)

type (
Int = sdkmath.Int
Uint = sdkmath.Uint
Expand Down

0 comments on commit 5d3de69

Please sign in to comment.