Skip to content

Commit

Permalink
rpc: add PoWHash to getblockverbose result
Browse files Browse the repository at this point in the history
  • Loading branch information
chappjc committed Jul 18, 2023
1 parent 216132d commit 0f02b24
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
11 changes: 11 additions & 0 deletions internal/rpcserver/rpcserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -1969,8 +1969,19 @@ func handleGetBlock(_ context.Context, s *Server, cmd interface{}) (interface{},
return nil, rpcInternalError(err.Error(), "Unable to retrieve median block time")
}

isBlake3PowActive, err := s.isBlake3PowAgendaActive(&blockHeader.PrevBlock)
if err != nil {
return nil, err
}
powHashFn := blockHeader.PowHashV1
if isBlake3PowActive {
powHashFn = blockHeader.PowHashV2
}
powHash := powHashFn()

blockReply := types.GetBlockVerboseResult{
Hash: c.Hash,
PoWHash: powHash.String(),
Version: blockHeader.Version,
MerkleRoot: blockHeader.MerkleRoot.String(),
StakeRoot: blockHeader.StakeRoot.String(),
Expand Down
4 changes: 4 additions & 0 deletions internal/rpcserver/rpcserverhandlers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3763,6 +3763,8 @@ func TestHandleGetBlock(t *testing.T) {
blk := dcrutil.NewBlock(&block432100)
blkHash := blk.Hash()
blkHashString := blkHash.String()
powHash := blkHeader.PowHashV1() // pre-DCP0011 activation
powHashString := powHash.String()
blkBytes, err := blk.Bytes()
if err != nil {
t.Fatalf("error serializing block: %+v", err)
Expand Down Expand Up @@ -3827,6 +3829,7 @@ func TestHandleGetBlock(t *testing.T) {
}(),
result: types.GetBlockVerboseResult{
Hash: blkHashString,
PoWHash: powHashString,
Version: blkHeader.Version,
MerkleRoot: blkHeader.MerkleRoot.String(),
StakeRoot: blkHeader.StakeRoot.String(),
Expand Down Expand Up @@ -3882,6 +3885,7 @@ func TestHandleGetBlock(t *testing.T) {
}(),
result: types.GetBlockVerboseResult{
Hash: blkHashString,
PoWHash: powHashString,
Version: blkHeader.Version,
MerkleRoot: blkHeader.MerkleRoot.String(),
StakeRoot: blkHeader.StakeRoot.String(),
Expand Down
1 change: 1 addition & 0 deletions rpc/jsonrpc/types/chainsvrresults.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ type GetAddedNodeInfoResult struct {
// hex-encoded string. Contains Decred additions.
type GetBlockVerboseResult struct {
Hash string `json:"hash"`
PoWHash string `json:"powhash"`
Confirmations int64 `json:"confirmations"`
Size int32 `json:"size"`
Height int64 `json:"height"`
Expand Down

0 comments on commit 0f02b24

Please sign in to comment.