payments: don't redefine compensation rates twice

Change-Id: Ic00abe3795a000d4f0284c99f270180123a2f663
This commit is contained in:
JT Olio 2023-06-09 12:42:19 -04:00 committed by Storj Robot
parent e83e98e46a
commit 3fff61f04a
7 changed files with 33 additions and 38 deletions

View File

@ -416,10 +416,6 @@ func (planet *Planet) newSatellite(ctx context.Context, prefix string, index int
config.Tally.ReadRollupBatchSize = 0
config.Rollup.DeleteTallies = false
config.Payments.BonusRate = 0
config.Payments.NodeEgressBandwidthPrice = 0
config.Payments.NodeRepairBandwidthPrice = 0
config.Payments.NodeAuditBandwidthPrice = 0
config.Payments.NodeDiskSpacePrice = 0
config.Identity.CertPath = ""
config.Identity.KeyPath = ""
config.Metainfo.DatabaseURL = ""

View File

@ -639,6 +639,7 @@ func NewAPI(log *zap.Logger, full *identity.FullIdentity, db DB,
peer.Reputation.Service,
peer.DB.StoragenodeAccounting(),
config.Payments,
config.Compensation,
)
if err := pb.DRPCRegisterNodeStats(peer.Server.DRPC(), peer.NodeStats.Endpoint); err != nil {
return nil, errs.Combine(err, peer.Close())

View File

@ -11,7 +11,7 @@ import (
// Config contains configuration for the calculations this package performs.
type Config struct {
Rates struct {
AtRestGBHours Rate `user:"true" help:"rate for data at rest per GB/hour" default:"0.00000205"`
AtRestGBHours Rate `user:"true" help:"rate for data at rest per GB/hour" default:"0.00000208"`
GetTB Rate `user:"true" help:"rate for egress bandwidth per TB" default:"20.00"`
PutTB Rate `user:"true" help:"rate for ingress bandwidth per TB" default:"0"`
GetRepairTB Rate `user:"true" help:"rate for repair egress bandwidth per TB" default:"10.00"`

View File

@ -6,6 +6,7 @@ package nodestats
import (
"context"
"github.com/shopspring/decimal"
"github.com/spacemonkeygo/monkit/v3"
"go.uber.org/zap"
@ -13,6 +14,7 @@ import (
"storj.io/common/pb"
"storj.io/common/rpc/rpcstatus"
"storj.io/storj/satellite/accounting"
"storj.io/storj/satellite/compensation"
"storj.io/storj/satellite/overlay"
"storj.io/storj/satellite/payments/paymentsconfig"
"storj.io/storj/satellite/reputation"
@ -33,16 +35,18 @@ type Endpoint struct {
reputation *reputation.Service
accounting accounting.StoragenodeAccounting
config paymentsconfig.Config
compConfig compensation.Config
}
// NewEndpoint creates new endpoint.
func NewEndpoint(log *zap.Logger, overlay overlay.DB, reputation *reputation.Service, accounting accounting.StoragenodeAccounting, config paymentsconfig.Config) *Endpoint {
func NewEndpoint(log *zap.Logger, overlay overlay.DB, reputation *reputation.Service, accounting accounting.StoragenodeAccounting, config paymentsconfig.Config, compConfig compensation.Config) *Endpoint {
return &Endpoint{
log: log,
overlay: overlay,
reputation: reputation,
accounting: accounting,
config: config,
compConfig: compConfig,
}
}
@ -127,15 +131,24 @@ func (e *Endpoint) DailyStorageUsage(ctx context.Context, req *pb.DailyStorageUs
}, nil
}
var dollarsToCents = decimal.NewFromInt(100)
var dollarsPerGBHourTocentsPerTBMonth = decimal.NewFromInt(100 * 1000 * 720)
// PricingModel returns pricing model for storagenode.
func (e *Endpoint) PricingModel(ctx context.Context, req *pb.PricingModelRequest) (_ *pb.PricingModelResponse, err error) {
defer mon.Task()(&ctx)(&err)
// PricingModelResponse wants cents/TB and cents/TB-mo.
// e.compConfig values are in $/TB and $/GB-h.
// For converting monthly rates into hourly rates, months have been
// standardized as being a 720 hour interval. This pricing model response
// is purely for display and is okay to convert backwards.
return &pb.PricingModelResponse{
EgressBandwidthPrice: e.config.NodeEgressBandwidthPrice,
RepairBandwidthPrice: e.config.NodeRepairBandwidthPrice,
DiskSpacePrice: e.config.NodeDiskSpacePrice,
AuditBandwidthPrice: e.config.NodeAuditBandwidthPrice,
EgressBandwidthPrice: decimal.Decimal(e.compConfig.Rates.GetTB).Mul(dollarsToCents).IntPart(),
RepairBandwidthPrice: decimal.Decimal(e.compConfig.Rates.GetRepairTB).Mul(dollarsToCents).IntPart(),
AuditBandwidthPrice: decimal.Decimal(e.compConfig.Rates.GetAuditTB).Mul(dollarsToCents).IntPart(),
DiskSpacePrice: decimal.Decimal(e.compConfig.Rates.AtRestGBHours).Mul(dollarsPerGBHourTocentsPerTBMonth).IntPart(),
}, nil
}

View File

@ -27,17 +27,13 @@ type Config struct {
Provider string `help:"payments provider to use" default:""`
MockProvider stripe.Client `internal:"true"`
BillingConfig billing.Config
StripeCoinPayments stripe.Config
Storjscan storjscan.Config
UsagePrice ProjectUsagePrice
BonusRate int64 `help:"amount of percents that user will earn as bonus credits by depositing in STORJ tokens" default:"10"`
NodeEgressBandwidthPrice int64 `help:"price node receive for storing TB of egress in cents" default:"2000"`
NodeRepairBandwidthPrice int64 `help:"price node receive for storing TB of repair in cents" default:"1000"`
NodeAuditBandwidthPrice int64 `help:"price node receive for storing TB of audit in cents" default:"1000"`
NodeDiskSpacePrice int64 `help:"price node receive for storing disk space in cents/TB" default:"150"`
UsagePriceOverrides ProjectUsagePriceOverrides `help:"semicolon-separated usage price overrides in the format partner:storage,egress,segment,egress_discount_ratio. The egress discount ratio is the ratio of free egress per unit-month of storage"`
PackagePlans PackagePlans `help:"semicolon-separated partner package plans in the format partner:price,credit. Price and credit are in cents USD."`
BillingConfig billing.Config
StripeCoinPayments stripe.Config
Storjscan storjscan.Config
UsagePrice ProjectUsagePrice
BonusRate int64 `help:"amount of percents that user will earn as bonus credits by depositing in STORJ tokens" default:"10"`
UsagePriceOverrides ProjectUsagePriceOverrides `help:"semicolon-separated usage price overrides in the format partner:storage,egress,segment,egress_discount_ratio. The egress discount ratio is the ratio of free egress per unit-month of storage"`
PackagePlans PackagePlans `help:"semicolon-separated partner package plans in the format partner:price,credit. Price and credit are in cents USD."`
}
// ProjectUsagePrice holds the configuration for the satellite's project usage price model.

View File

@ -113,7 +113,7 @@
compensation.dispose-percent: 50
# rate for data at rest per GB/hour
compensation.rates.at-rest-gb-hours: "0.00000205"
compensation.rates.at-rest-gb-hours: "0.00000208"
# rate for audit egress bandwidth per TB
compensation.rates.get-audit-tb: "10"
@ -844,18 +844,6 @@ identity.key-path: /root/.local/share/storj/identity/satellite/identity.key
# amount of percents that user will earn as bonus credits by depositing in STORJ tokens
# payments.bonus-rate: 10
# price node receive for storing TB of audit in cents
# payments.node-audit-bandwidth-price: 1000
# price node receive for storing disk space in cents/TB
# payments.node-disk-space-price: 150
# price node receive for storing TB of egress in cents
# payments.node-egress-bandwidth-price: 2000
# price node receive for storing TB of repair in cents
# payments.node-repair-bandwidth-price: 1000
# semicolon-separated partner package plans in the format partner:price,credit. Price and credit are in cents USD.
# payments.package-plans: ""

View File

@ -19,6 +19,7 @@ import (
"storj.io/common/testcontext"
"storj.io/storj/private/testplanet"
"storj.io/storj/satellite"
"storj.io/storj/satellite/compensation"
"storj.io/storj/storagenode/payouts/estimatedpayouts"
"storj.io/storj/storagenode/pricing"
"storj.io/storj/storagenode/reputation"
@ -52,10 +53,10 @@ func TestStorageNodeApi(t *testing.T) {
StorageNodeCount: 1,
Reconfigure: testplanet.Reconfigure{
Satellite: func(log *zap.Logger, index int, config *satellite.Config) {
config.Payments.NodeEgressBandwidthPrice = 2000
config.Payments.NodeAuditBandwidthPrice = 1000
config.Payments.NodeRepairBandwidthPrice = 1000
config.Payments.NodeDiskSpacePrice = 150
config.Compensation.Rates.GetTB = compensation.RequireRateFromString("20")
config.Compensation.Rates.GetAuditTB = compensation.RequireRateFromString("10")
config.Compensation.Rates.GetRepairTB = compensation.RequireRateFromString("10")
config.Compensation.Rates.AtRestGBHours = compensation.RequireRateFromString(".00000208")
},
},
},