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 1 commit
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
2 changes: 1 addition & 1 deletion CHANGELOG_PENDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Friendly reminder, we have a [bug bounty program](https://hackerone.com/tendermi

### FEATURES:

- [eventbus] add proposer and proposal info to CompleteProposal event
- [eventbus] create new event types for NewRound and CompleteProposal. add proposed block info to CompleteProposal event and proposer info to NewRound event
ebuchman marked this conversation as resolved.
Show resolved Hide resolved

### IMPROVEMENTS:

Expand Down
20 changes: 18 additions & 2 deletions consensus/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -405,8 +405,24 @@ func ensureNewVote(voteCh <-chan interface{}, height int64, round int) {
}

func ensureNewRound(roundCh <-chan interface{}, height int64, round int) {
ensureNewEvent(roundCh, height, round, ensureTimeout,
"Timeout expired while waiting for NewRound event")
select {
case <-time.After(ensureTimeout):
panic("Timeout expired while waiting for NewRound event")
case ev := <-roundCh:
rs, ok := ev.(types.EventDataNewRound)
if !ok {
panic(
fmt.Sprintf(
"expected a EventDataNewRound, got %v.Wrong subscription channel?",
reflect.TypeOf(rs)))
}
if rs.Height != height {
ebuchman marked this conversation as resolved.
Show resolved Hide resolved
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 ensureNewTimeout(timeoutCh <-chan interface{}, height int64, round int, timeout int64) {
Expand Down
2 changes: 1 addition & 1 deletion consensus/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -776,7 +776,7 @@ func (cs *ConsensusState) enterNewRound(height int64, round int) {
cs.Votes.SetRound(round + 1) // also track next round (round+1) to allow round-skipping
cs.triggeredTimeoutPrecommit = false

cs.eventBus.PublishEventNewRound(cs.RoundStateEvent())
cs.eventBus.PublishEventNewRound(cs.NewRoundEvent())
cs.metrics.Rounds.Set(float64(round))

// Wait for txs to be available in the mempool
Expand Down
18 changes: 14 additions & 4 deletions consensus/types/round_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,23 @@ func (rs *RoundState) RoundStateSimple() RoundStateSimple {
}
}

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

ednr := types.EventDataNewRound{
Height: rs.Height,
Round: rs.Round,
Step: rs.Step.String(),
ProposerAddress: addr,
ProposerIndex: idx,
}
return ednr
}

// CompleteProposalEvent returns information about a proposed block as an event.
func (rs *RoundState) CompleteProposalEvent() types.EventDataCompleteProposal {
// We must construct BlockID from ProposalBlock and ProposalBlockParts
// cs.Proposal is not guaranteed to be set when this function is called
blockId := types.BlockID{
Expand All @@ -128,8 +140,6 @@ func (rs *RoundState) CompleteProposalEvent() types.EventDataCompleteProposal {
Height: rs.Height,
Round: rs.Round,
Step: rs.Step.String(),
ProposerAddress: addr,
ProposerIndex: idx,
BlockID: blockId,
ebuchman marked this conversation as resolved.
Show resolved Hide resolved
}
return edcp
Expand Down
2 changes: 1 addition & 1 deletion types/event_bus.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func (b *EventBus) PublishEventTimeoutWait(data EventDataRoundState) error {
return b.Publish(EventTimeoutWait, data)
}

func (b *EventBus) PublishEventNewRound(data EventDataRoundState) error {
func (b *EventBus) PublishEventNewRound(data EventDataNewRound) error {
return b.Publish(EventNewRound, 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 @@ -96,7 +96,7 @@ func TestEventBusPublish(t *testing.T) {
require.NoError(t, err)
err = eventBus.PublishEventTimeoutWait(EventDataRoundState{})
require.NoError(t, err)
err = eventBus.PublishEventNewRound(EventDataRoundState{})
err = eventBus.PublishEventNewRound(EventDataNewRound{})
require.NoError(t, err)
err = eventBus.PublishEventCompleteProposal(EventDataCompleteProposal{})
require.NoError(t, err)
Expand Down
14 changes: 12 additions & 2 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(EventDataNewRound{}, "tendermint/event/NewRound", nil)
cdc.RegisterConcrete(EventDataCompleteProposal{}, "tendermint/event/CompleteProposal", nil)
cdc.RegisterConcrete(EventDataVote{}, "tendermint/event/Vote", nil)
cdc.RegisterConcrete(EventDataProposalHeartbeat{}, "tendermint/event/ProposalHeartbeat", nil)
Expand Down Expand Up @@ -81,12 +82,21 @@ type EventDataRoundState struct {
RoundState interface{} `json:"-"`
}

type EventDataNewRound struct {
Height int64 `json:"height"`
Round int `json:"round"`
Step string `json:"step"`
ProposerAddress Address `json:"proposer_address"`
kevlubkcm marked this conversation as resolved.
Show resolved Hide resolved
ProposerIndex int `json:"proposer_index"`

// private, not exposed to websockets
RoundState interface{} `json:"-"`
}

type EventDataCompleteProposal struct {
Height int64 `json:"height"`
Round int `json:"round"`
Step string `json:"step"`
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.

}

Expand Down