Documentation
¶
Overview ¶
Package payerreport implements the payer report generator and verifier interfaces.
Index ¶
- Constants
- Variables
- func AddReportLogFields(logger *zap.Logger, report *PayerReport) *zap.Logger
- func GenerateMerkleTree(payers PayerMap) (*merkle.MerkleTree, error)
- func ValidateReportIndex(index *big.Int) (int32, error)
- type AttestationStatus
- type BuildPayerReportParams
- type FetchReportsQuery
- func (f *FetchReportsQuery) WithAttestationStatus(statuses ...AttestationStatus) *FetchReportsQuery
- func (f *FetchReportsQuery) WithCreatedAfter(createdAfter time.Time) *FetchReportsQuery
- func (f *FetchReportsQuery) WithEndSequenceID(endSequenceID uint64) *FetchReportsQuery
- func (f *FetchReportsQuery) WithMinAttestations(minAttestations int32) *FetchReportsQuery
- func (f *FetchReportsQuery) WithOriginatorNodeID(originatorNodeID uint32) *FetchReportsQuery
- func (f *FetchReportsQuery) WithReportID(payerReportID ReportID) *FetchReportsQuery
- func (f *FetchReportsQuery) WithStartSequenceID(startSequenceID uint64) *FetchReportsQuery
- func (f *FetchReportsQuery) WithSubmissionStatus(statuses ...SubmissionStatus) *FetchReportsQuery
- type IPayerReportGenerator
- type IPayerReportStore
- type IPayerReportVerifier
- type NodeSignature
- type PayerMap
- type PayerReport
- type PayerReportAttestation
- type PayerReportGenerationParams
- type PayerReportGenerator
- type PayerReportVerifier
- type PayerReportWithInputs
- type PayerReportWithStatus
- type ReportID
- type Store
- func (s *Store) CreateAttestation(ctx context.Context, attestation *PayerReportAttestation, ...) error
- func (s *Store) CreatePayerReport(ctx context.Context, report *PayerReport, ...) (*ReportID, error)
- func (s *Store) FetchReport(ctx context.Context, id ReportID) (*PayerReportWithStatus, error)
- func (s *Store) FetchReports(ctx context.Context, query *FetchReportsQuery) ([]*PayerReportWithStatus, error)
- func (s *Store) ForceSetReportSubmitted(ctx context.Context, id ReportID, reportIndex int32) error
- func (s *Store) GetAdvisoryLocker(ctx context.Context) (db.ITransactionScopedAdvisoryLocker, error)
- func (s *Store) GetLatestSequenceID(ctx context.Context, originatorNodeID int32) (int64, error)
- func (s *Store) Queries() *queries.Queries
- func (s *Store) SetReportAttestationApproved(ctx context.Context, id ReportID) error
- func (s *Store) SetReportAttestationRejected(ctx context.Context, id ReportID) error
- func (s *Store) SetReportSettled(ctx context.Context, id ReportID) error
- func (s *Store) SetReportSubmissionRejected(ctx context.Context, id ReportID) error
- func (s *Store) SetReportSubmitted(ctx context.Context, id ReportID, reportIndex int32) error
- func (s *Store) StoreAttestation(ctx context.Context, attestation *PayerReportAttestation) error
- func (s *Store) StoreReport(ctx context.Context, report *PayerReport) (int64, error)
- func (s *Store) StoreSyncedAttestation(ctx context.Context, envelope *envelopes.OriginatorEnvelope, payerID int32) error
- func (s *Store) StoreSyncedReport(ctx context.Context, envelope *envelopes.OriginatorEnvelope, payerID int32, ...) error
- type SubmissionStatus
- type VerifyMerkleRootResult
- type VerifyReportResult
Constants ¶
const ( SubmissionPending SubmissionStatus = iota SubmissionSubmitted = 1 SubmissionSettled = 2 SubmissionRejected = 3 )
const ( AttestationPending AttestationStatus = iota AttestationApproved = 1 AttestationRejected = 2 )
Variables ¶
var ( ErrActiveNodeIDTooLarge = errors.New("active node ID is > max int32") ErrEndMinuteSinceEpochTooLarge = errors.New("end minute since epoch is > max int32") ErrEndSequenceIDTooLarge = errors.New("end sequence ID is > max int64") ErrInvalidReportID = errors.New("invalid report ID") ErrNoActiveNodeIDs = errors.New("no active node IDs") ErrNodesCountTooLarge = errors.New("nodes count is > max int32") ErrOriginatorNodeIDTooLarge = errors.New("originator node ID is > max int32") ErrReportNil = errors.New("report is nil") ErrReportNotFound = errors.New("report not found") ErrStartSequenceIDTooLarge = errors.New("start sequence ID is > max int64") ErrReportIndexTooLarge = errors.New("report index is > max int32") )
var ( ErrMismatchOriginator = errors.New( "originator id mismatch between old and new report", ) ErrInvalidReportStart = errors.New( "report does not start where the previous report ended", ) ErrInvalidSequenceID = errors.New("invalid sequence id") ErrInvalidOriginatorID = errors.New("originator id is 0") ErrNoNodes = errors.New("no nodes in report") ErrInvalidPayersMerkleRoot = errors.New("payers merkle root is invalid") ErrMessageAtStartSequenceIDNotFound = errors.New("message at start sequence id not found") ErrMessageAtEndSequenceIDNotFound = errors.New("message at end sequence id not found") )
Functions ¶
func AddReportLogFields ¶ added in v1.0.0
func AddReportLogFields(logger *zap.Logger, report *PayerReport) *zap.Logger
func GenerateMerkleTree ¶ added in v1.0.0
func GenerateMerkleTree(payers PayerMap) (*merkle.MerkleTree, error)
Types ¶
type AttestationStatus ¶ added in v0.5.0
type AttestationStatus int16
type BuildPayerReportParams ¶ added in v0.5.0
type FetchReportsQuery ¶ added in v0.5.0
type FetchReportsQuery struct {
SubmissionStatusIn []SubmissionStatus
AttestationStatusIn []AttestationStatus
StartSequenceID *uint64
EndSequenceID *uint64
CreatedAfter time.Time
OriginatorNodeID *uint32
PayerReportID []byte
MinAttestations *int32
}
func NewFetchReportsQuery ¶ added in v0.5.0
func NewFetchReportsQuery() *FetchReportsQuery
func (*FetchReportsQuery) WithAttestationStatus ¶ added in v0.5.0
func (f *FetchReportsQuery) WithAttestationStatus( statuses ...AttestationStatus, ) *FetchReportsQuery
func (*FetchReportsQuery) WithCreatedAfter ¶ added in v0.5.0
func (f *FetchReportsQuery) WithCreatedAfter(createdAfter time.Time) *FetchReportsQuery
func (*FetchReportsQuery) WithEndSequenceID ¶ added in v0.5.0
func (f *FetchReportsQuery) WithEndSequenceID(endSequenceID uint64) *FetchReportsQuery
func (*FetchReportsQuery) WithMinAttestations ¶ added in v0.5.0
func (f *FetchReportsQuery) WithMinAttestations(minAttestations int32) *FetchReportsQuery
func (*FetchReportsQuery) WithOriginatorNodeID ¶ added in v0.5.0
func (f *FetchReportsQuery) WithOriginatorNodeID(originatorNodeID uint32) *FetchReportsQuery
func (*FetchReportsQuery) WithReportID ¶ added in v0.5.0
func (f *FetchReportsQuery) WithReportID(payerReportID ReportID) *FetchReportsQuery
func (*FetchReportsQuery) WithStartSequenceID ¶ added in v0.5.0
func (f *FetchReportsQuery) WithStartSequenceID(startSequenceID uint64) *FetchReportsQuery
func (*FetchReportsQuery) WithSubmissionStatus ¶ added in v0.5.0
func (f *FetchReportsQuery) WithSubmissionStatus(statuses ...SubmissionStatus) *FetchReportsQuery
type IPayerReportGenerator ¶ added in v0.5.0
type IPayerReportGenerator interface {
GenerateReport(
ctx context.Context,
params PayerReportGenerationParams,
) (*PayerReportWithInputs, error)
}
type IPayerReportStore ¶ added in v0.5.0
type IPayerReportStore interface {
StoreReport(ctx context.Context, report *PayerReport) (int64, error)
CreatePayerReport(
ctx context.Context,
report *PayerReport,
payerEnvelope *envelopes.PayerEnvelope,
) (*ReportID, error)
CreateAttestation(
ctx context.Context,
attestation *PayerReportAttestation,
payerEnvelope *envelopes.PayerEnvelope,
) error
FetchReport(ctx context.Context, id ReportID) (*PayerReportWithStatus, error)
FetchReports(ctx context.Context, query *FetchReportsQuery) ([]*PayerReportWithStatus, error)
StoreSyncedReport(
ctx context.Context,
envelope *envelopes.OriginatorEnvelope,
payerID int32,
domainSeparator common.Hash,
) error
StoreSyncedAttestation(
ctx context.Context,
envelope *envelopes.OriginatorEnvelope,
payerID int32,
) error
SetReportSubmitted(ctx context.Context, id ReportID, reportIndex int32) error
ForceSetReportSubmitted(ctx context.Context, id ReportID, reportIndex int32) error
SetReportSettled(ctx context.Context, id ReportID) error
SetReportSubmissionRejected(ctx context.Context, id ReportID) error
SetReportAttestationApproved(ctx context.Context, id ReportID) error
SetReportAttestationRejected(ctx context.Context, id ReportID) error
Queries() *queries.Queries
GetAdvisoryLocker(
ctx context.Context,
) (db.ITransactionScopedAdvisoryLocker, error)
GetLatestSequenceID(ctx context.Context, originatorNodeID int32) (int64, error)
}
type IPayerReportVerifier ¶ added in v0.5.0
type IPayerReportVerifier interface {
VerifyReport(
ctx context.Context,
prevReport *PayerReport,
newReport *PayerReport,
) (VerifyReportResult, error)
GetPayerMap(
ctx context.Context,
report *PayerReport,
) (PayerMap, error)
}
type NodeSignature ¶
type PayerReport ¶
type PayerReport struct {
ID ReportID
// The Originator Node that the report is about
OriginatorNodeID uint32
// The report applies to messages with sequence IDs > StartSequenceID
StartSequenceID uint64
// The report applies to messages with sequence IDs <= EndSequenceID
EndSequenceID uint64
// The timestamp of the message at EndSequenceID
EndMinuteSinceEpoch uint32
// The merkle root of the Payers mapping
PayersMerkleRoot common.Hash
// The active node IDs in the report
ActiveNodeIDs []uint32
// The index of the report on the blockchain (null if not yet submitted or submission status is not tracked)
SubmittedReportIndex *uint32
}
func (*PayerReport) ToClientEnvelope ¶ added in v0.5.0
func (p *PayerReport) ToClientEnvelope() (*envelopes.ClientEnvelope, error)
func (*PayerReport) ToProto ¶ added in v0.4.0
func (p *PayerReport) ToProto() *proto.PayerReport
type PayerReportAttestation ¶
type PayerReportAttestation struct {
Report *PayerReport
NodeSignature NodeSignature
}
func NewPayerReportAttestation ¶ added in v0.5.0
func NewPayerReportAttestation( report *PayerReport, nodeSignature NodeSignature, ) *PayerReportAttestation
func (*PayerReportAttestation) ToClientEnvelope ¶ added in v0.5.0
func (a *PayerReportAttestation) ToClientEnvelope() (*envelopes.ClientEnvelope, error)
func (*PayerReportAttestation) ToProto ¶ added in v0.5.0
func (a *PayerReportAttestation) ToProto() *proto.PayerReportAttestation
type PayerReportGenerator ¶ added in v0.5.0
type PayerReportGenerator struct {
// contains filtered or unexported fields
}
func NewPayerReportGenerator ¶ added in v0.5.0
func NewPayerReportGenerator( logger *zap.Logger, queries *queries.Queries, registry registry.NodeRegistry, domainSeparator common.Hash, ) *PayerReportGenerator
func (*PayerReportGenerator) GenerateReport ¶ added in v0.5.0
func (p *PayerReportGenerator) GenerateReport( ctx context.Context, params PayerReportGenerationParams, ) (*PayerReportWithInputs, error)
type PayerReportVerifier ¶ added in v0.5.0
type PayerReportVerifier struct {
// contains filtered or unexported fields
}
func NewPayerReportVerifier ¶ added in v0.5.0
func NewPayerReportVerifier(logger *zap.Logger, store IPayerReportStore) *PayerReportVerifier
func (*PayerReportVerifier) GetPayerMap ¶ added in v1.0.0
func (p *PayerReportVerifier) GetPayerMap( ctx context.Context, report *PayerReport, ) (PayerMap, error)
GetPayerMap regenerates the payer map for a given report.
This function queries the database to build the payer map based on the report's sequence ID range and returns the map of payer addresses to their total spend in picoDollars.
- @param ctx The context.
- @param report The payer report to build the map for.
- @return The payer map or an error.
func (*PayerReportVerifier) VerifyReport ¶ added in v1.0.0
func (p *PayerReportVerifier) VerifyReport( ctx context.Context, prevReport *PayerReport, newReport *PayerReport, ) (VerifyReportResult, error)
VerifyReport verifies a payer report.
This function checks that the new report is valid and that it is a valid transition from the previous report.
- The previous report is assumed to be valid, and does not get validated again.
- Will regenerate the payer map and verify that the merkle root is correct. *
- @param prevReport The previous report.
- @param newReport The new report.
type PayerReportWithInputs ¶ added in v0.5.0
type PayerReportWithInputs struct {
PayerReport
// The payers in the report and the number of messages they paid for
Payers map[common.Address]currency.PicoDollar
MerkleTree *merkle.MerkleTree
NodeIDs []uint32
}
PayerReportWithInputs is a superset of a PayerReport that includes the payers and node IDs.
func BuildPayerReport ¶ added in v0.5.0
func BuildPayerReport(params BuildPayerReportParams) (*PayerReportWithInputs, error)
type PayerReportWithStatus ¶ added in v0.5.0
type PayerReportWithStatus struct {
PayerReport
AttestationSignatures []NodeSignature
// Whether the report has been submitted to the blockchain or not
SubmissionStatus SubmissionStatus
// Status of the current node's attestation of the report
AttestationStatus AttestationStatus
// The timestamp of when the report was inserted into the node's database
CreatedAt time.Time
}
type Store ¶ added in v0.5.0
type Store struct {
// contains filtered or unexported fields
}
func (*Store) CreateAttestation ¶ added in v0.5.0
func (s *Store) CreateAttestation( ctx context.Context, attestation *PayerReportAttestation, payerEnvelope *envelopes.PayerEnvelope, ) error
CreateAttestation is called by the attester of a report. Updates the attestation status of the report and writes a staged originator envelope to the database that can be synced to other nodes.
func (*Store) CreatePayerReport ¶ added in v0.5.0
func (s *Store) CreatePayerReport( ctx context.Context, report *PayerReport, payerEnvelope *envelopes.PayerEnvelope, ) (*ReportID, error)
func (*Store) FetchReport ¶ added in v0.5.0
func (*Store) FetchReports ¶ added in v0.5.0
func (s *Store) FetchReports( ctx context.Context, query *FetchReportsQuery, ) ([]*PayerReportWithStatus, error)
func (*Store) ForceSetReportSubmitted ¶ added in v1.0.0
ForceSetReportSubmitted is used to set the report submitted status to submitted, regardless of the previous status. This is a dangerous operation and should only be used in rare cases, when the system has to guarantee consistency between the database and the chain, where the chain is the source of truth.
func (*Store) GetAdvisoryLocker ¶ added in v1.0.0
func (*Store) GetLatestSequenceID ¶ added in v1.0.0
func (*Store) SetReportAttestationApproved ¶ added in v0.5.1
func (*Store) SetReportAttestationRejected ¶ added in v0.5.1
func (*Store) SetReportSettled ¶ added in v0.5.1
func (*Store) SetReportSubmissionRejected ¶ added in v1.0.0
func (*Store) SetReportSubmitted ¶ added in v0.5.1
func (*Store) StoreAttestation ¶ added in v0.5.0
func (s *Store) StoreAttestation(ctx context.Context, attestation *PayerReportAttestation) error
StoreAttestation stores an attestation in the database.
func (*Store) StoreReport ¶ added in v0.5.0
StoreReport stores a report in the database. No validations have been performed, and no originator envelope is stored.
func (*Store) StoreSyncedAttestation ¶ added in v0.5.0
type SubmissionStatus ¶ added in v0.5.0
type SubmissionStatus int16