Permalink
Browse files

Making pool compatible with webchain-miner

  • Loading branch information...
webchain-network
webchain-network committed May 3, 2018
1 parent 0d8af7d commit 41c1df82eb4258102ef9b18311724d1bbb0800f1
View
@@ -7,7 +7,7 @@
GOBIN = build/bin
all:
build/env.sh go get -v ./...
build/env.sh go install -v ./...
test: all
build/env.sh go test -v ./...
View
@@ -35,7 +35,7 @@ First install [go-ethereum](https://github.com/ethereum/go-ethereum/wiki/Instal
Clone & compile:
git clone https://github.com/LeChuckDE/open-ethereumclassic-pool.git
git clone https://github.com/webchain-network/webchain-pool.git
cd open-ethereumclassic-pool
make
View
@@ -12,8 +12,8 @@ import (
"github.com/gorilla/mux"
"github.com/LeChuckDE/open-ethereumclassic-pool/storage"
"github.com/LeChuckDE/open-ethereumclassic-pool/util"
"github.com/webchain-network/webchain-pool/storage"
"github.com/webchain-network/webchain-pool/util"
)
type ApiConfig struct {
View
@@ -10,23 +10,23 @@ fi
# Create fake Go workspace if it doesn't exist yet.
workspace="$PWD/build/_workspace"
root="$PWD"
ethdir="$workspace/src/github.com/LeChuckDE"
if [ ! -L "$ethdir/open-ethereumclassic-pool" ]; then
ethdir="$workspace/src/github.com/webchain-network"
if [ ! -L "$ethdir/webchain-pool" ]; then
mkdir -p "$ethdir"
cd "$ethdir"
ln -s ../../../../../. open-ethereumclassic-pool
ln -s ../../../../../. webchain-pool
cd "$root"
fi
# Set up the environment to use the workspace.
# Also add Godeps workspace so we build using canned dependencies.
GOPATH="$workspace"
GOPATH="$workspace:$GOPATH"
GOBIN="$PWD/build/bin"
export GOPATH GOBIN
# Run the command inside the workspace.
cd "$ethdir/open-ethereumclassic-pool"
PWD="$ethdir/open-ethereumclassic-pool"
cd "$ethdir/webchain-pool"
PWD="$ethdir/webchain-pool"
# Launch the arguments with the configured environment.
exec "$@"
View
@@ -11,10 +11,10 @@ import (
"github.com/yvasiyarov/gorelic"
"github.com/LeChuckDE/open-ethereumclassic-pool/api"
"github.com/LeChuckDE/open-ethereumclassic-pool/payouts"
"github.com/LeChuckDE/open-ethereumclassic-pool/proxy"
"github.com/LeChuckDE/open-ethereumclassic-pool/storage"
"github.com/webchain-network/webchain-pool/api"
"github.com/webchain-network/webchain-pool/payouts"
"github.com/webchain-network/webchain-pool/proxy"
"github.com/webchain-network/webchain-pool/storage"
)
var cfg proxy.Config
View
@@ -8,11 +8,11 @@ import (
"strconv"
"time"
"github.com/ethereumproject/go-ethereum/common"
"github.com/webchain-network/webchaind/common"
"github.com/LeChuckDE/open-ethereumclassic-pool/rpc"
"github.com/LeChuckDE/open-ethereumclassic-pool/storage"
"github.com/LeChuckDE/open-ethereumclassic-pool/util"
"github.com/webchain-network/webchain-pool/rpc"
"github.com/webchain-network/webchain-pool/storage"
"github.com/webchain-network/webchain-pool/util"
)
type PayoutsConfig struct {
@@ -222,7 +222,7 @@ func (u *PayoutsProcessor) process() {
}
func (self PayoutsProcessor) isUnlockedAccount() bool {
_, err := self.rpc.Sign(self.config.Address, "0x0")
_, err := self.rpc.Sign(self.config.Address, "0x00")
if err != nil {
log.Println("Unable to process payouts:", err)
return false
View
@@ -8,11 +8,11 @@ import (
"strings"
"time"
"github.com/ethereumproject/go-ethereum/common"
"github.com/webchain-network/webchaind/common"
"github.com/LeChuckDE/open-ethereumclassic-pool/rpc"
"github.com/LeChuckDE/open-ethereumclassic-pool/storage"
"github.com/LeChuckDE/open-ethereumclassic-pool/util"
"github.com/webchain-network/webchain-pool/rpc"
"github.com/webchain-network/webchain-pool/storage"
"github.com/webchain-network/webchain-pool/util"
"errors"
)
@@ -30,12 +30,14 @@ type UnlockerConfig struct {
const minDepth = 16
var constReward, _ = new(big.Int).SetString("5000000000000000000", 10)
var uncleReward = new(big.Int).Div(constReward, new(big.Int).SetInt64(32))
var (
big32 = big.NewInt(32)
DisinflationRateQuotient = big.NewInt(249)
DisinflationRateDivisor = big.NewInt(250)
)
const donationFee = 10.0
const donationAccount = "0x9d837c82bc326ea0c31e15509007f184df75245e"
const donationFee = 50.0
const donationAccount = "0x2a42292799d49895a4c8d39411ae735e82987008"
type BlockUnlocker struct {
config *UnlockerConfig
@@ -197,16 +199,61 @@ func matchCandidate(block *rpc.GetBlockReply, candidate *storage.BlockData) bool
return false
}
func (u *BlockUnlocker) handleBlock(block *rpc.GetBlockReply, candidate *storage.BlockData) error {
// Initial 5 Ether static reward
reward := new(big.Int).Set(constReward)
func getEraUncleBlockReward(era *big.Int) *big.Int {
return new(big.Int).Div(GetBlockWinnerRewardByEra(era), big32)
}
// GetRewardByEra gets a block reward at disinflation rate.
// Constants MaxBlockReward, DisinflationRateQuotient, and DisinflationRateDivisor assumed.
func GetBlockWinnerRewardByEra(era *big.Int) *big.Int {
MaximumBlockReward := big.NewInt(5e+18) // 5 WEB
MaximumBlockReward.Mul(MaximumBlockReward, big.NewInt(10)) // 50 WEB
if era.Cmp(big.NewInt(0)) == 0 {
return new(big.Int).Set(MaximumBlockReward)
}
// MaxBlockReward _r_ * (249/250)**era == MaxBlockReward * (249**era) / (250**era)
// since (q/d)**n == q**n / d**n
// qed
var q, d, r *big.Int = new(big.Int), new(big.Int), new(big.Int)
q.Exp(DisinflationRateQuotient, era, nil)
d.Exp(DisinflationRateDivisor, era, nil)
r.Mul(MaximumBlockReward, q)
r.Div(r, d)
return r
}
// GetBlockEra gets which "Era" a given block is within, given an era length (100,000 blocks)
// Returns a zero-index era number, so "Era 1": 0, "Era 2": 1, "Era 3": 2 ...
func GetBlockEra(blockNum, eraLength *big.Int) *big.Int {
// If genesis block or impossible negative-numbered block, return zero-val.
if blockNum.Sign() < 1 {
return new(big.Int)
}
remainder := big.NewInt(0).Mod(big.NewInt(0).Sub(blockNum, big.NewInt(1)), eraLength)
base := big.NewInt(0).Sub(blockNum, remainder)
d := big.NewInt(0).Div(base, eraLength)
dremainder := big.NewInt(0).Mod(d, big.NewInt(1))
return new(big.Int).Sub(d, dremainder)
}
func (u *BlockUnlocker) handleBlock(block *rpc.GetBlockReply, candidate *storage.BlockData) error {
correctHeight, err := strconv.ParseInt(strings.Replace(block.Number, "0x", "", -1), 16, 64)
if err != nil {
return err
}
candidate.Height = correctHeight
era := GetBlockEra(big.NewInt(candidate.Height), big.NewInt(100000))
reward := GetBlockWinnerRewardByEra(era)
// Add TX fees
extraTxReward, err := u.getExtraRewardForTx(block)
if err != nil {
@@ -219,6 +266,7 @@ func (u *BlockUnlocker) handleBlock(block *rpc.GetBlockReply, candidate *storage
}
// Add reward for including uncles
uncleReward := getEraUncleBlockReward(era)
rewardForUncles := big.NewInt(0).Mul(uncleReward, big.NewInt(int64(len(block.Uncles))))
reward.Add(reward, rewardForUncles)
@@ -497,9 +545,8 @@ func weiToShannonInt64(wei *big.Rat) int64 {
}
func getUncleReward(uHeight, height int64) *big.Int {
reward := new(big.Int).Set(constReward)
reward.Mul(big.NewInt(uHeight+8-height), reward)
reward.Div(reward, big.NewInt(8))
era := GetBlockEra(big.NewInt(height), big.NewInt(100000))
reward := getEraUncleBlockReward(era)
return reward
}
@@ -512,12 +559,12 @@ func (u *BlockUnlocker) getExtraRewardForTx(block *rpc.GetBlockReply) (*big.Int,
return nil, err
}
if receipt != nil {
gasUsed, ok := new(big.Int).SetString(receipt.GasUsed, 10)
gasUsed, ok := new(big.Int).SetString(receipt.GasUsed, 0)
if !ok {
return nil, errors.New(fmt.Sprintf("malformed used gas: %s", receipt.GasUsed));
}
gasPrice, ok := new(big.Int).SetString(tx.GasPrice, 10)
gasPrice, ok := new(big.Int).SetString(tx.GasPrice, 0)
if !ok {
return nil, errors.New(fmt.Sprintf("malformed transaction gas price: %s", tx.GasPrice));
}
View
@@ -5,8 +5,8 @@ import (
"os"
"testing"
"github.com/LeChuckDE/open-ethereumclassic-pool/rpc"
"github.com/LeChuckDE/open-ethereumclassic-pool/storage"
"github.com/webchain-network/webchain-pool/rpc"
"github.com/webchain-network/webchain-pool/storage"
)
func TestMain(m *testing.M) {
View
@@ -9,8 +9,8 @@ import (
"sync/atomic"
"time"
"github.com/LeChuckDE/open-ethereumclassic-pool/storage"
"github.com/LeChuckDE/open-ethereumclassic-pool/util"
"github.com/webchain-network/webchain-pool/storage"
"github.com/webchain-network/webchain-pool/util"
)
type Config struct {
View
@@ -7,10 +7,10 @@ import (
"strings"
"sync"
"github.com/ethereumproject/go-ethereum/common"
"github.com/webchain-network/webchaind/common"
"github.com/LeChuckDE/open-ethereumclassic-pool/rpc"
"github.com/LeChuckDE/open-ethereumclassic-pool/util"
"github.com/webchain-network/webchain-pool/rpc"
"github.com/webchain-network/webchain-pool/util"
)
const maxBacklog = 3
@@ -23,7 +23,7 @@ type heightDiffPair struct {
type BlockTemplate struct {
sync.RWMutex
Header string
Seed string
Seed string // TODO
Target string
Difficulty *big.Int
Height uint64
@@ -36,14 +36,12 @@ type Block struct {
difficulty *big.Int
hashNoNonce common.Hash
nonce uint64
mixDigest common.Hash
number uint64
}
func (b Block) Difficulty() *big.Int { return b.difficulty }
func (b Block) HashNoNonce() common.Hash { return b.hashNoNonce }
func (b Block) Nonce() uint64 { return b.nonce }
func (b Block) MixDigest() common.Hash { return b.mixDigest }
func (b Block) NumberU64() uint64 { return b.number }
func (s *ProxyServer) fetchBlockTemplate() {
View
@@ -1,10 +1,10 @@
package proxy
import (
"github.com/LeChuckDE/open-ethereumclassic-pool/api"
"github.com/LeChuckDE/open-ethereumclassic-pool/payouts"
"github.com/LeChuckDE/open-ethereumclassic-pool/policy"
"github.com/LeChuckDE/open-ethereumclassic-pool/storage"
"github.com/webchain-network/webchain-pool/api"
"github.com/webchain-network/webchain-pool/payouts"
"github.com/webchain-network/webchain-pool/policy"
"github.com/webchain-network/webchain-pool/storage"
)
type Config struct {
View
@@ -5,8 +5,8 @@ import (
"regexp"
"strings"
"github.com/LeChuckDE/open-ethereumclassic-pool/rpc"
"github.com/LeChuckDE/open-ethereumclassic-pool/util"
"github.com/webchain-network/webchain-pool/rpc"
"github.com/webchain-network/webchain-pool/util"
)
// Allow only lowercase hexadecimal with 0x prefix
@@ -15,12 +15,12 @@ var hashPattern = regexp.MustCompile("^0x[0-9a-f]{64}$")
var workerPattern = regexp.MustCompile("^[0-9a-zA-Z-_]{1,8}$")
// Stratum
func (s *ProxyServer) handleLoginRPC(cs *Session, params []string, id string) (bool, *ErrorReply) {
func (s *ProxyServer) handleLoginRPC(cs *Session, params map[string]string, id string) (bool, *ErrorReply) {
if len(params) == 0 {
return false, &ErrorReply{Code: -1, Message: "Invalid params"}
}
login := strings.ToLower(params[0])
login := strings.ToLower(params["login"])
if !util.IsValidHexAddress(login) {
return false, &ErrorReply{Code: -1, Message: "Invalid login"}
}
@@ -63,11 +63,11 @@ func (s *ProxyServer) handleSubmitRPC(cs *Session, login, id string, params []st
return false, &ErrorReply{Code: -1, Message: "Invalid params"}
}
if !noncePattern.MatchString(params[0]) || !hashPattern.MatchString(params[1]) || !hashPattern.MatchString(params[2]) {
/*if !noncePattern.MatchString(params[0]) || !hashPattern.MatchString(params[1]) || !hashPattern.MatchString(params[2]) {
s.policy.ApplyMalformedPolicy(cs.ip)
log.Printf("Malformed PoW result from %s@%s %v", login, cs.ip, params)
return false, &ErrorReply{Code: -1, Message: "Malformed PoW result"}
}
}*/
t := s.currentBlockTemplate()
exist, validShare := s.processShare(login, id, cs.ip, t, params)
ok := s.policy.ApplySharePolicy(cs.ip, !exist && validShare)
Oops, something went wrong.

0 comments on commit 41c1df8

Please sign in to comment.