Documentation ¶
Overview ¶
Package smartpool defines interfaces for interaction between SmartPool and user, SmartPool and external resources such as Ethereum client (geth, partity), ethminer, persistent storage.
It also defines some core interfaces for its sub packages to interact to each other.
Index ¶
- Constants
- Variables
- func BigToBase62(num *big.Int) string
- func BytesToBig(data []byte) *big.Int
- type BranchElement
- type Claim
- type Contract
- type Input
- func (i *Input) ContractAddress() string
- func (i *Input) ExtraData() string
- func (i *Input) HotStop() bool
- func (i *Input) KeystorePath() string
- func (i *Input) MinerAddress() string
- func (i *Input) RPCEndpoint() string
- func (i *Input) SetContractAddress(addr common.Address)
- func (i *Input) SetExtraData(extra string)
- func (i *Input) SetMinerAddress(addr common.Address)
- func (i *Input) ShareDifficulty() *big.Int
- func (i *Input) ShareThreshold() int
- func (i *Input) SubmitInterval() time.Duration
- type NetworkClient
- type PersistentStorage
- type PoolMonitor
- type SPHash
- type Share
- type ShareReceiver
- type Solution
- type StdOut
- type UserInput
- type UserOutput
- type Word
- type Work
Constants ¶
const ( HashLength = 16 WordLength = 128 BranchElementLength = 32 )
const VERSION = "0.2.1"
Variables ¶
var Output = &StdOut{}
Global output mechanism
Functions ¶
func BigToBase62 ¶
return 11 chars base 62 representation of a big int base chars are 0-9 a-z A-Z
func BytesToBig ¶
Types ¶
type BranchElement ¶
type BranchElement [BranchElementLength]byte
func BranchElementFromHash ¶
func BranchElementFromHash(a, b SPHash) BranchElement
func (BranchElement) Big ¶
func (h BranchElement) Big() *big.Int
func (BranchElement) Bytes ¶
func (h BranchElement) Bytes() []byte
func (BranchElement) Hex ¶
func (h BranchElement) Hex() string
func (BranchElement) Str ¶
func (h BranchElement) Str() string
type Claim ¶
type Claim interface { // NumShares returns number of shares that the claim is holding // Difficulty returns the min difficulty across all of its shares Difficulty() *big.Int // Min returns the min counter of the augmented merkle root Min() *big.Int // Max returns the max counter of the augmented merkle root Max() *big.Int // AugMerkle returns the hash of the augmented merkle root AugMerkle() SPHash // SetEvidence sets the share index to be used to prove the claim SetEvidence(shareIndex *big.Int) // CounterBranch returns array of counters in proof branch of the share CounterBranch() []*big.Int // HashBranch returns array of hashes in proof branch of the share HashBranch() []*big.Int }
Claim represent a batch of shares which needs to reorganize its shares in ascending order of share counter.
type Contract ¶
type Contract interface { // Version return contract version which is useful for backward and forward // compatibility when the contract is redeployed in some occasions. Version() string // IsRegistered returns true when the miner's address is already recognized // as a user of the pool. It returns false otherwise. IsRegistered() bool // CanRegister returns true when the miner's address can actually register // to the pool. It returns false when the contract side decided to refuse // the address. CanRegister() bool // Register takes an address and register it to the pool. Register(paymentAddress common.Address) error // SubmitClaim takes some necessary parameters that represent a claim and // submit to the contract using miner's address. The address should be // unlocked first. SubmitClaim(claim Claim) error // proof to the contract to represent correctness of the submitted claim. // GetShareIndex must be called after SubmitClaim to get shareIndex which // is used to pass to VerifyClaim. If GetShareIndex is called before // SubmitClaim, the index will have no meaning to contract. GetShareIndex(claim Claim) *big.Int // VerifyClaim takes some necessary parameters that provides complete proof // of a share with index shareIndex in the cliam and submit to contract side // in order to prove that the claim is valid so the miner can take credit // of it. VerifyClaim(shareIndex *big.Int, claim Claim) error }
Contract is the interface for smartpool to interact with contract side of SmartPool protocol. Contract can be used for only one caller (Ethereum account) per instance.
type Input ¶
type Input struct {
// contains filtered or unexported fields
}
func (*Input) ContractAddress ¶
func (*Input) KeystorePath ¶
func (*Input) MinerAddress ¶
func (*Input) RPCEndpoint ¶
func (*Input) SetContractAddress ¶ added in v0.2.0
func (*Input) SetExtraData ¶
func (*Input) SetMinerAddress ¶
func (*Input) ShareDifficulty ¶
func (*Input) ShareThreshold ¶
func (*Input) SubmitInterval ¶
type NetworkClient ¶
type NetworkClient interface { // GetWork returns a Work for SmartPool to give to the miner. How the work // is formed is upto structs implementing this interface. GetWork() Work // SubmitSolution submits the solution that miner has submitted to SmartPool // so the full block solution can take credits. It also maintain workflow // between miner and the network client. SubmitSolution(s Solution) bool // ReadyToMine returns true when the network is ready to give and accept // pow work and solution. It returns false otherwise. ReadyToMine() bool // Configure configs etherbase and extradata to the network client Configure(etherbase common.Address, extradata string) error }
NetworkClient represents client for blockchain network that miner is mining on. Network can be Ethereum, Ethereum Classic, ZCash, Bitcoin... For Ethereum, client can be Geth or Parity. Smartpool should only interact with network client via this interface and it doesn't care if the client is Geth or Partity or any other clients. Communication mechanism is upto structs implementing this interface.
type PersistentStorage ¶
type PersistentStorage interface { }
PersistentStorage is the gateway for smartpool to interact with external persistent storage such as a file system, a database or even a cloud based service. Smartpool should only persist something via this interface.
type PoolMonitor ¶
type SPHash ¶
type SPHash [HashLength]byte
type Share ¶
type Share interface { // which contains many shares. This counter must be increasing as shares // share coming. In other words, later share must have bigger counter. Counter() *big.Int ShareDifficulty() *big.Int // merkle tree. Hash() SPHash // hash. It returns false otherwise. FullSolution() bool }
Share represent a solution of a Work that comes from the miner.
type ShareReceiver ¶
type ShareReceiver interface {
}ShareReceiver represents SmartPool itself which accepts solutions from miners.
type Solution ¶
type Solution interface { // WorkID returns the ID to identify the work it is trying to solve WorkID() string }
Solution represents a solution for a work
type UserInput ¶
type UserInput interface { RPCEndpoint() string KeystorePath() string SubmitInterval() time.Duration ContractAddress() string MinerAddress() string ExtraData() string HotStop() bool }
UserInput represents all necessary user specific inputs to run SmartPool client. Some of them can have default values depend on the actual structs implementing the interface.
type UserOutput ¶
type UserOutput interface { // TODO: Add necessary methods // TODO: This might take information about internal detail such as: // number of claim submitted, number of claim verified, // number of claim accepted, number of share per claim on average, // average hash rate,... Printf(format string, a ...interface{}) (n int, err error) }
UserOutput accepts all the information that SmartPool wants to tell the user. It's only responsibility is to accept information. How the information is delivered to user is upto structs implementing the interface.
type Work ¶
type Work interface { ID() string // AcceptSolution takes solution to construct and return a Share representing // the solution that came from miner. AcceptSolution(sol Solution) Share }
Work represents SmartPool work that miner needs to solve to have valid shares. Work is easier (has smaller difficulty) than actual Ethereum work that the miner can get from the network.
Directories ¶
Path | Synopsis |
---|---|
cmd
|
|
Package ethereum contains all necessary components to plug into smartpool to work with ethereum blockchain.
|
Package ethereum contains all necessary components to plug into smartpool to work with ethereum blockchain. |
Package protocol implements smartpool secured protocol between client side and contract side.
|
Package protocol implements smartpool secured protocol between client side and contract side. |