smartpool

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: 5 Imported by: 0

README

Smartpool - The first decentralized mining pool based on smart contract (alpha)

Gitter

Ropsten testnet

Smartpool is live on Ropsten testnet. This repository consists of the client software. The smart contract repository is here.

Requirements
OS

The client is currently tested only on Mac OS and Ubuntu.

Golang compiler

Golang compiler version 1.7 or higher.

Parity client

Ethereum Parity client version 1.5.9 or higher.

Geth client

Ethereum Geth client needs to be compiled from source.

Ethminer

We support CPU and GPU mining with ethminer version 1.2.9 or higher.

ETH balance

To run smartpool you must have a Ropsten testnet account with least 0.5 Ether. You can get testnet Ethers from metamask faucets or ping us on our gitter channel.

Note: To get Ether from metamask faucet, you need to install metamask browser add-on.

Installation
  1. git clone https://github.com/SmartPool/smartpool-client.git
  2. cd smartpool-client
  3. ./compile.sh

Note: If you are on MacOS, there is a issue with Go and XCode 8.3 that might make you see killed ./smartpool error. To fix this issue, please run build/env.sh go build -o smartpool -ldflags -s cmd/ropsten/ropsten.go instead of ./compile.sh.

Running
  1. Run Geth on Ropsten testnet: geth --testnet --fast --rpc --rpcapi "db,eth,net,web3,miner" or Parity: parity --chain ropsten --jsonrpc-apis "web3,eth,net,parity,traces,rpc,parity_set"
  2. Run smartpool client ./smartpool --keystore keystore_path --miner account. Where
  • keystore_path is a path to a directory that contains your account key. E.g., $HOME/.local/share/io.parity.ethereum/keys/kovan/.
  • account is the address of your account. E.g., 0x2ba80fe2811f8e0ea5eabf8e07697f7e9f5ae56c.
  • E.g., ./smartpool --keystore ~/Library/Ethereum/testnet/keystore --miner 0xe034afdcc2ba0441ff215ee9ba0da3e86450108d.
  1. Enter your key passphrase.
  2. Run ethminer -F localhost:1633 or ethminer -G -F localhost:1633 if you mine with your GPU.

Kovan testnet

Smartpool is also live on Kovan testnet.

Parity client

Ethereum Parity client version 1.5.9 or higher.

ETH balance

To run smartpool you must have a testnet Kovan account with least 0.5 Ether. You can get testnet Ethers from faucets.

Installation
  1. git clone https://github.com/SmartPool/smartpool-client.git
  2. cd smartpool-client
  3. ./kovan_compile.sh
Running
  1. Run Parity on Kovan testnet. parity --chain kovan --jsonrpc-apis "web3,eth,net,parity,traces,rpc,parity_set"
  2. Run smartpool client ./kovan --keystore keystore_path --miner account --spcontract 0x0398ae5a974FE8179B6B0ab9baF4d5f366E932Bf. Where
  • keystore_path is a path to a directory that contains your account key. E.g., $HOME/.local/share/io.parity.ethereum/keys/kovan/.
  • account is the address of your account. E.g., 0x2ba80fe2811f8e0ea5eabf8e07697f7e9f5ae56c
  1. Enter your key passphrase.
  2. Run ethminer -F localhost:1633 or ethminer -G -F localhost:1633 if you mine with your GPU.

Support

Contact us at gitter for support.

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

View Source
const (
	HashLength          = 16
	WordLength          = 128
	BranchElementLength = 32
)
View Source
const VERSION = "0.2.1"

Variables

View Source
var Output = &StdOut{}

Global output mechanism

Functions

func BigToBase62

func BigToBase62(num *big.Int) string

return 11 chars base 62 representation of a big int base chars are 0-9 a-z A-Z

func BytesToBig

func BytesToBig(data []byte) *big.Int

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
	NumShares() *big.Int
	GetShare(index int) Share
	// 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
	// GetShareIndex returns index of the share that is requested to submit
	// 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 NewInput

func NewInput(
	rpcEndPoint string,
	keystorePath string,
	shareThreshold int,
	shareDifficulty *big.Int,
	submitInterval time.Duration,
	contractAddr string,
	minerAddr string,
	extraData string,
	hotStop bool,
) *Input

func (*Input) ContractAddress

func (i *Input) ContractAddress() string

func (*Input) ExtraData

func (i *Input) ExtraData() string

func (*Input) HotStop

func (i *Input) HotStop() bool

func (*Input) KeystorePath

func (i *Input) KeystorePath() string

func (*Input) MinerAddress

func (i *Input) MinerAddress() string

func (*Input) RPCEndpoint

func (i *Input) RPCEndpoint() string

func (*Input) SetContractAddress

func (i *Input) SetContractAddress(addr common.Address)

func (*Input) SetExtraData

func (i *Input) SetExtraData(extra string)

func (*Input) SetMinerAddress

func (i *Input) SetMinerAddress(addr common.Address)

func (*Input) ShareDifficulty

func (i *Input) ShareDifficulty() *big.Int

func (*Input) ShareThreshold

func (i *Input) ShareThreshold() int

func (*Input) SubmitInterval

func (i *Input) SubmitInterval() time.Duration

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
	SubmitHashrate(hashrate hexutil.Uint64, id common.Hash) 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 {
	Persist(data interface{}, id string) error
	Load(data interface{}, id string) (interface{}, error)
}

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 PoolMonitor interface {
	RequireClientUpdate() bool
	RequireContractUpdate() bool
	ContractAddress() common.Address
}

type Rig

type Rig interface {
	ID() string
}

Rig represents mining actor that will be directly interactive with smartpool.

type SPHash

type SPHash [HashLength]byte

func (SPHash) Big

func (h SPHash) Big() *big.Int

func (SPHash) Bytes

func (h SPHash) Bytes() []byte

func (SPHash) Hex

func (h SPHash) Hex() string

func (SPHash) Str

func (h SPHash) Str() string

type Share

type Share interface {
	// Counter returns the counter to be used in augmented merkle tree of a claim
	// 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
	// Difficulty returns the difficulty of the share that miner has solved.
	ShareDifficulty() *big.Int
	// Hash return the hash of the share to be used as leaf hash of the augmented
	// merkle tree.
	Hash() SPHash
	// FullSolution returns true if the share is solution for its full block pow
	// hash. It returns false otherwise.
	FullSolution() bool
}

Share represent a solution of a Work that comes from the miner.

type ShareReceiver

type ShareReceiver interface {
	AcceptSolution(s Solution) Share
}

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 StatRecorder

type StatRecorder interface {
	RecordShare(status string, share Share, rig Rig)
	RecordClaim(status string, claim Claim)
	RecordHashrate(hashrate hexutil.Uint64, id common.Hash, rig Rig)
	// Notify StatRecorder how many share were restored from last session
	// so StatRecorder can track number of abandoned shares
	ShareRestored(noshares uint64)

	OverallFarmStat() interface{}
	FarmStat(start uint64, end uint64) interface{}
	OverallRigStat(rig Rig) interface{}
	RigStat(rig Rig, start uint64, end uint64) interface{}

	Persist(storage PersistentStorage) error
}

type StdOut

type StdOut struct{}

func (StdOut) Printf

func (StdOut) Printf(format string, a ...interface{}) (n int, err error)

type UserInput

type UserInput interface {
	RPCEndpoint() string
	KeystorePath() string
	ShareThreshold() int
	ShareDifficulty() *big.Int
	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 Word

type Word [WordLength]byte

func (Word) ToUint256Array

func (w Word) ToUint256Array() []*big.Int

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.

Jump to

Keyboard shortcuts

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