Skip to content

Commit

Permalink
Don't include selectedParentHash in block verbose data if it's nil + …
Browse files Browse the repository at this point in the history
…Fix test vectors in rpc-stability (#1668)

* Fix submitBlockRequest in rpc-stability/commands.json

* Don't include selectedParentHash in block verbose data if it's nil (a.k.a. genesis)
  • Loading branch information
svarogg authored Apr 8, 2021
1 parent 347dd8f commit 9bb8123
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
20 changes: 12 additions & 8 deletions app/rpc/rpccontext/verbosedata.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package rpccontext

import (
"encoding/hex"
difficultyPackage "github.com/kaspanet/kaspad/util/difficulty"
"github.com/pkg/errors"
"math"
"math/big"

difficultyPackage "github.com/kaspanet/kaspad/util/difficulty"
"github.com/pkg/errors"

"github.com/kaspanet/kaspad/domain/consensus/utils/hashes"

"github.com/kaspanet/kaspad/domain/consensus/utils/estimatedsize"
Expand Down Expand Up @@ -62,12 +63,15 @@ func (ctx *Context) PopulateBlockWithVerboseData(block *appmessage.RPCBlock, dom
}

block.VerboseData = &appmessage.RPCBlockVerboseData{
Hash: blockHash.String(),
Difficulty: ctx.GetDifficultyRatio(domainBlockHeader.Bits(), ctx.Config.ActiveNetParams),
ChildrenHashes: hashes.ToStrings(childrenHashes),
SelectedParentHash: selectedParentHash.String(),
IsHeaderOnly: blockInfo.BlockStatus == externalapi.StatusHeaderOnly,
BlueScore: blockInfo.BlueScore,
Hash: blockHash.String(),
Difficulty: ctx.GetDifficultyRatio(domainBlockHeader.Bits(), ctx.Config.ActiveNetParams),
ChildrenHashes: hashes.ToStrings(childrenHashes),
IsHeaderOnly: blockInfo.BlockStatus == externalapi.StatusHeaderOnly,
BlueScore: blockInfo.BlueScore,
}
// selectedParentHash will be nil in the genesis block
if selectedParentHash != nil {
block.VerboseData.SelectedParentHash = selectedParentHash.String()
}

if blockInfo.BlockStatus == externalapi.StatusHeaderOnly {
Expand Down
2 changes: 1 addition & 1 deletion stability-tests/rpc-stability/run/commands.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{"getBlockDagInfoRequest": {}}
{"getBlockRequest": {"hash": "0000691a26e1cd33ed9d0587d774181726f4e38eecd722a858d3baaa1fd19250"}}
{"getBlockRequest": {"hash": "666661a26e1cd33ed9d0587d774181726f4e38eecd722a858d3baaa1fd19250"}}
{"submitBlockRequest": {"block": {"header":{"version":1,"parentHashes":[],"hashMerkleRoot":{"bytes":"0000000000000000000000000000000000000000000"},"acceptedIdMerkleRoot":{"bytes":"0000000000000000000000000000000000000000000"},"utxoCommitment":{"bytes":"0000000000000000000000000000000000000000000"},"timestamp":1593528309396,"bits":511705087,"nonce":282366},"transactions":[{"version":1,"inputs":[],"outputs":[],"lockTime":0,"subnetworkId":{"bytes":"100000000000000000000000000"},"gas":0,"payload":"AAAAAAAAAAAXqRTaF0XptUm9C/oaVplxx366MM1aS4drYXNwYS1kZXZuZXQ="}]}}}
{"submitBlockRequest": {"block": {"header":{"version":1,"parentHashes":[],"hashMerkleRoot":"0000000000000000000000000000000000000000000","acceptedIdMerkleRoot":"0000000000000000000000000000000000000000000","utxoCommitment": "0000000000000000000000000000000000000000000","timestamp":1593528309396,"bits":511705087,"nonce":282366},"transactions":[{"version":1,"inputs":[],"outputs":[],"lockTime":0,"subnetworkId":"100000000000000000000000000","gas":0,"payload":"AAAAAAAAAAAXqRTaF0XptUm9C/oaVplxx366MM1aS4drYXNwYS1kZXZuZXQ="}]}}}
{"submitTransactionRequest": {"transaction": {"version":1,"inputs":[],"outputs":[],"lockTime":0,"subnetworkId":"100000000000000000000000000","gas":0,"payload":"AAAAAAAAAAAXqRTaF0XptUm9C/oaVplxx366MM1aS4drYXNwYS1kZXZuZXQ="}}}

0 comments on commit 9bb8123

Please sign in to comment.