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

[EFM] Recoverable Random Beacon State Machine follow up updates #6815

Open
wants to merge 12 commits into
base: feature/efm-recovery
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fixed broken unit tests
durkmurder committed Dec 16, 2024
commit 5dfc4c7a3bc8838d01dc517ec470ebfae2338a9e
22 changes: 14 additions & 8 deletions engine/consensus/dkg/reactor_engine_test.go
Original file line number Diff line number Diff line change
@@ -378,15 +378,18 @@ func (suite *ReactorEngineSuite_CommittedPhase) SetupTest() {
// * set the DKG end state to Success
func (suite *ReactorEngineSuite_CommittedPhase) TestDKGSuccess() {

epochCommit := unittest.EpochCommitFixture(unittest.CommitWithCounter(suite.NextEpochCounter()))
entry := unittest.EpochStateFixture(unittest.WithNextEpochProtocolState(), func(entry *flow.RichEpochStateEntry) {
entry.NextEpochCommit.Counter = suite.NextEpochCounter()
entry.NextEpoch.CommitID = entry.NextEpochCommit.ID()
})
epochProtocolState := protocol.NewEpochProtocolState(suite.T())
epochProtocolState.On("EpochCommit").Return(epochCommit)
epochProtocolState.On("Entry").Return(entry)
suite.snap.On("EpochProtocolState").Return(epochProtocolState, nil)
suite.dkgState.On("CommitMyBeaconPrivateKey", suite.NextEpochCounter(), epochCommit).Return(nil).Once()
suite.dkgState.On("CommitMyBeaconPrivateKey", suite.NextEpochCounter(), entry.NextEpochCommit).Return(nil).Once()
suite.engine.EpochCommittedPhaseStarted(suite.epochCounter, suite.firstBlock)
suite.Require().Equal(0, suite.warnsLogged)
// ensure we commit my beacon private key
suite.dkgState.AssertCalled(suite.T(), "CommitMyBeaconPrivateKey", suite.NextEpochCounter(), epochCommit)
suite.dkgState.AssertCalled(suite.T(), "CommitMyBeaconPrivateKey", suite.NextEpochCounter(), entry.NextEpochCommit)
}

// TestInconsistentKey tests the path where we are checking the global DKG
@@ -444,11 +447,14 @@ func (suite *ReactorEngineSuite_CommittedPhase) TestStartupInCommittedPhase_DKGS
suite.dkgState.On("IsDKGStarted", suite.NextEpochCounter()).Return(true, nil).Once()
suite.DKGState = flow.DKGStateCompleted

epochCommit := unittest.EpochCommitFixture(unittest.CommitWithCounter(suite.NextEpochCounter()))
entry := unittest.EpochStateFixture(unittest.WithNextEpochProtocolState(), func(entry *flow.RichEpochStateEntry) {
entry.NextEpochCommit.Counter = suite.NextEpochCounter()
entry.NextEpoch.CommitID = entry.NextEpochCommit.ID()
})
epochProtocolState := protocol.NewEpochProtocolState(suite.T())
epochProtocolState.On("EpochCommit").Return(epochCommit)
epochProtocolState.On("Entry").Return(entry)
suite.snap.On("EpochProtocolState").Return(epochProtocolState, nil)
suite.dkgState.On("CommitMyBeaconPrivateKey", suite.NextEpochCounter(), epochCommit).Return(nil).Once()
suite.dkgState.On("CommitMyBeaconPrivateKey", suite.NextEpochCounter(), entry.NextEpochCommit).Return(nil).Once()

// start up the engine
unittest.AssertClosesBefore(suite.T(), suite.engine.Ready(), time.Second)
@@ -460,7 +466,7 @@ func (suite *ReactorEngineSuite_CommittedPhase) TestStartupInCommittedPhase_DKGS
mock.Anything,
)
// ensure we commit my beacon private key
suite.dkgState.AssertCalled(suite.T(), "CommitMyBeaconPrivateKey", suite.NextEpochCounter(), epochCommit)
suite.dkgState.AssertCalled(suite.T(), "CommitMyBeaconPrivateKey", suite.NextEpochCounter(), entry.NextEpochCommit)
}

// TestStartupInCommittedPhase_DKGSuccess tests that the dkg end state is correctly
14 changes: 9 additions & 5 deletions module/dkg/recovery_test.go
Original file line number Diff line number Diff line change
@@ -39,7 +39,7 @@ type BeaconKeyRecoverySuite struct {
currentEpochCounter uint64
nextEpochCounter uint64
currentEpochPhase flow.EpochPhase
epochCommit *flow.EpochCommit
nextEpochCommit *flow.EpochCommit
}

func (s *BeaconKeyRecoverySuite) SetupTest() {
@@ -54,12 +54,16 @@ func (s *BeaconKeyRecoverySuite) SetupTest() {
s.currentEpochPhase = flow.EpochPhaseCommitted
s.currentEpochCounter = uint64(0)
s.nextEpochCounter = uint64(1)
s.epochCommit = unittest.EpochCommitFixture(unittest.CommitWithCounter(s.nextEpochCounter))
entry := unittest.EpochStateFixture(unittest.WithNextEpochProtocolState(), func(entry *flow.RichEpochStateEntry) {
entry.NextEpochCommit.Counter = s.nextEpochCounter
entry.NextEpoch.CommitID = entry.NextEpochCommit.ID()
})
s.nextEpochCommit = entry.NextEpochCommit

s.local.On("NodeID").Return(unittest.IdentifierFixture()).Maybe()
s.epochProtocolState.On("Epoch").Return(s.currentEpochCounter).Maybe()
s.epochProtocolState.On("EpochPhase").Return(func() flow.EpochPhase { return s.currentEpochPhase }).Maybe()
s.epochProtocolState.On("EpochCommit").Return(s.epochCommit, nil).Maybe()
s.epochProtocolState.On("Entry").Return(entry, nil).Maybe()
s.nextEpoch.On("Counter").Return(s.nextEpochCounter, nil).Maybe()

epochs := mockprotocol.NewEpochQuery(s.T())
@@ -310,7 +314,7 @@ func (s *BeaconKeyRecoverySuite) TestNewBeaconKeyRecovery_RecoverKey() {
dkg.On("KeyShare", s.local.NodeID()).Return(myBeaconKey.PublicKey(), nil).Once()
s.nextEpoch.On("DKG").Return(dkg, nil).Once()

dkgState.On("UpsertMyBeaconPrivateKey", s.nextEpochCounter, myBeaconKey, s.epochCommit).Return(nil).Once()
dkgState.On("UpsertMyBeaconPrivateKey", s.nextEpochCounter, myBeaconKey, s.nextEpochCommit).Return(nil).Once()

recovery, err := NewBeaconKeyRecovery(unittest.Logger(), s.local, s.state, dkgState)
require.NoError(s.T(), err)
@@ -366,7 +370,7 @@ func (s *BeaconKeyRecoverySuite) TestEpochFallbackModeExited() {
dkg.On("KeyShare", s.local.NodeID()).Return(myBeaconKey.PublicKey(), nil).Once()
s.nextEpoch.On("DKG").Return(dkg, nil).Once()

s.dkgState.On("UpsertMyBeaconPrivateKey", s.nextEpochCounter, myBeaconKey, s.epochCommit).Return(nil).Once()
s.dkgState.On("UpsertMyBeaconPrivateKey", s.nextEpochCounter, myBeaconKey, s.nextEpochCommit).Return(nil).Once()

recovery.EpochFallbackModeExited(s.currentEpochCounter, s.head)
s.dkgState.AssertNumberOfCalls(s.T(), "UpsertMyBeaconPrivateKey", 1)