Skip to content
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

Update core data types #17

Merged
merged 5 commits into from
Apr 18, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 65 additions & 7 deletions types/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,34 @@ const (
MaxAminoOverheadForBlock int64 = 11
)

// DataAvailabilityHeader contains the row and column roots of the erasure
// coded version of the data in Block.Data.
// Therefor the original Block.Data is arranged in a
// k × k matrix, which is then "extended" to a
// 2k × 2k matrix applying multiple times Reed-Solomon encoding.
// For details see Section 5.2: https://arxiv.org/abs/1809.09044
type DataAvailabilityHeader struct {
// RowRoot_j = root((M_{j,1} || M_{j,2} || ... || M_{j,2k} ))
RowsRoots [][]byte
// ColumnRoot_j = root((M_{1,j} || M_{2,j} || ... || M_{2k,j} ))
ColumnRoots [][]byte
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there's not a type for hash digests then we should add one. Is there is then []byte can be replaced with it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is none. At least a type alias would be good! Will add in a followup PR!

}

// Hash computes the root of the row and column roots
// TODO: feed this into Header.DataHash.
func (dah *DataAvailabilityHeader) Hash() {
panic("TODO: implement")
}

// Block defines the atomic unit of a Tendermint blockchain.
type Block struct {
mtx sync.Mutex
Header `json:"header"`
Data `json:"data"`
Evidence EvidenceData `json:"evidence"`
LastCommit *Commit `json:"last_commit"`
mtx sync.Mutex

Header `json:"header"`
Data `json:"data"`
DataAvailabilityHeader DataAvailabilityHeader
liamsi marked this conversation as resolved.
Show resolved Hide resolved
Evidence EvidenceData `json:"evidence"`
LastCommit *Commit `json:"last_commit"`
}

// ValidateBasic performs basic validation that doesn't involve state data.
Expand Down Expand Up @@ -332,7 +353,9 @@ type Header struct {

// hashes of block data
LastCommitHash tmbytes.HexBytes `json:"last_commit_hash"` // commit from validators from the last block
DataHash tmbytes.HexBytes `json:"data_hash"` // transactions
// DataHash = root((rowRoot_1 || rowRoot_2 || ... ||rowRoot_2k || columnRoot1 || columnRoot2 || ... || columnRoot2k))
// Block.DataAvailabilityHeader for stores (row|column)Root_i // TODO ...
DataHash tmbytes.HexBytes `json:"data_hash"` // transactions

// hashes from the app output from the prev block
ValidatorsHash tmbytes.HexBytes `json:"validators_hash"` // validators for the current block
Expand Down Expand Up @@ -806,18 +829,53 @@ func (sh SignedHeader) StringIndented(indent string) string {

//-----------------------------------------------------------------------------

// Data contains the set of transactions included in the block
// Data contains the data that will be erasure coded and is guaranteed to be available
// via the data availability scheme.
//
// TODO: update Data.Hash() to data availability root
// and clarify this here too.
//
// Data consists of:
// - the set of transactions included in the block
// - intermediate state roots computed from the Tx of the previous block
// - Evidence included in the block
// - LazyLedger (namespaced) messages included in the block
type Data struct {

// Txs that will be applied by state @ block.Height+1.
// NOTE: not all txs here are valid. We're just agreeing on the order first.
// This means that block.AppHash does not include these txs.
Txs Txs `json:"txs"`

// Intermediate state roots of the Txs included in block.Height
// and executed by state state @ block.Height+1.
//
// TODO: replace with a dedicated type `IntermediateStateRoot`
// as soon as we settle on the format / sparse Merkle tree etc
IntermediateStateRoots []tmbytes.HexBytes
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you wonder about tmbytes.HexBytes: just think of it as []byte (it's just for encoding really).


// The messages included in this block.
// TODO: clarify the relation between Txs and Messages and
// define a mechanism to split up both (maybe via CheckTx)
Messages []Message

// Volatile
hash tmbytes.HexBytes
}

type Message struct {
// NamespaceID defines the namespace of this message, i.e. the
// namespace it will use in the namespaced Merkle tree.
//
// TODO: spec out constrains and
// introduce dedicated type instead of just []byte
NamespaceID []byte

// Data is the actual data contained in the message
// (e.g. a block of an optimistic rollup sidechain).
liamsi marked this conversation as resolved.
Show resolved Hide resolved
Data []byte
}

// Hash returns the hash of the data
func (data *Data) Hash() tmbytes.HexBytes {
if data == nil {
Expand Down