Skip to content

Commit

Permalink
fixed getdifficulty to find best difficulty on both algos
Browse files Browse the repository at this point in the history
  • Loading branch information
Loki Verloren committed Nov 22, 2018
1 parent de10606 commit c69ef18
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 8 deletions.
51 changes: 46 additions & 5 deletions rpcserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -2270,13 +2270,54 @@ func handleGetCurrentNet(s *rpcServer, cmd interface{}, closeChan <-chan struct{
// handleGetDifficulty implements the getdifficulty command.
// TODO: This command should default to the configured algo for cpu mining and take an optional parameter to query by algo
func handleGetDifficulty(s *rpcServer, cmd interface{}, closeChan <-chan struct{}) (interface{}, error) {
c := cmd.(*btcjson.GetDifficultyCmd)
fmt.Println("Getting difficulty...", c.Algo)
best := s.cfg.Chain.BestSnapshot()
var a uint32 = 2
if best.Version == 514 {
a = 514
prev, err := s.cfg.Chain.BlockByHash(&best.Hash)
if err != nil {
fmt.Println("ERROR", err)
}
var algo uint32 = prev.MsgBlock().Header.Version
fmt.Println(algo, best.Height)
if algo != 514 {
algo = 2
}
bestbits := best.Bits
fmt.Printf("%08x\n", bestbits)
if c.Algo == "scrypt" && algo != 514 {
fmt.Println("We were asked for scrypt but latest is sha256d")
algo=514
for {
if prev.MsgBlock().Header.Version != 514 {
ph := prev.MsgBlock().Header.PrevBlock
prev, err = s.cfg.Chain.BlockByHash(&ph)
if err != nil {
fmt.Println("ERROR", err)
}
continue
}
bestbits = uint32(prev.MsgBlock().Header.Bits)
break
}
}

return getDifficultyRatio(best.Bits, s.cfg.ChainParams, a), nil
if c.Algo == "sha256d" && algo != 2 {
fmt.Println("We were asked for sha256d but latest is scrypt")
algo=2
for {
if prev.MsgBlock().Header.Version == 514 {
ph := prev.MsgBlock().Header.PrevBlock
prev, err = s.cfg.Chain.BlockByHash(&ph)
if err != nil {
fmt.Println("ERROR", err)
}
continue
}
bestbits = uint32(prev.MsgBlock().Header.Bits)
break
}
}
fmt.Printf("bits %08x algo %d\n", bestbits, algo)
return getDifficultyRatio(bestbits, s.cfg.ChainParams, algo), nil
}

// handleGetGenerate implements the getgenerate command.
Expand Down
7 changes: 4 additions & 3 deletions rpcserverhelp.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,9 +353,10 @@ var helpDescsEnUS = map[string]string{
"getcurrentnet--result0": "The network identifer",

// GetDifficultyCmd help.
"getdifficulty--synopsis": "Returns the proof-of-work difficulty as a multiple of the minimum difficulty, according to the currently configured cpu mining algorithm.",
"getdifficulty-algo": "Defaults to the configured --algo for the CPU miner, can be set to sha256 or scrypt",
"getdifficulty--result0": "The difficulty of the requested algorithm",
"getdifficulty--synopsis": "Returns the proof-of-work difficulty as a multiple of the minimum difficulty, according to the currently configured cpu mining algorithm.",
"getdifficulty-algo": "Defaults to the configured --algo for the CPU miner, can be set to sha256 or scrypt",
"getdifficulty--condition0": "algo=sha256d or scrypt",
"getdifficulty--result0": "The difficulty of the requested algorithm",

// GetGenerateCmd help.
"getgenerate--synopsis": "Returns if the server is set to generate coins (mine) or not.",
Expand Down

0 comments on commit c69ef18

Please sign in to comment.