accounting

package
v1.4.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 1, 2023 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package accounting provides functionalities needed to do per-peer accounting.

Index

Constants

This section is empty.

Variables

View Source
var (

	// ErrDisconnectThresholdExceeded denotes a peer has exceeded the disconnect threshold.
	ErrDisconnectThresholdExceeded = errors.New("disconnect threshold exceeded")
	ErrLowAvailableExceeded        = errors.New("low available balance")
)

Functions

This section is empty.

Types

type Accounting

type Accounting struct {
	// contains filtered or unexported fields
}

Accounting is the main implementation of the accounting interface.

func NewAccounting

func NewAccounting(
	paymentTolerance,
	paymentThreshold *big.Int,
	logger logging.Logger,
	store storage.StateStorer,
	settlement settlement.Interface,
) *Accounting

NewAccounting creates a new Accounting instance with the provided options.

func (*Accounting) AsyncNotifyPayment

func (a *Accounting) AsyncNotifyPayment(peer boson.Address, traffic *big.Int) error

func (*Accounting) Credit

func (a *Accounting) Credit(ctx context.Context, peer boson.Address, traffic uint64) error

Credit increases the amount of credit we have with the given peer (and decreases existing debt).

func (*Accounting) Debit

func (a *Accounting) Debit(peer boson.Address, traffic uint64) error

Debit increases the amount of debt we have with the given peer (and decreases existing credit).

func (*Accounting) Metrics

func (a *Accounting) Metrics() []prometheus.Collector

Metrics returns the prometheus Collector for the accounting service.

func (*Accounting) NotifyPayment

func (a *Accounting) NotifyPayment(peer boson.Address, traffic *big.Int) error

func (*Accounting) Reserve

func (a *Accounting) Reserve(peer boson.Address, traffic uint64) (err error)

Reserve reserves a portion of the balance for peer and attempts settlements if necessary.

type Interface

type Interface interface {
	Reserve(peer boson.Address, traffic uint64) error
	// Credit increases the balance the peer has with us (we "pay" the peer).
	Credit(ctx context.Context, peer boson.Address, traffic uint64) error
	// Debit increases the balance we have with the peer (we get "paid" back).
	Debit(peer boson.Address, traffic uint64) error
}

Interface is the Accounting interface.

Directories

Path Synopsis
Package mock provides a mock implementation for the accounting interface.
Package mock provides a mock implementation for the accounting interface.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL