graderStake

package
v0.5.1-0...-a476b4b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 25, 2021 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const S1Band = float64(0.01) // 1%

S1Band is the size of the band employed in the grading algorithm, specified as percentage

View Source
const S2Band = float64(0.01) // 1%

S2Band is the size of the band employed in the grading algorithm, specified as percentage

View Source
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 S1Payout

func S1Payout(index int) int64

S1Payout is the amount of Pegtoshi given to the SPR with the specified index

func TrimmedMeanFloat

func TrimmedMeanFloat(data []float64, p int) float64

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.

func NewGrader

func NewGrader(version uint8, height int32) (BlockGrader, error)

NewGrader instantiates a IBlockGrader Grader for a specific version.

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) Clone

func (o *GradingSPR) Clone() *GradingSPR

Clone the GradingSPR

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:

  1. Take the top 50 entries with the best proof of work
  2. Remove top and low's 1% band from each of the 32 assets
  3. Calculate the average of each of the 32 assets
  4. 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.
  5. Throw out the SPR with the highest distance
  6. Repeat 3-4 until there are only 25 SPRs left
  7. 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) Version

func (s1 *S1BlockGrader) Version() uint8

Version 5

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) Count

func (b *S1GradedBlock) Count() int

func (*S1GradedBlock) Cutoff

func (b *S1GradedBlock) Cutoff() int

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:

  1. Take the top 50 entries with the best proof of work
  2. Remove top and low's 1% band from each of the 32 assets
  3. Calculate the average of each of the 32 assets
  4. 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.
  5. Throw out the SPR with the highest distance
  6. Repeat 3-4 until there are only 25 SPRs left
  7. 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) Version

func (s2 *S2BlockGrader) Version() uint8

Version 6

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) Count

func (b *S2GradedBlock) Count() int

func (*S2GradedBlock) Cutoff

func (b *S2GradedBlock) Cutoff() int

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:

  1. Take the top 50 entries with the best proof of work
  2. Remove top and low's 1% band from each of the 32 assets
  3. Calculate the average of each of the 32 assets
  4. 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.
  5. Throw out the SPR with the highest distance
  6. Repeat 3-4 until there are only 25 SPRs left
  7. 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) Version

func (s3 *S3BlockGrader) Version() uint8

Version 7

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) Count

func (b *S3GradedBlock) Count() int

func (*S3GradedBlock) Cutoff

func (b *S3GradedBlock) Cutoff() int

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL