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

[R4R] Add proposer to NewRound event and proposal info to CompleteProposal event #2767

Merged
merged 14 commits into from
Nov 15, 2018
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 18 additions & 2 deletions consensus/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -416,8 +416,24 @@ func ensureNewTimeout(timeoutCh <-chan interface{}, height int64, round int, tim
}

func ensureNewProposal(proposalCh <-chan interface{}, height int64, round int) {
ensureNewEvent(proposalCh, height, round, ensureTimeout,
"Timeout expired while waiting for NewProposal event")
select {
case <-time.After(ensureTimeout):
panic("Timeout expired while waiting for NewProposal event")
case ev := <-proposalCh:
rs, ok := ev.(types.EventDataCompleteProposal)
if !ok {
panic(
fmt.Sprintf(
"expected a EventDataCompleteProposal, got %v.Wrong subscription channel?",
reflect.TypeOf(rs)))
}
if rs.Height != height {
panic(fmt.Sprintf("expected height %v, got %v", height, rs.Height))
}
if rs.Round != round {
panic(fmt.Sprintf("expected round %v, got %v", round, rs.Round))
}
}
}

func ensureNewValidBlock(validBlockCh <-chan interface{}, height int64, round int) {
Expand Down
4 changes: 2 additions & 2 deletions consensus/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -1408,7 +1408,7 @@ func (cs *ConsensusState) defaultSetProposal(proposal *types.Proposal) error {
return nil
}

// Verify POLRound, which must be -1 or in range [0, proposal.Round).
// Verify POLRound, which must be -1 or in range [0, proposal.Round).
if proposal.POLRound < -1 ||
(proposal.POLRound >= 0 && proposal.POLRound >= proposal.Round) {
return ErrInvalidProposalPOLRound
Expand Down Expand Up @@ -1466,7 +1466,7 @@ func (cs *ConsensusState) addProposalBlockPart(msg *BlockPartMessage, peerID p2p
}
// NOTE: it's possible to receive complete proposal blocks for future rounds without having the proposal
cs.Logger.Info("Received complete proposal block", "height", cs.ProposalBlock.Height, "hash", cs.ProposalBlock.Hash())
cs.eventBus.PublishEventCompleteProposal(cs.RoundStateEvent())
cs.eventBus.PublishEventCompleteProposal(cs.CompleteProposalEvent())

// Update Valid* if we can.
prevotes := cs.Votes.Prevotes(cs.Round)
Expand Down
22 changes: 22 additions & 0 deletions consensus/types/round_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,28 @@ func (rs *RoundState) RoundStateSimple() RoundStateSimple {
}
}

// CompleteProposalEvent returns information about a proposed block as an event.
func (rs *RoundState) CompleteProposalEvent() types.EventDataCompleteProposal {
addr := rs.Validators.GetProposer().Address
idx, _ := rs.Validators.GetByAddress(addr)

// We must construct BlockID from ProposalBlock and ProposalBlockParts
// cs.Proposal is not guaranteed to be set when this function is called
blockId := types.BlockID{
Hash: rs.ProposalBlock.Hash(),
PartsHeader: rs.ProposalBlockParts.Header(),
}

edcp := types.EventDataCompleteProposal{
ebuchman marked this conversation as resolved.
Show resolved Hide resolved
Height: rs.Height,
Round: rs.Round,
ProposerAddress: addr,
ProposerIndex: idx,
BlockID: blockId,
ebuchman marked this conversation as resolved.
Show resolved Hide resolved
}
return edcp
}

// RoundStateEvent returns the H/R/S of the RoundState as an event.
func (rs *RoundState) RoundStateEvent() types.EventDataRoundState {
// copy the RoundState.
Expand Down
2 changes: 1 addition & 1 deletion types/event_bus.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ func (b *EventBus) PublishEventNewRound(data EventDataRoundState) error {
return b.Publish(EventNewRound, data)
}

func (b *EventBus) PublishEventCompleteProposal(data EventDataRoundState) error {
func (b *EventBus) PublishEventCompleteProposal(data EventDataCompleteProposal) error {
return b.Publish(EventCompleteProposal, data)
}

Expand Down
2 changes: 1 addition & 1 deletion types/event_bus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func TestEventBusPublish(t *testing.T) {
require.NoError(t, err)
err = eventBus.PublishEventNewRound(EventDataRoundState{})
require.NoError(t, err)
err = eventBus.PublishEventCompleteProposal(EventDataRoundState{})
err = eventBus.PublishEventCompleteProposal(EventDataCompleteProposal{})
require.NoError(t, err)
err = eventBus.PublishEventPolka(EventDataRoundState{})
require.NoError(t, err)
Expand Down
9 changes: 9 additions & 0 deletions types/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ func RegisterEventDatas(cdc *amino.Codec) {
cdc.RegisterConcrete(EventDataNewBlockHeader{}, "tendermint/event/NewBlockHeader", nil)
cdc.RegisterConcrete(EventDataTx{}, "tendermint/event/Tx", nil)
cdc.RegisterConcrete(EventDataRoundState{}, "tendermint/event/RoundState", nil)
cdc.RegisterConcrete(EventDataCompleteProposal{}, "tendermint/event/CompleteProposal", nil)
cdc.RegisterConcrete(EventDataVote{}, "tendermint/event/Vote", nil)
cdc.RegisterConcrete(EventDataProposalHeartbeat{}, "tendermint/event/ProposalHeartbeat", nil)
cdc.RegisterConcrete(EventDataValidatorSetUpdates{}, "tendermint/event/ValidatorSetUpdates", nil)
Expand Down Expand Up @@ -80,6 +81,14 @@ type EventDataRoundState struct {
RoundState interface{} `json:"-"`
}

type EventDataCompleteProposal struct {
Height int64 `json:"height"`
Round int `json:"round"`
ProposerAddress Address `json:"proposer_address"`
ProposerIndex int `json:"proposer_index"`
BlockID BlockID `json:"block_id"`
kevlubkcm marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we want to add the ValidatorInfo to this event as well? Seems it would make sense

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I had it there at first, but EventDataNewRound seems like the correct place to put it. Can add it back if you like.

Copy link
Contributor

Choose a reason for hiding this comment

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

No worries. Let's leave it as is for now - can always add it later.

}

type EventDataVote struct {
Vote *Vote
}
Expand Down