-
Notifications
You must be signed in to change notification settings - Fork 95
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
miscelaneous small changes #2087
Merged
Changes from 6 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
cc4cad9
more type level utils and JsonTextRepresentation wrapper
larskuhtz 9372b85
add encodeB64UrlNoPadding
larskuhtz c0e3a7b
add HasTextRepresentation instance for Natural
larskuhtz d23f971
add IdxGet instance for ChainMap
larskuhtz 74125bf
Move BlockPayloadHash into separate module
larskuhtz bdd6446
add Chainweb.Ranked
larskuhtz d1e8b64
add Chainweb.MinerReward module
larskuhtz dd779c8
Apply suggestions from code review
larskuhtz 30e020a
Merge pull request #2088 from kadena-io/lars/miner-rewards
larskuhtz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
{-# LANGUAGE DataKinds #-} | ||
{-# LANGUAGE DeriveAnyClass #-} | ||
{-# LANGUAGE DeriveGeneric #-} | ||
{-# LANGUAGE DerivingStrategies #-} | ||
{-# LANGUAGE FlexibleInstances #-} | ||
{-# LANGUAGE GeneralizedNewtypeDeriving #-} | ||
{-# LANGUAGE MultiParamTypeClasses #-} | ||
{-# LANGUAGE TypeFamilies #-} | ||
{-# LANGUAGE PatternSynonyms #-} | ||
{-# LANGUAGE ImportQualifiedPost #-} | ||
|
||
-- | | ||
-- Module: Chainweb.BlockPayloadHash | ||
-- Copyright: Copyright © 2024 Kadena LLC. | ||
-- License: MIT | ||
-- Maintainer: Lars Kuhtz <[email protected]> | ||
-- Stability: experimental | ||
-- | ||
module Chainweb.BlockPayloadHash | ||
( BlockPayloadHash | ||
, BlockPayloadHash_(..) | ||
, encodeBlockPayloadHash | ||
, decodeBlockPayloadHash | ||
, nullBlockPayloadHash | ||
|
||
-- * Ranked Block Payload Hash | ||
, type RankedBlockPayloadHash | ||
, pattern RankedBlockPayloadHash | ||
, _rankedBlockPayloadHashHash | ||
, _rankedBlockPayloadHashHeight | ||
, encodeRankedBlockPayloadHash | ||
, decodeRankedBlockPayloadHash | ||
) where | ||
|
||
import Control.DeepSeq | ||
import Control.Monad | ||
|
||
import Data.Aeson | ||
import Data.ByteArray qualified as BA | ||
import Data.Hashable | ||
|
||
import GHC.Generics (Generic) | ||
|
||
-- internal modules | ||
|
||
import Chainweb.BlockHeight | ||
import Chainweb.Crypto.MerkleLog | ||
import Chainweb.MerkleLogHash | ||
import Chainweb.MerkleUniverse | ||
import Chainweb.Ranked | ||
import Chainweb.Utils | ||
import Chainweb.Utils.Serialization | ||
|
||
-- -------------------------------------------------------------------------- -- | ||
-- BlockPayloadHash | ||
|
||
-- | The Merkle root of a block payload evaluation | ||
-- | ||
-- NOTE: for historic reasons this is called `BlockPayloadHash`. A more accurate | ||
-- name would be `PayloadEvaluationHash`. | ||
-- | ||
-- This is computed by payload provider of the respective block payload. It is | ||
-- treated by Chainweb consensus as the root of a Chainweb Merkle (sub-) tree. | ||
-- It is the responsibility of the payload provider that this interpretation is | ||
-- cryptographically sound. | ||
-- | ||
-- Semantically, the hash must completely authenticate the block payload and | ||
-- payload evaluation results, including all updates to the internal state of | ||
-- the payload provider (but not complete state itself). | ||
-- | ||
-- It is not required to authenticate the complete internal state of the payload | ||
-- provider. (Although it is strongly recommended that payload providers support | ||
-- this by including a state root into the payload Merkle tree. Pact currently | ||
-- does not support this.) | ||
-- | ||
-- Beside of unambiguously authenticating the evaluation of the payload, it is | ||
-- up to the respective payload provider to decide what cryptographic protocol | ||
-- is used to compute this value and what can be proven about the payload. | ||
-- | ||
-- Binary format: 32 bytes. | ||
-- | ||
type BlockPayloadHash = BlockPayloadHash_ ChainwebMerkleHashAlgorithm | ||
|
||
newtype BlockPayloadHash_ a = BlockPayloadHash (MerkleLogHash a) | ||
deriving (Show, Eq, Ord, Generic) | ||
deriving anyclass (NFData) | ||
deriving newtype (BA.ByteArrayAccess) | ||
deriving newtype (Hashable, ToJSON, FromJSON) | ||
deriving newtype (ToJSONKey, FromJSONKey) | ||
|
||
encodeBlockPayloadHash :: BlockPayloadHash_ a -> Put | ||
encodeBlockPayloadHash (BlockPayloadHash w) = encodeMerkleLogHash w | ||
|
||
decodeBlockPayloadHash | ||
:: MerkleHashAlgorithm a | ||
=> Get (BlockPayloadHash_ a) | ||
decodeBlockPayloadHash = BlockPayloadHash <$!> decodeMerkleLogHash | ||
|
||
instance MerkleHashAlgorithm a => IsMerkleLogEntry a ChainwebHashTag (BlockPayloadHash_ a) where | ||
type Tag (BlockPayloadHash_ a) = 'BlockPayloadHashTag | ||
toMerkleNode = encodeMerkleTreeNode | ||
fromMerkleNode = decodeMerkleTreeNode | ||
{-# INLINE toMerkleNode #-} | ||
{-# INLINE fromMerkleNode #-} | ||
|
||
instance HasTextRepresentation BlockPayloadHash where | ||
toText (BlockPayloadHash h) = toText h | ||
fromText = fmap BlockPayloadHash . fromText | ||
{-# INLINE toText #-} | ||
{-# INLINE fromText #-} | ||
|
||
nullBlockPayloadHash :: MerkleHashAlgorithm a => BlockPayloadHash_ a | ||
nullBlockPayloadHash = BlockPayloadHash nullHashBytes | ||
{-# INLINE nullBlockPayloadHash #-} | ||
|
||
-- -------------------------------------------------------------------------- -- | ||
-- Ranked Block Payload Hash | ||
|
||
type RankedBlockPayloadHash = Ranked BlockPayloadHash | ||
|
||
pattern RankedBlockPayloadHash | ||
:: BlockHeight | ||
-> BlockPayloadHash | ||
-> RankedBlockPayloadHash | ||
pattern RankedBlockPayloadHash | ||
{ _rankedBlockPayloadHashHeight | ||
, _rankedBlockPayloadHashHash | ||
} | ||
= Ranked _rankedBlockPayloadHashHeight _rankedBlockPayloadHashHash | ||
{-# COMPLETE RankedBlockPayloadHash #-} | ||
|
||
encodeRankedBlockPayloadHash :: RankedBlockPayloadHash -> Put | ||
encodeRankedBlockPayloadHash = encodeRanked encodeBlockPayloadHash | ||
|
||
decodeRankedBlockPayloadHash :: Get RankedBlockPayloadHash | ||
decodeRankedBlockPayloadHash = decodeRanked decodeBlockPayloadHash | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we still need
RankedBlockHeader
with theRanked
newtype? I suppose if we make it wrap aRanked BlockHeader
, that will waste some memory by duplicating the height.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, that's the reasoning for not using
Ranked
withBlockHeader
.