Skip to content

Commit a5ceabd

Browse files
committed
add current difficulty to /consensus response
Fixes NebulousLabs#1396
1 parent 6a9988f commit a5ceabd

File tree

4 files changed

+13
-6
lines changed

4 files changed

+13
-6
lines changed

api/consensus.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ type ConsensusGET struct {
1616
Height types.BlockHeight `json:"height"`
1717
CurrentBlock types.BlockID `json:"currentblock"`
1818
Target types.Target `json:"target"`
19+
Difficulty types.Currency `json:"difficulty"`
1920
}
2021

2122
// consensusHandler handles the API calls to /consensus.
@@ -27,6 +28,7 @@ func (api *API) consensusHandler(w http.ResponseWriter, req *http.Request, _ htt
2728
Height: api.cs.Height(),
2829
CurrentBlock: cbid,
2930
Target: currentTarget,
31+
Difficulty: currentTarget.Difficulty(),
3032
})
3133
}
3234

doc/API.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,8 @@ returns information about the consensus set, such as the current block height.
173173
"synced": true,
174174
"height": 62248,
175175
"currentblock": "00000000000008a84884ba827bdc868a17ba9c14011de33ff763bd95779a9cf1",
176-
"target": [0,0,0,0,0,0,11,48,125,79,116,89,136,74,42,27,5,14,10,31,23,53,226,238,202,219,5,204,38,32,59,165]
176+
"target": [0,0,0,0,0,0,11,48,125,79,116,89,136,74,42,27,5,14,10,31,23,53,226,238,202,219,5,204,38,32,59,165],
177+
"difficulty": "1234"
177178
}
178179
```
179180

doc/api/Consensus.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,10 @@ returns information about the consensus set, such as the current block height.
4343

4444
// An immediate child block of this block must have a hash less than this
4545
// target for it to be valid.
46-
"target": [0,0,0,0,0,0,11,48,125,79,116,89,136,74,42,27,5,14,10,31,23,53,226,238,202,219,5,204,38,32,59,165]
46+
"target": [0,0,0,0,0,0,11,48,125,79,116,89,136,74,42,27,5,14,10,31,23,53,226,238,202,219,5,204,38,32,59,165],
47+
48+
// The difficulty of the current block target.
49+
"difficulty": "1234" // arbitrary-precision integer
4750
}
4851
```
4952

siac/consensuscmd.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,11 @@ func consensuscmd() {
2929
}
3030
if cg.Synced {
3131
fmt.Printf(`Synced: %v
32-
Block: %v
33-
Height: %v
34-
Target: %v
35-
`, yesNo(cg.Synced), cg.CurrentBlock, cg.Height, cg.Target)
32+
Block: %v
33+
Height: %v
34+
Target: %v
35+
Difficulty: %v
36+
`, yesNo(cg.Synced), cg.CurrentBlock, cg.Height, cg.Target, cg.Difficulty)
3637
} else {
3738
estimatedHeight := estimatedHeightAt(time.Now())
3839
estimatedProgress := float64(cg.Height) / float64(estimatedHeight) * 100

0 commit comments

Comments
 (0)