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
- type Claim
- func (c *Claim) AddShare(s smartpool.Share)
- func (c *Claim) AugMerkle() smartpool.SPHash
- func (c *Claim) CounterBranch() []*big.Int
- func (c *Claim) Difficulty() *big.Int
- func (c *Claim) GetShare(index int) smartpool.Share
- func (c *Claim) HashBranch() []*big.Int
- func (c *Claim) Max() *big.Int
- func (c *Claim) Min() *big.Int
- func (c *Claim) NumShares() *big.Int
- func (c *Claim) SetEvidence(shareIndex *big.Int)
- type ClaimRepo
- type InMemClaimRepo
- func (cr *InMemClaimRepo) AddShare(s smartpool.Share) error
- func (cr *InMemClaimRepo) GetClaim(number uint64) smartpool.Claim
- func (cr *InMemClaimRepo) GetCurrentClaim(threshold int) smartpool.Claim
- func (cr *InMemClaimRepo) NoActiveShares() uint64
- func (cr *InMemClaimRepo) Persist(storage smartpool.PersistentStorage) error
- type Shares
- type SmartPool
- func (sp *SmartPool) AcceptSolution(rig smartpool.Rig, s smartpool.Solution) bool
- func (sp *SmartPool) Exit()
- func (sp *SmartPool) GetCurrentClaim(threshold int) smartpool.Claim
- func (sp *SmartPool) GetVerificationIndex(claim smartpool.Claim) *big.Int
- func (sp *SmartPool) GetWork(rig smartpool.Rig) smartpool.Work
- func (sp *SmartPool) Register(addr common.Address) bool
- func (sp *SmartPool) Run() bool
- func (sp *SmartPool) SealClaim() smartpool.Claim
- func (sp *SmartPool) Submit() (bool, error)
- func (sp *SmartPool) SubmitHashrate(rig smartpool.Rig, hashrate hexutil.Uint64, id common.Hash) bool
- func (sp *SmartPool) SubmitterRunning() bool
Constants ¶
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 (*Claim) CounterBranch ¶
func (*Claim) Difficulty ¶
func (*Claim) HashBranch ¶
func (*Claim) SetEvidence ¶
type ClaimRepo ¶
type ClaimRepo interface { 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 }AddShare(s smartpool.Share)
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 SmartPool ¶
type SmartPool struct { PoolMonitor smartpool.PoolMonitor 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 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:
- Register the miner if needed
- Give miner works
- 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
- Package shares into a claim after interval of an amount of time.
- Then Submit the claim to the contract
- 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 ¶
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) GetCurrentClaim ¶
GetCurrentClaim returns new claim containing unsubmitted shares. If there is no new shares, it returns nil.
func (*SmartPool) GetVerificationIndex ¶
func (*SmartPool) GetWork ¶
func (sp *SmartPool) GetWork(rig smartpool.Rig) smartpool.Work
GetWork returns miner work
func (*SmartPool) Register ¶
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 ¶
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) Submit ¶
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.