Documentation ¶
Index ¶
- Constants
- Variables
- func InitLX()
- func V1Payout(index int) int64
- func V2Payout(index int) int64
- type BlockGrader
- type DecodeError
- type GradedBlock
- type GradingOPR
- func ValidateV1(entryhash []byte, extids [][]byte, height int32, winners []string, ...) (*GradingOPR, error)
- func ValidateV2(entryhash []byte, extids [][]byte, height int32, winners []string, ...) (*GradingOPR, error)
- func ValidateV3(entryhash []byte, extids [][]byte, height int32, winners []string, ...) (*GradingOPR, error)
- func ValidateV4(entryhash []byte, extids [][]byte, height int32, winners []string, ...) (*GradingOPR, error)
- type V1BlockGrader
- func (v1 *V1BlockGrader) AddOPR(entryhash []byte, extids [][]byte, content []byte) error
- func (bg *V1BlockGrader) Count() int
- func (bg *V1BlockGrader) GetPreviousWinners() []string
- func (v1 *V1BlockGrader) Grade() GradedBlock
- func (v1 *V1BlockGrader) GradeCustom(cutoff int) GradedBlock
- func (bg *V1BlockGrader) Height() int32
- func (v1 *V1BlockGrader) Payout(index int) int64
- func (v1 *V1BlockGrader) Version() uint8
- func (v1 *V1BlockGrader) WinnerAmount() int
- type V1GradedBlock
- func (b *V1GradedBlock) AmountGraded() int
- func (b *V1GradedBlock) Count() int
- func (b *V1GradedBlock) Cutoff() int
- func (b *V1GradedBlock) Graded() []*GradingOPR
- func (g *V1GradedBlock) Version() uint8
- func (g *V1GradedBlock) WinnerAmount() int
- func (g *V1GradedBlock) Winners() []*GradingOPR
- func (g *V1GradedBlock) WinnersShortHashes() []string
- type V2BlockGrader
- func (v2 *V2BlockGrader) AddOPR(entryhash []byte, extids [][]byte, content []byte) error
- func (bg *V2BlockGrader) Count() int
- func (bg *V2BlockGrader) GetPreviousWinners() []string
- func (v2 *V2BlockGrader) Grade() GradedBlock
- func (v2 *V2BlockGrader) GradeCustom(cutoff int) GradedBlock
- func (bg *V2BlockGrader) Height() int32
- func (v2 *V2BlockGrader) Payout(index int) int64
- func (v2 *V2BlockGrader) Version() uint8
- func (v2 *V2BlockGrader) WinnerAmount() int
- type V2GradedBlock
- func (b *V2GradedBlock) AmountGraded() int
- func (b *V2GradedBlock) Count() int
- func (b *V2GradedBlock) Cutoff() int
- func (b *V2GradedBlock) Graded() []*GradingOPR
- func (g *V2GradedBlock) Version() uint8
- func (g *V2GradedBlock) WinnerAmount() int
- func (g *V2GradedBlock) Winners() []*GradingOPR
- func (g *V2GradedBlock) WinnersShortHashes() []string
- type V3BlockGrader
- func (v3 *V3BlockGrader) AddOPR(entryhash []byte, extids [][]byte, content []byte) error
- func (bg *V3BlockGrader) Count() int
- func (bg *V3BlockGrader) GetPreviousWinners() []string
- func (v3 *V3BlockGrader) Grade() GradedBlock
- func (v3 *V3BlockGrader) GradeCustom(cutoff int) GradedBlock
- func (bg *V3BlockGrader) Height() int32
- func (v3 *V3BlockGrader) Version() uint8
- type V3GradedBlock
- type V4BlockGrader
- func (v4 *V4BlockGrader) AddOPR(entryhash []byte, extids [][]byte, content []byte) error
- func (bg *V4BlockGrader) Count() int
- func (bg *V4BlockGrader) GetPreviousWinners() []string
- func (v4 *V4BlockGrader) Grade() GradedBlock
- func (v4 *V4BlockGrader) GradeCustom(cutoff int) GradedBlock
- func (bg *V4BlockGrader) Height() int32
- func (v4 *V4BlockGrader) Version() uint8
- type V4GradedBlock
- type ValidateError
Constants ¶
const V2Band = float64(0.01) // 1%
V2Band is the size of the band employed in the grading algorithm, specified as percentage
Variables ¶
var LX *lxr.LXRHash
LX holds an instance of lxrhash
Functions ¶
func InitLX ¶
func InitLX()
The init function for LX is expensive. So we should explicitly call the init if we intend to use it. Make the init call idempotent
Types ¶
type BlockGrader ¶
type BlockGrader interface { // Height returns the height the block grader is set to Height() int32 // Version returns the version of the underlying grader Version() uint8 // GetPreviousWinners returns the set of previous winners the grader was initialized with GetPreviousWinners() []string // AddOPR adds an opr to the set to be graded. The content is decoded using the underlying version's format // and validated based on the specified height and set of previous winners. // // Returns an error if an entry could not be validated. AddOPR(entryhash []byte, extids [][]byte, content []byte) error // Grade grades the block using the default settings for that version. // For more details, see each version's Grade() function. // If the result is empty, there are no winners. Grade() GradedBlock // GradeCustom grades the OPRs using that version's algorithm and a custom cutoff for the top X GradeCustom(cutoff int) GradedBlock // Count returns the number of OPRs that have been added Count() int // Payout returns the amount of Pegtoshi awarded to the OPR at the specified index Payout(index int) int64 }
BlockGrader allows you to grade a single block. Each version has its own struct, which must be instantiated with the height and set of previous winners.
type DecodeError ¶
type DecodeError struct{ Msg string }
DecodeError indicates that there was a problem Unmarshalling the content
func NewDecodeError ¶
func NewDecodeError(m string) *DecodeError
NewDecodeError creates a new DecodeError with the specified message
func (*DecodeError) Error ¶
func (d *DecodeError) Error() string
type GradedBlock ¶
type GradedBlock interface { // WinnersShortHashes returns the shorthashes of the winning OPRs. // This result can be used to set the next block's previous winners. // The amount varies between versions. // If there are no winners in this block, the previous block's winners are used. WinnersShortHashes() []string // Winners returns the winning OPRs Winners() []*GradingOPR // Graded returns the top X OPRs that made it to the next stage of grading Graded() []*GradingOPR // Version returns the underlying grader's version Version() uint8 // Cutoff returns the amount OPRs that made it to the second stage of grading Cutoff() int // Count returns the total count of OPRs that were used in this GradedBlock Count() int // WinnerAmount returns the version specific amount of winners. WinnerAmount() int }
GradedBlock is an immutable set of graded oprs
type GradingOPR ¶
type GradingOPR struct { // Factom Entry variables EntryHash []byte Nonce []byte SelfReportedDifficulty uint64 // Grading Variables Grade float64 OPRHash []byte // Decoded OPR OPR opr.OPR // contains filtered or unexported fields }
GradingOPR holds the temporary variables used during the grading process
func ValidateV1 ¶
func ValidateV1(entryhash []byte, extids [][]byte, height int32, winners []string, content []byte) (*GradingOPR, error)
ValidateV1 validates the provided data using the specified parameters
func ValidateV2 ¶
func ValidateV2(entryhash []byte, extids [][]byte, height int32, winners []string, content []byte) (*GradingOPR, error)
ValidateV2 validates the provided data using the specified parameters
func ValidateV3 ¶
func ValidateV3(entryhash []byte, extids [][]byte, height int32, winners []string, content []byte) (*GradingOPR, error)
ValidateV2 validates the provided data using the specified parameters
func ValidateV4 ¶ added in v0.5.0
func ValidateV4(entryhash []byte, extids [][]byte, height int32, winners []string, content []byte) (*GradingOPR, error)
ValidateV4 validates the provided data using the specified parameters
func (*GradingOPR) Payout ¶
func (o *GradingOPR) Payout() int64
Payout is the amount of Pegtoshi this OPR would be rewarded with. Only valid for GradingOPRs coming from a GradedBlock
func (*GradingOPR) Position ¶
func (o *GradingOPR) Position() int
Position is the index of the OPR in the Graded set. Position 0 is the winner. Only valid for GradingOPRs coming from a GradedBlock
func (*GradingOPR) Shorthash ¶
func (o *GradingOPR) Shorthash() string
Shorthash is the hex-encoded first 8 bytes of the entry hash
type V1BlockGrader ¶
type V1BlockGrader struct {
// contains filtered or unexported fields
}
V1BlockGrader implements the first OPR that PegNet launched with. Entries are encoded in JSON with 10 winners each block. The list of assets can be found in `opr.V1Assets`
func (*V1BlockGrader) AddOPR ¶
func (v1 *V1BlockGrader) AddOPR(entryhash []byte, extids [][]byte, content []byte) error
AddOPR verifies and adds a V1 OPR.
func (*V1BlockGrader) Count ¶
func (bg *V1BlockGrader) Count() int
Count will return the total number of OPRs stored in the block. If the set has been graded, this number may be less than the amount of OPRs added due to duplicate filter and self reported difficulty checks
func (*V1BlockGrader) GetPreviousWinners ¶
func (bg *V1BlockGrader) GetPreviousWinners() []string
GetPreviousWinners returns the set of previous winners
func (*V1BlockGrader) Grade ¶
func (v1 *V1BlockGrader) Grade() GradedBlock
Grade the OPRs. The V1 algorithm works the following way:
- Take the top 50 entries with the best proof of work
- Calculate the average of each of the 32 assets
- Calculate the distance for each OPR, where the distance is the sum of the quadratic distances to the average of each asset
- Throw out the OPR with the highest distance
- Repeat 3-4 until there are only 10 OPRs left
func (*V1BlockGrader) GradeCustom ¶
func (v1 *V1BlockGrader) GradeCustom(cutoff int) GradedBlock
GradeCustom grades the block using a custom cutoff for the top X
func (*V1BlockGrader) Height ¶
func (bg *V1BlockGrader) Height() int32
Height returns the height the block grader is set to
func (*V1BlockGrader) Payout ¶
func (v1 *V1BlockGrader) Payout(index int) int64
Payout returns the amount of Pegtoshi awarded to the OPR at the specified index
func (*V1BlockGrader) WinnerAmount ¶
func (v1 *V1BlockGrader) WinnerAmount() int
WinnerAmount is the number of OPRs that receive a payout
type V1GradedBlock ¶
type V1GradedBlock struct {
// contains filtered or unexported fields
}
V1GradedBlock is an opr set that has been graded. The set should be read only through it's interface implementation.
func (*V1GradedBlock) AmountGraded ¶
func (b *V1GradedBlock) AmountGraded() int
AmountToGrade returns the number of OPRs the grading algorithm attempted to use in the process.
func (*V1GradedBlock) Graded ¶
func (b *V1GradedBlock) Graded() []*GradingOPR
Graded returns the OPRs that made it into the cutoff
func (*V1GradedBlock) Version ¶
func (g *V1GradedBlock) Version() uint8
Version returns the underlying grader's version
func (*V1GradedBlock) WinnerAmount ¶
func (g *V1GradedBlock) WinnerAmount() int
WinnerAmount is the number of OPRs that receive a payout
func (*V1GradedBlock) Winners ¶
func (g *V1GradedBlock) Winners() []*GradingOPR
Winners returns the winning OPRs
func (*V1GradedBlock) WinnersShortHashes ¶
func (g *V1GradedBlock) WinnersShortHashes() []string
WinnersShortHashes returns the shorthashes of the winning OPRs.
type V2BlockGrader ¶
type V2BlockGrader struct {
// contains filtered or unexported fields
}
V2BlockGrader implements the V2 grading algorithm. Entries are encoded in Protobuf with 25 winners each block. Valid assets can be found in ´opr.V2Assets´
func (*V2BlockGrader) AddOPR ¶
func (v2 *V2BlockGrader) AddOPR(entryhash []byte, extids [][]byte, content []byte) error
AddOPR verifies and adds a V2 OPR.
func (*V2BlockGrader) Count ¶
func (bg *V2BlockGrader) Count() int
Count will return the total number of OPRs stored in the block. If the set has been graded, this number may be less than the amount of OPRs added due to duplicate filter and self reported difficulty checks
func (*V2BlockGrader) GetPreviousWinners ¶
func (bg *V2BlockGrader) GetPreviousWinners() []string
GetPreviousWinners returns the set of previous winners
func (*V2BlockGrader) Grade ¶
func (v2 *V2BlockGrader) Grade() GradedBlock
Grade the OPRs. The V2 algorithm works the following way:
- Take the top 50 entries with the best proof of work
- Calculate the average of each of the 32 assets
- Calculate the distance of each OPR to the average, where distance is the sum of quadratic differences to the average of each asset. If an asset is within `band`% of the average, that asset's distance is 0.
- Throw out the OPR with the highest distance
- Repeat 3-4 until there are only 25 OPRs left
- Repeat 3 but this time don't apply the band and don't throw out OPRs, just reorder them until you are left with one
func (*V2BlockGrader) GradeCustom ¶
func (v2 *V2BlockGrader) GradeCustom(cutoff int) GradedBlock
GradeCustom grades the block using a custom cutoff for the top X
func (*V2BlockGrader) Height ¶
func (bg *V2BlockGrader) Height() int32
Height returns the height the block grader is set to
func (*V2BlockGrader) Payout ¶
func (v2 *V2BlockGrader) Payout(index int) int64
Payout returns the amount of Pegtoshi awarded to the OPR at the specified index
func (*V2BlockGrader) WinnerAmount ¶
func (v2 *V2BlockGrader) WinnerAmount() int
WinnerAmount is the number of OPRs that receive a payout
type V2GradedBlock ¶
type V2GradedBlock struct {
// contains filtered or unexported fields
}
V2GradedBlock is an opr set that has been graded. The set should be read only through it's interface implementation.
func (*V2GradedBlock) AmountGraded ¶
func (b *V2GradedBlock) AmountGraded() int
AmountToGrade returns the number of OPRs the grading algorithm attempted to use in the process.
func (*V2GradedBlock) Graded ¶
func (b *V2GradedBlock) Graded() []*GradingOPR
Graded returns the OPRs that made it into the cutoff
func (*V2GradedBlock) Version ¶
func (g *V2GradedBlock) Version() uint8
Version returns the underlying grader's version
func (*V2GradedBlock) WinnerAmount ¶
func (g *V2GradedBlock) WinnerAmount() int
WinnerAmount returns the version specific amount of winners.
func (*V2GradedBlock) Winners ¶
func (g *V2GradedBlock) Winners() []*GradingOPR
Winners returns the winning OPRs
func (*V2GradedBlock) WinnersShortHashes ¶
func (g *V2GradedBlock) WinnersShortHashes() []string
WinnersShortHashes returns the shorthashes of the winning OPRs.
type V3BlockGrader ¶
type V3BlockGrader struct {
V2BlockGrader
}
V3BlockGrader implements the V2 grading algorithm but requires PEG to have a price.
func (*V3BlockGrader) AddOPR ¶
func (v3 *V3BlockGrader) AddOPR(entryhash []byte, extids [][]byte, content []byte) error
AddOPR verifies and adds a V3 OPR.
func (*V3BlockGrader) Count ¶
func (bg *V3BlockGrader) Count() int
Count will return the total number of OPRs stored in the block. If the set has been graded, this number may be less than the amount of OPRs added due to duplicate filter and self reported difficulty checks
func (*V3BlockGrader) GetPreviousWinners ¶
func (bg *V3BlockGrader) GetPreviousWinners() []string
GetPreviousWinners returns the set of previous winners
func (*V3BlockGrader) Grade ¶
func (v3 *V3BlockGrader) Grade() GradedBlock
Grade the OPRs. The V2 algorithm works the following way:
- Take the top 50 entries with the best proof of work
- Calculate the average of each of the 32 assets
- Calculate the distance of each OPR to the average, where distance is the sum of quadratic differences to the average of each asset. If an asset is within `band`% of the average, that asset's distance is 0.
- Throw out the OPR with the highest distance
- Repeat 3-4 until there are only 25 OPRs left
- Repeat 3 but this time don't apply the band and don't throw out OPRs, just reorder them until you are left with one
func (*V3BlockGrader) GradeCustom ¶
func (v3 *V3BlockGrader) GradeCustom(cutoff int) GradedBlock
GradeCustom grades the block using a custom cutoff for the top X
type V3GradedBlock ¶
type V3GradedBlock struct {
GradedBlock
}
V3GradedBlock is an opr set that has been graded. The set should be read only through it's interface implementation.
func (*V3GradedBlock) Version ¶
func (g *V3GradedBlock) Version() uint8
Version returns the underlying grader's version
type V4BlockGrader ¶ added in v0.5.0
type V4BlockGrader struct { // intentionally v2 and not v3. // v2 implements the correct grading for v3 and v4. The only // difference is validation rules and in v4, some additional currencies. V2BlockGrader }
V4BlockGrader implements the V2 grading algorithm but requires PEG to have a price.
func (*V4BlockGrader) AddOPR ¶ added in v0.5.0
func (v4 *V4BlockGrader) AddOPR(entryhash []byte, extids [][]byte, content []byte) error
AddOPR verifies and adds a V4 OPR.
func (*V4BlockGrader) Count ¶ added in v0.5.0
func (bg *V4BlockGrader) Count() int
Count will return the total number of OPRs stored in the block. If the set has been graded, this number may be less than the amount of OPRs added due to duplicate filter and self reported difficulty checks
func (*V4BlockGrader) GetPreviousWinners ¶ added in v0.5.0
func (bg *V4BlockGrader) GetPreviousWinners() []string
GetPreviousWinners returns the set of previous winners
func (*V4BlockGrader) Grade ¶ added in v0.5.0
func (v4 *V4BlockGrader) Grade() GradedBlock
Grade the OPRs. The V2 algorithm works the following way:
- Take the top 50 entries with the best proof of work
- Calculate the average of each of the 32 assets
- Calculate the distance of each OPR to the average, where distance is the sum of quadratic differences to the average of each asset. If an asset is within `band`% of the average, that asset's distance is 0.
- Throw out the OPR with the highest distance
- Repeat 3-4 until there are only 25 OPRs left
- Repeat 3 but this time don't apply the band and don't throw out OPRs, just reorder them until you are left with one
func (*V4BlockGrader) GradeCustom ¶ added in v0.5.0
func (v4 *V4BlockGrader) GradeCustom(cutoff int) GradedBlock
GradeCustom grades the block using a custom cutoff for the top X
type V4GradedBlock ¶ added in v0.5.0
type V4GradedBlock struct {
GradedBlock
}
V4GradedBlock is an opr set that has been graded. The set should be read only through it's interface implementation.
func (*V4GradedBlock) Version ¶ added in v0.5.0
func (g *V4GradedBlock) Version() uint8
Version returns the underlying grader's version
type ValidateError ¶
type ValidateError struct{ Msg string }
ValidateError indicates that there is an incompatibility with the data
func NewValidateError ¶
func NewValidateError(m string) *ValidateError
NewValidateError creates a new ValidateError with the specified message
func (*ValidateError) Error ¶
func (v *ValidateError) Error() string