Skip to content

Commit

Permalink
rename testBlockHeader' into newBlockHeader
Browse files Browse the repository at this point in the history
  • Loading branch information
larskuhtz committed Apr 3, 2019
1 parent 02fb07b commit 1cfe35e
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 21 deletions.
43 changes: 24 additions & 19 deletions src/Chainweb/BlockHeader.hs
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,11 @@ module Chainweb.BlockHeader
-- * Genesis BlockHeader
, isGenesisBlockHeader

-- * Create a new BlockHeader
, newBlockHeader

-- * Testing
, testBlockHeader
, testBlockHeader'
, testBlockHeaders
, testBlockHeadersWithNonce
, testBlockPayload
Expand Down Expand Up @@ -678,23 +680,9 @@ hashPayload v cid b = BlockPayloadHash $ MerkleLogHash
]

-- -------------------------------------------------------------------------- --
-- TreeDBEntry instance
-- Create new BlockHeader

instance TreeDbEntry BlockHeader where
type Key BlockHeader = BlockHash
key = _blockHash
rank = int . _blockHeight
parent e
| isGenesisBlockHeader e = Nothing
| otherwise = Just (_blockParent e)

-- -------------------------------------------------------------------------- --
-- Testing

testBlockPayload :: BlockHeader -> BlockPayloadHash
testBlockPayload b = hashPayload (_blockChainwebVersion b) b "TEST PAYLOAD"

testBlockHeader'
newBlockHeader
:: ChainNodeId
-- ^ Miner
-> BlockHashRecord
Expand All @@ -710,7 +698,7 @@ testBlockHeader'
-> BlockHeader
-- ^ parent block header
-> BlockHeader
testBlockHeader' miner adj pay nonce target t b = fromLog $ newMerkleLog
newBlockHeader miner adj pay nonce target t b = fromLog $ newMerkleLog
$ nonce
:+: BlockCreationTime t
:+: _blockHash b
Expand All @@ -726,6 +714,23 @@ testBlockHeader' miner adj pay nonce target t b = fromLog $ newMerkleLog
cid = _chainId b
v = _blockChainwebVersion b

-- -------------------------------------------------------------------------- --
-- TreeDBEntry instance

instance TreeDbEntry BlockHeader where
type Key BlockHeader = BlockHash
key = _blockHash
rank = int . _blockHeight
parent e
| isGenesisBlockHeader e = Nothing
| otherwise = Just (_blockParent e)

-- -------------------------------------------------------------------------- --
-- Testing

testBlockPayload :: BlockHeader -> BlockPayloadHash
testBlockPayload b = hashPayload (_blockChainwebVersion b) b "TEST PAYLOAD"

testBlockHeader
:: ChainNodeId
-- ^ Miner
Expand All @@ -739,7 +744,7 @@ testBlockHeader
-- ^ parent block header
-> BlockHeader
testBlockHeader miner adj nonce target b
= testBlockHeader' miner adj (testBlockPayload b) nonce target (add second t) b
= newBlockHeader miner adj (testBlockPayload b) nonce target (add second t) b
where
BlockCreationTime t = _blockCreationTime b

Expand Down
2 changes: 1 addition & 1 deletion src/Chainweb/Cut/Test.hs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ createNewCut n target t pay nid i c = do
p = c ^?! ixg cid

newHeader :: BlockHashRecord -> BlockHeader
newHeader as = testBlockHeader' (nodeIdFromNodeId nid cid) as pay n target t p
newHeader as = newBlockHeader (nodeIdFromNodeId nid cid) as pay n target t p

-- | Try to get all adjacent hashes dependencies.
--
Expand Down
2 changes: 1 addition & 1 deletion src/Chainweb/Miner/POW.hs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ mineCut logfun conf nid cutDb !c !nonce !adjustments = do

-- Assemble block without Nonce and Timestamp
--
let candidateHeader = testBlockHeader'
let candidateHeader = newBlockHeader
(nodeIdFromNodeId nid cid)
adjParents
(_payloadWithOutputsPayloadHash payload)
Expand Down

0 comments on commit 1cfe35e

Please sign in to comment.