sidechain

package
v5.0.4 Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2025 License: MIT Imports: 31 Imported by: 0

Documentation

Index

Constants

View Source
const (
	UncleBlockDepth   = 3
	MaxTxOutputReward = (1 << 56) - 1
)
View Source
const (
	ShareVersion_None = ShareVersion(iota)

	// ShareVersion_V1 Initial version.
	ShareVersion_V1

	// ShareVersion_V2 Introduced in P2Pool v3.0+
	ShareVersion_V2

	// ShareVersion_V3 Introduced in P2Pool v4.0+ with merge mining support
	ShareVersion_V3
)
View Source
const (
	SideExtraNonce = transaction.TxExtraTagNonce

	// SideIdentifierHash Depending on version, this can be a PoolBlock TemplateId or Merkle Root Hash
	SideIdentifierHash = transaction.TxExtraTagMergeMining
)
View Source
const LargestMinimumDifficulty = 1000000000
View Source
const MaxUncleCount = uint64(math.MaxUint64) / types.HashSize
View Source
const PoolBlockMaxSideChainHeight = 31556952000

PoolBlockMaxSideChainHeight 1000 years at 1 block/second. It should be enough for any normal use.

View Source
const PoolBlockMaxTemplateSize = 128*1024 - (1 + 4)

PoolBlockMaxTemplateSize Max P2P message size (128 KB) minus BLOCK_RESPONSE header (5 bytes)

View Source
const SideExtraNonceMaxSize = SideExtraNonceSize + 10
View Source
const SideExtraNonceSize = 4
View Source
const SmallestMinimumDifficulty = 100000

Variables

View Source
var ConsensusDefault = &Consensus{
	NetworkType:       NetworkMainnet,
	PoolName:          "mainnet test 2",
	TargetBlockTime:   10,
	MinimumDifficulty: 100000,
	ChainWindowSize:   2160,
	UnclePenalty:      20,
	HardForks:         p2poolMainNetHardForks,
	MoneroHardForks:   monero.NetworkHardFork(monero.MainNetwork),
	Id:                types.Hash{34, 175, 126, 231, 181, 11, 104, 146, 227, 153, 218, 107, 44, 108, 68, 39, 178, 81, 4, 212, 169, 4, 142, 0, 177, 110, 157, 240, 68, 7, 249, 24},
}
View Source
var ConsensusMini = &Consensus{
	NetworkType:       NetworkMainnet,
	PoolName:          "mini",
	TargetBlockTime:   10,
	MinimumDifficulty: 100000,
	ChainWindowSize:   2160,
	UnclePenalty:      20,
	HardForks:         p2poolMainNetHardForks,
	MoneroHardForks:   monero.NetworkHardFork(monero.MainNetwork),
	Id:                types.Hash{57, 130, 201, 26, 149, 174, 199, 250, 66, 80, 189, 18, 108, 216, 194, 220, 136, 23, 63, 24, 64, 113, 221, 44, 219, 86, 39, 163, 53, 24, 126, 196},
}
View Source
var ConsensusNano = &Consensus{
	NetworkType:       NetworkMainnet,
	PoolName:          "nano",
	TargetBlockTime:   30,
	MinimumDifficulty: 100000,
	ChainWindowSize:   2160,
	UnclePenalty:      10,
	HardForks:         p2poolMainNetHardForks,
	MoneroHardForks:   monero.NetworkHardFork(monero.MainNetwork),
	Id:                types.Hash{171, 248, 206, 148, 210, 226, 114, 99, 250, 145, 221, 96, 13, 216, 23, 63, 104, 53, 129, 168, 244, 80, 141, 138, 157, 250, 50, 54, 37, 189, 5, 89},
}
View Source
var ErrNoDifficulty = errors.New("could not get difficulty")
View Source
var ErrNoMainDifficulty = errors.New("could not get main difficulty")
View Source
var ErrPanic = errors.New("panic while processing")
View Source
var ErrParentInvalid = errors.New("parent is invalid")
View Source
var ErrParentNotVerified = errors.New("parent is not verified")
View Source
var ExtraChainKeyOnionAddressV3 = crypto.Keccak256([]byte("onion_address_v3"))

ExtraChainKeyOnionAddressV3 Format PublicKeyBytes (PUBKEY) | varint(0) | varint(0) https://spec.torproject.org/rend-spec/encoding-onion-addresses.html

View Source
var ExtraChainKeySubaddressViewPub = crypto.Keccak256([]byte("subaddress_viewpub"))

ExtraChainKeySubaddressViewPub Format PublicKeyBytes (subaddress view pub) | varint(0) | varint(0)

View Source
var PoolBlockMaxCumulativeDifficulty = types.NewDifficulty(13019633956666736640, 1710)

PoolBlockMaxCumulativeDifficulty 1000 years at 1 TH/s. It should be enough for any normal use.

Functions

func BlocksInPPLNSWindow

func BlocksInPPLNSWindow(tip *PoolBlock, consensus *Consensus, difficultyByHeight block.GetDifficultyByHeightFunc, getByTemplateId GetByTemplateIdFunc, addWeightFunc PoolBlockWindowAddWeightFunc) (bottomHeight uint64, err error)

func CalculateEnoteCarrot

func CalculateEnoteCarrot(derivationCache DerivationCacheInterface, a *address.PackedAddressWithSubaddress, seed types.Hash, blockIndex, amount uint64) (enote *carrot.CoinbaseEnoteV1)

func CalculateOutputCarrot

func CalculateOutputCarrot(enote *carrot.CoinbaseEnoteV1, txType uint8, outputIndex uint64) transaction.Output

func CalculateOutputCryptonote

func CalculateOutputCryptonote(derivationCache DerivationCacheInterface, txType uint8, a *address.PackedAddress, txPrivateKey curve25519.PrivateKeyBytes, txPrivateKeyScalar *curve25519.Scalar, outputIndex, amount uint64) transaction.Output

func CalculateOutputs

func CalculateOutputs(block *PoolBlock, consensus *Consensus, difficultyByHeight block.GetDifficultyByHeightFunc, getByTemplateId GetByTemplateIdFunc, derivationCache DerivationCacheInterface, preAllocatedShares Shares, preAllocatedRewards []uint64) (outputs transaction.Outputs, pubs []curve25519.PublicKeyBytes, bottomHeight uint64, err error)

func CalculateTransactionPrivateKeySeed

func CalculateTransactionPrivateKeySeed(main, side []byte) (result types.Hash)

func GetDeterministicTransactionPrivateKey

func GetDeterministicTransactionPrivateKey(out *curve25519.Scalar, seed, previousMoneroId types.Hash) *curve25519.Scalar

func GetDifficultyForNextBlock

func GetDifficultyForNextBlock(tip *PoolBlock, consensus *Consensus, getByTemplateId GetByTemplateIdFunc, preAllocatedDifficultyData []DifficultyData, preAllocatedTimestampData []uint64) (difficulty types.Difficulty, verifyError, invalidError error)

GetDifficultyForNextBlock Gets the difficulty at tip (the next block will require this difficulty) preAllocatedDifficultyData should contain enough capacity to fit all entries to iterate through. preAllocatedTimestampDifferences should contain enough capacity to fit all differences.

Ported from SideChain::get_difficulty() from C p2pool, somewhat based on Blockchain::get_difficulty_for_next_block() from Monero with the addition of uncles

func IsLongerChain

func IsLongerChain(block, candidate *PoolBlock, consensus *Consensus, getByTemplateId GetByTemplateIdFunc, getChainMainByHash GetChainMainByHashFunc) (isLonger, isAlternative bool)

func IterateBlocksInPPLNSWindow

func IterateBlocksInPPLNSWindow(tip *PoolBlock, consensus *Consensus, difficultyByHeight block.GetDifficultyByHeightFunc, getByTemplateId GetByTemplateIdFunc, addWeightFunc PoolBlockWindowAddWeightFunc, slotFunc func(slot PoolBlockWindowSlot)) error

func NextDifficulty

func NextDifficulty(consensus *Consensus, timestamps []uint64, difficultyData []DifficultyData) (nextDifficulty types.Difficulty, err error)

NextDifficulty returns the next block difficulty based on gathered timestamp/difficulty data Returns error on wrap/overflow/underflow on uint128 operations

func ShuffleSequence

func ShuffleSequence(majorVersion uint8, shareVersion ShareVersion, privateKeySeed types.Hash, items int, swap func(i, j int))

ShuffleSequence Iterates through a swap sequence according to consensus parameters.

func ShuffleShares

func ShuffleShares[T any](shares []T, majorVersion uint8, shareVersion ShareVersion, privateKeySeed types.Hash)

ShuffleShares Shuffles shares according to consensus parameters via ShuffleSequence. Requires pre-sorted shares based on address

func SplitReward

func SplitReward(preAllocatedRewards []uint64, reward uint64, shares Shares) (rewards []uint64)

func SplitRewardAllocate

func SplitRewardAllocate(reward uint64, shares Shares) (rewards []uint64)

Types

type Cache

type Cache interface {
	GetBlob(key []byte) (blob []byte, err error)
	SetBlob(key, blob []byte) (err error)
	RemoveBlob(key []byte) (err error)
}

type ChainMain

type ChainMain struct {
	Difficulty types.Difficulty
	Height     uint64
	Timestamp  uint64
	Reward     uint64
	Id         types.Hash
}

type CoinbaseExtraTag

type CoinbaseExtraTag int

type Consensus

type Consensus struct {
	NetworkType       NetworkType `json:"network_type"`
	PoolName          string      `json:"name"`
	PoolPassword      string      `json:"password"`
	TargetBlockTime   uint64      `json:"block_time"`
	MinimumDifficulty uint64      `json:"min_diff"`
	ChainWindowSize   uint64      `json:"pplns_window"`
	UnclePenalty      uint64      `json:"uncle_penalty"`

	// Extra additional string to add for testing usually
	Extra string `json:"extra,omitempty"`

	// HardForks optional sidechain hardfork information for p2pool
	// If empty it will be filled with the default hardfork list to the corresponding NetworkType
	// Note: this is not supported by p2pool itself
	HardForks []monero.HardFork `json:"hard_forks,omitempty"`

	// HardForks optional mainchain hardfork information
	// If empty it will be filled with the default hardfork list to the corresponding NetworkType
	// Note: this is not supported by p2pool itself
	MoneroHardForks []monero.HardFork `json:"monero_hard_forks,omitempty"`

	Id types.Hash `json:"id"`
	// contains filtered or unexported fields
}

func NewConsensus

func NewConsensus(networkType NetworkType, poolName, poolPassword, extra string, targetBlockTime, minimumDifficulty, chainWindowSize, unclePenalty uint64) *Consensus

func NewConsensusFromJSON

func NewConsensusFromJSON(data []byte) (*Consensus, error)

func (*Consensus) ApplyUnclePenalty

func (c *Consensus) ApplyUnclePenalty(weight types.Difficulty) (uncleWeight, unclePenalty types.Difficulty)

ApplyUnclePenalty Applies UnclePenalty efficiently

func (*Consensus) CalculateId

func (c *Consensus) CalculateId() types.Hash

func (*Consensus) CalculateSideChainIdFromBlobs

func (c *Consensus) CalculateSideChainIdFromBlobs(mainBlob, sideBlob []byte) (result types.Hash)

func (*Consensus) CalculateSideTemplateId

func (c *Consensus) CalculateSideTemplateId(share *PoolBlock) (result types.Hash)

func (*Consensus) CalculateSideTemplateIdPreAllocated

func (c *Consensus) CalculateSideTemplateIdPreAllocated(share *PoolBlock, buf []byte) (result types.Hash)

func (*Consensus) DefaultPort

func (c *Consensus) DefaultPort() uint16

func (*Consensus) GetHasher

func (c *Consensus) GetHasher() randomx.Hasher

func (*Consensus) InitHasher

func (c *Consensus) InitHasher(n int, flags ...randomx.Flag) error

func (*Consensus) InitTestHasher

func (c *Consensus) InitTestHasher() error

func (*Consensus) IsDefault

func (c *Consensus) IsDefault() bool

func (*Consensus) IsMini

func (c *Consensus) IsMini() bool

func (*Consensus) IsNano

func (c *Consensus) IsNano() bool

func (*Consensus) SeedNode

func (c *Consensus) SeedNode() string

func (*Consensus) SeedNodes

func (c *Consensus) SeedNodes() []string

func (*Consensus) TorNodes

func (c *Consensus) TorNodes() []p2pooltypes.OnionAddressV3

type ConsensusProvider

type ConsensusProvider interface {
	Consensus() *Consensus
}

type DerivationCache

type DerivationCache struct {
	// contains filtered or unexported fields
}

func NewDerivationLRUCache

func NewDerivationLRUCache() *DerivationCache

func NewDerivationMapCache

func NewDerivationMapCache() *DerivationCache

func NewDerivationNilCache

func NewDerivationNilCache() *DerivationCache

func (*DerivationCache) Clear

func (d *DerivationCache) Clear()

func (*DerivationCache) GetCarrotCoinbaseEnote

func (d *DerivationCache) GetCarrotCoinbaseEnote(a *address.PackedAddressWithSubaddress, seed types.Hash, blockIndex, amount uint64) *carrot.CoinbaseEnoteV1

func (*DerivationCache) GetDeterministicTransactionKey

func (d *DerivationCache) GetDeterministicTransactionKey(seed types.Hash, prevId types.Hash) *crypto.KeyPair[curve25519.VarTimeOperations]

func (*DerivationCache) GetEphemeralPublicKey

func (d *DerivationCache) GetEphemeralPublicKey(a *address.PackedAddress, txKey curve25519.PrivateKeyBytes, txKeyScalar *curve25519.Scalar, outputIndex uint64) (curve25519.PublicKeyBytes, uint8)

type DerivationCacheInterface

type DerivationCacheInterface interface {
	GetEphemeralPublicKey(a *address.PackedAddress, txKeySlice curve25519.PrivateKeyBytes, txKeyScalar *curve25519.Scalar, outputIndex uint64) (curve25519.PublicKeyBytes, uint8)
	GetDeterministicTransactionKey(seed types.Hash, prevId types.Hash) *crypto.KeyPair[curve25519.VarTimeOperations]
	GetCarrotCoinbaseEnote(a *address.PackedAddressWithSubaddress, seed types.Hash, blockIndex, amount uint64) *carrot.CoinbaseEnoteV1
}

type DifficultyData

type DifficultyData struct {
	// contains filtered or unexported fields
}

type FakeServer

type FakeServer struct {
	Tip *PoolBlock
	// contains filtered or unexported fields
}

func GetFakeTestServer

func GetFakeTestServer(consensus *Consensus) *FakeServer

func GetFakeTestServerWithRPC

func GetFakeTestServerWithRPC(consensus *Consensus, rpcClient *client.Client) *FakeServer

func (*FakeServer) Broadcast

func (s *FakeServer) Broadcast(block *PoolBlock)

func (*FakeServer) BroadcastMoneroBlock

func (s *FakeServer) BroadcastMoneroBlock(block *mainblock.Block)

func (*FakeServer) ClearCachedBlocks

func (s *FakeServer) ClearCachedBlocks()

func (*FakeServer) ClientRPC

func (s *FakeServer) ClientRPC() *client.Client

func (*FakeServer) Consensus

func (s *FakeServer) Consensus() *Consensus

func (*FakeServer) Context

func (s *FakeServer) Context() context.Context

func (*FakeServer) DownloadMinimalBlockHeaders

func (s *FakeServer) DownloadMinimalBlockHeaders(currentHeight uint64) error

func (*FakeServer) GetBlob

func (s *FakeServer) GetBlob(key []byte) (blob []byte, err error)

func (*FakeServer) GetChainMainByHash

func (s *FakeServer) GetChainMainByHash(hash types.Hash) *ChainMain

func (*FakeServer) GetChainMainByHeight

func (s *FakeServer) GetChainMainByHeight(height uint64) *ChainMain

func (*FakeServer) GetChainMainTip

func (s *FakeServer) GetChainMainTip() *ChainMain

func (*FakeServer) GetDifficultyByHeight

func (s *FakeServer) GetDifficultyByHeight(height uint64) types.Difficulty

func (*FakeServer) GetMinerDataTip

func (s *FakeServer) GetMinerDataTip() *p2pooltypes.MinerData

func (*FakeServer) GetMinimalBlockHeaderByHash

func (s *FakeServer) GetMinimalBlockHeaderByHash(hash types.Hash) *mainblock.Header

func (*FakeServer) GetMinimalBlockHeaderByHeight

func (s *FakeServer) GetMinimalBlockHeaderByHeight(height uint64) *mainblock.Header

func (*FakeServer) RemoveBlob

func (s *FakeServer) RemoveBlob(key []byte) (err error)

func (*FakeServer) SetBlob

func (s *FakeServer) SetBlob(key, blob []byte) (err error)

func (*FakeServer) SideChain

func (s *FakeServer) SideChain() *SideChain

func (*FakeServer) Store

func (s *FakeServer) Store(block *PoolBlock)

func (*FakeServer) SubmitBlock

func (s *FakeServer) SubmitBlock(block *mainblock.Block)

func (*FakeServer) UpdateBlockFound

func (s *FakeServer) UpdateBlockFound(data *ChainMain, block *PoolBlock)

func (*FakeServer) UpdateTip

func (s *FakeServer) UpdateTip(tip *PoolBlock)

type FullId

type FullId [FullIdSize]byte

func FullIdFromString

func FullIdFromString(s string) (FullId, error)

func (FullId) ExtraNonce

func (id FullId) ExtraNonce() uint32

func (FullId) Nonce

func (id FullId) Nonce() uint32

func (FullId) String

func (id FullId) String() string

func (FullId) TemplateId

func (id FullId) TemplateId() types.Hash

type GetByMainHeightFunc

type GetByMainHeightFunc func(height uint64) UniquePoolBlockSlice

type GetByMainIdFunc

type GetByMainIdFunc func(h types.Hash) *PoolBlock

type GetBySideHeightFunc

type GetBySideHeightFunc func(height uint64) UniquePoolBlockSlice

type GetByTemplateIdFunc

type GetByTemplateIdFunc func(h types.Hash) *PoolBlock

type GetChainMainByHashFunc

type GetChainMainByHashFunc func(h types.Hash) *ChainMain

GetChainMainByHashFunc if h = types.ZeroHash, return tip

type IterationCache

type IterationCache struct {
	Parent *PoolBlock
	Uncles []*PoolBlock
}

IterationCache Used for fast scan backwards, and of uncles Only maybe available in verified blocks

type MergeMiningExtra

type MergeMiningExtra []MergeMiningExtraData

func (MergeMiningExtra) BufferLength

func (d MergeMiningExtra) BufferLength() (size int)

func (MergeMiningExtra) Get

func (d MergeMiningExtra) Get(chainId types.Hash) ([]byte, bool)

func (MergeMiningExtra) Merge

func (MergeMiningExtra) Set

func (d MergeMiningExtra) Set(chainId types.Hash, data []byte) MergeMiningExtra

func (MergeMiningExtra) Sort

func (d MergeMiningExtra) Sort()

type MergeMiningExtraData

type MergeMiningExtraData struct {
	ChainId types.Hash `json:"chain_id"`
	// Data has merge mining hash and difficulty (two varints for low and high 64 bits) in the beginning,
	// the rest is arbitrary and depends on the merge mined chain's requirements
	Data types.Bytes `json:"data,omitempty"`
}

func (MergeMiningExtraData) BufferLength

func (d MergeMiningExtraData) BufferLength() (size int)

type NetworkType

type NetworkType int
const (
	NetworkInvalid NetworkType = iota
	NetworkMainnet
	NetworkTestnet
	NetworkStagenet
)

func (NetworkType) AddressNetwork

func (n NetworkType) AddressNetwork() (uint8, error)

func (NetworkType) MarshalJSON

func (n NetworkType) MarshalJSON() ([]byte, error)

func (NetworkType) MustAddressNetwork

func (n NetworkType) MustAddressNetwork() uint8

func (NetworkType) String

func (n NetworkType) String() string

func (NetworkType) SubaddressNetwork

func (n NetworkType) SubaddressNetwork() (uint8, error)

func (*NetworkType) UnmarshalJSON

func (n *NetworkType) UnmarshalJSON(b []byte) error

type NilDerivationCache

type NilDerivationCache struct {
}

func (*NilDerivationCache) Clear

func (d *NilDerivationCache) Clear()

func (*NilDerivationCache) GetCarrotCoinbaseEnote

func (d *NilDerivationCache) GetCarrotCoinbaseEnote(a *address.PackedAddressWithSubaddress, seed types.Hash, blockIndex, amount uint64) *carrot.CoinbaseEnoteV1

func (*NilDerivationCache) GetDeterministicTransactionKey

func (d *NilDerivationCache) GetDeterministicTransactionKey(seed types.Hash, prevId types.Hash) *crypto.KeyPair[curve25519.VarTimeOperations]

func (*NilDerivationCache) GetEphemeralPublicKey

func (d *NilDerivationCache) GetEphemeralPublicKey(a *address.PackedAddress, _ curve25519.PrivateKeyBytes, txKeyScalar *curve25519.Scalar, outputIndex uint64) (curve25519.PublicKeyBytes, uint8)

type P2PoolInterface

type P2PoolInterface interface {
	ConsensusProvider
	Cache
	Context() context.Context
	UpdateTip(tip *PoolBlock)
	BroadcastMoneroBlock(block *mainblock.Block)
	Broadcast(block *PoolBlock)
	ClientRPC() *client.Client
	GetChainMainByHeight(height uint64) *ChainMain
	GetChainMainByHash(hash types.Hash) *ChainMain
	GetMinimalBlockHeaderByHeight(height uint64) *mainblock.Header
	GetMinimalBlockHeaderByHash(hash types.Hash) *mainblock.Header
	GetDifficultyByHeight(height uint64) types.Difficulty
	UpdateBlockFound(data *ChainMain, block *PoolBlock)
	SubmitBlock(block *mainblock.Block)
	GetChainMainTip() *ChainMain
	GetMinerDataTip() *p2pooltypes.MinerData
	Store(block *PoolBlock)
	ClearCachedBlocks()
}

type PoolBlock

type PoolBlock struct {
	Main mainblock.Block `json:"main"`

	Side SideData `json:"side"`

	Depth    atomic.Uint64 `json:"-"`
	Verified atomic.Bool   `json:"-"`
	Invalid  atomic.Bool   `json:"-"`

	WantBroadcast atomic.Bool `json:"-"`
	Broadcasted   atomic.Bool `json:"-"`
	Thinned       atomic.Bool `json:"-"`

	Metadata PoolBlockReceptionMetadata `json:"metadata"`

	CachedShareVersion ShareVersion `json:"share_version"`
	// contains filtered or unexported fields
}

func (*PoolBlock) AppendBinaryFlags

func (b *PoolBlock) AppendBinaryFlags(preAllocatedBuf []byte, pruned, compact bool) (buf []byte, err error)

func (*PoolBlock) BufferLength

func (b *PoolBlock) BufferLength() int

func (*PoolBlock) CalculateFullId

func (b *PoolBlock) CalculateFullId(consensus *Consensus) FullId

func (*PoolBlock) CalculateShareVersion

func (b *PoolBlock) CalculateShareVersion(consensus *Consensus) ShareVersion

func (*PoolBlock) CalculateTransactionPrivateKeySeed

func (b *PoolBlock) CalculateTransactionPrivateKeySeed() types.Hash

func (*PoolBlock) CoinbaseExtra

func (b *PoolBlock) CoinbaseExtra(tag CoinbaseExtraTag) []byte

func (*PoolBlock) CoinbaseId

func (b *PoolBlock) CoinbaseId() types.Hash

func (*PoolBlock) CoinbasePublicKeys

func (b *PoolBlock) CoinbasePublicKeys() (result []curve25519.PublicKeyBytes)

func (*PoolBlock) ExtraNonce

func (b *PoolBlock) ExtraNonce() uint32

func (*PoolBlock) FastSideTemplateId

func (b *PoolBlock) FastSideTemplateId(consensus *Consensus) types.Hash

FastSideTemplateId Returns SideTemplateId from either coinbase extra tags or pruned data, or main block if not pruned

func (*PoolBlock) FillPrivateKeys

func (b *PoolBlock) FillPrivateKeys(derivationCache DerivationCacheInterface)

func (*PoolBlock) FillTransactionParentIndices

func (b *PoolBlock) FillTransactionParentIndices(consensus *Consensus, parent *PoolBlock) bool

func (*PoolBlock) FillTransactionsFromTransactionParentIndices

func (b *PoolBlock) FillTransactionsFromTransactionParentIndices(consensus *Consensus, parent *PoolBlock) error

func (*PoolBlock) FromCompactReader

func (b *PoolBlock) FromCompactReader(consensus *Consensus, derivationCache DerivationCacheInterface, reader utils.ReaderAndByteReader) (err error)

FromCompactReader used in Protocol 1.1 and above

func (*PoolBlock) FromReader

func (b *PoolBlock) FromReader(consensus *Consensus, derivationCache DerivationCacheInterface, reader utils.ReaderAndByteReader) (err error)

func (*PoolBlock) FullId

func (b *PoolBlock) FullId(consensus *Consensus) FullId

func (*PoolBlock) GetAddress

func (*PoolBlock) GetConsensusPackedAddress

func (b *PoolBlock) GetConsensusPackedAddress(targetMajorVersion uint8) address.PackedAddressWithSubaddress

GetConsensusPackedAddress Gets the address to use for sidechain share weight calculation dependent on target major version

func (*PoolBlock) GetMergeMineExtraSubaddress

func (b *PoolBlock) GetMergeMineExtraSubaddress() *address.PackedAddressWithSubaddress

func (*PoolBlock) GetOnionAddressV3

func (b *PoolBlock) GetOnionAddressV3() *p2pooltypes.OnionAddressV3

func (*PoolBlock) GetPayoutAddress

func (b *PoolBlock) GetPayoutAddress(networkType NetworkType) *address.Address

GetPayoutAddress Special function that checks if a subaddress has been specified, on the right network Not consensus

func (*PoolBlock) GetPrivateKeySeed

func (b *PoolBlock) GetPrivateKeySeed() types.Hash

func (*PoolBlock) GetTransactionOutputType

func (b *PoolBlock) GetTransactionOutputType() uint8

func (*PoolBlock) IsProofHigherThanDifficulty

func (b *PoolBlock) IsProofHigherThanDifficulty(hasher randomx.Hasher, f mainblock.GetSeedByHeightFunc) bool

func (*PoolBlock) IsProofHigherThanDifficultyWithError

func (b *PoolBlock) IsProofHigherThanDifficultyWithError(hasher randomx.Hasher, f mainblock.GetSeedByHeightFunc) (bool, error)

func (*PoolBlock) IsProofHigherThanMainDifficulty

func (b *PoolBlock) IsProofHigherThanMainDifficulty(hasher randomx.Hasher, difficultyFunc mainblock.GetDifficultyByHeightFunc, seedFunc mainblock.GetSeedByHeightFunc) bool

func (*PoolBlock) IsProofHigherThanMainDifficultyWithError

func (b *PoolBlock) IsProofHigherThanMainDifficultyWithError(hasher randomx.Hasher, difficultyFunc mainblock.GetDifficultyByHeightFunc, seedFunc mainblock.GetSeedByHeightFunc) (bool, error)

func (*PoolBlock) MainDifficulty

func (*PoolBlock) MainId

func (b *PoolBlock) MainId() types.Hash

func (*PoolBlock) MarshalBinary

func (b *PoolBlock) MarshalBinary() ([]byte, error)

func (*PoolBlock) MarshalBinaryFlags

func (b *PoolBlock) MarshalBinaryFlags(pruned, compact bool) ([]byte, error)

func (*PoolBlock) MergeMiningTag

func (b *PoolBlock) MergeMiningTag() merge_mining.Tag

func (*PoolBlock) NeedsCompactTransactionFilling

func (b *PoolBlock) NeedsCompactTransactionFilling() bool

func (*PoolBlock) NeedsPostProcess

func (b *PoolBlock) NeedsPostProcess() bool

func (*PoolBlock) NeedsPreProcess

func (b *PoolBlock) NeedsPreProcess() bool

func (*PoolBlock) PowHash

func (*PoolBlock) PowHashWithError

func (b *PoolBlock) PowHashWithError(hasher randomx.Hasher, f mainblock.GetSeedByHeightFunc) (powHash types.Hash, err error)

func (*PoolBlock) PreProcessBlock

func (b *PoolBlock) PreProcessBlock(consensus *Consensus, derivationCache DerivationCacheInterface, preAllocatedShares Shares, difficultyByHeight mainblock.GetDifficultyByHeightFunc, getTemplateById GetByTemplateIdFunc) (missingBlocks []types.Hash, err error)

PreProcessBlock processes and fills the block data from either pruned or compact modes

func (*PoolBlock) PreProcessBlockWithOutputs

func (b *PoolBlock) PreProcessBlockWithOutputs(consensus *Consensus, getTemplateById GetByTemplateIdFunc, calculateOutputs func() (outputs transaction.Outputs, pubs []curve25519.PublicKeyBytes, bottomHeight uint64, err error)) (missingBlocks []types.Hash, err error)

PreProcessBlockWithOutputs processes and fills the block data from either pruned or compact modes

func (*PoolBlock) ShareVersion

func (b *PoolBlock) ShareVersion() ShareVersion

func (*PoolBlock) ShareVersionSignaling

func (b *PoolBlock) ShareVersionSignaling() ShareVersion

func (*PoolBlock) SideTemplateId

func (b *PoolBlock) SideTemplateId(consensus *Consensus) types.Hash

func (*PoolBlock) UnmarshalBinary

func (b *PoolBlock) UnmarshalBinary(consensus *Consensus, derivationCache DerivationCacheInterface, data []byte) error

func (*PoolBlock) UnmarshalJSON

func (b *PoolBlock) UnmarshalJSON(buf []byte) (err error)

type PoolBlockReceptionMetadata

type PoolBlockReceptionMetadata struct {
	// LocalTime Moment the block was received from a source
	LocalTime time.Time `json:"local_time"`
	// AddressPort The address and port of the peer who broadcasted or sent us this block
	// If the peer specified a listen port, the port will be that instead of current connection one
	AddressPort netip.AddrPort `json:"address_port"`
	// PeerId The peer id of the peer who broadcasted or sent us this block
	PeerId uint64 `json:"peer_id,omitzero"`

	SoftwareId      uint32 `json:"software_id"`
	SoftwareVersion uint32 `json:"software_version"`
}

func (*PoolBlockReceptionMetadata) MarshalBinary

func (m *PoolBlockReceptionMetadata) MarshalBinary() ([]byte, error)

func (*PoolBlockReceptionMetadata) UnmarshalBinary

func (m *PoolBlockReceptionMetadata) UnmarshalBinary(buf []byte) error

type PoolBlockWindowAddWeightFunc

type PoolBlockWindowAddWeightFunc func(b *PoolBlock, weight types.Difficulty)

type PoolBlockWindowSlot

type PoolBlockWindowSlot struct {
	Block *PoolBlock
	// Uncles that count for the window weight
	Uncles UniquePoolBlockSlice
}

type PreAllocatedSharesPool

type PreAllocatedSharesPool struct {
	// contains filtered or unexported fields
}

func NewPreAllocatedSharesPool

func NewPreAllocatedSharesPool[T uint64 | int](n T) *PreAllocatedSharesPool

func (*PreAllocatedSharesPool) Get

func (p *PreAllocatedSharesPool) Get() Shares

func (*PreAllocatedSharesPool) Put

func (p *PreAllocatedSharesPool) Put(s Shares)

type PruneMode

type PruneMode int

PruneMode The mode on how to prune blocks within SideChain Can be set before any blocks are added, or, a greater value in runtime. For example, can go from PruneModeNone to PruneModeDefault, or PruneModeDefault to PruneModeThin

const (
	// PruneModeNone Never prune old blocks
	// Do not use on production
	PruneModeNone PruneMode = -1
	// PruneModeDefault The default, keeps all blocks required to do full verification.
	// Matches upstream p2pool behavior
	PruneModeDefault PruneMode = 0
	// PruneModeThin Prunes blocks like PruneModeDefault, except unnecessary data is removed from all but a few on top. Useful to reduce memory usage
	// These pruned blocks cannot be sent to clients
	// TODO: prune crypto cache as well?
	PruneModeThin PruneMode = 1
)

type Share

type Share struct {
	Address address.PackedAddressWithSubaddress
	Weight  types.Difficulty
}

type ShareVersion

type ShareVersion uint8

func P2PoolShareVersion

func P2PoolShareVersion(consensus *Consensus, timestamp uint64) ShareVersion

P2PoolShareVersion Different miners can have different timestamps, so a temporary mix of old and new blocks is allowed

func (ShareVersion) String

func (v ShareVersion) String() string

func (ShareVersion) Supports

func (v ShareVersion) Supports(majorVersion uint8) bool

type Shares

type Shares []*Share

func GetShares

func GetShares(tip *PoolBlock, consensus *Consensus, difficultyByHeight block.GetDifficultyByHeightFunc, getByTemplateId GetByTemplateIdFunc, preAllocatedShares Shares) (shares Shares, bottomHeight uint64, err error)

func GetSharesOrdered

func GetSharesOrdered(tip *PoolBlock, consensus *Consensus, difficultyByHeight block.GetDifficultyByHeightFunc, getByTemplateId GetByTemplateIdFunc, preAllocatedShares Shares) (shares Shares, bottomHeight uint64, err error)

func PreAllocateShares

func PreAllocateShares[T uint64 | int](n T) Shares

func (Shares) Clone

func (s Shares) Clone() (o Shares)

func (Shares) Compact

func (s Shares) Compact() Shares

Compact Merges duplicate Share entries based on Address len(s) must be greater than 0

func (Shares) Index

func (Shares) Sort

func (s Shares) Sort()

Sort Consensus way of sorting Shares

type SideChain

type SideChain struct {
	// contains filtered or unexported fields
}

func NewSideChain

func NewSideChain(server P2PoolInterface) *SideChain

func (*SideChain) AddPoolBlock

func (c *SideChain) AddPoolBlock(block *PoolBlock) (err error)

func (*SideChain) AddPoolBlockExternal

func (c *SideChain) AddPoolBlockExternal(block *PoolBlock) (missingBlocks []types.Hash, err error, ban bool)

func (*SideChain) BlockSeen

func (c *SideChain) BlockSeen(block *PoolBlock) bool

func (*SideChain) BlockUnsee

func (c *SideChain) BlockUnsee(block *PoolBlock)

func (*SideChain) Consensus

func (c *SideChain) Consensus() *Consensus

func (*SideChain) DerivationCache

func (c *SideChain) DerivationCache() *DerivationCache

func (*SideChain) Difficulty

func (c *SideChain) Difficulty() types.Difficulty

func (*SideChain) GetChainTip

func (c *SideChain) GetChainTip() *PoolBlock

func (*SideChain) GetDifficulty

func (c *SideChain) GetDifficulty(tip *PoolBlock) (difficulty types.Difficulty, verifyError, invalidError error)

func (*SideChain) GetHighestKnownTip

func (c *SideChain) GetHighestKnownTip() *PoolBlock

func (*SideChain) GetMissingBlocks

func (c *SideChain) GetMissingBlocks() []types.Hash

func (*SideChain) GetParent

func (c *SideChain) GetParent(block *PoolBlock) *PoolBlock

func (*SideChain) GetPoolBlockByMerkleRoot

func (c *SideChain) GetPoolBlockByMerkleRoot(id types.Hash) *PoolBlock

func (*SideChain) GetPoolBlockByTemplateId

func (c *SideChain) GetPoolBlockByTemplateId(id types.Hash) *PoolBlock

func (*SideChain) GetPoolBlockCount

func (c *SideChain) GetPoolBlockCount() int

func (*SideChain) GetPoolBlocksByHeight

func (c *SideChain) GetPoolBlocksByHeight(height uint64) []*PoolBlock

func (*SideChain) GetPoolBlocksFromTip

func (c *SideChain) GetPoolBlocksFromTip(id types.Hash) (chain, uncles UniquePoolBlockSlice)

func (*SideChain) GetPoolBlocksFromTipWithDepth

func (c *SideChain) GetPoolBlocksFromTipWithDepth(id types.Hash, depth uint64) (chain, uncles UniquePoolBlockSlice)

func (*SideChain) GetPossibleUncles

func (c *SideChain) GetPossibleUncles(tip *PoolBlock, forHeight uint64) (uncles []*PoolBlock)

func (*SideChain) GetPruneMode

func (c *SideChain) GetPruneMode() PruneMode

func (*SideChain) IsLongerChain

func (c *SideChain) IsLongerChain(block, candidate *PoolBlock) (isLonger, isAlternative bool)

func (*SideChain) LastUpdated

func (c *SideChain) LastUpdated() time.Time

func (*SideChain) PoolBlockExternalVerify

func (c *SideChain) PoolBlockExternalVerify(block *PoolBlock) (missingBlocks []types.Hash, err error, ban bool)

func (*SideChain) PreCalcFinished

func (c *SideChain) PreCalcFinished() bool

func (*SideChain) PreprocessBlock

func (c *SideChain) PreprocessBlock(block *PoolBlock) (missingBlocks []types.Hash, err error)

func (*SideChain) Server

func (c *SideChain) Server() P2PoolInterface

func (*SideChain) SetPruneMode

func (c *SideChain) SetPruneMode(mode PruneMode) error

func (*SideChain) WatchMainChainBlock

func (c *SideChain) WatchMainChainBlock(mainData *ChainMain, possibleId types.Hash)

type SideData

type SideData struct {
	PublicKey    address.PackedAddress `json:"public_key"`
	IsSubaddress bool                  `json:"is_subaddress,omitempty"`

	CoinbasePrivateKeySeed types.Hash `json:"coinbase_private_key_seed,omitzero"`
	// CoinbasePrivateKey filled or calculated on decoding,
	CoinbasePrivateKey curve25519.PrivateKeyBytes `json:"coinbase_private_key"`
	// Parent Template Id of the parent of this share, or zero if genesis
	Parent types.Hash `json:"parent"`
	// Uncles List of Template Ids of the uncles this share contains
	Uncles               []types.Hash     `json:"uncles,omitempty"`
	Height               uint64           `json:"height"`
	Difficulty           types.Difficulty `json:"difficulty"`
	CumulativeDifficulty types.Difficulty `json:"cumulative_difficulty"`

	// MerkleProof Merkle proof for merge mining, available in ShareVersion ShareVersion_V3 and above
	MerkleProof crypto.MerkleProof `json:"merkle_proof,omitempty"`

	// MergeMiningExtra vector of (chain ID, chain data) pairs
	// Chain data format is arbitrary and depends on the merge mined chain's requirements
	MergeMiningExtra MergeMiningExtra `json:"merge_mining_extra,omitempty"`

	// ExtraBuffer Arbitrary extra data, available in ShareVersion ShareVersion_V2 and above
	ExtraBuffer SideDataExtraBuffer `json:"extra_buffer"`
}

func (*SideData) AppendBinary

func (b *SideData) AppendBinary(preAllocatedBuf []byte, majorVersion uint8, version ShareVersion) (buf []byte, err error)

func (*SideData) BufferLength

func (b *SideData) BufferLength(majorVersion uint8, version ShareVersion) (size int)

func (*SideData) FromReader

func (b *SideData) FromReader(reader utils.ReaderAndByteReader, majorVersion uint8, version ShareVersion) (err error)

func (*SideData) MarshalBinary

func (b *SideData) MarshalBinary(majorVersion uint8, version ShareVersion) (buf []byte, err error)

func (*SideData) UnmarshalBinary

func (b *SideData) UnmarshalBinary(data []byte, majorVersion uint8, version ShareVersion) error

type SideDataExtraBuffer

type SideDataExtraBuffer struct {
	SoftwareId          p2pooltypes.SoftwareId      `json:"software_id"`
	SoftwareVersion     p2pooltypes.SoftwareVersion `json:"software_version"`
	RandomNumber        uint32                      `json:"random_number"`
	SideChainExtraNonce uint32                      `json:"side_chain_extra_nonce"`
}

type UniquePoolBlockSlice

type UniquePoolBlockSlice []*PoolBlock

func LoadSideChainTestData

func LoadSideChainTestData(consensus *Consensus, derivationCache DerivationCacheInterface, reader io.Reader, patchedBlocks ...[]byte) (UniquePoolBlockSlice, error)

func (UniquePoolBlockSlice) Get

func (s UniquePoolBlockSlice) Get(consensus *Consensus, id types.Hash) *PoolBlock

func (UniquePoolBlockSlice) GetHeight

func (s UniquePoolBlockSlice) GetHeight(height uint64) (result UniquePoolBlockSlice)

Jump to

Keyboard shortcuts

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