Permalink
Browse files

Fix latest parity rpc breaking changes

  • Loading branch information...
sammy007 committed Jun 7, 2018
1 parent bcfc0eb commit 34040466e2c392dc8dc6104e571875cbcfbec0c8
Showing with 26 additions and 50 deletions.
  1. +10 −14 README.md
  2. +2 −2 payouts/unlocker.go
  3. +12 −32 proxy/blocks.go
  4. +2 −2 rpc/rpc.go
@@ -10,7 +10,7 @@

* Support for HTTP and Stratum mining
* Detailed block stats with luck percentage and full reward
* Failover geth instances: geth high availability built in
* Parity nodes rpc failover built in
* Modern beautiful Ember.js frontend
* Separate stats for workers: can highlight timed-out workers so miners can perform maintenance of rigs
* JSON-API for stats
@@ -25,7 +25,7 @@
Dependencies:

* go >= 1.9
* geth or parity
* parity (will not work with geth)
* redis-server >= 2.8.0
* nodejs >= 4 LTS
* nginx
@@ -134,7 +134,7 @@ otherwise you will get errors on start because of JSON comments.**
"maxConn": 8192
},
// Try to get new job from geth in this interval
// Try to get new job from node in this interval
"blockRefreshInterval": "120ms",
"stateUpdateInterval": "3s",
// Require this share difficulty from miners
@@ -208,10 +208,10 @@ otherwise you will get errors on start because of JSON comments.**
"purgeOnly": false
},
// Check health of each geth node in this interval
// Check health of each node in this interval
"upstreamCheckInterval": "5s",
/* List of geth nodes to poll for new jobs. Pool will try to get work from
/* List of parity nodes to poll for new jobs. Pool will try to get work from
first alive one and check in background for failed to back up.
Current block template of the pool is always cached in RAM indeed.
*/
@@ -254,9 +254,9 @@ otherwise you will get errors on start because of JSON comments.**
"keepTxFees": false,
// Run unlocker in this interval
"interval": "10m",
// Geth instance node rpc endpoint for unlocking blocks
// Parity node rpc endpoint for unlocking blocks
"daemon": "http://127.0.0.1:8545",
// Rise error if can't reach geth in this amount of time
// Rise error if can't reach parity
"timeout": "10s"
},
@@ -267,13 +267,13 @@ otherwise you will get errors on start because of JSON comments.**
"requirePeers": 25,
// Run payouts in this interval
"interval": "12h",
// Geth instance node rpc endpoint for payouts processing
// Parity node rpc endpoint for payouts processing
"daemon": "http://127.0.0.1:8545",
// Rise error if can't reach geth in this amount of time
// Rise error if can't reach parity
"timeout": "10s",
// Address with pool balance
"address": "0x0",
// Let geth to determine gas and gasPrice
// Let parity to determine gas and gasPrice
"autoGas": true,
// Gas amount and price for payout tx (advanced users only)
"gas": "21000",
@@ -303,10 +303,6 @@ I recommend this deployment strategy:
* Don't run payouts and unlocker modules as part of mining node. Create separate configs for both, launch independently and make sure you have a single instance of each module running.
* If `poolFeeAddress` is not specified all pool profit will remain on coinbase address. If it specified, make sure to periodically send some dust back required for payments.

### Alternative Ethereum Implementations

This pool is tested to work with [Ethcore's Parity](https://github.com/ethcore/parity). Mining and block unlocking works, but I am not sure about payouts and suggest to run *official* geth node for payments.

### Credits

Made by sammy007. Licensed under GPLv3.
@@ -253,7 +253,7 @@ func (u *BlockUnlocker) unlockPendingBlocks() {
return
}

current, err := u.rpc.GetPendingBlock()
current, err := u.rpc.GetLatestBlock()
if err != nil {
u.halt = true
u.lastFail = err
@@ -351,7 +351,7 @@ func (u *BlockUnlocker) unlockAndCreditMiners() {
return
}

current, err := u.rpc.GetPendingBlock()
current, err := u.rpc.GetLatestBlock()
if err != nil {
u.halt = true
u.lastFail = err
@@ -47,37 +47,37 @@ func (b Block) MixDigest() common.Hash { return b.mixDigest }
func (b Block) NumberU64() uint64 { return b.number }

func (s *ProxyServer) fetchBlockTemplate() {
rpc := s.rpc()
r := s.rpc()
t := s.currentBlockTemplate()
pendingReply, height, diff, err := s.fetchPendingBlock()
reply, err := r.GetWork()
if err != nil {
log.Printf("Error while refreshing pending block on %s: %s", rpc.Name, err)
return
}
reply, err := rpc.GetWork()
if err != nil {
log.Printf("Error while refreshing block template on %s: %s", rpc.Name, err)
log.Printf("Error while refreshing block template on %s: %s", r.Name, err)
return
}
// No need to update, we have fresh job
if t != nil && t.Header == reply[0] {
return
}
diff := util.TargetHexToDiff(reply[2])
height, err := strconv.ParseUint(strings.Replace(reply[3], "0x", "", -1), 16, 64)

pendingReply.Difficulty = util.ToHex(s.config.Proxy.Difficulty)
pendingReply := &rpc.GetBlockReplyPart{
Difficulty: util.ToHex(s.config.Proxy.Difficulty),
Number: reply[3],
}

newTemplate := BlockTemplate{
Header: reply[0],
Seed: reply[1],
Target: reply[2],
Height: height,
Difficulty: big.NewInt(diff),
Difficulty: diff,
GetPendingBlockCache: pendingReply,
headers: make(map[string]heightDiffPair),
}
// Copy job backlog and add current one
newTemplate.headers[reply[0]] = heightDiffPair{
diff: util.TargetHexToDiff(reply[2]),
diff: diff,
height: height,
}
if t != nil {
@@ -88,30 +88,10 @@ func (s *ProxyServer) fetchBlockTemplate() {
}
}
s.blockTemplate.Store(&newTemplate)
log.Printf("New block to mine on %s at height %d / %s", rpc.Name, height, reply[0][0:10])
log.Printf("New block to mine on %s at height %d / %s / %d", r.Name, height, reply[0][0:10], diff)

// Stratum
if s.config.Proxy.Stratum.Enabled {
go s.broadcastNewJobs()
}
}

func (s *ProxyServer) fetchPendingBlock() (*rpc.GetBlockReplyPart, uint64, int64, error) {
rpc := s.rpc()
reply, err := rpc.GetPendingBlock()
if err != nil {
log.Printf("Error while refreshing pending block on %s: %s", rpc.Name, err)
return nil, 0, 0, err
}
blockNumber, err := strconv.ParseUint(strings.Replace(reply.Number, "0x", "", -1), 16, 64)
if err != nil {
log.Println("Can't parse pending block number")
return nil, 0, 0, err
}
blockDiff, err := strconv.ParseInt(strings.Replace(reply.Difficulty, "0x", "", -1), 16, 64)
if err != nil {
log.Println("Can't parse pending block difficulty")
return nil, 0, 0, err
}
return reply, blockNumber, blockDiff, nil
}
@@ -98,8 +98,8 @@ func (r *RPCClient) GetWork() ([]string, error) {
return reply, err
}

func (r *RPCClient) GetPendingBlock() (*GetBlockReplyPart, error) {
rpcResp, err := r.doPost(r.Url, "eth_getBlockByNumber", []interface{}{"pending", false})
func (r *RPCClient) GetLatestBlock() (*GetBlockReplyPart, error) {
rpcResp, err := r.doPost(r.Url, "eth_getBlockByNumber", []interface{}{"latest", false})
if err != nil {
return nil, err
}

0 comments on commit 3404046

Please sign in to comment.