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

feat!: remove square size from block data #1051

Merged

Conversation

rach-id
Copy link
Member

@rach-id rach-id commented Jul 28, 2023

Description

Closes #1045


PR checklist

  • Tests written/updated
  • Changelog entry added in .changelog (we use
    unclog to manage our changelog)
  • Updated relevant documentation (docs/ or spec/) and code comments

@rach-id rach-id added C:types Component: types breaking labels Jul 28, 2023
@rach-id rach-id self-assigned this Jul 28, 2023
Copy link
Member

@evan-forbes evan-forbes left a comment

Choose a reason for hiding this comment

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

wait, why are we removing the data hash from block data? Isn't this how we are passing the data root from the app back to core?

@rach-id
Copy link
Member Author

rach-id commented Jul 30, 2023

I guess that changed, and we're using this:

// Celestia passes the data root back as the second to last transaction
// and the big endian encoding of the square size as the last transaction.
if len(rpp.Txs) < 2 {
panic("state machine returned an invalid prepare proposal response: expected at least 2 transactions")
}
if len(rpp.Txs[len(rpp.Txs)-2]) != tmhash.Size {
panic(fmt.Sprintf("state machine returned an invalid prepare proposal response: expected second to last transaction to be a hash, got %d bytes", len(rpp.Txs[len(rpp.Txs)-2])))
}
if len(rpp.Txs[len(rpp.Txs)-1]) != 8 {
panic("state machine returned an invalid prepare proposal response: expected last transaction to be a uint64 (square size)")
}

Note: the PR is to main and not to current releases branch

types/block.go Outdated
Comment on lines 1118 to 1119
data.SquareSize = dp.SquareSize
data.hash = dp.Hash
Copy link
Member

Choose a reason for hiding this comment

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

this is what I was referring to @sweexordious

if we don't do this, then when we call data.Hash()

celestia-core/types/block.go

Lines 1025 to 1037 in d02553f

// Hash returns the hash of the data
func (data *Data) Hash() cmtbytes.HexBytes {
if data == nil {
return (Txs{}).Hash()
}
if data.hash == nil {
data.hash = data.Txs.Hash() // NOTE: leaves of merkle tree are TxIDs
}
// this is the expected behavior where `data.hash` was set by celestia-app
// in PrepareProposal
return data.hash
}

we will not use the celestia-app version of the hash

Copy link
Member

Choose a reason for hiding this comment

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

this change is ignoring the hash we're passing back and instead we're using the standard tendermint one which is why the tests pass fine (that's actually the only reason we allow this to occur at all)

Copy link
Member

Choose a reason for hiding this comment

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

it certainly doesn't have to be in this PR, but since this mechanism is so hidden it would probably be a good idea to include a test to ensure that we don't miss this in the future. Currently, those tests are only in the application, but we should be able to modify one of the test applications here to modify the data root

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch 🙏

what do you think about this? f84fa8a

We could either do this, or move those two lines that set the data hash and square size to the DataFromProto method. However, we will also need to change:

block.Data, _ = types.DataFromProto(&cmtproto.Data{
Txs: rpp.Txs[:len(rpp.Txs)-2],
})

to take the whole rpp.Txs slice with the square size and the data hash appended at the end.

What do you think?

Copy link
Member

Choose a reason for hiding this comment

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

we call data.Hash() in other places, therefore we are unable to only set the value in the header

if we change one of the test applications to also modify the header, then we will be able to test this issue

@cmwaters
Copy link
Contributor

Theoretically it is possible to remove the hash field from the data struct so long as the data root can be directly added to the header.

@rach-id
Copy link
Member Author

rach-id commented Jul 31, 2023

Theoretically it is possible to remove the hash field from the data struct so long as the data root can be directly added to the header.

Agreed. But I checked comet and apparently they still have that in the types.Data struct. Also, in this PR I am leaving the square size there because it is being used here:

txs := append(block.Data.Txs.ToSliceOfBytes(), block.DataHash, squareSizeBytes)

state/execution.go Outdated Show resolved Hide resolved
@cmwaters cmwaters force-pushed the remove_hash_and_square_size_from_data branch from e20e0f1 to 8859c76 Compare August 23, 2023 12:59
evan-forbes
evan-forbes previously approved these changes Aug 23, 2023
Copy link
Member

@evan-forbes evan-forbes left a comment

Choose a reason for hiding this comment

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

thanks for fixing 👍

@evan-forbes evan-forbes changed the title feat!: remove square size and data hash from block data feat!: remove square size from block data Aug 23, 2023
cmwaters
cmwaters previously approved these changes Aug 24, 2023
Copy link
Contributor

@cmwaters cmwaters left a comment

Choose a reason for hiding this comment

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

approving my own changes like...

evan-forbes
evan-forbes previously approved these changes Aug 24, 2023
Copy link
Member

@evan-forbes evan-forbes left a comment

Choose a reason for hiding this comment

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

one last hardcoded test I think

TestBlockchainMessageVectors

@cmwaters
Copy link
Contributor

Yup I'm on it

@cmwaters cmwaters dismissed stale reviews from evan-forbes and themself via 6c675e6 August 24, 2023 15:04
@cmwaters cmwaters merged commit 8f3e050 into celestiaorg:main Aug 25, 2023
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking C:types Component: types
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Remove the data hash and square size from Data
3 participants