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!: sync with mainline ABCI #1003

Merged
merged 13 commits into from
Jul 20, 2023
Merged

feat!: sync with mainline ABCI #1003

merged 13 commits into from
Jul 20, 2023

Conversation

cmwaters
Copy link
Contributor

@cmwaters cmwaters commented Apr 26, 2023

Description

This PR modifies the ABCI interface to match that of CometBFT v0.37 and v0.47 of the SDK. There is no utility to extracting out blobs into a separate field within Data.

To get past the problem of the data availabiilty hash and the square size, the last transaction returned by the celestia state machine should always be that square size and the second to last transaction should always be the data hash


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

func EncodeDataRootTuple(height uint64, dataRoot [32]byte, squareSize uint64) ([]byte, error) {
func EncodeDataRootTuple(height uint64, dataRoot []byte) ([]byte, error) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

It seems like this previously relied on the square size but when I follow the link https://github.com/celestiaorg/quantum-gravity-bridge/blob/5edb5906766b63eb6b9c24314df554feb1e83506/src/DataRootTuple.sol#L8 it seems that only the height and data root are used. Is it possible to remove the square size here? cc @sweexordious

Copy link
Member

Choose a reason for hiding this comment

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

there is a PR for that: celestiaorg/blobstream-contracts#145

Copy link
Member

Choose a reason for hiding this comment

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

Opened this to maybe remove the square size:
celestiaorg/blobstream-contracts#154

Copy link
Member

Choose a reason for hiding this comment

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

@cmwaters square size can be removed. Do you want to do it in this PR? or I open a subsequent PR to remove it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's great. Let's do it in a subsequent PR

Copy link
Member

Choose a reason for hiding this comment

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

@cmwaters cmwaters marked this pull request as draft April 27, 2023 08:13
@cmwaters cmwaters self-assigned this Apr 27, 2023
@cmwaters
Copy link
Contributor Author

Converting this as a draft for now. It seems my original assumption that the SquareSize was no longer needed in the consensus node is wrong - we still need it as part of the QGB setup. Will need to think a little more about the design here

Copy link
Collaborator

@rootulp rootulp left a comment

Choose a reason for hiding this comment

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

No blocking feedback, overall I'm a fan of this!

abci/types/result.go Outdated Show resolved Hide resolved
abci/types/result.go Outdated Show resolved Hide resolved
state/execution.go Outdated Show resolved Hide resolved
@cmwaters cmwaters marked this pull request as ready for review June 15, 2023 08:33
@cmwaters
Copy link
Contributor Author

Opening this PR back for review again. This is for after mainnet just to be clear. I think we might even want to create a new branch v0.37.x-celestia and merge this into that (or use main)

@rootulp
Copy link
Collaborator

rootulp commented Jun 15, 2023

This is for after mainnet just to be clear.

Does anyone have permission to create a new milestone in this repo? It could benefit from a Post-mainnet milestone (similar to celestia-app).

Screenshot 2023-06-15 at 11 58 34 AM

@@ -98,11 +101,18 @@ func (BaseApplication) ApplySnapshotChunk(req RequestApplySnapshotChunk) Respons
}

func (BaseApplication) PrepareProposal(req RequestPrepareProposal) ResponsePrepareProposal {
return ResponsePrepareProposal{BlockData: req.BlockData}
squareSize := len(req.Txs)
Copy link
Collaborator

Choose a reason for hiding this comment

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

[question] why is the squareSize set to the number of transactions? I think of these as two distinct values. For example, a block with 100 send transactions could have a square size of 4.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah this is a good point. So I've made the decision here that I want celestia-core to be specific to celestia-app. Concretely, we extend the rules around PrepareProposal and ProcessProposal that there must always be two transactions returned and the last and second to last are the squareSize and dataHash respectively. It's obviously somewhat hacky but means we keep within the boundaries of ABCI and are able to use the SDK without requiring a fork.

If the rule isn't followed, consensus panics. I could have chosen to simply ignore the rules when an application sends back 0 txs (thus supporting all the test applications in Tendermint) but I felt better to actually enforce the rule thus I had to modify all the test applications including the BaseApplication.

The square size and hash here are placeholders. I could use the value 0 (which is invalid in the case of Celestia) instead. This should not be used outside of testing

Copy link
Collaborator

Choose a reason for hiding this comment

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

[optional] Thanks for clarifying that they are placeholders. If they are expected to be overwritten by celestia-app, then proposal to do something like:

func (BaseApplication) PrepareProposal(req RequestPrepareProposal) ResponsePrepareProposal {
	placeholderDataHash := tmhash.Sum(nil)
	placeholderSquareSizeBytes := make([]byte, 8)
	binary.BigEndian.PutUint64(placeholderSquareSizeBytes, uint64(1))

	// placeholderDataHash and placeholderSquareSizeBytes are expected to be
	// overwritten by celestia-app.
	req.Txs = append(req.Txs, placeholderDataHash, placeholderSquareSizeBytes)
	return ResponsePrepareProposal{Txs: req.Txs}
}

abci/types/application.go Show resolved Hide resolved
abci/types/result.go Outdated Show resolved Hide resolved
@@ -254,5 +254,13 @@ func (app *CounterApplication) Commit() abci.ResponseCommit {

func (app *CounterApplication) PrepareProposal(
req abci.RequestPrepareProposal) abci.ResponsePrepareProposal {
return abci.ResponsePrepareProposal{BlockData: req.BlockData}
dataHash := types.ToTxs(req.Txs).Hash()
squareSize := len(req.Txs)
Copy link
Collaborator

Choose a reason for hiding this comment

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

same question regarding the relationship between squareSize and req.Txs

Copy link
Collaborator

Choose a reason for hiding this comment

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

[nit] can these placeholders look identical to PrepareProposal in abci/types/application.go

tendermint.types.Data block_data = 1;
// If an application decides to populate block_data with extra information, they can not exceed this value.
int64 block_data_size = 2;
repeated bytes txs = 2;
Copy link
Collaborator

Choose a reason for hiding this comment

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

[question] can the protobuf field 2 be reused? Is it a breaking change if it is reused? Asking b/c prior to this PR field 2 was a in64 for block_data_size

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes this is an important detail. AFAIK we can't simply reserve those numbers and slide all the field numbers down if we want to have compatibility with the mainline version (in this case the SDK would not be able to decode the ABCI request that celestia-core would send). Thus we need to break ABCI. I've thought about this a bit and I don't think breaking ABCI will affect the backwards compatibility promises we make of our state machine. PrepareProposal and ProcessProposal (and all the other methods should work the same for v1 and v2)

proto/tendermint/abci/types.proto Outdated Show resolved Hide resolved
state/execution.go Outdated Show resolved Hide resolved
state/execution.go Outdated Show resolved Hide resolved
Comment on lines +485 to +488
/*
TODO: Include vote extensions information when implementing vote extensions.
VoteExtension: []byte{},
*/
Copy link
Collaborator

Choose a reason for hiding this comment

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

[uber nit] I think it's convention to use // for this type of comment

Go provides C-style /* */ block comments and C++-style // line comments. Line comments are the norm; block comments appear mostly as package comments, but are useful within an expression or to disable large swaths of code.

Source: https://go.dev/doc/effective_go

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is just copied from cometbft/cometbft but I don't mind changing it to //

Copy link
Collaborator

Choose a reason for hiding this comment

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

Oh no worries, we can preserve /* style comments if that's what is upstream.

@cmwaters cmwaters added this to the Post-mainnet milestone Jun 16, 2023
rootulp
rootulp previously approved these changes Jun 16, 2023
@@ -98,11 +101,18 @@ func (BaseApplication) ApplySnapshotChunk(req RequestApplySnapshotChunk) Respons
}

func (BaseApplication) PrepareProposal(req RequestPrepareProposal) ResponsePrepareProposal {
return ResponsePrepareProposal{BlockData: req.BlockData}
squareSize := len(req.Txs)
Copy link
Collaborator

Choose a reason for hiding this comment

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

[optional] Thanks for clarifying that they are placeholders. If they are expected to be overwritten by celestia-app, then proposal to do something like:

func (BaseApplication) PrepareProposal(req RequestPrepareProposal) ResponsePrepareProposal {
	placeholderDataHash := tmhash.Sum(nil)
	placeholderSquareSizeBytes := make([]byte, 8)
	binary.BigEndian.PutUint64(placeholderSquareSizeBytes, uint64(1))

	// placeholderDataHash and placeholderSquareSizeBytes are expected to be
	// overwritten by celestia-app.
	req.Txs = append(req.Txs, placeholderDataHash, placeholderSquareSizeBytes)
	return ResponsePrepareProposal{Txs: req.Txs}
}

@@ -254,5 +254,13 @@ func (app *CounterApplication) Commit() abci.ResponseCommit {

func (app *CounterApplication) PrepareProposal(
req abci.RequestPrepareProposal) abci.ResponsePrepareProposal {
return abci.ResponsePrepareProposal{BlockData: req.BlockData}
dataHash := types.ToTxs(req.Txs).Hash()
squareSize := len(req.Txs)
Copy link
Collaborator

Choose a reason for hiding this comment

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

[nit] can these placeholders look identical to PrepareProposal in abci/types/application.go

test/e2e/app/app.go Outdated Show resolved Hide resolved
@cmwaters cmwaters changed the base branch from v0.34.x-celestia to main June 21, 2023 12:51
Copy link
Collaborator

@rootulp rootulp left a comment

Choose a reason for hiding this comment

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

Overall LGTM w/ one blocking comment

README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
abci/types/application.go Outdated Show resolved Hide resolved
Copy link
Member

@rach-id rach-id left a comment

Choose a reason for hiding this comment

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

Concerning the PR description:

`SquareSize` is also no longer needed...

It is still needed for QGB. I guess the description needs to be updated

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.

do we also need to change the data root to use the second to last hash?

celestia-core/types/block.go

Lines 1025 to 1037 in c3ab251

// 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
}

otherwise LGTM, should be nice

Comment on lines -393 to +421
enum EvidenceType {
message ExtendedVoteInfo {
Validator validator = 1 [(gogoproto.nullable) = false];
bool signed_last_block = 2;
bytes vote_extension = 3; // Reserved for future use
}
Copy link
Member

Choose a reason for hiding this comment

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

is_this_vote_extensions

@cmwaters
Copy link
Contributor Author

It is still needed for QGB. I guess the description needs to be updated

Yes square size is still present. I will update the description

@cmwaters
Copy link
Contributor Author

do we also need to change the data root to use the second to last hash?

No because the txs in the data struct don't actually contain the hash. The hash (as well as the square size) remains part of the Data struct so the txs in their are simply the transactions to be committed.

The "hack" with the two extra transactions is purely across the ABCI layer

@cmwaters cmwaters merged commit 2c6cde4 into main Jul 20, 2023
33 checks passed
@cmwaters cmwaters deleted the cal/abci branch July 20, 2023 10:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants