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 ¶
- 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
- type Shares
- type SmartPool
- func (sp *SmartPool) AcceptSolution(s smartpool.Solution) bool
- func (sp *SmartPool) GetCurrentClaim(threshold int) smartpool.Claim
- func (sp *SmartPool) GetVerificationIndex(claim smartpool.Claim) *big.Int
- func (sp *SmartPool) GetWork() 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)
Constants ¶
This section is empty.
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 { // 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 }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)
func (*InMemClaimRepo) GetClaim ¶
func (cr *InMemClaimRepo) GetClaim(number uint64) smartpool.Claim
func (*InMemClaimRepo) GetCurrentClaim ¶
func (cr *InMemClaimRepo) GetCurrentClaim(threshold int) smartpool.Claim
type SmartPool ¶
type SmartPool struct { PoolMonitor smartpool.PoolMonitor NetworkClient smartpool.NetworkClient Contract smartpool.Contract ClaimRepo ClaimRepo LatestCounter *big.Int ContractAddress common.Address MinerAddress common.Address ExtraData string SubmitInterval time.Duration HotStop bool // 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 (*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() 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.