protocol

package
v0.0.13 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2025 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RelayHasherSize = sha256.Size
	TrieHasherSize  = sha256.Size
	TrieRootSize    = TrieHasherSize + trieRootMetadataSize
	TrieRootSumSize = 8 // TODO_CONSIDERATION: Export this from the SMT package.

)

Variables

View Source
var (
	NewRelayHasher = sha256.New
	NewTrieHasher  = sha256.New
)
View Source
var (
	// BaseRelayDifficultyHashBz is the chosen "highest" (easiest) target hash,
	// which corresponds to the lowest possible difficulty.
	//
	// In simple terms, it mean "every relay is a volume applicable relay".
	//
	// It other words, it is used to normalize all relay mining difficulties.
	//
	// Bitcoin uses a similar concept, where the target hash is defined as the hash:
	// - https://bitcoin.stackexchange.com/questions/107976/bitcoin-difficulty-why-leading-0s
	// - https://bitcoin.stackexchange.com/questions/121920/is-it-always-possible-to-find-a-number-whose-hash-starts-with-a-certain-number-o
	BaseRelayDifficultyHashHex   = "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" // all relays are payable
	BaseRelayDifficultyHashBz, _ = hex.DecodeString(BaseRelayDifficultyHashHex)
)

Functions

func ComputeNewDifficultyTargetHash added in v0.0.10

func ComputeNewDifficultyTargetHash(prevTargetHash []byte, targetNumRelays, newRelaysEma uint64) []byte

ComputeNewDifficultyTargetHash computes the new difficulty target hash based on the target number of relays we want the network to mine and the new EMA of the number of relays.

func GetPathForProof added in v0.0.4

func GetPathForProof(blockHash []byte, sessionId string) []byte

GetPathForProof computes the path to be used for proof validation by hashing the block hash and session id.

func GetRelayDifficultyMultiplier added in v0.0.10

func GetRelayDifficultyMultiplier(relayDifficultyHash []byte) *big.Rat

GetRelayDifficultyMultiplier returns the inverse of GetRelayDifficultyProbability to scale onchain volume applicable relays to estimated serviced offchain relays.

func GetRelayDifficultyMultiplierToFloat32 added in v0.0.10

func GetRelayDifficultyMultiplierToFloat32(relayDifficultyHash []byte) float32

GetRelayDifficultyMultiplierToFloat32 returns a human readable integer representation of GetRelayDifficultyProbability. THIS IS TO BE USED FOR TELEMETRY PURPOSES ONLY. See the following discussing for why we're using a float32: https://github.com/pokt-network/poktroll/pull/771#discussion_r1761517063

func GetRelayDifficultyProbability added in v0.0.10

func GetRelayDifficultyProbability(relayDifficultyHash []byte) *big.Rat

GetRelayDifficultyProbability returns a fraction that determines the probability that a target (i.e. difficulty) hash is relative to the baseline.

func GetRelayHashFromBytes added in v0.0.5

func GetRelayHashFromBytes(relayBz []byte) (hash [RelayHasherSize]byte)

GetRelayHashFromBytes returns the hash of the relay (full, request or response) bytes. It is used as helper in the case that the relay is already marshaled and centralizes the hasher used.

func IsRelayVolumeApplicable added in v0.0.5

func IsRelayVolumeApplicable(relayHash, targetHash []byte) bool

IsRelayVolumeApplicable returns true if the relay IS reward / volume applicable. A relay is reward / volume applicable IFF its hash is less than the target hash.

  • relayHash is the hash of the relay to be checked.
  • targetHash is the hash of the relay difficulty target for a particular service.

func NewSMTSpec added in v0.0.12

func NewSMTSpec() *smt.TrieSpec

NewSMTSpec returns the SMT specification used for proof verification. A new hasher is created for each call to prevent concurrency issues from shared state.

func SMTValueHasher added in v0.0.12

func SMTValueHasher() smt.TrieSpecOption

func ScaleRelayDifficultyHash added in v0.0.10

func ScaleRelayDifficultyHash(
	initialDifficultyHashBz []byte,
	difficultyScalingRatio *big.Rat,
) []byte

ScaleRelayDifficultyHash scales the provided hash based on the given ratio. If the ratio is less than 1, the hash will be scaled down. DEV_NOTE: Only exposed publicly for testing purposes.

Types

This section is empty.

Jump to

Keyboard shortcuts

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