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 Proposal to include DAHeader #248

Merged
merged 17 commits into from
Mar 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
10 changes: 6 additions & 4 deletions consensus/byzantine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -376,8 +376,9 @@ 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)
p1 := proposal1.ToProto()
proposal1 := types.NewProposal(height, round, polRound, propBlockID, &block1.DataAvailabilityHeader)
p1, err := proposal1.ToProto()
require.NoError(t, err)
if err := cs.privValidator.SignProposal(cs.state.ChainID, p1); err != nil {
t.Error(err)
}
Expand All @@ -390,8 +391,9 @@ 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)
p2 := proposal2.ToProto()
proposal2 := types.NewProposal(height, round, polRound, propBlockID, &block2.DataAvailabilityHeader)
p2, err := proposal2.ToProto()
require.NoError(t, err)
if err := cs.privValidator.SignProposal(cs.state.ChainID, p2); err != nil {
t.Error(err)
}
Expand Down
7 changes: 5 additions & 2 deletions consensus/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,11 @@ func decideProposal(

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

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

"github.com/lazyledger/lazyledger-core/crypto/merkle"
"github.com/lazyledger/lazyledger-core/crypto/tmhash"
"github.com/lazyledger/lazyledger-core/libs/bits"
tmrand "github.com/lazyledger/lazyledger-core/libs/rand"
"github.com/lazyledger/lazyledger-core/p2p"
Expand Down Expand Up @@ -46,6 +47,8 @@ func TestMsgToProto(t *testing.T) {
pbParts, err := parts.ToProto()
require.NoError(t, err)

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

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

v := &types.Vote{
ValidatorAddress: []byte("add_more_exclamation"),
Expand Down Expand Up @@ -390,7 +400,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}}},
"1a720a7008201001180120012a480a206164645f6d6f72655f6578636c616d6174696f6e5f6d61726b735f636f64652d1224080112206164645f6d6f72655f6578636c616d6174696f6e5f6d61726b735f636f64652d320608c0b89fdc053a146164645f6d6f72655f6578636c616d6174696f6e"},
"1a740a7208201001180120012a480a206164645f6d6f72655f6578636c616d6174696f6e5f6d61726b735f636f64652d1224080112206164645f6d6f72655f6578636c616d6174696f6e5f6d61726b735f636f64652d320608c0b89fdc053a146164645f6d6f72655f6578636c616d6174696f6e4200"},
{"ProposalPol", &tmcons.Message{Sum: &tmcons.Message_ProposalPol{
ProposalPol: &tmcons.ProposalPOL{Height: 1, ProposalPolRound: 1}}},
"2206080110011a00"},
Expand Down
20 changes: 12 additions & 8 deletions consensus/replay_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -367,8 +367,9 @@ 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)
p := proposal.ToProto()
proposal := types.NewProposal(vss[1].Height, round, -1, blockID, &propBlock.DataAvailabilityHeader)
p, err := proposal.ToProto()
require.NoError(t, err)
if err := vss[1].SignProposal(config.ChainID(), p); err != nil {
t.Fatal("failed to sign bad proposal", err)
}
Expand Down Expand Up @@ -397,8 +398,9 @@ 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)
p = proposal.ToProto()
proposal = types.NewProposal(vss[2].Height, round, -1, blockID, &propBlock.DataAvailabilityHeader)
p, err = proposal.ToProto()
require.NoError(t, err)
if err := vss[2].SignProposal(config.ChainID(), p); err != nil {
t.Fatal("failed to sign bad proposal", err)
}
Expand Down Expand Up @@ -454,8 +456,9 @@ func TestSimulateValidatorsChange(t *testing.T) {

selfIndex := valIndexFn(0)

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

selfIndex = valIndexFn(0)
proposal = types.NewProposal(vss[1].Height, round, -1, blockID)
p = proposal.ToProto()
proposal = types.NewProposal(vss[1].Height, round, -1, blockID, &propBlock.DataAvailabilityHeader)
p, err = proposal.ToProto()
require.NoError(t, err)
if err := vss[1].SignProposal(config.ChainID(), p); err != nil {
t.Fatal("failed to sign bad proposal", err)
}
Expand Down
15 changes: 12 additions & 3 deletions consensus/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -1087,8 +1087,13 @@ 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)
p := proposal.ToProto()
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()))
Wondertan marked this conversation as resolved.
Show resolved Hide resolved
return
}

if err := cs.privValidator.SignProposal(cs.state.ChainID, p); err == nil {
proposal.Signature = p.Signature

Expand Down Expand Up @@ -1750,7 +1755,11 @@ func (cs *State) defaultSetProposal(proposal *types.Proposal) error {
return ErrInvalidProposalPOLRound
}

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

// Verify signature
if !cs.Validators.GetProposer().PubKey.VerifySignature(
types.ProposalSignBytes(cs.state.ChainID, p), proposal.Signature,
Expand Down
15 changes: 9 additions & 6 deletions consensus/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,9 @@ 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)
p := proposal.ToProto()
proposal := types.NewProposal(vs2.Height, round, -1, blockID, &propBlock.DataAvailabilityHeader)
p, err := proposal.ToProto()
require.NoError(t, err)
if err := vs2.SignProposal(config.ChainID(), p); err != nil {
t.Fatal("failed to sign bad proposal", err)
}
Expand Down Expand Up @@ -260,8 +261,9 @@ 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)
p := proposal.ToProto()
proposal := types.NewProposal(height, round, -1, blockID, &propBlock.DataAvailabilityHeader)
p, err := proposal.ToProto()
require.NoError(t, err)
if err := vs2.SignProposal(config.ChainID(), p); err != nil {
t.Fatal("failed to sign bad proposal", err)
}
Expand Down Expand Up @@ -1083,8 +1085,9 @@ 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)
p := newProp.ToProto()
newProp := types.NewProposal(height, round, 0, propBlockID0, &propBlock0.DataAvailabilityHeader)
p, err := newProp.ToProto()
require.NoError(t, err)
if err := vs3.SignProposal(config.ChainID(), p); err != nil {
t.Fatal(err)
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ require (
github.com/ipfs/go-path v0.0.9 // indirect
github.com/ipfs/interface-go-ipfs-core v0.4.0
github.com/lazyledger/lazyledger-core/p2p/ipld/plugin v0.0.0-20210219190522-0eccfb24e2aa
github.com/lazyledger/nmt v0.2.0
github.com/lazyledger/nmt v0.3.1
github.com/lazyledger/rsmt2d v0.1.1-0.20210327010029-ef1d6c54461e
github.com/libp2p/go-buffer-pool v0.0.2
github.com/minio/highwayhash v1.0.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -607,8 +607,8 @@ github.com/lazyledger/go-verifcid v0.0.1-lazypatch h1:jAVwUw+DhuCzx5IcYpFh6d6HWx
github.com/lazyledger/go-verifcid v0.0.1-lazypatch/go.mod h1:kXPYu0XqTNUKWA1h3M95UHjUqBzDwXVVt/RXZDjKJmQ=
github.com/lazyledger/merkletree v0.0.0-20201214195110-6901c4c3c75f h1:jbyPAH6o6hGte4RtZBaqWs2n4Fl6hS7qJGXX3qnjiy4=
github.com/lazyledger/merkletree v0.0.0-20201214195110-6901c4c3c75f/go.mod h1:10PA0NlnYtB8HrtwIDQAyTKWp8TEZ0zBZCGlYC/7+QE=
github.com/lazyledger/nmt v0.2.0 h1:jKpC+XMSc4P1asLvutSwyMlgUDnAvv1HAVyzal21MbA=
github.com/lazyledger/nmt v0.2.0/go.mod h1:tY7ypPX26Sbkt6F8EbPl3AT33B5N0BJe4OVPbq849YI=
github.com/lazyledger/nmt v0.3.1 h1:zP172RR33Es4dhb88GmUr9kBpAkH6Wcl7nQGJ3HQzu4=
github.com/lazyledger/nmt v0.3.1/go.mod h1:tY7ypPX26Sbkt6F8EbPl3AT33B5N0BJe4OVPbq849YI=
github.com/lazyledger/rsmt2d v0.1.1-0.20210327010029-ef1d6c54461e h1:3mwa4b4v9puYIFsfRN6TsXMbUagvhLtIzXWHN2GFHB4=
github.com/lazyledger/rsmt2d v0.1.1-0.20210327010029-ef1d6c54461e/go.mod h1:ORR2U7THCNr1fpUhwYqZN7QCFJ20iR2uiIWfXKz3KJ4=
github.com/libp2p/go-addr-util v0.0.1/go.mod h1:4ac6O7n9rIAKB1dnd+s8IbbMXkt+oBpzX4/+RACcnlQ=
Expand Down
4 changes: 2 additions & 2 deletions p2p/ipld/nmt_wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ func (w *ErasuredNamespacedMerkleTree) Push(data []byte, idx rsmt2d.SquareIndex)
} else {
copy(nsID, data[:types.NamespaceSize])
}

nidAndData := append(append(make([]byte, 0, types.NamespaceSize+len(data)), nsID...), data...)
// push to the underlying tree
err := w.tree.Push(nsID, data)
err := w.tree.Push(nidAndData)
// panic on error
if err != nil {
panic(err)
Expand Down
2 changes: 1 addition & 1 deletion p2p/ipld/nmt_wrapper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func TestRootErasuredNamespacedMerkleTree(t *testing.T) {

for i, d := range data {
tree.Push(d, rsmt2d.SquareIndex{Axis: uint(0), Cell: uint(i)})
err := nmtTree.Push(d[:types.NamespaceSize], d[types.NamespaceSize:])
err := nmtTree.Push(d)
if err != nil {
t.Error(err)
}
Expand Down
2 changes: 1 addition & 1 deletion p2p/ipld/plugin/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require (
github.com/ipfs/go-ipfs-api v0.2.0
github.com/ipfs/go-ipld-format v0.2.0
github.com/ipfs/go-verifcid v0.0.1
github.com/lazyledger/nmt v0.2.0
github.com/lazyledger/nmt v0.3.1
// rsmt2d is only used in tests:
github.com/lazyledger/rsmt2d v0.1.1-0.20210327010029-ef1d6c54461e
github.com/multiformats/go-multihash v0.0.14
Expand Down
Loading