Skip to content

Commit

Permalink
Remove the DataAvailabilityHeader from the Proposal (#518)
Browse files Browse the repository at this point in the history
* remove the DAH from the proposal

* fix hardcoded tests

* remove uneccessary error in toproto method
  • Loading branch information
evan-forbes authored Aug 25, 2021
1 parent af333a2 commit 410b857
Show file tree
Hide file tree
Showing 20 changed files with 347 additions and 555 deletions.
10 changes: 4 additions & 6 deletions consensus/byzantine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -380,9 +380,8 @@ func byzantineDecideProposalFunc(t *testing.T, height int64, round int32, cs *St
// Create a new proposal block from state/txs from the mempool.
block1, blockParts1 := cs.createProposalBlock()
polRound, propBlockID := cs.ValidRound, types.BlockID{Hash: block1.Hash(), PartSetHeader: blockParts1.Header()}
proposal1 := types.NewProposal(height, round, polRound, propBlockID, &block1.DataAvailabilityHeader)
p1, err := proposal1.ToProto()
require.NoError(t, err)
proposal1 := types.NewProposal(height, round, polRound, propBlockID)
p1 := proposal1.ToProto()
if err := cs.privValidator.SignProposal(cs.state.ChainID, p1); err != nil {
t.Error(err)
}
Expand All @@ -395,9 +394,8 @@ func byzantineDecideProposalFunc(t *testing.T, height int64, round int32, cs *St
// Create a new proposal block from state/txs from the mempool.
block2, blockParts2 := cs.createProposalBlock()
polRound, propBlockID = cs.ValidRound, types.BlockID{Hash: block2.Hash(), PartSetHeader: blockParts2.Header()}
proposal2 := types.NewProposal(height, round, polRound, propBlockID, &block2.DataAvailabilityHeader)
p2, err := proposal2.ToProto()
require.NoError(t, err)
proposal2 := types.NewProposal(height, round, polRound, propBlockID)
p2 := proposal2.ToProto()
if err := cs.privValidator.SignProposal(cs.state.ChainID, p2); err != nil {
t.Error(err)
}
Expand Down
7 changes: 2 additions & 5 deletions consensus/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,11 +200,8 @@ func decideProposal(

// Make proposal
polRound, propBlockID := validRound, types.BlockID{Hash: block.Hash(), PartSetHeader: blockParts.Header()}
proposal = types.NewProposal(height, round, polRound, propBlockID, &block.DataAvailabilityHeader)
p, err := proposal.ToProto()
if err != nil {
panic(err)
}
proposal = types.NewProposal(height, round, polRound, propBlockID)
p := proposal.ToProto()
if err := vs.SignProposal(chainID, p); err != nil {
panic(err)
}
Expand Down
5 changes: 1 addition & 4 deletions consensus/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,7 @@ func MsgToProto(msg Message) (*tmcons.Message, error) {
},
}
case *ProposalMessage:
pbP, err := msg.Proposal.ToProto()
if err != nil {
return nil, err
}
pbP := msg.Proposal.ToProto()

pb = tmcons.Message{
Sum: &tmcons.Message_Proposal{
Expand Down
17 changes: 3 additions & 14 deletions consensus/msgs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,12 @@ import (
"github.com/stretchr/testify/require"

"github.com/celestiaorg/celestia-core/crypto/merkle"
"github.com/celestiaorg/celestia-core/crypto/tmhash"
"github.com/celestiaorg/celestia-core/libs/bits"
tmrand "github.com/celestiaorg/celestia-core/libs/rand"
"github.com/celestiaorg/celestia-core/p2p"
tmcons "github.com/celestiaorg/celestia-core/proto/tendermint/consensus"
tmproto "github.com/celestiaorg/celestia-core/proto/tendermint/types"
"github.com/celestiaorg/celestia-core/types"
"github.com/celestiaorg/celestia-core/types/consts"
)

func TestMsgToProto(t *testing.T) {
Expand Down Expand Up @@ -48,8 +46,6 @@ func TestMsgToProto(t *testing.T) {
pbParts, err := parts.ToProto()
require.NoError(t, err)

roots, err := types.NmtRootsFromBytes([][]byte{tmrand.Bytes(2*consts.NamespaceSize + tmhash.Size)})
require.NoError(t, err)
proposal := types.Proposal{
Type: tmproto.ProposalType,
Height: 1,
Expand All @@ -58,13 +54,8 @@ func TestMsgToProto(t *testing.T) {
BlockID: bi,
Timestamp: time.Now(),
Signature: tmrand.Bytes(20),
DAHeader: &types.DataAvailabilityHeader{
RowsRoots: roots,
ColumnRoots: roots,
},
}
pbProposal, err := proposal.ToProto()
require.NoError(t, err)
pbProposal := proposal.ToProto()

pv := types.NewMockPV()
pk, err := pv.GetPubKey()
Expand Down Expand Up @@ -361,10 +352,8 @@ func TestConsMsgsVectors(t *testing.T) {
BlockID: bi,
Timestamp: date,
Signature: []byte("add_more_exclamation"),
DAHeader: &types.DataAvailabilityHeader{},
}
pbProposal, err := proposal.ToProto()
require.NoError(t, err)
pbProposal := proposal.ToProto()

v := &types.Vote{
ValidatorAddress: []byte("add_more_exclamation"),
Expand Down Expand Up @@ -401,7 +390,7 @@ func TestConsMsgsVectors(t *testing.T) {
Height: 1, Round: 1, BlockPartSetHeader: pbPsh, BlockParts: pbBits, IsCommit: false}}},
"1231080110011a24080112206164645f6d6f72655f6578636c616d6174696f6e5f6d61726b735f636f64652d22050801120100"},
{"Proposal", &tmcons.Message{Sum: &tmcons.Message_Proposal{Proposal: &tmcons.Proposal{Proposal: *pbProposal}}},
"1a740a7208201001180120012a480a206164645f6d6f72655f6578636c616d6174696f6e5f6d61726b735f636f64652d1224080112206164645f6d6f72655f6578636c616d6174696f6e5f6d61726b735f636f64652d320608c0b89fdc053a146164645f6d6f72655f6578636c616d6174696f6e4200"},
"1a720a7008201001180120012a480a206164645f6d6f72655f6578636c616d6174696f6e5f6d61726b735f636f64652d1224080112206164645f6d6f72655f6578636c616d6174696f6e5f6d61726b735f636f64652d320608c0b89fdc053a146164645f6d6f72655f6578636c616d6174696f6e"},
{"ProposalPol", &tmcons.Message{Sum: &tmcons.Message_ProposalPol{
ProposalPol: &tmcons.ProposalPOL{Height: 1, ProposalPolRound: 1}}},
"2206080110011a00"},
Expand Down
20 changes: 8 additions & 12 deletions consensus/replay_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -371,9 +371,8 @@ func TestSimulateValidatorsChange(t *testing.T) {
propBlockParts := propBlock.MakePartSet(partSize)
blockID := types.BlockID{Hash: propBlock.Hash(), PartSetHeader: propBlockParts.Header()}

proposal := types.NewProposal(vss[1].Height, round, -1, blockID, &propBlock.DataAvailabilityHeader)
p, err := proposal.ToProto()
require.NoError(t, err)
proposal := types.NewProposal(vss[1].Height, round, -1, blockID)
p := proposal.ToProto()
if err := vss[1].SignProposal(config.ChainID(), p); err != nil {
t.Fatal("failed to sign bad proposal", err)
}
Expand Down Expand Up @@ -402,9 +401,8 @@ func TestSimulateValidatorsChange(t *testing.T) {
propBlockParts = propBlock.MakePartSet(partSize)
blockID = types.BlockID{Hash: propBlock.Hash(), PartSetHeader: propBlockParts.Header()}

proposal = types.NewProposal(vss[2].Height, round, -1, blockID, &propBlock.DataAvailabilityHeader)
p, err = proposal.ToProto()
require.NoError(t, err)
proposal = types.NewProposal(vss[2].Height, round, -1, blockID)
p = proposal.ToProto()
if err := vss[2].SignProposal(config.ChainID(), p); err != nil {
t.Fatal("failed to sign bad proposal", err)
}
Expand Down Expand Up @@ -460,9 +458,8 @@ func TestSimulateValidatorsChange(t *testing.T) {

selfIndex := valIndexFn(0)

proposal = types.NewProposal(vss[3].Height, round, -1, blockID, &propBlock.DataAvailabilityHeader)
p, err = proposal.ToProto()
require.NoError(t, err)
proposal = types.NewProposal(vss[3].Height, round, -1, blockID)
p = proposal.ToProto()
if err := vss[3].SignProposal(config.ChainID(), p); err != nil {
t.Fatal("failed to sign bad proposal", err)
}
Expand Down Expand Up @@ -520,9 +517,8 @@ func TestSimulateValidatorsChange(t *testing.T) {
sort.Sort(ValidatorStubsByPower(newVss))

selfIndex = valIndexFn(0)
proposal = types.NewProposal(vss[1].Height, round, -1, blockID, &propBlock.DataAvailabilityHeader)
p, err = proposal.ToProto()
require.NoError(t, err)
proposal = types.NewProposal(vss[1].Height, round, -1, blockID)
p = proposal.ToProto()
if err := vss[1].SignProposal(config.ChainID(), p); err != nil {
t.Fatal("failed to sign bad proposal", err)
}
Expand Down
13 changes: 3 additions & 10 deletions consensus/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -1084,12 +1084,8 @@ func (cs *State) defaultDecideProposal(height int64, round int32) {

// Make proposal
propBlockID := types.BlockID{Hash: block.Hash(), PartSetHeader: blockParts.Header()}
proposal := types.NewProposal(height, round, cs.ValidRound, propBlockID, &block.DataAvailabilityHeader)
p, err := proposal.ToProto()
if err != nil {
cs.Logger.Error(fmt.Sprintf("can't serialize proposal: %s", err.Error()))
return
}
proposal := types.NewProposal(height, round, cs.ValidRound, propBlockID)
p := proposal.ToProto()

if err := cs.privValidator.SignProposal(cs.state.ChainID, p); err == nil {
proposal.Signature = p.Signature
Expand Down Expand Up @@ -1739,10 +1735,7 @@ func (cs *State) defaultSetProposal(proposal *types.Proposal) error {
return ErrInvalidProposalPOLRound
}

p, err := proposal.ToProto()
if err != nil {
return err
}
p := proposal.ToProto()

// Verify signature
if !cs.Validators.GetProposer().PubKey.VerifySignature(
Expand Down
15 changes: 6 additions & 9 deletions consensus/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,8 @@ func TestStateBadProposal(t *testing.T) {
propBlock.AppHash = stateHash
propBlockParts := propBlock.MakePartSet(partSize)
blockID := types.BlockID{Hash: propBlock.Hash(), PartSetHeader: propBlockParts.Header()}
proposal := types.NewProposal(vs2.Height, round, -1, blockID, &propBlock.DataAvailabilityHeader)
p, err := proposal.ToProto()
require.NoError(t, err)
proposal := types.NewProposal(vs2.Height, round, -1, blockID)
p := proposal.ToProto()
if err := vs2.SignProposal(config.ChainID(), p); err != nil {
t.Fatal("failed to sign bad proposal", err)
}
Expand Down Expand Up @@ -264,9 +263,8 @@ func TestStateOversizedBlock(t *testing.T) {

propBlockParts := propBlock.MakePartSet(partSize)
blockID := types.BlockID{Hash: propBlock.Hash(), PartSetHeader: propBlockParts.Header()}
proposal := types.NewProposal(height, round, -1, blockID, &propBlock.DataAvailabilityHeader)
p, err := proposal.ToProto()
require.NoError(t, err)
proposal := types.NewProposal(height, round, -1, blockID)
p := proposal.ToProto()
if err := vs2.SignProposal(config.ChainID(), p); err != nil {
t.Fatal("failed to sign bad proposal", err)
}
Expand Down Expand Up @@ -1095,9 +1093,8 @@ func TestStateLockPOLSafety2(t *testing.T) {

round++ // moving to the next round
// in round 2 we see the polkad block from round 0
newProp := types.NewProposal(height, round, 0, propBlockID0, &propBlock0.DataAvailabilityHeader)
p, err := newProp.ToProto()
require.NoError(t, err)
newProp := types.NewProposal(height, round, 0, propBlockID0)
p := newProp.ToProto()
if err := vs3.SignProposal(config.ChainID(), p); err != nil {
t.Fatal(err)
}
Expand Down
10 changes: 3 additions & 7 deletions privval/file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,7 @@ func TestSignProposal(t *testing.T) {

// sign a proposal for first time
proposal := newProposal(height, round, block1)
pbp, err := proposal.ToProto()
require.NoError(t, err)
pbp := proposal.ToProto()
err = privVal.SignProposal("mychainid", pbp)
assert.NoError(err, "expected no error signing proposal")

Expand All @@ -254,8 +253,7 @@ func TestSignProposal(t *testing.T) {
}

for _, c := range cases {
p, err := c.ToProto()
require.NoError(t, err)
p := c.ToProto()
err = privVal.SignProposal("mychainid", p)
assert.Error(err, "expected error on signing conflicting proposal")
}
Expand Down Expand Up @@ -284,8 +282,7 @@ func TestDifferByTimestamp(t *testing.T) {
// test proposal
{
proposal := newProposal(height, round, block1)
pb, err := proposal.ToProto()
require.NoError(t, err)
pb := proposal.ToProto()
err = privVal.SignProposal(chainID, pb)
assert.NoError(t, err, "expected no error signing proposal")
signBytes := types.ProposalSignBytes(chainID, pb)
Expand Down Expand Up @@ -350,6 +347,5 @@ func newProposal(height int64, round int32, blockID types.BlockID) *types.Propos
Round: round,
BlockID: blockID,
Timestamp: tmtime.Now(),
DAHeader: &types.DataAvailabilityHeader{},
}
}
8 changes: 3 additions & 5 deletions privval/msgs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ func exampleProposal() *types.Proposal {
Hash: tmhash.Sum([]byte("blockID_part_set_header_hash")),
},
},
DAHeader: &types.DataAvailabilityHeader{},
}
}

Expand All @@ -70,8 +69,7 @@ func TestPrivvalVectors(t *testing.T) {

// Generate a simple proposal
proposal := exampleProposal()
proposalpb, err := proposal.ToProto()
require.NoError(t, err)
proposalpb := proposal.ToProto()

// Create a Reuseable remote error
remoteError := &privproto.RemoteSignerError{Code: 1, Description: "it's a error"}
Expand All @@ -89,8 +87,8 @@ func TestPrivvalVectors(t *testing.T) {
{"Vote Request", &privproto.SignVoteRequest{Vote: votepb}, "1a760a74080110031802224a0a208b01023386c371778ecb6368573e539afc3cc860ec3a2f614e54fe5652f4fc80122608c0843d122072db3d959635dff1bb567bedaa70573392c5159666a3f8caf11e413aac52207a2a0608f49a8ded0532146af1f4111082efb388211bc72c55bcd61e9ac3d538d5bb03"},
{"Vote Response", &privproto.SignedVoteResponse{Vote: *votepb, Error: nil}, "22760a74080110031802224a0a208b01023386c371778ecb6368573e539afc3cc860ec3a2f614e54fe5652f4fc80122608c0843d122072db3d959635dff1bb567bedaa70573392c5159666a3f8caf11e413aac52207a2a0608f49a8ded0532146af1f4111082efb388211bc72c55bcd61e9ac3d538d5bb03"},
{"Vote Response with error", &privproto.SignedVoteResponse{Vote: tmproto.Vote{}, Error: remoteError}, "22250a11220212002a0b088092b8c398feffffff0112100801120c697427732061206572726f72"},
{"Proposal Request", &privproto.SignProposalRequest{Proposal: proposalpb}, "2a720a7008011003180220022a4a0a208b01023386c371778ecb6368573e539afc3cc860ec3a2f614e54fe5652f4fc80122608c0843d122072db3d959635dff1bb567bedaa70573392c5159666a3f8caf11e413aac52207a320608f49a8ded053a10697427732061207369676e61747572654200"},
{"Proposal Response", &privproto.SignedProposalResponse{Proposal: *proposalpb, Error: nil}, "32720a7008011003180220022a4a0a208b01023386c371778ecb6368573e539afc3cc860ec3a2f614e54fe5652f4fc80122608c0843d122072db3d959635dff1bb567bedaa70573392c5159666a3f8caf11e413aac52207a320608f49a8ded053a10697427732061207369676e61747572654200"},
{"Proposal Request", &privproto.SignProposalRequest{Proposal: proposalpb}, "2a700a6e08011003180220022a4a0a208b01023386c371778ecb6368573e539afc3cc860ec3a2f614e54fe5652f4fc80122608c0843d122072db3d959635dff1bb567bedaa70573392c5159666a3f8caf11e413aac52207a320608f49a8ded053a10697427732061207369676e6174757265"},
{"Proposal Response", &privproto.SignedProposalResponse{Proposal: *proposalpb, Error: nil}, "32700a6e08011003180220022a4a0a208b01023386c371778ecb6368573e539afc3cc860ec3a2f614e54fe5652f4fc80122608c0843d122072db3d959635dff1bb567bedaa70573392c5159666a3f8caf11e413aac52207a320608f49a8ded053a10697427732061207369676e6174757265"},
{"Proposal Response with error", &privproto.SignedProposalResponse{Proposal: tmproto.Proposal{}, Error: remoteError}, "32250a112a021200320b088092b8c398feffffff0112100801120c697427732061206572726f72"},
}

Expand Down
22 changes: 7 additions & 15 deletions privval/signer_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ func TestSignerProposal(t *testing.T) {
POLRound: 2,
BlockID: types.BlockID{Hash: hash, PartSetHeader: types.PartSetHeader{Hash: hash, Total: 2}},
Timestamp: ts,
DAHeader: &types.DataAvailabilityHeader{},
}
want := &types.Proposal{
Type: tmproto.ProposalType,
Expand All @@ -134,7 +133,6 @@ func TestSignerProposal(t *testing.T) {
POLRound: 2,
BlockID: types.BlockID{Hash: hash, PartSetHeader: types.PartSetHeader{Hash: hash, Total: 2}},
Timestamp: ts,
DAHeader: &types.DataAvailabilityHeader{},
}

tc := tc
Expand All @@ -149,13 +147,11 @@ func TestSignerProposal(t *testing.T) {
}
})

p, err := want.ToProto()
require.NoError(t, err)
err = tc.mockPV.SignProposal(tc.chainID, p)
p := want.ToProto()
err := tc.mockPV.SignProposal(tc.chainID, p)
require.NoError(t, err)

p, err = have.ToProto()
require.NoError(t, err)
p = have.ToProto()
err = tc.signerClient.SignProposal(tc.chainID, p)
require.NoError(t, err)

Expand Down Expand Up @@ -342,21 +338,17 @@ func TestSignerSignProposalErrors(t *testing.T) {
BlockID: types.BlockID{Hash: hash, PartSetHeader: types.PartSetHeader{Hash: hash, Total: 2}},
Timestamp: ts,
Signature: []byte("signature"),
DAHeader: &types.DataAvailabilityHeader{},
}

p, err := proposal.ToProto()
require.NoError(t, err)
err = tc.signerClient.SignProposal(tc.chainID, p)
p := proposal.ToProto()
err := tc.signerClient.SignProposal(tc.chainID, p)
require.Equal(t, err.(*RemoteSignerError).Description, types.ErroringMockPVErr.Error())

p, err = proposal.ToProto()
require.NoError(t, err)
p = proposal.ToProto()
err = tc.mockPV.SignProposal(tc.chainID, p)
require.Error(t, err)

p, err = proposal.ToProto()
require.NoError(t, err)
p = proposal.ToProto()
err = tc.signerClient.SignProposal(tc.chainID, p)
require.Error(t, err)
}
Expand Down
Loading

0 comments on commit 410b857

Please sign in to comment.