Skip to content
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
1 change: 1 addition & 0 deletions cmd/di.go
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,7 @@ func (di *Dependencies) bootstrapNodeComponents(nodeOptions node.Options, tequil
nodeOptions.Transactor.RegistryAddress,
di.EventBus,
consumerDataGetter,
nodeOptions.Payments.ConsumerDataLeewayMegabytes,
),
di.ConnectionRegistry.CreateConnection,
di.EventBus,
Expand Down
8 changes: 8 additions & 0 deletions config/flags_payments.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,12 @@ var (
Usage: "Sets the minimum price of the service per gb. All proposals with a below above this bound will be filtered out and not visible.",
Value: 0,
}
// FlagPaymentsConsumerDataLeewayMegabytes sets the data amount the consumer agrees to pay before establishing a session
FlagPaymentsConsumerDataLeewayMegabytes = cli.Uint64Flag{
Name: "payments.consumer.data-leeway-megabytes",
Usage: "sets the data amount the consumer agrees to pay before establishing a session",
Value: 20,
}
)

// RegisterFlagsPayments function register payments flags to flag list.
Expand All @@ -100,6 +106,7 @@ func RegisterFlagsPayments(flags *[]cli.Flag) {
&FlagPaymentsConsumerPricePerMinuteLowerBound,
&FlagPaymentsConsumerPricePerGBUpperBound,
&FlagPaymentsConsumerPricePerGBLowerBound,
&FlagPaymentsConsumerDataLeewayMegabytes,
)
}

Expand All @@ -115,4 +122,5 @@ func ParseFlagsPayments(ctx *cli.Context) {
Current.ParseUInt64Flag(ctx, FlagPaymentsConsumerPricePerMinuteLowerBound)
Current.ParseUInt64Flag(ctx, FlagPaymentsConsumerPricePerGBUpperBound)
Current.ParseUInt64Flag(ctx, FlagPaymentsConsumerPricePerGBLowerBound)
Current.ParseUInt64Flag(ctx, FlagPaymentsConsumerDataLeewayMegabytes)
}
1 change: 1 addition & 0 deletions core/node/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ func GetOptions() *Options {
ConsumerLowerGBPriceBound: config.GetUInt64(config.FlagPaymentsConsumerPricePerGBLowerBound),
ConsumerUpperMinutePriceBound: config.GetUInt64(config.FlagPaymentsConsumerPricePerMinuteUpperBound),
ConsumerLowerMinutePriceBound: config.GetUInt64(config.FlagPaymentsConsumerPricePerMinuteLowerBound),
ConsumerDataLeewayMegabytes: config.GetUInt64(config.FlagPaymentsConsumerDataLeewayMegabytes),
},
Accountant: OptionsAccountant{
AccountantID: config.GetString(config.FlagAccountantID),
Expand Down
1 change: 1 addition & 0 deletions core/node/options_payments.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,5 @@ type OptionsPayments struct {
ConsumerLowerGBPriceBound uint64
ConsumerUpperMinutePriceBound uint64
ConsumerLowerMinutePriceBound uint64
ConsumerDataLeewayMegabytes uint64
}
2 changes: 1 addition & 1 deletion services/openvpn/service/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import (
"github.com/rs/zerolog/log"
)

const statisticsReportingIntervalInSeconds = 30
const statisticsReportingIntervalInSeconds = 1

type eventBus interface {
Publish(topic string, data interface{})
Expand Down
2 changes: 1 addition & 1 deletion services/wireguard/service/service_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ func (m *Manager) ProvideConfig(sessionID string, sessionConfig json.RawMessage)
return nil, errors.Wrap(err, "failed to setup NAT/firewall rules")
}

statsPublisher := newStatsPublisher(m.publisher, 3*time.Second)
statsPublisher := newStatsPublisher(m.publisher, time.Second)
go statsPublisher.start(sessionID, conn)

destroy := func() {
Expand Down
5 changes: 4 additions & 1 deletion session/pingpong/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/mysteriumnetwork/node/communication"
"github.com/mysteriumnetwork/node/core/connection"
"github.com/mysteriumnetwork/node/core/node"
"github.com/mysteriumnetwork/node/datasize"
"github.com/mysteriumnetwork/node/eventbus"
"github.com/mysteriumnetwork/node/identity"
"github.com/mysteriumnetwork/node/market"
Expand Down Expand Up @@ -144,7 +145,8 @@ func ExchangeFactoryFunc(
channelImplementation string,
registryAddress string,
eventBus eventbus.EventBus,
getConsumerInfo getConsumerInfo) func(paymentInfo session.PaymentInfo,
getConsumerInfo getConsumerInfo,
dataLeewayMegabytes uint64) func(paymentInfo session.PaymentInfo,
dialog communication.Dialog,
consumer, provider, accountant identity.Identity, proposal market.ServiceProposal, sessionID string) (connection.PaymentIssuer, error) {
return func(paymentInfo session.PaymentInfo,
Expand Down Expand Up @@ -178,6 +180,7 @@ func ExchangeFactoryFunc(
AccountantAddress: accountant,
ConsumerInfoGetter: getConsumerInfo,
SessionID: sessionID,
DataLeeway: datasize.MiB * datasize.BitSize(dataLeewayMegabytes),
}
return NewInvoicePayer(deps), nil
}
Expand Down
8 changes: 7 additions & 1 deletion session/pingpong/invoice_payer.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (

"github.com/cenkalti/backoff/v4"
"github.com/mysteriumnetwork/node/core/connection"
"github.com/mysteriumnetwork/node/datasize"
"github.com/mysteriumnetwork/node/eventbus"
"github.com/mysteriumnetwork/node/market"

Expand All @@ -45,6 +46,7 @@ var ErrProviderOvercharge = errors.New("provider is overcharging")

const consumerFirstInvoiceTolerance = 1.35
const consumerInvoiceTolerance = 1.05
const dataLeeway = datasize.MiB * 20

// PeerExchangeMessageSender allows for sending of exchange messages.
type PeerExchangeMessageSender interface {
Expand Down Expand Up @@ -100,6 +102,7 @@ type InvoicePayerDeps struct {
EventBus eventbus.EventBus
AccountantAddress identity.Identity
ConsumerInfoGetter getConsumerInfo
DataLeeway datasize.BitSize
}

// NewInvoicePayer returns a new instance of exchange message tracker.
Expand Down Expand Up @@ -226,7 +229,10 @@ func (ip *InvoicePayer) isInvoiceOK(invoice crypto.Invoice) error {
return ErrWrongProvider
}

shouldBe := calculatePaymentAmount(ip.deps.TimeTracker.Elapsed(), ip.getDataTransferred(), ip.deps.Proposal.PaymentMethod)
transfered := ip.getDataTransferred()
transfered.up += ip.deps.DataLeeway.Bytes()

shouldBe := calculatePaymentAmount(ip.deps.TimeTracker.Elapsed(), transfered, ip.deps.Proposal.PaymentMethod)

upperBound := uint64(math.Trunc(float64(shouldBe) * consumerInvoiceTolerance))
if !ip.receivedFirst {
Expand Down