Skip to content

Commit

Permalink
unfinished, quickly hacked together exploration of:
Browse files Browse the repository at this point in the history
 1. what it would take to remove the PartSetHeader from BlockID
 2. keep gossiping as is vs change gossiping

 Conclusion 1. could be finished in a few days (really): most time will be spent fixing tests. It will create a lot of changes but if carefully committed, it should still be reviewable.
 Need clarity if we should remove the DAHeader from the Proposal until we switch to gossiping e.g. to rows / erasured data etc.
 ref #434 #184)
  • Loading branch information
liamsi committed Jun 27, 2021
1 parent 004a1a9 commit 664604e
Show file tree
Hide file tree
Showing 55 changed files with 450 additions and 976 deletions.
220 changes: 44 additions & 176 deletions abci/types/types.pb.go

Large diffs are not rendered by default.

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}}}, "1ac2020abf020a5d0a02080b1803220b088092b8c398feffffff012a021200380142204c149a7cfadc92b669b0cbfa4951a1b18c2d9f3177a3b8756d39ebb96e9d63317220e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b85512130a0b48656c6c6f20576f726c6412001a0022001ac8010a3000000000000000010000000000000001b81cb5596c28d044214b9f935e4af7dbe76e417f6182d86fbee68bfff7b2ff3a0a30ffffffffffffffffffffffffffffffffc4096ba8fccf882c309896e9168fa43fe62fccb752cb12d5160cc1d9c2ebffe7123000000000000000010000000000000001b81cb5596c28d044214b9f935e4af7dbe76e417f6182d86fbee68bfff7b2ff3a1230ffffffffffffffffffffffffffffffffc4096ba8fccf882c309896e9168fa43fe62fccb752cb12d5160cc1d9c2ebffe7"},
BlockResponse: &bcproto.BlockResponse{Block: bpb}}}, "1ac0020abd020a5b0a02080b1803220b088092b8c398feffffff012a00380142204c149a7cfadc92b669b0cbfa4951a1b18c2d9f3177a3b8756d39ebb96e9d63317220e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b85512130a0b48656c6c6f20576f726c6412001a0022001ac8010a3000000000000000010000000000000001b81cb5596c28d044214b9f935e4af7dbe76e417f6182d86fbee68bfff7b2ff3a0a30ffffffffffffffffffffffffffffffffc4096ba8fccf882c309896e9168fa43fe62fccb752cb12d5160cc1d9c2ebffe7123000000000000000010000000000000001b81cb5596c28d044214b9f935e4af7dbe76e417f6182d86fbee68bfff7b2ff3a1230ffffffffffffffffffffffffffffffffc4096ba8fccf882c309896e9168fa43fe62fccb752cb12d5160cc1d9c2ebffe7"},
{"NoBlockResponseMessage", &bcproto.Message{Sum: &bcproto.Message_NoBlockResponse{
NoBlockResponse: &bcproto.NoBlockResponse{Height: 1}}}, "12020801"},
{"NoBlockResponseMessage", &bcproto.Message{Sum: &bcproto.Message_NoBlockResponse{
Expand Down
6 changes: 3 additions & 3 deletions blockchain/v0/reactor.go
Original file line number Diff line number Diff line change
Expand Up @@ -387,9 +387,9 @@ FOR_LOOP:
}

var (
firstParts = first.MakePartSet(types.BlockPartSizeBytes)
firstPartSetHeader = firstParts.Header()
firstID = types.BlockID{Hash: first.Hash(), PartSetHeader: firstPartSetHeader}
firstParts = first.MakePartSet(types.BlockPartSizeBytes)
/*firstPartSetHeader = firstParts.Header()*/
firstID = types.BlockID{Hash: first.Hash() /*, PartSetHeader: firstPartSetHeader*/}
)

// Finally, verify the first block using the second's commit
Expand Down
2 changes: 1 addition & 1 deletion blockchain/v0/reactor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func newBlockchainReactor(
thisBlock := makeBlock(blockHeight, state, lastCommit)

thisParts := thisBlock.MakePartSet(types.BlockPartSizeBytes)
blockID := types.BlockID{Hash: thisBlock.Hash(), PartSetHeader: thisParts.Header()}
blockID := types.BlockID{Hash: thisBlock.Hash()}

state, _, err = blockExec.ApplyBlock(state, blockID, thisBlock)
if err != nil {
Expand Down
8 changes: 4 additions & 4 deletions consensus/byzantine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -385,8 +385,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)
polRound, propBlockID := cs.ValidRound, types.BlockID{Hash: block1.Hash()}
proposal1 := types.NewProposal(height, round, polRound, propBlockID, &block1.DataAvailabilityHeader, blockParts1.Header())
p1, err := proposal1.ToProto()
require.NoError(t, err)
if err := cs.privValidator.SignProposal(cs.state.ChainID, p1); err != nil {
Expand All @@ -400,8 +400,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)
polRound, propBlockID = cs.ValidRound, types.BlockID{Hash: block2.Hash()}
proposal2 := types.NewProposal(height, round, polRound, propBlockID, &block2.DataAvailabilityHeader, blockParts2.Header())
p2, err := proposal2.ToProto()
require.NoError(t, err)
if err := cs.privValidator.SignProposal(cs.state.ChainID, p2); err != nil {
Expand Down
7 changes: 4 additions & 3 deletions consensus/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ func (vs *validatorStub) signVote(
Round: vs.Round,
Timestamp: tmtime.Now(),
Type: voteType,
BlockID: types.BlockID{Hash: hash, PartSetHeader: header},
BlockID: types.BlockID{Hash: hash},
PartSetHeader: header,
}
v := vote.ToProto()
err = vs.PrivValidator.SignVote(config.ChainID(), v)
Expand Down Expand Up @@ -205,8 +206,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)
polRound, propBlockID := validRound, types.BlockID{Hash: block.Hash()}
proposal = types.NewProposal(height, round, polRound, propBlockID, &block.DataAvailabilityHeader, blockParts.Header())
p, err := proposal.ToProto()
if err != nil {
panic(err)
Expand Down
4 changes: 2 additions & 2 deletions consensus/invalid_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ func invalidDoPrevoteFunc(t *testing.T, height int64, round int32, cs *State, sw
Timestamp: cs.voteTime(),
Type: tmproto.PrecommitType,
BlockID: types.BlockID{
Hash: blockHash,
PartSetHeader: types.PartSetHeader{Total: 1, Hash: tmrand.Bytes(32)}},
Hash: blockHash,
},
}
p := precommit.ToProto()
err = cs.privValidator.SignVote(cs.state.ChainID, p)
Expand Down
6 changes: 2 additions & 4 deletions consensus/msgs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ func TestMsgToProto(t *testing.T) {
}
pbPsh := psh.ToProto()
bi := types.BlockID{
Hash: tmrand.Bytes(32),
PartSetHeader: psh,
Hash: tmrand.Bytes(32),
}
pbBi := bi.ToProto()
bits := bits.NewBitArray(1)
Expand Down Expand Up @@ -333,8 +332,7 @@ func TestConsMsgsVectors(t *testing.T) {
pbPsh := psh.ToProto()

bi := types.BlockID{
Hash: []byte("add_more_exclamation_marks_code-"),
PartSetHeader: psh,
Hash: []byte("add_more_exclamation_marks_code-"),
}
pbBi := bi.ToProto()
bits := bits.NewBitArray(1)
Expand Down
18 changes: 9 additions & 9 deletions consensus/reactor.go
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ OUTER_LOOP:
"blockstoreBase", conR.conS.blockStore.Base(), "blockstoreHeight", conR.conS.blockStore.Height())
time.Sleep(conR.conS.config.PeerGossipSleepDuration)
} else {
ps.InitProposalBlockParts(blockMeta.BlockID.PartSetHeader)
ps.InitProposalBlockParts(blockMeta.PartSetHeader)
}
// continue the loop since prs is a copy and not effected by this initialization
continue OUTER_LOOP
Expand Down Expand Up @@ -597,17 +597,17 @@ func (conR *Reactor) gossipDataForCatchup(logger log.Logger, rs *cstypes.RoundSt
"blockstoreBase", conR.conS.blockStore.Base(), "blockstoreHeight", conR.conS.blockStore.Height())
time.Sleep(conR.conS.config.PeerGossipSleepDuration)
return
} else if !blockMeta.BlockID.PartSetHeader.Equals(prs.ProposalBlockPartSetHeader) {
} else if !blockMeta.PartSetHeader.Equals(prs.ProposalBlockPartSetHeader) {
logger.Info("Peer ProposalBlockPartSetHeader mismatch, sleeping",
"blockPartSetHeader", blockMeta.BlockID.PartSetHeader, "peerBlockPartSetHeader", prs.ProposalBlockPartSetHeader)
"blockPartSetHeader", blockMeta.PartSetHeader, "peerBlockPartSetHeader", prs.ProposalBlockPartSetHeader)
time.Sleep(conR.conS.config.PeerGossipSleepDuration)
return
}
// Load the part
part := conR.conS.blockStore.LoadBlockPart(prs.Height, index)
if part == nil {
logger.Error("Could not load part", "index", index,
"blockPartSetHeader", blockMeta.BlockID.PartSetHeader, "peerBlockPartSetHeader", prs.ProposalBlockPartSetHeader)
"blockPartSetHeader", blockMeta.PartSetHeader, "peerBlockPartSetHeader", prs.ProposalBlockPartSetHeader)
time.Sleep(conR.conS.config.PeerGossipSleepDuration)
return
}
Expand Down Expand Up @@ -783,7 +783,7 @@ OUTER_LOOP:
Height: prs.Height,
Round: prs.Round,
Type: tmproto.PrevoteType,
BlockID: maj23,
BlockID: maj23.BlockID,
}))
time.Sleep(conR.conS.config.PeerQueryMaj23SleepDuration)
}
Expand All @@ -800,7 +800,7 @@ OUTER_LOOP:
Height: prs.Height,
Round: prs.Round,
Type: tmproto.PrecommitType,
BlockID: maj23,
BlockID: maj23.BlockID,
}))
time.Sleep(conR.conS.config.PeerQueryMaj23SleepDuration)
}
Expand All @@ -817,7 +817,7 @@ OUTER_LOOP:
Height: prs.Height,
Round: prs.ProposalPOLRound,
Type: tmproto.PrevoteType,
BlockID: maj23,
BlockID: maj23.BlockID,
}))
time.Sleep(conR.conS.config.PeerQueryMaj23SleepDuration)
}
Expand Down Expand Up @@ -1017,8 +1017,8 @@ func (ps *PeerState) SetHasProposal(proposal *types.Proposal) {
return
}

ps.PRS.ProposalBlockPartSetHeader = proposal.BlockID.PartSetHeader
ps.PRS.ProposalBlockParts = bits.NewBitArray(int(proposal.BlockID.PartSetHeader.Total))
ps.PRS.ProposalBlockPartSetHeader = proposal.PartSetHeader
ps.PRS.ProposalBlockParts = bits.NewBitArray(int(proposal.PartSetHeader.Total))
ps.PRS.ProposalPOLRound = proposal.POLRound
ps.PRS.ProposalPOL = nil // Nil until ProposalPOLMessage received.
}
Expand Down
8 changes: 0 additions & 8 deletions consensus/reactor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -928,10 +928,6 @@ func TestVoteSetMaj23MessageValidateBasic(t *testing.T) {
validBlockID := types.BlockID{}
invalidBlockID := types.BlockID{
Hash: bytes.HexBytes{},
PartSetHeader: types.PartSetHeader{
Total: 1,
Hash: []byte{0},
},
}

testCases := []struct { // nolint: maligned
Expand Down Expand Up @@ -975,10 +971,6 @@ func TestVoteSetBitsMessageValidateBasic(t *testing.T) {
{func(msg *VoteSetBitsMessage) {
msg.BlockID = types.BlockID{
Hash: bytes.HexBytes{},
PartSetHeader: types.PartSetHeader{
Total: 1,
Hash: []byte{0},
},
}
}, "wrong BlockID: wrong PartSetHeader: wrong Hash:"},
{func(msg *VoteSetBitsMessage) { msg.Votes = bits.NewBitArray(types.MaxVotesCount + 1) },
Expand Down
2 changes: 1 addition & 1 deletion consensus/replay.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func (cs *State) readReplayMessage(msg *TimedWALMessage, newStepSub types.Subscr
case *ProposalMessage:
p := msg.Proposal
cs.Logger.Info("Replay: Proposal", "height", p.Height, "round", p.Round, "header",
p.BlockID.PartSetHeader, "pol", p.POLRound, "peer", peerID)
p.BlockID, "pol", p.POLRound, "peer", peerID)
case *BlockPartMessage:
cs.Logger.Info("Replay: BlockPart", "height", msg.Height, "round", msg.Round, "peer", peerID)
case *VoteMessage:
Expand Down
26 changes: 13 additions & 13 deletions consensus/replay_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -370,9 +370,9 @@ func TestSimulateValidatorsChange(t *testing.T) {
assert.Nil(t, err)
propBlock, _ := css[0].createProposalBlock() // changeProposer(t, cs1, vs2)
propBlockParts := propBlock.MakePartSet(partSize)
blockID := types.BlockID{Hash: propBlock.Hash(), PartSetHeader: propBlockParts.Header()}
blockID := types.BlockID{Hash: propBlock.Hash()}

proposal := types.NewProposal(vss[1].Height, round, -1, blockID, &propBlock.DataAvailabilityHeader)
proposal := types.NewProposal(vss[1].Height, round, -1, blockID, &propBlock.DataAvailabilityHeader, propBlockParts.Header())
p, err := proposal.ToProto()
require.NoError(t, err)
if err := vss[1].SignProposal(config.ChainID(), p); err != nil {
Expand Down Expand Up @@ -401,9 +401,9 @@ func TestSimulateValidatorsChange(t *testing.T) {
assert.Nil(t, err)
propBlock, _ = css[0].createProposalBlock() // changeProposer(t, cs1, vs2)
propBlockParts = propBlock.MakePartSet(partSize)
blockID = types.BlockID{Hash: propBlock.Hash(), PartSetHeader: propBlockParts.Header()}
blockID = types.BlockID{Hash: propBlock.Hash()}

proposal = types.NewProposal(vss[2].Height, round, -1, blockID, &propBlock.DataAvailabilityHeader)
proposal = types.NewProposal(vss[2].Height, round, -1, blockID, &propBlock.DataAvailabilityHeader, propBlockParts.Header())
p, err = proposal.ToProto()
require.NoError(t, err)
if err := vss[2].SignProposal(config.ChainID(), p); err != nil {
Expand Down Expand Up @@ -439,7 +439,7 @@ func TestSimulateValidatorsChange(t *testing.T) {
assert.Nil(t, err)
propBlock, _ = css[0].createProposalBlock() // changeProposer(t, cs1, vs2)
propBlockParts = propBlock.MakePartSet(partSize)
blockID = types.BlockID{Hash: propBlock.Hash(), PartSetHeader: propBlockParts.Header()}
blockID = types.BlockID{Hash: propBlock.Hash()}
newVss := make([]*validatorStub, nVals+1)
copy(newVss, vss[:nVals+1])
sort.Sort(ValidatorStubsByPower(newVss))
Expand All @@ -461,7 +461,7 @@ func TestSimulateValidatorsChange(t *testing.T) {

selfIndex := valIndexFn(0)

proposal = types.NewProposal(vss[3].Height, round, -1, blockID, &propBlock.DataAvailabilityHeader)
proposal = types.NewProposal(vss[3].Height, round, -1, blockID, &propBlock.DataAvailabilityHeader, propBlockParts.Header())
p, err = proposal.ToProto()
require.NoError(t, err)
if err := vss[3].SignProposal(config.ChainID(), p); err != nil {
Expand Down Expand Up @@ -515,13 +515,13 @@ func TestSimulateValidatorsChange(t *testing.T) {
assert.Nil(t, err)
propBlock, _ = css[0].createProposalBlock() // changeProposer(t, cs1, vs2)
propBlockParts = propBlock.MakePartSet(partSize)
blockID = types.BlockID{Hash: propBlock.Hash(), PartSetHeader: propBlockParts.Header()}
blockID = types.BlockID{Hash: propBlock.Hash()}
newVss = make([]*validatorStub, nVals+3)
copy(newVss, vss[:nVals+3])
sort.Sort(ValidatorStubsByPower(newVss))

selfIndex = valIndexFn(0)
proposal = types.NewProposal(vss[1].Height, round, -1, blockID, &propBlock.DataAvailabilityHeader)
proposal = types.NewProposal(vss[1].Height, round, -1, blockID, &propBlock.DataAvailabilityHeader, propBlockParts.Header())
p, err = proposal.ToProto()
require.NoError(t, err)
if err := vss[1].SignProposal(config.ChainID(), p); err != nil {
Expand Down Expand Up @@ -788,10 +788,9 @@ func testHandshakeReplay(t *testing.T, config *cfg.Config, nBlocks int, mode uin
}

func applyBlock(stateStore sm.Store, st sm.State, blk *types.Block, proxyApp proxy.AppConns) sm.State {
testPartSize := types.BlockPartSizeBytes
blockExec := sm.NewBlockExecutor(stateStore, log.TestingLogger(), proxyApp.Consensus(), mempool, evpool)

blkID := types.BlockID{Hash: blk.Hash(), PartSetHeader: blk.MakePartSet(testPartSize).Header()}
blkID := types.BlockID{Hash: blk.Hash()}
newState, _, err := blockExec.ApplyBlock(st, blkID, blk)
if err != nil {
panic(err)
Expand Down Expand Up @@ -1149,7 +1148,7 @@ func readPieceFromWAL(msg *TimedWALMessage) interface{} {
case msgInfo:
switch msg := m.Msg.(type) {
case *ProposalMessage:
return &msg.Proposal.BlockID.PartSetHeader
return &msg.Proposal.PartSetHeader
case *BlockPartMessage:
return msg.Part
case *VoteMessage:
Expand Down Expand Up @@ -1208,8 +1207,9 @@ func (bs *mockBlockStore) LoadBlockByHash(ctx context.Context, hash []byte) (*ty
func (bs *mockBlockStore) LoadBlockMeta(height int64) *types.BlockMeta {
block := bs.chain[height-1]
return &types.BlockMeta{
BlockID: types.BlockID{Hash: block.Hash(), PartSetHeader: block.MakePartSet(types.BlockPartSizeBytes).Header()},
Header: block.Header,
BlockID: types.BlockID{Hash: block.Hash()},
Header: block.Header,
PartSetHeader: block.MakePartSet(types.BlockPartSizeBytes).Header(),
}
}
func (bs *mockBlockStore) LoadBlockPart(height int64, index int) *types.Part { return nil }
Expand Down
Loading

0 comments on commit 664604e

Please sign in to comment.