forked from TrueCloudLab/frostfs-node
685b593af3
Implement component that analyzes audit results and generates transactions for payment of awards for successfully passed audit. When calculating the total fee, the declared price of the node (attribute) and the total volume of storage groups, which were successfully audited by the container, are taken into account. In one call the calculator processes all audit results for the previous epoch (relative to the calculated parameter). Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
90 lines
2.4 KiB
Go
90 lines
2.4 KiB
Go
package audit
|
|
|
|
import (
|
|
"math/big"
|
|
|
|
"github.com/nspcc-dev/neofs-api-go/pkg/audit"
|
|
"github.com/nspcc-dev/neofs-api-go/pkg/container"
|
|
"github.com/nspcc-dev/neofs-api-go/pkg/object"
|
|
"github.com/nspcc-dev/neofs-api-go/pkg/owner"
|
|
)
|
|
|
|
// CalculatorPrm groups the parameters of Calculator's constructor.
|
|
type CalculatorPrm struct {
|
|
ResultStorage ResultStorage
|
|
|
|
ContainerStorage ContainerStorage
|
|
|
|
PlacementCalculator PlacementCalculator
|
|
|
|
SGStorage SGStorage
|
|
|
|
AccountStorage AccountStorage
|
|
|
|
Exchanger Exchanger
|
|
}
|
|
|
|
// ResultStorage is an interface of storage of the audit results.
|
|
type ResultStorage interface {
|
|
// Must return all audit results by epoch number.
|
|
AuditResultsForEpoch(epoch uint64) ([]*audit.Result, error)
|
|
}
|
|
|
|
// NodeInfo groups the data about the storage node
|
|
// necessary for calculating audit fees.
|
|
type NodeInfo interface {
|
|
// Must return storage price of the node for one epoch in GASe-12.
|
|
Price() *big.Int
|
|
|
|
// Must return public key of the node.
|
|
PublicKey() []byte
|
|
}
|
|
|
|
// ContainerInfo groups the data about NeoFS container
|
|
// necessary for calculating audit fee.
|
|
type ContainerInfo interface {
|
|
// Must return identifier of the container owner.
|
|
Owner() *owner.ID
|
|
}
|
|
|
|
// ContainerStorage is an interface of
|
|
// storage of the NeoFS containers.
|
|
type ContainerStorage interface {
|
|
// Must return information about the container by ID.
|
|
ContainerInfo(*container.ID) (ContainerInfo, error)
|
|
}
|
|
|
|
// PlacementCalculator is a component interface
|
|
// that builds placement vectors.
|
|
type PlacementCalculator interface {
|
|
// Must return information about the nodes from container cid of the epoch e.
|
|
ContainerNodes(e uint64, cid *container.ID) ([]NodeInfo, error)
|
|
}
|
|
|
|
// SGInfo groups the data about NeoFS storage group
|
|
// necessary for calculating audit fee.
|
|
type SGInfo interface {
|
|
// Must return sum size of the all group members.
|
|
Size() uint64
|
|
}
|
|
|
|
// SGStorage is an interface of storage of the storage groups.
|
|
type SGStorage interface {
|
|
// Must return information about the storage group by address.
|
|
SGInfo(*object.Address) (SGInfo, error)
|
|
}
|
|
|
|
// AccountStorage is an network member accounts interface.
|
|
type AccountStorage interface {
|
|
// Must resolve information about the storage node
|
|
// to its ID in system.
|
|
ResolveKey(NodeInfo) (*owner.ID, error)
|
|
}
|
|
|
|
// Exchanger is an interface of monetary component.
|
|
type Exchanger interface {
|
|
// Must transfer amount of GASe-12 from sender to recipient.
|
|
//
|
|
// Amount must be positive.
|
|
Transfer(sender, recipient *owner.ID, amount *big.Int)
|
|
}
|