From 5d3de69c065b534d635f3c4145fa51214543dec6 Mon Sep 17 00:00:00 2001 From: forcodedancing Date: Mon, 26 Jun 2023 14:27:25 +0800 Subject: [PATCH] feat: refine payment and update default parameter (#297) --- x/sp/types/params.go | 6 +++--- x/storage/keeper/keeper.go | 13 ++++++++----- x/storage/keeper/payment.go | 3 ++- x/storage/types/types.go | 6 ------ 4 files changed, 13 insertions(+), 15 deletions(-) diff --git a/x/sp/types/params.go b/x/sp/types/params.go index 273309622..16e53d4b6 100644 --- a/x/sp/types/params.go +++ b/x/sp/types/params.go @@ -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 ( diff --git a/x/storage/keeper/keeper.go b/x/storage/keeper/keeper.go index 2dd3b5a5c..043f62c53 100644 --- a/x/storage/keeper/keeper.go +++ b/x/storage/keeper/keeper.go @@ -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) @@ -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, diff --git a/x/storage/keeper/payment.go b/x/storage/keeper/payment.go index 39e460964..75e8a7c8d 100644 --- a/x/storage/keeper/payment.go +++ b/x/storage/keeper/payment.go @@ -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) diff --git a/x/storage/types/types.go b/x/storage/types/types.go index c5b0f7469..9fd708905 100644 --- a/x/storage/types/types.go +++ b/x/storage/types/types.go @@ -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