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

fix: setting data root in CreateProposalBlock #1271

Merged
merged 12 commits into from
Apr 23, 2024
4 changes: 2 additions & 2 deletions abci/types/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package types
import (
"context"

"github.com/cometbft/cometbft/crypto/tmhash"
"github.com/cometbft/cometbft/crypto/merkle"
)

// Application is an interface that enables any finite, deterministic state machine
Expand Down Expand Up @@ -96,7 +96,7 @@ func (BaseApplication) ApplySnapshotChunk(req RequestApplySnapshotChunk) Respons

func (BaseApplication) PrepareProposal(req RequestPrepareProposal) ResponsePrepareProposal {
// we use placeholder values for the hash
rootulp marked this conversation as resolved.
Show resolved Hide resolved
req.Txs = append(req.Txs, tmhash.Sum(nil))
req.Txs = append(req.Txs, merkle.HashFromByteSlices(req.Txs))
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 what was causing the test to fail. We were using idential hashes so the blockID.Hash was the same but blockID.PartSetHeader was different

return ResponsePrepareProposal{Txs: req.Txs}
}

Expand Down
2 changes: 1 addition & 1 deletion blockchain/msgs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func TestBlockchainMessageVectors(t *testing.T) {
BlockRequest: &bcproto.BlockRequest{Height: math.MaxInt64}}},
"0a0a08ffffffffffffffff7f"},
{"BlockResponseMessage", &bcproto.Message{Sum: &bcproto.Message_BlockResponse{
BlockResponse: &bcproto.BlockResponse{Block: bpb}}}, "1a93010a90010a5b0a02080b1803220b088092b8c398feffffff012a0212003a20c4da88e876062aa1543400d50d0eaa0dac88096057949cfb7bca7f3a48c04bf96a20e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855122f0a0b48656c6c6f20576f726c643220c4da88e876062aa1543400d50d0eaa0dac88096057949cfb7bca7f3a48c04bf91a00"},
BlockResponse: &bcproto.BlockResponse{Block: bpb}}}, "1a700a6e0a5b0a02080b1803220b088092b8c398feffffff012a0212003a20c4da88e876062aa1543400d50d0eaa0dac88096057949cfb7bca7f3a48c04bf96a20e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855120d0a0b48656c6c6f20576f726c641a00"},
{"NoBlockResponseMessage", &bcproto.Message{Sum: &bcproto.Message_NoBlockResponse{
NoBlockResponse: &bcproto.NoBlockResponse{Height: 1}}}, "12020801"},
{"NoBlockResponseMessage", &bcproto.Message{Sum: &bcproto.Message_NoBlockResponse{
Expand Down
4 changes: 2 additions & 2 deletions consensus/byzantine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -464,9 +464,9 @@ func TestByzantineConflictingProposalsWithPartition(t *testing.T) {
select {
case <-done:
case <-tick.C:
for i, reactor := range reactors {
for i := range reactors {
t.Logf(fmt.Sprintf("Consensus Reactor %v", i))
t.Logf(fmt.Sprintf("%v", reactor))
t.Logf(fmt.Sprintf("round state: %v", css[i].GetRoundState()))
}
t.Fatalf("Timed out waiting for all validators to commit first block")
}
Expand Down
1 change: 0 additions & 1 deletion pkg/trace/schema/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@ func WriteBlockSummary(client trace.Tracer, block *types.Block, size int) {
Height: block.Height,
UnixMillisecondTimestamp: block.Time.UnixMilli(),
TxCount: len(block.Data.Txs),
SquareSize: block.SquareSize,
BlockSize: size,
Proposer: block.ProposerAddress.String(),
LastCommitRound: block.LastCommit.Round,
Expand Down
1 change: 1 addition & 0 deletions proto/tendermint/store/types.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

246 changes: 141 additions & 105 deletions proto/tendermint/types/types.pb.go

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions proto/tendermint/types/types.proto
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,13 @@ message Data {
// NOTE: not all txs here are valid. We're just agreeing on the order first.
repeated bytes txs = 1;

reserved 2, 3, 4, 5;
reserved 2, 3, 4;
// field number 2 is reserved for intermediate state roots
// field number 3 is reserved for evidence
// field number 4 is reserved for blobs
// field number 5 is reserved for square size

// SquareSize is the number of rows or columns in the original data square.
uint64 square_size = 5;

// Hash is the root of a binary Merkle tree where the leaves of the tree are
// the row and column roots of an extended data square. Hash is often referred
Expand Down
12 changes: 6 additions & 6 deletions state/execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"github.com/cometbft/cometbft/libs/log"
mempl "github.com/cometbft/cometbft/mempool"
cmtstate "github.com/cometbft/cometbft/proto/tendermint/state"
cmtproto "github.com/cometbft/cometbft/proto/tendermint/types"
"github.com/cometbft/cometbft/proxy"
"github.com/cometbft/cometbft/types"
)
Expand Down Expand Up @@ -145,10 +144,9 @@ func (blockExec *BlockExecutor) CreateProposalBlock(
}

// update the block with the response from PrepareProposal
block.Data, _ = types.DataFromProto(&cmtproto.Data{
Txs: rpp.Txs[:len(rpp.Txs)-1],
Hash: rpp.Txs[len(rpp.Txs)-1],
Copy link
Contributor

Choose a reason for hiding this comment

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

The Hash is left unset, is it intentional?

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. We could probably remove it from the Data struct if we wanted to

Copy link
Contributor

Choose a reason for hiding this comment

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

So, wouldn't that be a breaking behaviour, namely it has been previously set and with the new change it is not?

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 that would be breaking, but it just breaks celestia-app, not downstream users

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually going to revert this because I don't think it makes sense to break app just yet

})
block.Data.Txs = types.ToTxs(rpp.Txs[:len(rpp.Txs)-1])
// update the data hash with the one passed back by celestia-app
block.DataHash = rpp.Txs[len(rpp.Txs)-1]

var blockDataSize int
for _, tx := range block.Txs {
Expand All @@ -167,7 +165,9 @@ func (blockExec *BlockExecutor) ProcessProposal(
) (bool, error) {

// Similar to PrepareProposal, the last transaction provided to Celestia
// in ProcessProposal is the data hash
// in ProcessProposal is the data hash. The data hash needs to be passed to
// the application so that it can be verified against the nodes own construction
// of the data square
txs := append(block.Data.Txs.ToSliceOfBytes(), block.DataHash)

resp, err := blockExec.proxyApp.ProcessProposalSync(abci.RequestProcessProposal{
Expand Down
4 changes: 0 additions & 4 deletions test/e2e/tests/block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,5 @@ func TestBlock_SignedData(t *testing.T) {
if !bytes.Equal(resp.Commit.BlockID.Hash, resp.Header.Hash()) {
t.Fatal("commit is for a different block")
}

if !bytes.Equal(resp.Header.DataHash, resp.Data.Hash()) {
t.Fatal("data does not match header data hash")
}
})
}
19 changes: 4 additions & 15 deletions types/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -1007,26 +1007,21 @@ func CommitFromProto(cp *cmtproto.Commit) (*Commit, error) {

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

// Data contains all the available Data of the block.
// Data with reserved namespaces (Txs, IntermediateStateRoots, Evidence) and
// Celestia application specific Blobs.
// Data contains all the Txs in a 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"`

// SquareSize is the size of the square after splitting all the block data
// into shares. The erasure data is discarded after generation, and keeping this
// value avoids unnecessarily regenerating all of the shares when returning
// proofs that some element was included in the block
SquareSize uint64 `json:"square_size"`

rootulp marked this conversation as resolved.
Show resolved Hide resolved
// Volatile
hash cmtbytes.HexBytes
}

// Hash returns the hash of the data
// NOTE: for the data hash, Celestia overwrites this one and uses what is
// known as the data availaibility hash which is the merkle root of a square
// encoding of the block
func (data *Data) Hash() cmtbytes.HexBytes {
if data == nil {
return (Txs{}).Hash()
Expand All @@ -1035,8 +1030,6 @@ func (data *Data) Hash() cmtbytes.HexBytes {
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
}

Expand Down Expand Up @@ -1094,8 +1087,6 @@ func (data *Data) ToProto() cmtproto.Data {
tp.Txs = txBzs
}

tp.Hash = data.hash

return *tp
}

Expand All @@ -1117,8 +1108,6 @@ func DataFromProto(dp *cmtproto.Data) (Data, error) {
data.Txs = Txs{}
}

data.hash = dp.Hash

return *data, nil
}

Expand Down
Loading