Documentation
¶
Overview ¶
Package payerreport implements the payer report generator and verifier interfaces.
Index ¶
- Constants
- Variables
- 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 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) 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) SetReportSubmitted(ctx context.Context, id ReportID) error
- func (s *Store) StoreAttestation(ctx context.Context, attestation *PayerReportAttestation) error
- func (s *Store) StoreReport(ctx context.Context, report *PayerReport) 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
Constants ¶
const ( SubmissionPending SubmissionStatus = iota SubmissionSubmitted = 1 SubmissionSettled = 2 )
const ( AttestationPending AttestationStatus = iota AttestationApproved = 1 AttestationRejected = 2 )
Variables ¶
var ( ErrNoActiveNodeIDs = errors.New("no active node IDs") ErrInvalidReportID = errors.New("invalid report ID") ErrOriginatorNodeIDTooLarge = errors.New("originator node ID is > max int32") ErrStartSequenceIDTooLarge = errors.New("start sequence ID is > max int64") ErrEndSequenceIDTooLarge = errors.New("end sequence ID is > max int64") ErrEndMinuteSinceEpochTooLarge = errors.New("end minute since epoch is > max int32") ErrNodesCountTooLarge = errors.New("nodes count is > max int32") ErrActiveNodeIDTooLarge = errors.New("active node ID is > max int32") ErrReportNotFound = errors.New("report not found") ErrReportNil = errors.New("report is nil") )
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") ErrMessageNotAtMinuteEnd = errors.New( "sequence id is not the last message in the minute", ) ErrMessageAtStartSequenceIDNotFound = errors.New("message at start sequence id not found") ErrMessageAtEndSequenceIDNotFound = errors.New("message at end sequence id not found") ErrMerkleRootMismatch = errors.New("payers merkle root mismatch") )
Functions ¶
This section is empty.
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) 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) error
SetReportSettled(ctx context.Context, id ReportID) error
SetReportAttestationApproved(ctx context.Context, id ReportID) error
SetReportAttestationRejected(ctx context.Context, id ReportID) error
Queries() *queries.Queries
}
type IPayerReportVerifier ¶ added in v0.5.0
type IPayerReportVerifier interface {
IsValidReport(
ctx context.Context,
prevReport *PayerReport,
newReport *PayerReport,
) (bool, 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
}
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( log *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(log *zap.Logger, store IPayerReportStore) *PayerReportVerifier
func (*PayerReportVerifier) IsValidReport ¶ added in v0.5.0
func (p *PayerReportVerifier) IsValidReport( ctx context.Context, prevReport *PayerReport, newReport *PayerReport, ) (bool, error)
IsValidReport validates 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) SetReportAttestationApproved ¶ added in v0.5.1
func (*Store) SetReportAttestationRejected ¶ added in v0.5.1
func (*Store) SetReportSettled ¶ added in v0.5.1
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
func (s *Store) StoreReport(ctx context.Context, report *PayerReport) error
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