protocol

package
v0.0.0-...-c598841 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2023 License: BSD-4-Clause, MIT Imports: 13 Imported by: 0

Documentation

Overview

Package protocol implements smartpool secured protocol between client side and contract side. It works on high abstraction level of interfaces and types of smartpool package.

Index

Constants

View Source
const COUNTER_FILE string = "counter"

Variables

This section is empty.

Functions

This section is empty.

Types

type Claim

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

func NewClaim

func NewClaim() *Claim

func (*Claim) AddShare

func (c *Claim) AddShare(s smartpool.Share)

func (*Claim) AugMerkle

func (c *Claim) AugMerkle() smartpool.SPHash

func (*Claim) CounterBranch

func (c *Claim) CounterBranch() []*big.Int

func (*Claim) Difficulty

func (c *Claim) Difficulty() *big.Int

func (*Claim) GetShare

func (c *Claim) GetShare(index int) smartpool.Share

func (*Claim) HashBranch

func (c *Claim) HashBranch() []*big.Int

func (*Claim) Max

func (c *Claim) Max() *big.Int

func (*Claim) Min

func (c *Claim) Min() *big.Int

func (*Claim) NumShares

func (c *Claim) NumShares() *big.Int

func (*Claim) SetEvidence

func (c *Claim) SetEvidence(shareIndex *big.Int)

type ClaimRepo

type ClaimRepo interface {
	// AddShare stores share to current active claim
	AddShare(s smartpool.Share) error
	// GetCurrentClaim returns the active claim, seal it as closed claim and
	// initialize a new active claim to store coming shares. In the mean time
	// the sealed claim should be used by SmartPool to do the protocol.
	// GetCurrentClaim returns nil when there are not enough shares in the claim
	// as compared to the threshold.
	GetCurrentClaim(threshold int) smartpool.Claim
	Persist(storage smartpool.PersistentStorage) error
	NoActiveShares() uint64
}

ClaimRepo holds many claims but only 1 active clam at a time which is storing coming shares.

type InMemClaimRepo

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

InMemClaimRepo implements ClaimRepo interface. It stores claims in one start up. However this claim repo doesn't persist verified claims and even the active claim. So if the client is shutdown, all past claims and current shares information will be lost. This shouldn't be used in production.

func NewInMemClaimRepo

func NewInMemClaimRepo() *InMemClaimRepo

func (*InMemClaimRepo) AddShare

func (cr *InMemClaimRepo) AddShare(s smartpool.Share) error

func (*InMemClaimRepo) GetClaim

func (cr *InMemClaimRepo) GetClaim(number uint64) smartpool.Claim

func (*InMemClaimRepo) GetCurrentClaim

func (cr *InMemClaimRepo) GetCurrentClaim(threshold int) smartpool.Claim

func (*InMemClaimRepo) NoActiveShares

func (cr *InMemClaimRepo) NoActiveShares() uint64

func (*InMemClaimRepo) Persist

func (cr *InMemClaimRepo) Persist(storage smartpool.PersistentStorage) error

type Shares

type Shares []smartpool.Share

func (Shares) Len

func (s Shares) Len() int

func (Shares) Less

func (s Shares) Less(i, j int) bool

func (Shares) Swap

func (s Shares) Swap(i, j int)

type SmartPool

type SmartPool struct {
	PoolMonitor     smartpool.PoolMonitor
	ShareReceiver   smartpool.ShareReceiver
	NetworkClient   smartpool.NetworkClient
	Contract        smartpool.Contract
	StatRecorder    smartpool.StatRecorder
	ClaimRepo       ClaimRepo
	Storage         smartpool.PersistentStorage
	LatestCounter   *big.Int
	ContractAddress common.Address
	MinerAddress    common.Address
	ExtraData       string
	SubmitInterval  time.Duration
	ShareThreshold  int
	HotStop         bool

	SubmitterStopped chan bool

	Input smartpool.UserInput
	// contains filtered or unexported fields
}

SmartPool represent smartpool protocol which interacts smartpool high level interfaces and types together to do following procedures:

  1. Register the miner if needed
  2. Give miner works
  3. Accept solutions from miners and construct corresponding shares to add into current active claim. It returns true when the share is successfully added, false otherwise. A share can only be added when it's counter is greater than the maximum counter of the last verified claim
  4. Package shares into a claim after interval of an amount of time.
  5. Then Submit the claim to the contract
  6. Then If successful, submit the claim proof to the contract.

func NewSmartPool

func NewSmartPool(
	pm smartpool.PoolMonitor, sr smartpool.ShareReceiver,
	nc smartpool.NetworkClient, cr ClaimRepo, ps smartpool.PersistentStorage,
	co smartpool.Contract, stat smartpool.StatRecorder, ca common.Address,
	ma common.Address, ed string, interval time.Duration, threshold int,
	hotStop bool, input smartpool.UserInput) *SmartPool

func (*SmartPool) AcceptSolution

func (sp *SmartPool) AcceptSolution(rig smartpool.Rig, s smartpool.Solution) bool

AcceptSolution accepts solutions from miners and construct corresponding shares to add into current active claim. It returns true when the share is successfully added, false otherwise. A share can only be added when it's counter is greater than the maximum counter of the last verified claim

func (*SmartPool) Exit

func (sp *SmartPool) Exit()

func (*SmartPool) GetCurrentClaim

func (sp *SmartPool) GetCurrentClaim(threshold int) smartpool.Claim

GetCurrentClaim returns new claim containing unsubmitted shares. If there is no new shares, it returns nil.

func (*SmartPool) GetVerificationIndex

func (sp *SmartPool) GetVerificationIndex(claim smartpool.Claim) *big.Int

func (*SmartPool) GetWork

func (sp *SmartPool) GetWork(rig smartpool.Rig) smartpool.Work

GetWork returns miner work

func (*SmartPool) Register

func (sp *SmartPool) Register(addr common.Address) bool

Register registers miner address to the contract. It returns false if the miner address couldn't be able to register to the pool even though it didn't register before. It returns true otherwise, in this case, Register does nothing if the address registered before or registers the address if it didn't.

func (*SmartPool) Run

func (sp *SmartPool) Run() bool

Run can be called at most once to start a loop to submit and verify claims after an interval. If the loop has not been started, it starts the loop and return true, it return false otherwise.

func (*SmartPool) SealClaim

func (sp *SmartPool) SealClaim() smartpool.Claim

func (*SmartPool) Submit

func (sp *SmartPool) Submit() (bool, error)

Submit does all the protocol that communicates with the contract to submit the claim then verify it. It returns true when the claim is fully verified and accepted by the contract. It returns false otherwise.

func (*SmartPool) SubmitHashrate

func (sp *SmartPool) SubmitHashrate(rig smartpool.Rig, hashrate hexutil.Uint64, id common.Hash) bool

func (*SmartPool) SubmitterRunning

func (sp *SmartPool) SubmitterRunning() bool

Jump to

Keyboard shortcuts

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