Documentation
¶
Index ¶
- Constants
- func S1Payout(index int) int64
- func TrimmedMeanFloat(data []float64, p int) float64
- type BlockGrader
- type DecodeError
- type GradedBlock
- type GradingSPR
- func ValidateS1(entryhash []byte, extids [][]byte, height int32, content []byte) (*GradingSPR, error)
- func ValidateS2(entryhash []byte, extids [][]byte, height int32, content []byte) (*GradingSPR, error)
- func ValidateS3(entryhash []byte, extids [][]byte, height int32, content []byte) (*GradingSPR, error)
- type S1BlockGrader
- func (s1 *S1BlockGrader) AddSPR(entryhash []byte, extids [][]byte, content []byte) error
- func (bg *S1BlockGrader) Count() int
- func (bg *S1BlockGrader) GetPreviousWinners() []string
- func (s1 *S1BlockGrader) Grade() GradedBlock
- func (s1 *S1BlockGrader) GradeCustom(cutoff int) GradedBlock
- func (bg *S1BlockGrader) Height() int32
- func (s1 *S1BlockGrader) Payout(index int) int64
- func (s1 *S1BlockGrader) Version() uint8
- func (s1 *S1BlockGrader) WinnerAmount() int
- type S1GradedBlock
- func (b *S1GradedBlock) AmountGraded() int
- func (b *S1GradedBlock) Count() int
- func (b *S1GradedBlock) Cutoff() int
- func (b *S1GradedBlock) Graded() []*GradingSPR
- func (g *S1GradedBlock) Version() uint8
- func (g *S1GradedBlock) WinnerAmount() int
- func (g *S1GradedBlock) Winners() []*GradingSPR
- func (g *S1GradedBlock) WinnersShortHashes() []string
- type S2BlockGrader
- func (s2 *S2BlockGrader) AddSPR(entryhash []byte, extids [][]byte, content []byte) error
- func (bg *S2BlockGrader) Count() int
- func (bg *S2BlockGrader) GetPreviousWinners() []string
- func (s2 *S2BlockGrader) Grade() GradedBlock
- func (s2 *S2BlockGrader) GradeCustom(cutoff int) GradedBlock
- func (bg *S2BlockGrader) Height() int32
- func (s2 *S2BlockGrader) Payout(index int) int64
- func (s2 *S2BlockGrader) Version() uint8
- func (s2 *S2BlockGrader) WinnerAmount() int
- type S2GradedBlock
- func (b *S2GradedBlock) AmountGraded() int
- func (b *S2GradedBlock) Count() int
- func (b *S2GradedBlock) Cutoff() int
- func (b *S2GradedBlock) Graded() []*GradingSPR
- func (g *S2GradedBlock) Version() uint8
- func (g *S2GradedBlock) WinnerAmount() int
- func (g *S2GradedBlock) Winners() []*GradingSPR
- func (g *S2GradedBlock) WinnersShortHashes() []string
- type S3BlockGrader
- func (s3 *S3BlockGrader) AddSPR(entryhash []byte, extids [][]byte, content []byte) error
- func (bg *S3BlockGrader) Count() int
- func (bg *S3BlockGrader) GetPreviousWinners() []string
- func (s3 *S3BlockGrader) Grade() GradedBlock
- func (s3 *S3BlockGrader) GradeCustom(cutoff int) GradedBlock
- func (bg *S3BlockGrader) Height() int32
- func (s3 *S3BlockGrader) Payout(index int) int64
- func (s3 *S3BlockGrader) Version() uint8
- func (s3 *S3BlockGrader) WinnerAmount() int
- type S3GradedBlock
- func (b *S3GradedBlock) AmountGraded() int
- func (b *S3GradedBlock) Count() int
- func (b *S3GradedBlock) Cutoff() int
- func (b *S3GradedBlock) Graded() []*GradingSPR
- func (g *S3GradedBlock) Version() uint8
- func (g *S3GradedBlock) WinnerAmount() int
- func (g *S3GradedBlock) Winners() []*GradingSPR
- func (g *S3GradedBlock) WinnersShortHashes() []string
- type ValidateError
Constants ¶
const S1Band = float64(0.01) // 1%
S1Band is the size of the band employed in the grading algorithm, specified as percentage
const S2Band = float64(0.01) // 1%
S2Band is the size of the band employed in the grading algorithm, specified as percentage
const S3Band = float64(0.01) // 1%
S3Band is the size of the band employed in the grading algorithm, specified as percentage
Variables ¶
This section is empty.
Functions ¶
func TrimmedMeanFloat ¶
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
// AddSPR adds an spr 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.
AddSPR(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 SPRs using that version's algorithm and a custom cutoff for the top X
GradeCustom(cutoff int) GradedBlock
// Count returns the number of SPRs that have been added
Count() int
// Payout returns the amount of Pegtoshi awarded to the SPR 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 SPRs.
// 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 SPRs
Winners() []*GradingSPR
// Graded returns the top X SPRs that made it to the next stage of grading
Graded() []*GradingSPR
// Version returns the underlying grader's version
Version() uint8
// Cutoff returns the amount SPRs that made it to the second stage of grading
Cutoff() int
// Count returns the total count of SPRs 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 sprs
type GradingSPR ¶
type GradingSPR struct {
// Factom Entry variables
EntryHash []byte
CoinbaseAddress string
// Grading Variables
Grade float64
SPRHash []byte
// Decoded SPR
SPR spr.SPR
// contains filtered or unexported fields
}
GradingSPR holds the temporary variables used during the grading process
func ValidateS1 ¶
func ValidateS1(entryhash []byte, extids [][]byte, height int32, content []byte) (*GradingSPR, error)
ValidateS1 validates the provided data using the specified parameters
func ValidateS2 ¶
func ValidateS2(entryhash []byte, extids [][]byte, height int32, content []byte) (*GradingSPR, error)
ValidateS2 validates the provided data using the specified parameters
func ValidateS3 ¶
func ValidateS3(entryhash []byte, extids [][]byte, height int32, content []byte) (*GradingSPR, error)
ValidateS3 validates the provided data using the specified parameters
func (*GradingSPR) Payout ¶
func (o *GradingSPR) Payout() int64
Payout is the amount of Pegtoshi this SPR would be rewarded with. Only valid for GradingSPRs coming from a GradedBlock
func (*GradingSPR) Position ¶
func (o *GradingSPR) Position() int
Position is the index of the SPR in the Graded set. Position 0 is the winner. Only valid for GradingSPRs coming from a GradedBlock
func (*GradingSPR) Shorthash ¶
func (o *GradingSPR) Shorthash() string
Shorthash is the hex-encoded first 8 bytes of the entry hash
type S1BlockGrader ¶
type S1BlockGrader struct {
// contains filtered or unexported fields
}
S1BlockGrader implements the S1 grading algorithm. Entries are encoded in Protobuf with 25 winners each block. Valid assets can be found in ´opr.V5Assets´
func (*S1BlockGrader) AddSPR ¶
func (s1 *S1BlockGrader) AddSPR(entryhash []byte, extids [][]byte, content []byte) error
AddSPR verifies and adds a S1 SPR.
func (*S1BlockGrader) Count ¶
func (bg *S1BlockGrader) Count() int
Count will return the total number of SPRs stored in the block. If the set has been graded, this number may be less than the amount of SPRs added due to duplicate filter and self reported difficulty checks
func (*S1BlockGrader) GetPreviousWinners ¶
func (bg *S1BlockGrader) GetPreviousWinners() []string
GetPreviousWinners returns the set of previous winners
func (*S1BlockGrader) Grade ¶
func (s1 *S1BlockGrader) Grade() GradedBlock
Grade the SPRs. The S1 algorithm works the following way:
- Take the top 50 entries with the best proof of work
- Remove top and low's 1% band from each of the 32 assets
- Calculate the average of each of the 32 assets
- Calculate the distance of each SPR 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 SPR with the highest distance
- Repeat 3-4 until there are only 25 SPRs left
- Repeat 3 but this time don't apply the band and don't throw out SPRs, just reorder them until you are left with one
func (*S1BlockGrader) GradeCustom ¶
func (s1 *S1BlockGrader) GradeCustom(cutoff int) GradedBlock
GradeCustom grades the block using a custom cutoff for the top X
func (*S1BlockGrader) Height ¶
func (bg *S1BlockGrader) Height() int32
Height returns the height the block grader is set to
func (*S1BlockGrader) Payout ¶
func (s1 *S1BlockGrader) Payout(index int) int64
Payout returns the amount of Pegtoshi awarded to the SPR at the specified index
func (*S1BlockGrader) WinnerAmount ¶
func (s1 *S1BlockGrader) WinnerAmount() int
WinnerAmount is the number of SPRs that receive a payout
type S1GradedBlock ¶
type S1GradedBlock struct {
// contains filtered or unexported fields
}
S1GradedBlock is an spr set that has been graded. The set should be read only through it's interface implementation.
func (*S1GradedBlock) AmountGraded ¶
func (b *S1GradedBlock) AmountGraded() int
AmountToGrade returns the number of SPRs the grading algorithm attempted to use in the process.
func (*S1GradedBlock) Graded ¶
func (b *S1GradedBlock) Graded() []*GradingSPR
Graded returns the SPRs that made it into the cutoff
func (*S1GradedBlock) Version ¶
func (g *S1GradedBlock) Version() uint8
Version returns the underlying grader's version
func (*S1GradedBlock) WinnerAmount ¶
func (g *S1GradedBlock) WinnerAmount() int
WinnerAmount returns the version specific amount of winners.
func (*S1GradedBlock) Winners ¶
func (g *S1GradedBlock) Winners() []*GradingSPR
Winners returns the winning SPRs
func (*S1GradedBlock) WinnersShortHashes ¶
func (g *S1GradedBlock) WinnersShortHashes() []string
WinnersShortHashes returns the shorthashes of the winning SPRs.
type S2BlockGrader ¶
type S2BlockGrader struct {
// contains filtered or unexported fields
}
S2BlockGrader implements the s2 grading algorithm. Entries are encoded in Protobuf with 25 winners each block. Valid assets can be found in ´opr.V5Assets´
func (*S2BlockGrader) AddSPR ¶
func (s2 *S2BlockGrader) AddSPR(entryhash []byte, extids [][]byte, content []byte) error
AddSPR verifies and adds a s2 SPR.
func (*S2BlockGrader) Count ¶
func (bg *S2BlockGrader) Count() int
Count will return the total number of SPRs stored in the block. If the set has been graded, this number may be less than the amount of SPRs added due to duplicate filter and self reported difficulty checks
func (*S2BlockGrader) GetPreviousWinners ¶
func (bg *S2BlockGrader) GetPreviousWinners() []string
GetPreviousWinners returns the set of previous winners
func (*S2BlockGrader) Grade ¶
func (s2 *S2BlockGrader) Grade() GradedBlock
Grade the SPRs. The S1 algorithm works the following way:
- Take the top 50 entries with the best proof of work
- Remove top and low's 1% band from each of the 32 assets
- Calculate the average of each of the 32 assets
- Calculate the distance of each SPR 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 SPR with the highest distance
- Repeat 3-4 until there are only 25 SPRs left
- Repeat 3 but this time don't apply the band and don't throw out SPRs, just reorder them until you are left with one
func (*S2BlockGrader) GradeCustom ¶
func (s2 *S2BlockGrader) GradeCustom(cutoff int) GradedBlock
GradeCustom grades the block using a custom cutoff for the top X
func (*S2BlockGrader) Height ¶
func (bg *S2BlockGrader) Height() int32
Height returns the height the block grader is set to
func (*S2BlockGrader) Payout ¶
func (s2 *S2BlockGrader) Payout(index int) int64
Payout returns the amount of Pegtoshi awarded to the SPR at the specified index
func (*S2BlockGrader) WinnerAmount ¶
func (s2 *S2BlockGrader) WinnerAmount() int
WinnerAmount is the number of SPRs that receive a payout
type S2GradedBlock ¶
type S2GradedBlock struct {
// contains filtered or unexported fields
}
S1GradedBlock is an spr set that has been graded. The set should be read only through it's interface implementation.
func (*S2GradedBlock) AmountGraded ¶
func (b *S2GradedBlock) AmountGraded() int
AmountToGrade returns the number of SPRs the grading algorithm attempted to use in the process.
func (*S2GradedBlock) Graded ¶
func (b *S2GradedBlock) Graded() []*GradingSPR
Graded returns the SPRs that made it into the cutoff
func (*S2GradedBlock) Version ¶
func (g *S2GradedBlock) Version() uint8
Version returns the underlying grader's version
func (*S2GradedBlock) WinnerAmount ¶
func (g *S2GradedBlock) WinnerAmount() int
WinnerAmount returns the version specific amount of winners.
func (*S2GradedBlock) Winners ¶
func (g *S2GradedBlock) Winners() []*GradingSPR
Winners returns the winning SPRs
func (*S2GradedBlock) WinnersShortHashes ¶
func (g *S2GradedBlock) WinnersShortHashes() []string
WinnersShortHashes returns the shorthashes of the winning SPRs.
type S3BlockGrader ¶
type S3BlockGrader struct {
// contains filtered or unexported fields
}
S3BlockGrader implements the S3 grading algorithm. Entries are encoded in Protobuf with 25 winners each block. Valid assets can be found in ´opr.V5Assets´
func (*S3BlockGrader) AddSPR ¶
func (s3 *S3BlockGrader) AddSPR(entryhash []byte, extids [][]byte, content []byte) error
AddSPR verifies and adds a s3 SPR.
func (*S3BlockGrader) Count ¶
func (bg *S3BlockGrader) Count() int
Count will return the total number of SPRs stored in the block. If the set has been graded, this number may be less than the amount of SPRs added due to duplicate filter and self reported difficulty checks
func (*S3BlockGrader) GetPreviousWinners ¶
func (bg *S3BlockGrader) GetPreviousWinners() []string
GetPreviousWinners returns the set of previous winners
func (*S3BlockGrader) Grade ¶
func (s3 *S3BlockGrader) Grade() GradedBlock
Grade the SPRs. The S1 algorithm works the following way:
- Take the top 50 entries with the best proof of work
- Remove top and low's 1% band from each of the 32 assets
- Calculate the average of each of the 32 assets
- Calculate the distance of each SPR 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 SPR with the highest distance
- Repeat 3-4 until there are only 25 SPRs left
- Repeat 3 but this time don't apply the band and don't throw out SPRs, just reorder them until you are left with one
func (*S3BlockGrader) GradeCustom ¶
func (s3 *S3BlockGrader) GradeCustom(cutoff int) GradedBlock
GradeCustom grades the block using a custom cutoff for the top X
func (*S3BlockGrader) Height ¶
func (bg *S3BlockGrader) Height() int32
Height returns the height the block grader is set to
func (*S3BlockGrader) Payout ¶
func (s3 *S3BlockGrader) Payout(index int) int64
Payout returns the amount of Pegtoshi awarded to the SPR at the specified index
func (*S3BlockGrader) WinnerAmount ¶
func (s3 *S3BlockGrader) WinnerAmount() int
WinnerAmount is the number of SPRs that receive a payout
type S3GradedBlock ¶
type S3GradedBlock struct {
// contains filtered or unexported fields
}
S1GradedBlock is an spr set that has been graded. The set should be read only through it's interface implementation.
func (*S3GradedBlock) AmountGraded ¶
func (b *S3GradedBlock) AmountGraded() int
AmountToGrade returns the number of SPRs the grading algorithm attempted to use in the process.
func (*S3GradedBlock) Graded ¶
func (b *S3GradedBlock) Graded() []*GradingSPR
Graded returns the SPRs that made it into the cutoff
func (*S3GradedBlock) Version ¶
func (g *S3GradedBlock) Version() uint8
Version returns the underlying grader's version
func (*S3GradedBlock) WinnerAmount ¶
func (g *S3GradedBlock) WinnerAmount() int
WinnerAmount returns the version specific amount of winners.
func (*S3GradedBlock) Winners ¶
func (g *S3GradedBlock) Winners() []*GradingSPR
Winners returns the winning SPRs
func (*S3GradedBlock) WinnersShortHashes ¶
func (g *S3GradedBlock) WinnersShortHashes() []string
WinnersShortHashes returns the shorthashes of the winning SPRs.
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