Skip to content

Commit

Permalink
chore: remove discrete view channels from mirror kernel
Browse files Browse the repository at this point in the history
These were removed from other engine subsystems earlier but the mirror
kernel was overlooked by mistake. Now it only emits to the gossip
strategy output, as intended.
  • Loading branch information
mark-rushakoff committed Apr 24, 2024
1 parent 30ca2e0 commit 3d149fa
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 82 deletions.
15 changes: 7 additions & 8 deletions tm/tmengine/internal/tmmirror/internal/tmi/fixture_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/rollchains/gordian/tm/tmconsensus/tmconsensustest"
"github.com/rollchains/gordian/tm/tmengine/internal/tmeil"
"github.com/rollchains/gordian/tm/tmengine/internal/tmmirror/internal/tmi"
"github.com/rollchains/gordian/tm/tmengine/tmelink"
"github.com/rollchains/gordian/tm/tmstore/tmmemstore"
)

Expand All @@ -24,7 +25,8 @@ type KernelFixture struct {

// These channels are bidirectional in the fixture,
// because they are write-only in the config.
VotingViewOutCh, CommittingViewOutCh chan tmconsensus.VersionedRoundView

GossipStrategyOut chan tmelink.NetworkViewUpdate

NHRRequests chan chan tmi.NetworkHeightRound
SnapshotRequests chan tmi.SnapshotRequest
Expand All @@ -43,8 +45,8 @@ type KernelFixture struct {
func NewKernelFixture(t *testing.T, nVals int) *KernelFixture {
fx := tmconsensustest.NewStandardFixture(nVals)

votingViewOutCh := make(chan tmconsensus.VersionedRoundView) // Unbuffered like in production.
committingViewOutCh := make(chan tmconsensus.VersionedRoundView) // Unbuffered like in production.
// Unbuffered because the kernel needs to know exactly what was received.
gso := make(chan tmelink.NetworkViewUpdate)

// 1-buffered like production:
// "because it is possible that the caller
Expand Down Expand Up @@ -73,8 +75,7 @@ func NewKernelFixture(t *testing.T, nVals int) *KernelFixture {

Fx: fx,

VotingViewOutCh: votingViewOutCh,
CommittingViewOutCh: committingViewOutCh,
GossipStrategyOut: gso,

NHRRequests: nhrRequests,
SnapshotRequests: snapshotRequests,
Expand All @@ -100,9 +101,7 @@ func NewKernelFixture(t *testing.T, nVals int) *KernelFixture {
SignatureScheme: fx.SignatureScheme,
CommonMessageSignatureProofScheme: fx.CommonMessageSignatureProofScheme,

VotingViewOut: votingViewOutCh,
CommittingViewOut: committingViewOutCh,

GossipStrategyOut: gso,
StateMachineRoundActionsIn: smActionsIn,
StateMachineViewOut: smViewOut,

Expand Down
70 changes: 2 additions & 68 deletions tm/tmengine/internal/tmmirror/internal/tmi/kernel.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,9 @@ type Kernel struct {

pbf tmelink.ProposedBlockFetcher

votingViewOut,
committingViewOut,
nextRoundViewOut chan<- tmconsensus.VersionedRoundView

gossipOutCh chan<- tmelink.NetworkViewUpdate

stateMachineIn <-chan tmeil.StateMachineRoundActionSet
stateMachineViewOut chan<- tmconsensus.VersionedRoundView
stateMachineIn <-chan tmeil.StateMachineRoundActionSet

nhrRequests <-chan chan NetworkHeightRound
snapshotRequests <-chan SnapshotRequest
Expand Down Expand Up @@ -73,11 +68,6 @@ type KernelConfig struct {

ProposedBlockFetcher tmelink.ProposedBlockFetcher

// Views that are sent to the gossip strategy.
VotingViewOut,
CommittingViewOut,
NextRoundViewOut chan<- tmconsensus.VersionedRoundView

GossipStrategyOut chan<- tmelink.NetworkViewUpdate

StateMachineRoundActionsIn <-chan tmeil.StateMachineRoundActionSet
Expand Down Expand Up @@ -140,14 +130,9 @@ func NewKernel(ctx context.Context, log *slog.Logger, cfg KernelConfig) (*Kernel

// Channels provided through the config,
// i.e. channels coordinated by the Engine or Mirror.
votingViewOut: cfg.VotingViewOut,
committingViewOut: cfg.CommittingViewOut,
nextRoundViewOut: cfg.NextRoundViewOut,

gossipOutCh: cfg.GossipStrategyOut,

stateMachineIn: cfg.StateMachineRoundActionsIn,
stateMachineViewOut: cfg.StateMachineViewOut,
stateMachineIn: cfg.StateMachineRoundActionsIn,

nhrRequests: cfg.NHRRequests,
snapshotRequests: cfg.SnapshotRequests,
Expand Down Expand Up @@ -218,7 +203,6 @@ func (k *Kernel) mainLoop(ctx context.Context, s *kState) {
defer close(k.done)

for {
vo := k.viewOutputs(s)
smOut := s.StateMachineView.Output(s)

gsOut := k.gossipStrategyOutput(s)
Expand Down Expand Up @@ -267,15 +251,6 @@ func (k *Kernel) mainLoop(ctx context.Context, s *kState) {
case req := <-k.addPrecommitRequests:
k.addPrecommit(ctx, s, req)

case vo.VotingCh <- vo.VotingVal:
s.Voting.Outgoing.MarkSent()

case vo.CommittingCh <- vo.CommittingVal:
s.Committing.Outgoing.MarkSent()

case vo.NextRoundCh <- vo.NextRoundVal:
s.NextRound.Outgoing.MarkSent()

case gsOut.Ch <- gsOut.Val:
gsOut.MarkSent(s)

Expand Down Expand Up @@ -1041,47 +1016,6 @@ func (k *Kernel) advanceVotingRound(s *kState) error {
return nil
}

// viewOutputs is the collection of channels and values
// corresponding to round views that the Mirror tracks.
type viewOutputs struct {
VotingCh chan<- tmconsensus.VersionedRoundView
VotingVal tmconsensus.VersionedRoundView

CommittingCh chan<- tmconsensus.VersionedRoundView
CommittingVal tmconsensus.VersionedRoundView

NextRoundCh chan<- tmconsensus.VersionedRoundView
NextRoundVal tmconsensus.VersionedRoundView

// TODO: channels and values for NextHeight.
}

// kViewOutputs is a kernel method that returns a collection of
// output channels and values to send on those channels.
//
// Any output channels that have already sent the most recent value,
// will be set to nil so that no send is attempted.
func (k *Kernel) viewOutputs(s *kState) viewOutputs {
var out viewOutputs

if !s.Voting.Outgoing.HasBeenSent() {
out.VotingCh = k.votingViewOut
out.VotingVal = s.Voting.Outgoing.VRV
}

if !s.Committing.Outgoing.HasBeenSent() {
out.CommittingCh = k.committingViewOut
out.CommittingVal = s.Committing.Outgoing.VRV
}

if !s.NextRound.Outgoing.HasBeenSent() {
out.NextRoundCh = k.nextRoundViewOut
out.NextRoundVal = s.NextRound.Outgoing.VRV
}

return out
}

type gossipStrategyOut struct {
Ch chan<- tmelink.NetworkViewUpdate
Val tmelink.NetworkViewUpdate
Expand Down
12 changes: 6 additions & 6 deletions tm/tmengine/internal/tmmirror/internal/tmi/kernel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ func TestKernel_votesBeforeVotingRound(t *testing.T) {
kfx.Fx.SignProposal(ctx, &pb1, 0)

// Proposed blocks are sent directly.
_ = gtest.ReceiveSoon(t, kfx.VotingViewOutCh)
_ = gtest.ReceiveSoon(t, kfx.GossipStrategyOut)
gtest.SendSoon(t, kfx.AddPBRequests, pb1)
_ = gtest.ReceiveSoon(t, kfx.VotingViewOutCh)
_ = gtest.ReceiveSoon(t, kfx.GossipStrategyOut)

commitProof1 := kfx.Fx.PrecommitSignatureProof(
ctx,
Expand Down Expand Up @@ -78,7 +78,7 @@ func TestKernel_votesBeforeVotingRound(t *testing.T) {

// Confirm vote applied after being accepted
// (since the kernel does some work in the background here).
votingVRV := gtest.ReceiveSoon(t, kfx.VotingViewOutCh)
votingVRV := gtest.ReceiveSoon(t, kfx.GossipStrategyOut).Voting
require.Equal(t, uint64(2), votingVRV.Height)

// Update the fixture and go through the next height.
Expand All @@ -89,7 +89,7 @@ func TestKernel_votesBeforeVotingRound(t *testing.T) {
pb2 := kfx.Fx.NextProposedBlock([]byte("app_data_2"), 0)
kfx.Fx.SignProposal(ctx, &pb2, 0)
gtest.SendSoon(t, kfx.AddPBRequests, pb2)
_ = gtest.ReceiveSoon(t, kfx.VotingViewOutCh)
_ = gtest.ReceiveSoon(t, kfx.GossipStrategyOut)

commitProof2 := kfx.Fx.PrecommitSignatureProof(
ctx,
Expand Down Expand Up @@ -118,7 +118,7 @@ func TestKernel_votesBeforeVotingRound(t *testing.T) {
require.Equal(t, tmi.AddVoteAccepted, resp)

// Confirm on voting height 3.
votingVRV = gtest.ReceiveSoon(t, kfx.VotingViewOutCh)
votingVRV = gtest.ReceiveSoon(t, kfx.GossipStrategyOut).Voting
require.Equal(t, uint64(3), votingVRV.Height)

// Check if we need to advance the voting round.
Expand Down Expand Up @@ -149,7 +149,7 @@ func TestKernel_votesBeforeVotingRound(t *testing.T) {
require.Equal(t, tmi.AddVoteAccepted, resp)

// Confirm on voting height 3, round 1.
votingVRV = gtest.ReceiveSoon(t, kfx.VotingViewOutCh)
votingVRV = gtest.ReceiveSoon(t, kfx.GossipStrategyOut).Voting
require.Equal(t, uint64(3), votingVRV.Height)
require.Equal(t, uint32(1), votingVRV.Round)
}
Expand Down

0 comments on commit 3d149fa

Please sign in to comment.