diff --git a/Makefile b/Makefile index d130a5a869b..bb75cc65e50 100644 --- a/Makefile +++ b/Makefile @@ -16,4 +16,4 @@ fixalign: protoc: # Make sure the following prerequisites are installed before running these commands: # https://grpc.io/docs/languages/go/quickstart/#prerequisites - protoc --go_out=./ ./messages/proto/*.proto + protoc --go_out=./ ./messages/types/proto/*.proto diff --git a/core/broadcast.go b/core/broadcast.go new file mode 100644 index 00000000000..efa706c89a8 --- /dev/null +++ b/core/broadcast.go @@ -0,0 +1,108 @@ +package core + +import ( + "github.com/gnolang/go-tendermint/messages/types" +) + +// buildProposalMessage builds a proposal message using the given proposal +func (t *Tendermint) buildProposalMessage(proposal []byte) *types.ProposalMessage { + // TODO make thread safe + var ( + height = t.state.view.Height + round = t.state.view.Round + validRound = t.state.validRound + ) + + // Build the proposal message (assumes the node will sign it) + return &types.ProposalMessage{ + View: &types.View{ + Height: height, + Round: round, + }, + From: t.node.ID(), + Proposal: proposal, + ProposalRound: validRound, + } +} + +// buildPrevoteMessage builds a prevote message using the given proposal identifier +func (t *Tendermint) buildPrevoteMessage(id []byte) *types.PrevoteMessage { + // TODO make thread safe + var ( + height = t.state.view.Height + round = t.state.view.Round + + processID = t.node.ID() + ) + + return &types.PrevoteMessage{ + View: &types.View{ + Height: height, + Round: round, + }, + From: processID, + Identifier: id, + } +} + +// buildPrecommitMessage builds a precommit message using the given precommit identifier +func (t *Tendermint) buildPrecommitMessage(id []byte) *types.PrecommitMessage { + // TODO make thread safe + var ( + height = t.state.view.Height + round = t.state.view.Round + + processID = t.node.ID() + ) + + return &types.PrecommitMessage{ + View: &types.View{ + Height: height, + Round: round, + }, + From: processID, + Identifier: id, + } +} + +// broadcastProposal signs and broadcasts the given proposal message +func (t *Tendermint) broadcastProposal(proposal *types.ProposalMessage) { + message := &types.Message{ + Type: types.MessageType_PROPOSAL, + Signature: t.signer.Sign(proposal.Marshal()), + Payload: &types.Message_ProposalMessage{ + ProposalMessage: proposal, + }, + } + + // Broadcast the proposal message + t.broadcast.Broadcast(message) +} + +// broadcastPrevote signs and broadcasts the given prevote message +func (t *Tendermint) broadcastPrevote(prevote *types.PrevoteMessage) { + message := &types.Message{ + Type: types.MessageType_PREVOTE, + Signature: t.signer.Sign(prevote.Marshal()), + Payload: &types.Message_PrevoteMessage{ + PrevoteMessage: prevote, + }, + } + + // Broadcast the prevote message + t.broadcast.Broadcast(message) +} + +// broadcastPrecommit signs and broadcasts the given precommit message +func (t *Tendermint) broadcastPrecommit(precommit *types.PrecommitMessage) { + message := &types.Message{ + Type: types.MessageType_PRECOMMIT, + Signature: t.signer.Sign(precommit.Marshal()), + Payload: &types.Message_PrecommitMessage{ + PrecommitMessage: precommit, + }, + } + + // Broadcast the precommit message + t.broadcast.Broadcast(message) +} diff --git a/core/mocks_test.go b/core/mocks_test.go new file mode 100644 index 00000000000..55c6ffd3fb4 --- /dev/null +++ b/core/mocks_test.go @@ -0,0 +1,65 @@ +package core + +import "github.com/gnolang/go-tendermint/messages/types" + +type broadcastDelegate func(*types.Message) + +type mockBroadcast struct { + broadcastFn broadcastDelegate +} + +func (m *mockBroadcast) Broadcast(message *types.Message) { + if m.broadcastFn != nil { + m.broadcastFn(message) + } +} + +type ( + idDelegate func() []byte + hashDelegate func([]byte) []byte + buildProposalDelegate func(uint64) []byte +) + +type mockNode struct { + idFn idDelegate + hashFn hashDelegate + buildProposalFn buildProposalDelegate +} + +func (m *mockNode) ID() []byte { + if m.idFn != nil { + return m.idFn() + } + + return nil +} + +func (m *mockNode) Hash(proposal []byte) []byte { + if m.hashFn != nil { + return m.hashFn(proposal) + } + + return nil +} + +func (m *mockNode) BuildProposal(height uint64) []byte { + if m.buildProposalFn != nil { + return m.buildProposalFn(height) + } + + return nil +} + +type signDelegate func([]byte) []byte + +type mockSigner struct { + signFn signDelegate +} + +func (m *mockSigner) Sign(data []byte) []byte { + if m.signFn != nil { + return m.signFn(data) + } + + return nil +} diff --git a/core/state.go b/core/state.go new file mode 100644 index 00000000000..82ef7081f75 --- /dev/null +++ b/core/state.go @@ -0,0 +1,55 @@ +package core + +import "github.com/gnolang/go-tendermint/messages/types" + +// step is the current state step +type step uint8 + +const ( + propose step = iota + prevote + precommit +) + +func (n step) String() string { + switch n { + case propose: + return "propose" + case prevote: + return "prevote" + case precommit: + return "precommit" + } + + return "" +} + +// state holds information about the current consensus state +// TODO make thread safe +type state struct { + view *types.View + step step + + acceptedProposal *types.ProposalMessage + acceptedProposalID []byte + + lockedValue []byte + lockedRound int64 + + validValue []byte + validRound int64 +} + +// newState creates a fresh state using the given view +func newState(view *types.View) *state { + return &state{ + view: view, + step: propose, + acceptedProposal: nil, + acceptedProposalID: nil, + lockedValue: nil, + lockedRound: -1, + validValue: nil, + validRound: -1, + } +} diff --git a/core/store.go b/core/store.go new file mode 100644 index 00000000000..5b830da373c --- /dev/null +++ b/core/store.go @@ -0,0 +1,76 @@ +package core + +import ( + "github.com/gnolang/go-tendermint/messages" + "github.com/gnolang/go-tendermint/messages/types" +) + +// store is the message store +type store struct { + proposeMessages *messages.Collector[types.ProposalMessage] + prevoteMessages *messages.Collector[types.PrevoteMessage] + precommitMessages *messages.Collector[types.PrecommitMessage] +} + +// newStore creates a new message store +func newStore() *store { + return &store{ + proposeMessages: messages.NewCollector[types.ProposalMessage](), + prevoteMessages: messages.NewCollector[types.PrevoteMessage](), + precommitMessages: messages.NewCollector[types.PrecommitMessage](), + } +} + +// AddMessage adds a new message to the store +func (s *store) AddMessage(message *types.Message) { + switch message.Type { + case types.MessageType_PROPOSAL: + // Parse the propose message + wrappedMessage, ok := message.Payload.(*types.Message_ProposalMessage) + if !ok { + return + } + + // Get the proposal + proposal := wrappedMessage.ProposalMessage + + s.proposeMessages.AddMessage(proposal.View, proposal.From, proposal) + case types.MessageType_PREVOTE: + // Parse the prevote message + wrappedMessage, ok := message.Payload.(*types.Message_PrevoteMessage) + if !ok { + return + } + + // Get the prevote + prevote := wrappedMessage.PrevoteMessage + + s.prevoteMessages.AddMessage(prevote.View, prevote.From, prevote) + case types.MessageType_PRECOMMIT: + // Parse the precommit message + wrappedMessage, ok := message.Payload.(*types.Message_PrecommitMessage) + if !ok { + return + } + + // Get the precommit + precommit := wrappedMessage.PrecommitMessage + + s.precommitMessages.AddMessage(precommit.View, precommit.From, precommit) + } +} + +// SubscribeToPropose subscribes to incoming PROPOSE messages +func (s *store) SubscribeToPropose() (<-chan func() []*types.ProposalMessage, func()) { + return s.proposeMessages.Subscribe() +} + +// SubscribeToPrevote subscribes to incoming PREVOTE messages +func (s *store) SubscribeToPrevote() (<-chan func() []*types.PrevoteMessage, func()) { + return s.prevoteMessages.Subscribe() +} + +// SubscribeToPrecommit subscribes to incoming PRECOMMIT messages +func (s *store) SubscribeToPrecommit() (<-chan func() []*types.PrecommitMessage, func()) { + return s.precommitMessages.Subscribe() +} diff --git a/core/tendermint.go b/core/tendermint.go index eede6fb0f27..96a2fc0003e 100644 --- a/core/tendermint.go +++ b/core/tendermint.go @@ -1,207 +1,316 @@ package core import ( - "bytes" "context" - "errors" - "fmt" - "time" + "sync" + + "github.com/gnolang/go-tendermint/messages/types" ) -type State int +// TODO define the finalized proposal -const ( - Propose State = iota - Prevote - Precommit -) +type Tendermint struct { + verifier Verifier + node Node + broadcast Broadcast + signer Signer -type Proposer interface { - Get(height uint64, block []byte, round int64) []byte - Me() []byte -} + // wg is the barrier for keeping all + // parallel consensus processes synced + wg sync.WaitGroup -type Broadcast interface { - Broadcast(state State, height uint64, round int64, block []byte) -} + // state is the current Tendermint consensus state + state *state -type BlockValidator interface { - IsValid(height uint64, block []byte) bool - IsMajority(votes int) bool -} + // store is the message store + store *store -// TODO define the finalized proposal + // roundExpired is the channel for signalizing + // round change events (to the next round, from the current one) + roundExpired chan struct{} -// `NewTendermint` and `Init` must be called, -// in that order. before any messages can be processed -type Tendermint struct { - state State - round int64 - lockedBlock []byte - lockedRound int64 - validBlock []byte - validRound int64 - init bool - cfg *Config - validMsgsCnt [Precommit + 1]int - done bool + // timeouts hold state timeout information (constant) + timeouts map[step]timeout } -type Config struct { - ctx context.Context - height uint64 - p Proposer - b Broadcast - timeout time.Duration - block []byte - bv BlockValidator -} +// RunSequence runs the Tendermint consensus sequence for a given height, +// returning only when a proposal has been finalized (consensus reached), or +// the context has been cancelled +func (t *Tendermint) RunSequence(ctx context.Context, h uint64) []byte { + // Initialize the state before starting the sequence + t.state = newState(&types.View{ + Height: h, + Round: 0, + }) + + for { + // Set up the round context + ctxRound, cancelRound := context.WithCancel(ctx) + teardown := func() { + cancelRound() + t.wg.Wait() + } + + select { + case proposal := <-t.finalizeProposal(ctxRound): + teardown() + + return proposal + case _ = <-t.watchForRoundJumps(ctxRound): + teardown() -func NewTendermint(cfg *Config) *Tendermint { - t := &Tendermint{ - state: Propose, - round: 0, - lockedBlock: nil, - lockedRound: -1, - validBlock: nil, - validRound: -1, - cfg: cfg, - validMsgsCnt: [Precommit + 1]int{0, 0, 0}, + // TODO start NEW round (that was received) + case <-t.roundExpired: + teardown() + + // TODO start NEXT round (view.Round + 1) + case <-ctx.Done(): + teardown() + + // TODO log + return nil + } } +} - return t +// watchForRoundJumps monitors for F+1 (any) messages from a future round, and +// triggers the round switch context (channel) accordingly +func (t *Tendermint) watchForRoundJumps(ctx context.Context) <-chan uint64 { + // TODO make thread safe + var ( + _ = t.state.view + ch = make(chan uint64, 1) + ) + + t.wg.Add(1) + + go func() { + proposeCh, unsubscribeProposeFn := t.store.SubscribeToPropose() + prevoteCh, unsubscribePrevoteFn := t.store.SubscribeToPrevote() + precommitCh, unsubscribePrecommitFn := t.store.SubscribeToPrecommit() + + defer func() { + unsubscribeProposeFn() + unsubscribePrevoteFn() + unsubscribePrecommitFn() + }() + + signalRoundJump := func(round uint64) { + select { + case <-ctx.Done(): + case ch <- round: + } + } + + for { + select { + case <-ctx.Done(): + return + case getProposeFn := <-proposeCh: + // TODO count messages + _ = getProposeFn() + case getPrevoteFn := <-prevoteCh: + // TODO count messages + _ = getPrevoteFn() + case getPrecommitFn := <-precommitCh: + // TODO count messages + _ = getPrecommitFn() + } + + // TODO check if the condition (F+1) is met + // and signal the round jump + if false { + signalRoundJump(0) + } + } + }() + + return ch } -type Msg struct { - state State - height uint64 - round int64 - block []byte - from []byte +// finalizeProposal starts the proposal finalization sequence +func (t *Tendermint) finalizeProposal(ctx context.Context) <-chan []byte { + ch := make(chan []byte, 1) + + t.wg.Add(1) + + go func() { + defer func() { + close(ch) + t.wg.Done() + }() + + // Start the consensus round + t.startRound(ctx) + + // Run the consensus state machine, and save the finalized proposal (if any) + if finalizedProposal := t.runStates(ctx); finalizedProposal != nil { + ch <- finalizedProposal + } + }() + + return ch } -func (t *Tendermint) Init() error { - if !t.cfg.bv.IsValid(t.cfg.height, t.cfg.block) { - return errors.New(fmt.Sprintf("invalid height: %v block: %v\n", t.cfg.height, t.cfg.block)) +// startRound starts the consensus round. +// It is a required middle step (proposal evaluation) before +// the state machine is in full swing and +// the runs the same flow for everyone (proposer / non-proposers) +func (t *Tendermint) startRound(ctx context.Context) { + // TODO make thread safe + // Check if the current process is the proposer for this view + if !t.verifier.IsProposer(t.node.ID(), t.state.view.Height, t.state.view.Round) { + // The current process is NOT the proposer, only schedule a timeout + t.scheduleTimeoutPropose(ctx) + + return } - t.init = true - proposer := t.cfg.p.Get(t.cfg.height, t.cfg.block, t.round) + // The proposal value can either be: + // - an old (valid / locked) proposal from a previous round + // - a completely new proposal (built from scratch) + proposal := t.state.validValue - if bytes.Equal(t.cfg.p.Me(), proposer) { - t.cfg.b.Broadcast(Propose, t.cfg.height, t.round, t.cfg.block) - } else { - time.Sleep(t.cfg.timeout) - t.cfg.b.Broadcast(Prevote, t.cfg.height, t.round, t.cfg.block) - t.state = Prevote + // Check if a new proposal needs to be built + if proposal == nil { + // No previous valid value present, + // build a new proposal + proposal = t.node.BuildProposal(t.state.view.Height) } - return nil + + // Build the propose message + var ( + proposeMessage = t.buildProposalMessage(proposal) + id = t.node.Hash(proposal) + ) + + // Broadcast the proposal to other consensus nodes + t.broadcastProposal(proposeMessage) + + // TODO make thread safe + // Save the accepted proposal in the state. + // NOTE: This is different from validValue / lockedValue, + // since they require a 2F+1 quorum of specific messages + // in order to be set, whereas this is simply a reference + // value for different states (prevote, precommit) + t.state.acceptedProposal = proposeMessage + t.state.acceptedProposalID = id + + // Build and broadcast the prevote message + t.broadcastPrevote(t.buildPrevoteMessage(id)) + + // Since the current process is the proposer, + // it can directly move to the prevote state + // TODO make threads safe + t.state.step = prevote } -// ProcessMsg accepts a *Msg and potentially advances the state -// of the consensus. It returns an error if there was such and a boolean -// value indicating whether consensus has been reached or not. -func (t *Tendermint) ProcessMsg(m *Msg) (error, bool) { - if !t.cfg.bv.IsValid(m.height, m.block) { - return errors.New(fmt.Sprintf("invalid height: %v block: %v\n", m.height, m.block)), false - } - if !t.init { - return errors.New("not initialized"), false +// runStates runs the consensus states, depending on the current step +func (t *Tendermint) runStates(ctx context.Context) []byte { + for { + // TODO make thread safe + switch t.state.step { + case propose: + t.runPropose(ctx) + case prevote: + t.runPrevote(ctx) + case precommit: + return t.runPrecommit(ctx) + } } +} - if m.height != t.cfg.height { - return errors.New(fmt.Sprintf("expected height: %v got: %v\n", t.cfg.height, m.height)), false - } +// runPropose runs the propose state in which the process +// waits for a valid PROPOSE message +func (t *Tendermint) runPropose(ctx context.Context) { + // TODO make thread safe + var ( + _ = t.state.view + ) - proposer := t.cfg.p.Get(t.cfg.height, t.cfg.block, t.round) + ch, unsubscribeFn := t.store.SubscribeToPropose() + defer unsubscribeFn() - switch m.state { - case Propose: - if !bytes.Equal(m.from, proposer) { - return errors.New(fmt.Sprintf("expected proposer: %v got: %v\n", proposer, m.from)), false - } + for { + select { + case <-ctx.Done(): + return + case getMessagesFn := <-ch: + // TODO filter and verify messages + _ = getMessagesFn() - switch { - //22: - case t.state == Propose && t.validRound == -1: - if t.lockedRound == -1 || bytes.Equal(t.lockedBlock, m.block) { - t.cfg.b.Broadcast(Prevote, m.height, m.round, m.block) - } else { - t.cfg.b.Broadcast(Prevote, m.height, m.round, nil) - } - //28: - case t.state == Propose && t.cfg.bv.IsMajority(t.validMsgsCnt[Prevote]): - if t.validRound >= 0 || t.validRound < t.round { - if t.lockedRound == -1 || bytes.Equal(t.lockedBlock, m.block) { - t.cfg.b.Broadcast(Prevote, m.height, m.round, m.block) - } else { - t.cfg.b.Broadcast(Prevote, m.height, m.round, nil) - } - } - //36: - case t.state >= Prevote && t.cfg.bv.IsMajority(t.validMsgsCnt[Prevote]): - if t.state == Prevote { - t.lockedBlock = m.block - t.lockedRound = m.round - t.cfg.b.Broadcast(Precommit, m.height, m.round, m.block) - t.state = Precommit - } - t.validBlock = m.block - t.validRound = t.round - - //49: - case t.state >= Prevote && t.cfg.bv.IsMajority(t.validMsgsCnt[Precommit]): - decision := true //while decision[t.height] == nil - - if decision { - //decision[t.height] == m.block - t.cfg.height += 1 - t.round = 0 - err := t.Init() - - if err != nil { - return err, false - } - } + // TODO move to prevote if the proposal is valid } + } +} - t.state = Prevote - t.validMsgsCnt[Propose] += 1 - case Prevote: - if t.state == Prevote && t.cfg.bv.IsMajority(t.validMsgsCnt[Prevote]) { - //44: - if m.block == nil { - t.cfg.b.Broadcast(Precommit, t.cfg.height, t.round, nil) - } else { - //34: - time.Sleep(t.cfg.timeout) - if t.round == m.round && t.state == Prevote { - t.cfg.b.Broadcast(Precommit, t.cfg.height, t.round, t.cfg.block) - } - } - t.state = Precommit +// runPrevote runs the prevote state in which the process +// waits for a valid PREVOTE messages +func (t *Tendermint) runPrevote(ctx context.Context) { + // TODO make thread safe + var ( + _ = t.state.view + ) + + ch, unsubscribeFn := t.store.SubscribeToPrevote() + defer unsubscribeFn() + + for { + select { + case <-ctx.Done(): + return + case getMessagesFn := <-ch: + // TODO filter and verify messages + _ = getMessagesFn() + + // TODO move to precommit if the proposal is valid } + } +} - t.validMsgsCnt[Prevote] += 1 - //47: - case Precommit: - if m.round == t.round && t.cfg.bv.IsMajority(t.validMsgsCnt[Precommit]) { - var err error +// runPrecommit runs the precommit state in which the process +// waits for a valid PRECOMMIT messages +func (t *Tendermint) runPrecommit(ctx context.Context) []byte { + // TODO make thread safe + var ( + _ = t.state.view + ) - time.Sleep(t.cfg.timeout) - if t.round == m.round && t.state == Prevote { - t.round += 1 - err = t.Init() - } + ch, unsubscribeFn := t.store.SubscribeToPrecommit() + defer unsubscribeFn() - if err != nil { - return err, false - } - t.done = true + for { + select { + case <-ctx.Done(): + return nil + case getMessagesFn := <-ch: + // TODO filter and verify messages + _ = getMessagesFn() + + // TODO move to precommit if the proposal is valid } + } +} + +// AddMessage verifies and adds a new message to the consensus engine +func (t *Tendermint) AddMessage(message *types.Message) { + // Make sure the message is present + if message == nil { + return + } - t.validMsgsCnt[Precommit] += 1 + // Make sure the message payload is present + if message.Payload == nil { + return } - return nil, t.done + // TODO verify the message sender + + // TODO verify the message signature + + // TODO verify the message height + + // TODO verify the message round + + // TODO verify the message content (fields set) } diff --git a/core/tendermint_test.go b/core/tendermint_test.go deleted file mode 100644 index c7331c65e01..00000000000 --- a/core/tendermint_test.go +++ /dev/null @@ -1,201 +0,0 @@ -package core - -import ( - "errors" - "fmt" - "testing" - "time" -) - -type blMock struct { - validBlocks map[uint64]bool - isMajority bool -} - -func (b *blMock) IsValid(height uint64, block []byte) bool { - valid, ok := b.validBlocks[height] - if !ok { - // Default to true if height is not specified in the map - return true - } - return valid -} - -func (b *blMock) IsMajority(votes int) bool { - return b.isMajority -} - -type brMock struct{} - -func (b *brMock) Broadcast(state State, height uint64, round int64, block []byte) {} - -type prMock struct { - getFunc func(height uint64, block []byte, round int64) []byte - me []byte -} - -func (b *prMock) Get(height uint64, block []byte, round int64) []byte { - return b.getFunc(height, block, round) -} - -func (b *prMock) Me() []byte { - return b.me -} - -func TestTendermint_ProcessMsgOk(t *testing.T) { - tm := NewTendermint(&Config{ - ctx: nil, - height: 0, - p: &prMock{getFunc: func(height uint64, block []byte, round int64) []byte { - return []byte{0, 1, 2} - }, me: []byte{0, 1, 2}}, - b: &brMock{}, - timeout: 0, - block: nil, - bv: &blMock{ - isMajority: true, - validBlocks: map[uint64]bool{ - 1: true, // Height 1 is valid - 2: false, // Height 2 is invalid - }, - }, - }) - - err := tm.Init() - - if err != nil { - panic(err) - } - - err, finished := tm.ProcessMsg(&Msg{ - state: Propose, - height: 0, - round: 0, - block: []byte{1, 2, 3}, - from: []byte{0, 1, 2}, - }) - - if err != nil { - panic(err) - } - - err, finished = tm.ProcessMsg(&Msg{ - state: Prevote, - height: 0, - round: 0, - block: []byte{1, 2, 3}, - from: []byte{0, 1, 2}, - }) - - if err != nil { - panic(err) - } - - if finished { - panic("should not have finish as true on prevote") - } - - if tm.state != Precommit { - panic(fmt.Sprintf("expected state to be Precommit after majority Prevote, got: %+v", tm.state)) - } - - err, finished = tm.ProcessMsg(&Msg{ - state: Precommit, - height: 0, - round: 0, - block: []byte{1, 2, 3}, - from: []byte{0, 1, 2}, - }) - - if err != nil { - panic(err) - } - - if !finished { - panic("should have finish as true on majority Precommit") - } - - if tm.state != Precommit { - panic(fmt.Sprintf("expected state to be Precommit after majority Precommit, got: %+v", tm.state)) - } -} - -func TestTendermint_ProcessMsg(t *testing.T) { - cfg := &Config{ - ctx: nil, - height: 1, - p: &prMock{ - getFunc: func(height uint64, block []byte, round int64) []byte { - // Mock behavior for proposer get function - return []byte("MockProposer") - }, - me: []byte("MockProposer"), - }, - b: &brMock{}, - timeout: time.Second, - block: []byte("block"), - bv: &blMock{ - validBlocks: map[uint64]bool{ - 1: true, // Height 1 is valid - 2: false, // Height 2 is invalid - }, - isMajority: true, - }, - } - - // Create a new Tendermint instance - tendermint := NewTendermint(cfg) - - // Initialize Tendermint - err := tendermint.Init() - if err != nil { - t.Errorf("Error initializing Tendermint: %v", err) - } - - // Define test scenarios - tests := []struct { - name string - mockMsg *Msg - expectedErr error - expectedDone bool - }{ - { - name: "Valid Proposal", - mockMsg: &Msg{ - state: Propose, - height: 1, - round: 0, - block: []byte("block"), - from: []byte("MockProposer"), - }, - expectedErr: nil, - expectedDone: false, - }, - { - name: "Invalid Block", - mockMsg: &Msg{ - state: Propose, - height: 2, - round: 0, - block: []byte("invalid_block"), - from: []byte("MockProposer"), - }, - expectedErr: errors.New("invalid height: 2 block: [105 110 118 97 108 105 100 95 98 108 111 99 107]\n"), - expectedDone: false, - }, - // Add more test scenarios as needed - } - - // Run test scenarios - for _, test := range tests { - t.Run(test.name, func(t *testing.T) { - err, done := tendermint.ProcessMsg(test.mockMsg) - if (err != nil && test.expectedErr == nil) || (err == nil && test.expectedErr != nil) || (err != nil && test.expectedErr != nil && err.Error() != test.expectedErr.Error()) { - t.Errorf("Error mismatch for test '%s'. Expected: %v, Got: %v", test.name, test.expectedErr, err) - } - if done != test.expectedDone { - t.Errorf("Done status mismatch for test '%s'. Expected: %v, Got: %v", test.name, test.expectedDone, done) - } - }) - } -} diff --git a/core/timeout.go b/core/timeout.go new file mode 100644 index 00000000000..42dfb182bb3 --- /dev/null +++ b/core/timeout.go @@ -0,0 +1,68 @@ +package core + +import ( + "context" + "time" +) + +// timeout is a holder for timeout duration information (constant) +type timeout struct { + initial time.Duration // the initial timeout duration + delta time.Duration // the delta for future timeouts +} + +// calculateTimeout calculates a new timeout duration using +// the formula: +// +// timeout(r) = initTimeout + r * timeoutDelta +func (t timeout) calculateTimeout(round uint64) time.Duration { + return t.initial + time.Duration(round)*t.delta +} + +// scheduleTimeoutPropose schedules a future timeout propose trigger +func (t *Tendermint) scheduleTimeoutPropose(ctx context.Context) { + // TODO Make thread safe + // Fetch the current view, before the trigger is set + var ( + round = t.state.view.Round + + timeoutPropose = t.timeouts[t.state.step].calculateTimeout(round) + ) + + t.wg.Add(1) + + go func() { + defer t.wg.Done() + + select { + case <-ctx.Done(): + case <-time.After(timeoutPropose): + t.onTimeoutPropose(round) + } + }() +} + +// onTimeoutPropose executes the step +// as a result of the propose step timer going off +func (t *Tendermint) onTimeoutPropose(round uint64) { + // TODO make thread safe + var ( + // TODO Evaluate if the round information is even required. + // We cancel the top-level timeout context upon every round change, + // so this condition that the round != currentRound will always be false. + // Essentially, I believe the only param we do need to check is + // the current state in the SM, since this method can be executed async when + // the SM is in a different state + currentRound = t.state.view.Round + currentStep = t.state.step + ) + + // Make sure the timeout context is still valid + if currentRound != round || currentStep != propose { + // Timeout context no longer valid, ignore + return + } + + // Build and broadcast the prevote message, with an ID of NIL + t.broadcastPrevote(t.buildPrevoteMessage(nil)) +} diff --git a/core/timeout_test.go b/core/timeout_test.go new file mode 100644 index 00000000000..586fcb22efa --- /dev/null +++ b/core/timeout_test.go @@ -0,0 +1,103 @@ +package core + +import ( + "context" + "testing" + "time" + + "github.com/gnolang/go-tendermint/messages/types" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +func TestTimeout_CalculateTimeout(t *testing.T) { + t.Parallel() + + var ( + initial = 10 * time.Second + delta = 200 * time.Millisecond + + timeout = timeout{ + initial: initial, + delta: delta, + } + ) + + for round := uint64(0); round < 100; round++ { + assert.Equal( + t, + initial+time.Duration(round)*delta, + timeout.calculateTimeout(round), + ) + } +} + +func TestTimeout_ScheduleTimeoutPropose(t *testing.T) { + t.Parallel() + + var ( + capturedMessage *types.Message + id = []byte("node ID") + signature = []byte("signature") + view = &types.View{ + Height: 10, + Round: 0, + } + + mockBroadcast = &mockBroadcast{ + broadcastFn: func(message *types.Message) { + capturedMessage = message + }, + } + + mockNode = &mockNode{ + idFn: func() []byte { + return id + }, + } + + mockSigner = &mockSigner{ + signFn: func(_ []byte) []byte { + return signature + }, + } + ) + + tm := &Tendermint{ + state: newState(view), + timeouts: make(map[step]timeout), + broadcast: mockBroadcast, + node: mockNode, + signer: mockSigner, + } + + // Set the timeout data for the propose step + tm.timeouts[propose] = timeout{ + initial: 50 * time.Millisecond, + delta: 50 * time.Millisecond, + } + + // Schedule the timeout + ctx, cancelFn := context.WithTimeout(context.Background(), 5*time.Second) + defer cancelFn() + + tm.scheduleTimeoutPropose(ctx) + + // Wait for the timer to trigger + tm.wg.Wait() + + // Validate the prevote message was sent with a NIL value + require.NotNil(t, capturedMessage) + + require.Equal(t, capturedMessage.Type, types.MessageType_PREVOTE) + + message, ok := capturedMessage.Payload.(*types.Message_PrevoteMessage) + require.True(t, ok) + + assert.Equal(t, signature, capturedMessage.Signature) + + assert.Nil(t, message.PrevoteMessage.Identifier) + assert.Equal(t, id, message.PrevoteMessage.From) + assert.Equal(t, view.GetHeight(), message.PrevoteMessage.View.GetHeight()) + assert.Equal(t, view.GetRound(), message.PrevoteMessage.View.GetRound()) +} diff --git a/core/types.go b/core/types.go new file mode 100644 index 00000000000..392322f6af0 --- /dev/null +++ b/core/types.go @@ -0,0 +1,25 @@ +package core + +import ( + "github.com/gnolang/go-tendermint/messages/types" +) + +type Signer interface { + Sign(data []byte) []byte +} + +type Verifier interface { + IsProposer(id []byte, height uint64, round uint64) bool +} + +type Node interface { + ID() []byte + + Hash(proposal []byte) []byte + + BuildProposal(height uint64) []byte +} + +type Broadcast interface { + Broadcast(message *types.Message) +} diff --git a/messages/collector.go b/messages/collector.go index baed2deac52..f16dd3843f4 100644 --- a/messages/collector.go +++ b/messages/collector.go @@ -3,12 +3,14 @@ package messages import ( "fmt" "sync" + + "github.com/gnolang/go-tendermint/messages/types" ) // msgType is the combined message type interface, // for easy reference and type safety type msgType interface { - ProposalMessage | PrevoteMessage | PrecommitMessage + types.ProposalMessage | types.PrevoteMessage | types.PrecommitMessage } type ( @@ -41,7 +43,7 @@ func NewCollector[T msgType]() *Collector[T] { // Subscribe creates a new collector subscription. // Returns the channel for receiving messages, // as well as the unsubscribe method -func (c *Collector[T]) Subscribe() (<-chan MsgCallback[T], func()) { +func (c *Collector[T]) Subscribe() (<-chan func() []*T, func()) { c.subscriptionsMux.Lock() defer c.subscriptionsMux.Unlock() @@ -86,7 +88,7 @@ func (c *collection[T]) getMessages() []*T { } // AddMessage adds a new message to the collector -func (c *Collector[T]) AddMessage(view *View, from []byte, message *T) { +func (c *Collector[T]) AddMessage(view *types.View, from []byte, message *T) { c.collectionMux.Lock() // Add the message @@ -112,6 +114,6 @@ func (c *collection[T]) addMessage(key string, message *T) { // getCollectionKey constructs a key based on the // message sender and view information. // This key guarantees uniqueness in the message store -func getCollectionKey(from []byte, view *View) string { +func getCollectionKey(from []byte, view *types.View) string { return fmt.Sprintf("%s_%d_%d", from, view.Height, view.Round) } diff --git a/messages/collector_test.go b/messages/collector_test.go index fdcc23156c6..28e6265086a 100644 --- a/messages/collector_test.go +++ b/messages/collector_test.go @@ -7,6 +7,7 @@ import ( "testing" "time" + "github.com/gnolang/go-tendermint/messages/types" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -16,37 +17,37 @@ import ( func generateMessages( t *testing.T, count int, - view *View, - messageTypes ...MessageType, -) []*Message { + view *types.View, + messageTypes ...types.MessageType, +) []*types.Message { t.Helper() - messages := make([]*Message, 0, count) + messages := make([]*types.Message, 0, count) for index := 0; index < count; index++ { for _, messageType := range messageTypes { - message := &Message{ + message := &types.Message{ Type: messageType, } switch messageType { - case MessageType_PROPOSAL: - message.Payload = &Message_ProposalMessage{ - ProposalMessage: &ProposalMessage{ + case types.MessageType_PROPOSAL: + message.Payload = &types.Message_ProposalMessage{ + ProposalMessage: &types.ProposalMessage{ From: []byte(strconv.Itoa(index)), View: view, }, } - case MessageType_PREVOTE: - message.Payload = &Message_PrevoteMessage{ - PrevoteMessage: &PrevoteMessage{ + case types.MessageType_PREVOTE: + message.Payload = &types.Message_PrevoteMessage{ + PrevoteMessage: &types.PrevoteMessage{ From: []byte(strconv.Itoa(index)), View: view, }, } - case MessageType_PRECOMMIT: - message.Payload = &Message_PrecommitMessage{ - PrecommitMessage: &PrecommitMessage{ + case types.MessageType_PRECOMMIT: + message.Payload = &types.Message_PrecommitMessage{ + PrecommitMessage: &types.PrecommitMessage{ From: []byte(strconv.Itoa(index)), View: view, }, @@ -67,7 +68,7 @@ func TestCollector_AddMessage(t *testing.T) { t.Parallel() // Create the collector - c := NewCollector[ProposalMessage]() + c := NewCollector[types.ProposalMessage]() // Fetch the messages messages := c.GetMessages() @@ -81,26 +82,26 @@ func TestCollector_AddMessage(t *testing.T) { var ( count = 5 - initialView = &View{ + initialView = &types.View{ Height: 1, Round: 0, } ) // Create the collector - c := NewCollector[ProposalMessage]() + c := NewCollector[types.ProposalMessage]() generatedMessages := generateMessages( t, count, initialView, - MessageType_PROPOSAL, + types.MessageType_PROPOSAL, ) - expectedMessages := make([]*ProposalMessage, 0, count) + expectedMessages := make([]*types.ProposalMessage, 0, count) for _, message := range generatedMessages { - proposal, ok := message.Payload.(*Message_ProposalMessage) + proposal, ok := message.Payload.(*types.Message_ProposalMessage) require.True(t, ok) c.AddMessage(proposal.ProposalMessage.View, proposal.ProposalMessage.From, proposal.ProposalMessage) @@ -130,26 +131,26 @@ func TestCollector_AddMessage(t *testing.T) { var ( count = 5 - initialView = &View{ + initialView = &types.View{ Height: 1, Round: 0, } ) // Create the collector - c := NewCollector[PrevoteMessage]() + c := NewCollector[types.PrevoteMessage]() generatedMessages := generateMessages( t, count, initialView, - MessageType_PREVOTE, + types.MessageType_PREVOTE, ) - expectedMessages := make([]*PrevoteMessage, 0, count) + expectedMessages := make([]*types.PrevoteMessage, 0, count) for _, message := range generatedMessages { - prevote, ok := message.Payload.(*Message_PrevoteMessage) + prevote, ok := message.Payload.(*types.Message_PrevoteMessage) require.True(t, ok) c.AddMessage(prevote.PrevoteMessage.View, prevote.PrevoteMessage.From, prevote.PrevoteMessage) @@ -179,26 +180,26 @@ func TestCollector_AddMessage(t *testing.T) { var ( count = 5 - initialView = &View{ + initialView = &types.View{ Height: 1, Round: 0, } ) // Create the collector - c := NewCollector[PrecommitMessage]() + c := NewCollector[types.PrecommitMessage]() generatedMessages := generateMessages( t, count, initialView, - MessageType_PRECOMMIT, + types.MessageType_PRECOMMIT, ) - expectedMessages := make([]*PrecommitMessage, 0, count) + expectedMessages := make([]*types.PrecommitMessage, 0, count) for _, message := range generatedMessages { - precommit, ok := message.Payload.(*Message_PrecommitMessage) + precommit, ok := message.Payload.(*types.Message_PrecommitMessage) require.True(t, ok) c.AddMessage(precommit.PrecommitMessage.View, precommit.PrecommitMessage.From, precommit.PrecommitMessage) @@ -230,15 +231,15 @@ func TestCollector_AddDuplicateMessages(t *testing.T) { var ( count = 5 commonSender = []byte("sender 1") - commonType = MessageType_PREVOTE - view = &View{ + commonType = types.MessageType_PREVOTE + view = &types.View{ Height: 1, Round: 1, } ) // Create the collector - c := NewCollector[PrevoteMessage]() + c := NewCollector[types.PrevoteMessage]() generatedMessages := generateMessages( t, @@ -248,7 +249,7 @@ func TestCollector_AddDuplicateMessages(t *testing.T) { ) for _, message := range generatedMessages { - prevote, ok := message.Payload.(*Message_PrevoteMessage) + prevote, ok := message.Payload.(*types.Message_PrevoteMessage) require.True(t, ok) // Make sure each message is from the same sender @@ -269,26 +270,26 @@ func TestCollector_Subscribe(t *testing.T) { var ( count = 100 - view = &View{ + view = &types.View{ Height: 1, Round: 0, } ) // Create the collector - c := NewCollector[PrevoteMessage]() + c := NewCollector[types.PrevoteMessage]() generatedMessages := generateMessages( t, count, view, - MessageType_PREVOTE, + types.MessageType_PREVOTE, ) - expectedMessages := make([]*PrevoteMessage, 0, count) + expectedMessages := make([]*types.PrevoteMessage, 0, count) for _, message := range generatedMessages { - prevote, ok := message.Payload.(*Message_PrevoteMessage) + prevote, ok := message.Payload.(*types.Message_PrevoteMessage) require.True(t, ok) c.AddMessage(prevote.PrevoteMessage.View, prevote.PrevoteMessage.From, prevote.PrevoteMessage) @@ -300,7 +301,7 @@ func TestCollector_Subscribe(t *testing.T) { notifyCh, unsubscribeFn := c.Subscribe() defer unsubscribeFn() - var messages []*PrevoteMessage + var messages []*types.PrevoteMessage select { case callback := <-notifyCh: @@ -327,30 +328,30 @@ func TestCollector_Subscribe(t *testing.T) { var ( count = 100 - view = &View{ + view = &types.View{ Height: 1, Round: 0, } ) // Create the collector - c := NewCollector[PrevoteMessage]() + c := NewCollector[types.PrevoteMessage]() generatedMessages := generateMessages( t, count, view, - MessageType_PREVOTE, + types.MessageType_PREVOTE, ) - expectedMessages := make([]*PrevoteMessage, 0, count) + expectedMessages := make([]*types.PrevoteMessage, 0, count) // Create a subscription notifyCh, unsubscribeFn := c.Subscribe() defer unsubscribeFn() for _, message := range generatedMessages { - prevote, ok := message.Payload.(*Message_PrevoteMessage) + prevote, ok := message.Payload.(*types.Message_PrevoteMessage) require.True(t, ok) c.AddMessage(prevote.PrevoteMessage.View, prevote.PrevoteMessage.From, prevote.PrevoteMessage) @@ -359,7 +360,7 @@ func TestCollector_Subscribe(t *testing.T) { } var ( - messages []*PrevoteMessage + messages []*types.PrevoteMessage wg sync.WaitGroup ) diff --git a/messages/subscription.go b/messages/subscription.go index d537566d820..c3d3c23333d 100644 --- a/messages/subscription.go +++ b/messages/subscription.go @@ -9,15 +9,15 @@ type ( // subscriptions is the subscription store, // maps subscription id -> notification channel. // Usage of this type is NOT thread safe - subscriptions[T msgType] map[string]chan MsgCallback[T] + subscriptions[T msgType] map[string]chan func() []*T ) // add adds a new subscription to the subscription map. // Returns the subscription ID, and update channel -func (s *subscriptions[T]) add() (string, chan MsgCallback[T]) { +func (s *subscriptions[T]) add() (string, chan func() []*T) { var ( id = xid.New().String() - ch = make(chan MsgCallback[T], 1) + ch = make(chan func() []*T, 1) ) (*s)[id] = ch @@ -37,7 +37,7 @@ func (s *subscriptions[T]) remove(id string) { } // notify notifies all subscription listeners -func (s *subscriptions[T]) notify(callback MsgCallback[T]) { +func (s *subscriptions[T]) notify(callback func() []*T) { // Notify the listeners for _, ch := range *s { notifySubscription(ch, callback) @@ -47,7 +47,7 @@ func (s *subscriptions[T]) notify(callback MsgCallback[T]) { // notifySubscription alerts the notification channel // about a callback. This function is pure syntactic sugar func notifySubscription[T msgType]( - ch chan MsgCallback[T], + ch chan func() []*T, callback MsgCallback[T], ) { select { diff --git a/messages/types/messages.go b/messages/types/messages.go new file mode 100644 index 00000000000..8f8b57b4a84 --- /dev/null +++ b/messages/types/messages.go @@ -0,0 +1,60 @@ +package types + +import ( + "google.golang.org/protobuf/proto" +) + +// Marshal returns the marshalled message +func (m *ProposalMessage) Marshal() []byte { + //nolint:errcheck // No need to verify the error + raw, _ := proto.Marshal(&ProposalMessage{ + View: m.View, + From: m.From, + Proposal: m.Proposal, + ProposalRound: m.ProposalRound, + }) + + return raw +} + +// IsValid validates that the given message is valid +func (m *ProposalMessage) IsValid() bool { + // TODO implement + return true +} + +// Marshal returns the marshalled message +func (m *PrevoteMessage) Marshal() []byte { + //nolint:errcheck // No need to verify the error + raw, _ := proto.Marshal(&PrevoteMessage{ + View: m.View, + From: m.From, + Identifier: m.Identifier, + }) + + return raw +} + +// IsValid validates that the given message is valid +func (m *PrevoteMessage) IsValid() bool { + // TODO implement + return true +} + +// Marshal returns the marshalled message +func (m *PrecommitMessage) Marshal() []byte { + //nolint:errcheck // No need to verify the error + raw, _ := proto.Marshal(&PrecommitMessage{ + View: m.View, + From: m.From, + Identifier: m.Identifier, + }) + + return raw +} + +// IsValid validates that the given message is valid +func (m *PrecommitMessage) IsValid() bool { + // TODO implement + return true +} diff --git a/messages/messages.pb.go b/messages/types/messages.pb.go similarity index 64% rename from messages/messages.pb.go rename to messages/types/messages.pb.go index 479b1532dd0..9c5b476cb6f 100644 --- a/messages/messages.pb.go +++ b/messages/types/messages.pb.go @@ -2,9 +2,9 @@ // versions: // protoc-gen-go v1.28.1 // protoc v4.25.3 -// source: messages/proto/messages.proto +// source: messages/types/proto/messages.proto -package messages +package types import ( protoreflect "google.golang.org/protobuf/reflect/protoreflect" @@ -55,11 +55,11 @@ func (x MessageType) String() string { } func (MessageType) Descriptor() protoreflect.EnumDescriptor { - return file_messages_proto_messages_proto_enumTypes[0].Descriptor() + return file_messages_types_proto_messages_proto_enumTypes[0].Descriptor() } func (MessageType) Type() protoreflect.EnumType { - return &file_messages_proto_messages_proto_enumTypes[0] + return &file_messages_types_proto_messages_proto_enumTypes[0] } func (x MessageType) Number() protoreflect.EnumNumber { @@ -68,7 +68,7 @@ func (x MessageType) Number() protoreflect.EnumNumber { // Deprecated: Use MessageType.Descriptor instead. func (MessageType) EnumDescriptor() ([]byte, []int) { - return file_messages_proto_messages_proto_rawDescGZIP(), []int{0} + return file_messages_types_proto_messages_proto_rawDescGZIP(), []int{0} } // View is the consensus state associated with the message @@ -87,7 +87,7 @@ type View struct { func (x *View) Reset() { *x = View{} if protoimpl.UnsafeEnabled { - mi := &file_messages_proto_messages_proto_msgTypes[0] + mi := &file_messages_types_proto_messages_proto_msgTypes[0] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -100,7 +100,7 @@ func (x *View) String() string { func (*View) ProtoMessage() {} func (x *View) ProtoReflect() protoreflect.Message { - mi := &file_messages_proto_messages_proto_msgTypes[0] + mi := &file_messages_types_proto_messages_proto_msgTypes[0] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -113,7 +113,7 @@ func (x *View) ProtoReflect() protoreflect.Message { // Deprecated: Use View.ProtoReflect.Descriptor instead. func (*View) Descriptor() ([]byte, []int) { - return file_messages_proto_messages_proto_rawDescGZIP(), []int{0} + return file_messages_types_proto_messages_proto_rawDescGZIP(), []int{0} } func (x *View) GetHeight() uint64 { @@ -153,7 +153,7 @@ type Message struct { func (x *Message) Reset() { *x = Message{} if protoimpl.UnsafeEnabled { - mi := &file_messages_proto_messages_proto_msgTypes[1] + mi := &file_messages_types_proto_messages_proto_msgTypes[1] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -166,7 +166,7 @@ func (x *Message) String() string { func (*Message) ProtoMessage() {} func (x *Message) ProtoReflect() protoreflect.Message { - mi := &file_messages_proto_messages_proto_msgTypes[1] + mi := &file_messages_types_proto_messages_proto_msgTypes[1] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -179,7 +179,7 @@ func (x *Message) ProtoReflect() protoreflect.Message { // Deprecated: Use Message.ProtoReflect.Descriptor instead. func (*Message) Descriptor() ([]byte, []int) { - return file_messages_proto_messages_proto_rawDescGZIP(), []int{1} + return file_messages_types_proto_messages_proto_rawDescGZIP(), []int{1} } func (x *Message) GetType() MessageType { @@ -271,7 +271,7 @@ type ProposalMessage struct { func (x *ProposalMessage) Reset() { *x = ProposalMessage{} if protoimpl.UnsafeEnabled { - mi := &file_messages_proto_messages_proto_msgTypes[2] + mi := &file_messages_types_proto_messages_proto_msgTypes[2] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -284,7 +284,7 @@ func (x *ProposalMessage) String() string { func (*ProposalMessage) ProtoMessage() {} func (x *ProposalMessage) ProtoReflect() protoreflect.Message { - mi := &file_messages_proto_messages_proto_msgTypes[2] + mi := &file_messages_types_proto_messages_proto_msgTypes[2] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -297,7 +297,7 @@ func (x *ProposalMessage) ProtoReflect() protoreflect.Message { // Deprecated: Use ProposalMessage.ProtoReflect.Descriptor instead. func (*ProposalMessage) Descriptor() ([]byte, []int) { - return file_messages_proto_messages_proto_rawDescGZIP(), []int{2} + return file_messages_types_proto_messages_proto_rawDescGZIP(), []int{2} } func (x *ProposalMessage) GetView() *View { @@ -354,7 +354,7 @@ type PrevoteMessage struct { func (x *PrevoteMessage) Reset() { *x = PrevoteMessage{} if protoimpl.UnsafeEnabled { - mi := &file_messages_proto_messages_proto_msgTypes[3] + mi := &file_messages_types_proto_messages_proto_msgTypes[3] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -367,7 +367,7 @@ func (x *PrevoteMessage) String() string { func (*PrevoteMessage) ProtoMessage() {} func (x *PrevoteMessage) ProtoReflect() protoreflect.Message { - mi := &file_messages_proto_messages_proto_msgTypes[3] + mi := &file_messages_types_proto_messages_proto_msgTypes[3] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -380,7 +380,7 @@ func (x *PrevoteMessage) ProtoReflect() protoreflect.Message { // Deprecated: Use PrevoteMessage.ProtoReflect.Descriptor instead. func (*PrevoteMessage) Descriptor() ([]byte, []int) { - return file_messages_proto_messages_proto_rawDescGZIP(), []int{3} + return file_messages_types_proto_messages_proto_rawDescGZIP(), []int{3} } func (x *PrevoteMessage) GetView() *View { @@ -429,7 +429,7 @@ type PrecommitMessage struct { func (x *PrecommitMessage) Reset() { *x = PrecommitMessage{} if protoimpl.UnsafeEnabled { - mi := &file_messages_proto_messages_proto_msgTypes[4] + mi := &file_messages_types_proto_messages_proto_msgTypes[4] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -442,7 +442,7 @@ func (x *PrecommitMessage) String() string { func (*PrecommitMessage) ProtoMessage() {} func (x *PrecommitMessage) ProtoReflect() protoreflect.Message { - mi := &file_messages_proto_messages_proto_msgTypes[4] + mi := &file_messages_types_proto_messages_proto_msgTypes[4] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -455,7 +455,7 @@ func (x *PrecommitMessage) ProtoReflect() protoreflect.Message { // Deprecated: Use PrecommitMessage.ProtoReflect.Descriptor instead. func (*PrecommitMessage) Descriptor() ([]byte, []int) { - return file_messages_proto_messages_proto_rawDescGZIP(), []int{4} + return file_messages_types_proto_messages_proto_rawDescGZIP(), []int{4} } func (x *PrecommitMessage) GetView() *View { @@ -479,74 +479,75 @@ func (x *PrecommitMessage) GetIdentifier() []byte { return nil } -var File_messages_proto_messages_proto protoreflect.FileDescriptor - -var file_messages_proto_messages_proto_rawDesc = []byte{ - 0x0a, 0x1d, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x73, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, - 0x2f, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, - 0x34, 0x0a, 0x04, 0x56, 0x69, 0x65, 0x77, 0x12, 0x16, 0x0a, 0x06, 0x68, 0x65, 0x69, 0x67, 0x68, - 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x04, 0x52, 0x06, 0x68, 0x65, 0x69, 0x67, 0x68, 0x74, 0x12, - 0x14, 0x0a, 0x05, 0x72, 0x6f, 0x75, 0x6e, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x04, 0x52, 0x05, - 0x72, 0x6f, 0x75, 0x6e, 0x64, 0x22, 0x8e, 0x02, 0x0a, 0x07, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, - 0x65, 0x12, 0x20, 0x0a, 0x04, 0x74, 0x79, 0x70, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0e, 0x32, - 0x0c, 0x2e, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x54, 0x79, 0x70, 0x65, 0x52, 0x04, 0x74, - 0x79, 0x70, 0x65, 0x12, 0x1c, 0x0a, 0x09, 0x73, 0x69, 0x67, 0x6e, 0x61, 0x74, 0x75, 0x72, 0x65, - 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x09, 0x73, 0x69, 0x67, 0x6e, 0x61, 0x74, 0x75, 0x72, - 0x65, 0x12, 0x3c, 0x0a, 0x0f, 0x70, 0x72, 0x6f, 0x70, 0x6f, 0x73, 0x61, 0x6c, 0x4d, 0x65, 0x73, - 0x73, 0x61, 0x67, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x10, 0x2e, 0x50, 0x72, 0x6f, - 0x70, 0x6f, 0x73, 0x61, 0x6c, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x48, 0x00, 0x52, 0x0f, - 0x70, 0x72, 0x6f, 0x70, 0x6f, 0x73, 0x61, 0x6c, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x12, - 0x39, 0x0a, 0x0e, 0x70, 0x72, 0x65, 0x76, 0x6f, 0x74, 0x65, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, - 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0f, 0x2e, 0x50, 0x72, 0x65, 0x76, 0x6f, 0x74, - 0x65, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x48, 0x00, 0x52, 0x0e, 0x70, 0x72, 0x65, 0x76, - 0x6f, 0x74, 0x65, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x12, 0x3f, 0x0a, 0x10, 0x70, 0x72, - 0x65, 0x63, 0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x05, - 0x20, 0x01, 0x28, 0x0b, 0x32, 0x11, 0x2e, 0x50, 0x72, 0x65, 0x63, 0x6f, 0x6d, 0x6d, 0x69, 0x74, - 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x48, 0x00, 0x52, 0x10, 0x70, 0x72, 0x65, 0x63, 0x6f, - 0x6d, 0x6d, 0x69, 0x74, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x42, 0x09, 0x0a, 0x07, 0x70, - 0x61, 0x79, 0x6c, 0x6f, 0x61, 0x64, 0x22, 0x82, 0x01, 0x0a, 0x0f, 0x50, 0x72, 0x6f, 0x70, 0x6f, - 0x73, 0x61, 0x6c, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x12, 0x19, 0x0a, 0x04, 0x76, 0x69, - 0x65, 0x77, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x05, 0x2e, 0x56, 0x69, 0x65, 0x77, 0x52, - 0x04, 0x76, 0x69, 0x65, 0x77, 0x12, 0x12, 0x0a, 0x04, 0x66, 0x72, 0x6f, 0x6d, 0x18, 0x02, 0x20, - 0x01, 0x28, 0x0c, 0x52, 0x04, 0x66, 0x72, 0x6f, 0x6d, 0x12, 0x1a, 0x0a, 0x08, 0x70, 0x72, 0x6f, - 0x70, 0x6f, 0x73, 0x61, 0x6c, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x08, 0x70, 0x72, 0x6f, - 0x70, 0x6f, 0x73, 0x61, 0x6c, 0x12, 0x24, 0x0a, 0x0d, 0x70, 0x72, 0x6f, 0x70, 0x6f, 0x73, 0x61, - 0x6c, 0x52, 0x6f, 0x75, 0x6e, 0x64, 0x18, 0x04, 0x20, 0x01, 0x28, 0x03, 0x52, 0x0d, 0x70, 0x72, - 0x6f, 0x70, 0x6f, 0x73, 0x61, 0x6c, 0x52, 0x6f, 0x75, 0x6e, 0x64, 0x22, 0x5f, 0x0a, 0x0e, 0x50, - 0x72, 0x65, 0x76, 0x6f, 0x74, 0x65, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x12, 0x19, 0x0a, - 0x04, 0x76, 0x69, 0x65, 0x77, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x05, 0x2e, 0x56, 0x69, - 0x65, 0x77, 0x52, 0x04, 0x76, 0x69, 0x65, 0x77, 0x12, 0x12, 0x0a, 0x04, 0x66, 0x72, 0x6f, 0x6d, - 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x04, 0x66, 0x72, 0x6f, 0x6d, 0x12, 0x1e, 0x0a, 0x0a, - 0x69, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x66, 0x69, 0x65, 0x72, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0c, - 0x52, 0x0a, 0x69, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x66, 0x69, 0x65, 0x72, 0x22, 0x61, 0x0a, 0x10, - 0x50, 0x72, 0x65, 0x63, 0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, +var File_messages_types_proto_messages_proto protoreflect.FileDescriptor + +var file_messages_types_proto_messages_proto_rawDesc = []byte{ + 0x0a, 0x23, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x73, 0x2f, 0x74, 0x79, 0x70, 0x65, 0x73, + 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x73, 0x2e, + 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x34, 0x0a, 0x04, 0x56, 0x69, 0x65, 0x77, 0x12, 0x16, 0x0a, + 0x06, 0x68, 0x65, 0x69, 0x67, 0x68, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x04, 0x52, 0x06, 0x68, + 0x65, 0x69, 0x67, 0x68, 0x74, 0x12, 0x14, 0x0a, 0x05, 0x72, 0x6f, 0x75, 0x6e, 0x64, 0x18, 0x02, + 0x20, 0x01, 0x28, 0x04, 0x52, 0x05, 0x72, 0x6f, 0x75, 0x6e, 0x64, 0x22, 0x8e, 0x02, 0x0a, 0x07, + 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x12, 0x20, 0x0a, 0x04, 0x74, 0x79, 0x70, 0x65, 0x18, + 0x01, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x0c, 0x2e, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x54, + 0x79, 0x70, 0x65, 0x52, 0x04, 0x74, 0x79, 0x70, 0x65, 0x12, 0x1c, 0x0a, 0x09, 0x73, 0x69, 0x67, + 0x6e, 0x61, 0x74, 0x75, 0x72, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x09, 0x73, 0x69, + 0x67, 0x6e, 0x61, 0x74, 0x75, 0x72, 0x65, 0x12, 0x3c, 0x0a, 0x0f, 0x70, 0x72, 0x6f, 0x70, 0x6f, + 0x73, 0x61, 0x6c, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, + 0x32, 0x10, 0x2e, 0x50, 0x72, 0x6f, 0x70, 0x6f, 0x73, 0x61, 0x6c, 0x4d, 0x65, 0x73, 0x73, 0x61, + 0x67, 0x65, 0x48, 0x00, 0x52, 0x0f, 0x70, 0x72, 0x6f, 0x70, 0x6f, 0x73, 0x61, 0x6c, 0x4d, 0x65, + 0x73, 0x73, 0x61, 0x67, 0x65, 0x12, 0x39, 0x0a, 0x0e, 0x70, 0x72, 0x65, 0x76, 0x6f, 0x74, 0x65, + 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0f, 0x2e, + 0x50, 0x72, 0x65, 0x76, 0x6f, 0x74, 0x65, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x48, 0x00, + 0x52, 0x0e, 0x70, 0x72, 0x65, 0x76, 0x6f, 0x74, 0x65, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, + 0x12, 0x3f, 0x0a, 0x10, 0x70, 0x72, 0x65, 0x63, 0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x4d, 0x65, 0x73, + 0x73, 0x61, 0x67, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x11, 0x2e, 0x50, 0x72, 0x65, + 0x63, 0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x48, 0x00, 0x52, + 0x10, 0x70, 0x72, 0x65, 0x63, 0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, + 0x65, 0x42, 0x09, 0x0a, 0x07, 0x70, 0x61, 0x79, 0x6c, 0x6f, 0x61, 0x64, 0x22, 0x82, 0x01, 0x0a, + 0x0f, 0x50, 0x72, 0x6f, 0x70, 0x6f, 0x73, 0x61, 0x6c, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x12, 0x19, 0x0a, 0x04, 0x76, 0x69, 0x65, 0x77, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x05, 0x2e, 0x56, 0x69, 0x65, 0x77, 0x52, 0x04, 0x76, 0x69, 0x65, 0x77, 0x12, 0x12, 0x0a, 0x04, 0x66, 0x72, 0x6f, 0x6d, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x04, 0x66, 0x72, 0x6f, 0x6d, 0x12, - 0x1e, 0x0a, 0x0a, 0x69, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x66, 0x69, 0x65, 0x72, 0x18, 0x03, 0x20, - 0x01, 0x28, 0x0c, 0x52, 0x0a, 0x69, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x66, 0x69, 0x65, 0x72, 0x2a, - 0x37, 0x0a, 0x0b, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x54, 0x79, 0x70, 0x65, 0x12, 0x0c, - 0x0a, 0x08, 0x50, 0x52, 0x4f, 0x50, 0x4f, 0x53, 0x41, 0x4c, 0x10, 0x00, 0x12, 0x0b, 0x0a, 0x07, - 0x50, 0x52, 0x45, 0x56, 0x4f, 0x54, 0x45, 0x10, 0x01, 0x12, 0x0d, 0x0a, 0x09, 0x50, 0x52, 0x45, - 0x43, 0x4f, 0x4d, 0x4d, 0x49, 0x54, 0x10, 0x02, 0x42, 0x0b, 0x5a, 0x09, 0x2f, 0x6d, 0x65, 0x73, - 0x73, 0x61, 0x67, 0x65, 0x73, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x1a, 0x0a, 0x08, 0x70, 0x72, 0x6f, 0x70, 0x6f, 0x73, 0x61, 0x6c, 0x18, 0x03, 0x20, 0x01, 0x28, + 0x0c, 0x52, 0x08, 0x70, 0x72, 0x6f, 0x70, 0x6f, 0x73, 0x61, 0x6c, 0x12, 0x24, 0x0a, 0x0d, 0x70, + 0x72, 0x6f, 0x70, 0x6f, 0x73, 0x61, 0x6c, 0x52, 0x6f, 0x75, 0x6e, 0x64, 0x18, 0x04, 0x20, 0x01, + 0x28, 0x03, 0x52, 0x0d, 0x70, 0x72, 0x6f, 0x70, 0x6f, 0x73, 0x61, 0x6c, 0x52, 0x6f, 0x75, 0x6e, + 0x64, 0x22, 0x5f, 0x0a, 0x0e, 0x50, 0x72, 0x65, 0x76, 0x6f, 0x74, 0x65, 0x4d, 0x65, 0x73, 0x73, + 0x61, 0x67, 0x65, 0x12, 0x19, 0x0a, 0x04, 0x76, 0x69, 0x65, 0x77, 0x18, 0x01, 0x20, 0x01, 0x28, + 0x0b, 0x32, 0x05, 0x2e, 0x56, 0x69, 0x65, 0x77, 0x52, 0x04, 0x76, 0x69, 0x65, 0x77, 0x12, 0x12, + 0x0a, 0x04, 0x66, 0x72, 0x6f, 0x6d, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x04, 0x66, 0x72, + 0x6f, 0x6d, 0x12, 0x1e, 0x0a, 0x0a, 0x69, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x66, 0x69, 0x65, 0x72, + 0x18, 0x03, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x0a, 0x69, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x66, 0x69, + 0x65, 0x72, 0x22, 0x61, 0x0a, 0x10, 0x50, 0x72, 0x65, 0x63, 0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x4d, + 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x12, 0x19, 0x0a, 0x04, 0x76, 0x69, 0x65, 0x77, 0x18, 0x01, + 0x20, 0x01, 0x28, 0x0b, 0x32, 0x05, 0x2e, 0x56, 0x69, 0x65, 0x77, 0x52, 0x04, 0x76, 0x69, 0x65, + 0x77, 0x12, 0x12, 0x0a, 0x04, 0x66, 0x72, 0x6f, 0x6d, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, + 0x04, 0x66, 0x72, 0x6f, 0x6d, 0x12, 0x1e, 0x0a, 0x0a, 0x69, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x66, + 0x69, 0x65, 0x72, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x0a, 0x69, 0x64, 0x65, 0x6e, 0x74, + 0x69, 0x66, 0x69, 0x65, 0x72, 0x2a, 0x37, 0x0a, 0x0b, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, + 0x54, 0x79, 0x70, 0x65, 0x12, 0x0c, 0x0a, 0x08, 0x50, 0x52, 0x4f, 0x50, 0x4f, 0x53, 0x41, 0x4c, + 0x10, 0x00, 0x12, 0x0b, 0x0a, 0x07, 0x50, 0x52, 0x45, 0x56, 0x4f, 0x54, 0x45, 0x10, 0x01, 0x12, + 0x0d, 0x0a, 0x09, 0x50, 0x52, 0x45, 0x43, 0x4f, 0x4d, 0x4d, 0x49, 0x54, 0x10, 0x02, 0x42, 0x11, + 0x5a, 0x0f, 0x2f, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x73, 0x2f, 0x74, 0x79, 0x70, 0x65, + 0x73, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( - file_messages_proto_messages_proto_rawDescOnce sync.Once - file_messages_proto_messages_proto_rawDescData = file_messages_proto_messages_proto_rawDesc + file_messages_types_proto_messages_proto_rawDescOnce sync.Once + file_messages_types_proto_messages_proto_rawDescData = file_messages_types_proto_messages_proto_rawDesc ) -func file_messages_proto_messages_proto_rawDescGZIP() []byte { - file_messages_proto_messages_proto_rawDescOnce.Do(func() { - file_messages_proto_messages_proto_rawDescData = protoimpl.X.CompressGZIP(file_messages_proto_messages_proto_rawDescData) +func file_messages_types_proto_messages_proto_rawDescGZIP() []byte { + file_messages_types_proto_messages_proto_rawDescOnce.Do(func() { + file_messages_types_proto_messages_proto_rawDescData = protoimpl.X.CompressGZIP(file_messages_types_proto_messages_proto_rawDescData) }) - return file_messages_proto_messages_proto_rawDescData + return file_messages_types_proto_messages_proto_rawDescData } -var file_messages_proto_messages_proto_enumTypes = make([]protoimpl.EnumInfo, 1) -var file_messages_proto_messages_proto_msgTypes = make([]protoimpl.MessageInfo, 5) -var file_messages_proto_messages_proto_goTypes = []interface{}{ +var file_messages_types_proto_messages_proto_enumTypes = make([]protoimpl.EnumInfo, 1) +var file_messages_types_proto_messages_proto_msgTypes = make([]protoimpl.MessageInfo, 5) +var file_messages_types_proto_messages_proto_goTypes = []interface{}{ (MessageType)(0), // 0: MessageType (*View)(nil), // 1: View (*Message)(nil), // 2: Message @@ -554,7 +555,7 @@ var file_messages_proto_messages_proto_goTypes = []interface{}{ (*PrevoteMessage)(nil), // 4: PrevoteMessage (*PrecommitMessage)(nil), // 5: PrecommitMessage } -var file_messages_proto_messages_proto_depIdxs = []int32{ +var file_messages_types_proto_messages_proto_depIdxs = []int32{ 0, // 0: Message.type:type_name -> MessageType 3, // 1: Message.proposalMessage:type_name -> ProposalMessage 4, // 2: Message.prevoteMessage:type_name -> PrevoteMessage @@ -569,13 +570,13 @@ var file_messages_proto_messages_proto_depIdxs = []int32{ 0, // [0:7] is the sub-list for field type_name } -func init() { file_messages_proto_messages_proto_init() } -func file_messages_proto_messages_proto_init() { - if File_messages_proto_messages_proto != nil { +func init() { file_messages_types_proto_messages_proto_init() } +func file_messages_types_proto_messages_proto_init() { + if File_messages_types_proto_messages_proto != nil { return } if !protoimpl.UnsafeEnabled { - file_messages_proto_messages_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + file_messages_types_proto_messages_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*View); i { case 0: return &v.state @@ -587,7 +588,7 @@ func file_messages_proto_messages_proto_init() { return nil } } - file_messages_proto_messages_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + file_messages_types_proto_messages_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*Message); i { case 0: return &v.state @@ -599,7 +600,7 @@ func file_messages_proto_messages_proto_init() { return nil } } - file_messages_proto_messages_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { + file_messages_types_proto_messages_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*ProposalMessage); i { case 0: return &v.state @@ -611,7 +612,7 @@ func file_messages_proto_messages_proto_init() { return nil } } - file_messages_proto_messages_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { + file_messages_types_proto_messages_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*PrevoteMessage); i { case 0: return &v.state @@ -623,7 +624,7 @@ func file_messages_proto_messages_proto_init() { return nil } } - file_messages_proto_messages_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} { + file_messages_types_proto_messages_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*PrecommitMessage); i { case 0: return &v.state @@ -636,7 +637,7 @@ func file_messages_proto_messages_proto_init() { } } } - file_messages_proto_messages_proto_msgTypes[1].OneofWrappers = []interface{}{ + file_messages_types_proto_messages_proto_msgTypes[1].OneofWrappers = []interface{}{ (*Message_ProposalMessage)(nil), (*Message_PrevoteMessage)(nil), (*Message_PrecommitMessage)(nil), @@ -645,19 +646,19 @@ func file_messages_proto_messages_proto_init() { out := protoimpl.TypeBuilder{ File: protoimpl.DescBuilder{ GoPackagePath: reflect.TypeOf(x{}).PkgPath(), - RawDescriptor: file_messages_proto_messages_proto_rawDesc, + RawDescriptor: file_messages_types_proto_messages_proto_rawDesc, NumEnums: 1, NumMessages: 5, NumExtensions: 0, NumServices: 0, }, - GoTypes: file_messages_proto_messages_proto_goTypes, - DependencyIndexes: file_messages_proto_messages_proto_depIdxs, - EnumInfos: file_messages_proto_messages_proto_enumTypes, - MessageInfos: file_messages_proto_messages_proto_msgTypes, + GoTypes: file_messages_types_proto_messages_proto_goTypes, + DependencyIndexes: file_messages_types_proto_messages_proto_depIdxs, + EnumInfos: file_messages_types_proto_messages_proto_enumTypes, + MessageInfos: file_messages_types_proto_messages_proto_msgTypes, }.Build() - File_messages_proto_messages_proto = out.File - file_messages_proto_messages_proto_rawDesc = nil - file_messages_proto_messages_proto_goTypes = nil - file_messages_proto_messages_proto_depIdxs = nil + File_messages_types_proto_messages_proto = out.File + file_messages_types_proto_messages_proto_rawDesc = nil + file_messages_types_proto_messages_proto_goTypes = nil + file_messages_types_proto_messages_proto_depIdxs = nil } diff --git a/messages/proto/messages.proto b/messages/types/proto/messages.proto similarity index 98% rename from messages/proto/messages.proto rename to messages/types/proto/messages.proto index d2de47182a6..ea95787a3d6 100644 --- a/messages/proto/messages.proto +++ b/messages/types/proto/messages.proto @@ -1,6 +1,6 @@ syntax = "proto3"; -option go_package = "/messages"; +option go_package = "/messages/types"; // MessageType defines the types of messages // that are related to the consensus process