diff --git a/dot/digest/digest_integration_test.go b/dot/digest/digest_integration_test.go index 5080fdd276..9133f4af9a 100644 --- a/dot/digest/digest_integration_test.go +++ b/dot/digest/digest_integration_test.go @@ -316,7 +316,7 @@ func TestHandler_HandleNextEpochData(t *testing.T) { handler.handleBlockFinalisation(ctx) - stored, err := handler.epochState.(*state.EpochState).GetEpochData(targetEpoch, nil) + stored, err := handler.epochState.(*state.EpochState).GetEpochDataRaw(targetEpoch, nil) require.NoError(t, err) digestValue, err := digest.Value() @@ -326,8 +326,7 @@ func TestHandler_HandleNextEpochData(t *testing.T) { t.Fatal() } - res, err := act.ToEpochData() - require.NoError(t, err) + res := act.ToEpochDataRaw() require.Equal(t, res, stored) } diff --git a/dot/state/epoch.go b/dot/state/epoch.go index c318c3874e..98f124eaf6 100644 --- a/dot/state/epoch.go +++ b/dot/state/epoch.go @@ -95,15 +95,12 @@ func NewEpochStateFromGenesis(db database.Database, blockState *BlockState, nextConfigData: make(nextEpochMap[types.NextConfigDataV1]), } - auths, err := types.BABEAuthorityRawToAuthority(genesisConfig.GenesisAuthorities) - if err != nil { - return nil, err + epochDataRaw := &types.EpochDataRaw{ + Authorities: genesisConfig.GenesisAuthorities, + Randomness: genesisConfig.Randomness, } - err = s.SetEpochData(0, &types.EpochData{ - Authorities: auths, - Randomness: genesisConfig.Randomness, - }) + err = s.SetEpochDataRaw(0, epochDataRaw) if err != nil { return nil, err } @@ -235,10 +232,8 @@ func (s *EpochState) GetEpochForBlock(header *types.Header) (uint64, error) { return 0, errNoPreRuntimeDigest } -// SetEpochData sets the epoch data for a given epoch -func (s *EpochState) SetEpochData(epoch uint64, info *types.EpochData) error { - raw := info.ToEpochDataRaw() - +// SetEpochDataRaw sets the epoch data raw for a given epoch +func (s *EpochState) SetEpochDataRaw(epoch uint64, raw *types.EpochDataRaw) error { enc, err := scale.Marshal(*raw) if err != nil { return err @@ -247,17 +242,17 @@ func (s *EpochState) SetEpochData(epoch uint64, info *types.EpochData) error { return s.db.Put(epochDataKey(epoch), enc) } -// GetEpochData returns the epoch data for a given epoch persisted in database +// GetEpochDataRaw returns the raw epoch data for a given epoch persisted in database // otherwise will try to get the data from the in-memory map using the header // if the header params is nil then it will search only in database -func (s *EpochState) GetEpochData(epoch uint64, header *types.Header) (*types.EpochData, error) { - epochData, err := s.getEpochDataFromDatabase(epoch) +func (s *EpochState) GetEpochDataRaw(epoch uint64, header *types.Header) (*types.EpochDataRaw, error) { + epochDataRaw, err := s.getEpochDataRawFromDatabase(epoch) if err != nil && !errors.Is(err, database.ErrNotFound) { return nil, fmt.Errorf("failed to retrieve epoch data from database: %w", err) } - if epochData != nil { - return epochData, nil + if epochDataRaw != nil { + return epochDataRaw, nil } if header == nil { @@ -272,38 +267,33 @@ func (s *EpochState) GetEpochData(epoch uint64, header *types.Header) (*types.Ep return nil, fmt.Errorf("failed to get epoch data from memory: %w", err) } - epochData, err = inMemoryEpochData.ToEpochData() - if err != nil { - return nil, fmt.Errorf("cannot transform into epoch data: %w", err) - } - - return epochData, nil + return inMemoryEpochData.ToEpochDataRaw(), nil } -// getEpochDataFromDatabase returns the epoch data for a given epoch persisted in database -func (s *EpochState) getEpochDataFromDatabase(epoch uint64) (*types.EpochData, error) { +// getEpochDataRawFromDatabase returns the epoch data for a given epoch persisted in database +func (s *EpochState) getEpochDataRawFromDatabase(epoch uint64) (*types.EpochDataRaw, error) { enc, err := s.db.Get(epochDataKey(epoch)) if err != nil { return nil, err } - raw := &types.EpochDataRaw{} + raw := new(types.EpochDataRaw) err = scale.Unmarshal(enc, raw) if err != nil { - return nil, err + return nil, fmt.Errorf("unmarshaling into epoch data raw: %w", err) } - return raw.ToEpochData() + return raw, nil } -// GetLatestEpochData returns the EpochData for the current epoch -func (s *EpochState) GetLatestEpochData() (*types.EpochData, error) { +// GetLatestEpochDataRaw returns the EpochData for the current epoch +func (s *EpochState) GetLatestEpochDataRaw() (*types.EpochDataRaw, error) { curr, err := s.GetCurrentEpoch() if err != nil { return nil, err } - return s.GetEpochData(curr, nil) + return s.GetEpochDataRaw(curr, nil) } // SetConfigData sets the BABE config data for a given epoch @@ -586,7 +576,7 @@ func (s *EpochState) FinalizeBABENextEpochData(finalizedHeader *types.Header) er nextEpoch = finalizedBlockEpoch + 1 } - epochInDatabase, err := s.getEpochDataFromDatabase(nextEpoch) + epochRawInDatabase, err := s.getEpochDataRawFromDatabase(nextEpoch) // if an error occurs and the error is database.ErrNotFound we ignore // since this error is what we will handle in the next lines @@ -595,7 +585,7 @@ func (s *EpochState) FinalizeBABENextEpochData(finalizedHeader *types.Header) er } // epoch data already defined we don't need to lookup in the map - if epochInDatabase != nil { + if epochRawInDatabase != nil { return nil } @@ -604,12 +594,7 @@ func (s *EpochState) FinalizeBABENextEpochData(finalizedHeader *types.Header) er return fmt.Errorf("cannot find next epoch data: %w", err) } - ed, err := finalizedNextEpochData.ToEpochData() - if err != nil { - return fmt.Errorf("cannot transform epoch data: %w", err) - } - - err = s.SetEpochData(nextEpoch, ed) + err = s.SetEpochDataRaw(nextEpoch, finalizedNextEpochData.ToEpochDataRaw()) if err != nil { return fmt.Errorf("cannot set epoch data: %w", err) } diff --git a/dot/state/epoch_test.go b/dot/state/epoch_test.go index 93ec72b2b2..7a8c92c8d4 100644 --- a/dot/state/epoch_test.go +++ b/dot/state/epoch_test.go @@ -58,46 +58,42 @@ func TestEpochState_EpochData(t *testing.T) { keyring, err := keystore.NewSr25519Keyring() require.NoError(t, err) - auth := types.Authority{ - Key: keyring.Alice().Public().(*sr25519.PublicKey), + auth := types.AuthorityRaw{ + Key: keyring.Alice().Public().(*sr25519.PublicKey).AsBytes(), Weight: 1, } - info := &types.EpochData{ - Authorities: []types.Authority{auth}, + info := &types.EpochDataRaw{ + Authorities: []types.AuthorityRaw{auth}, Randomness: [32]byte{77}, } - err = s.SetEpochData(1, info) + err = s.SetEpochDataRaw(1, info) require.NoError(t, err) - res, err := s.GetEpochData(1, nil) + res, err := s.GetEpochDataRaw(1, nil) require.NoError(t, err) require.Equal(t, info.Randomness, res.Randomness) for i, auth := range res.Authorities { - expected, err := info.Authorities[i].Encode() - require.NoError(t, err) - res, err := auth.Encode() - require.NoError(t, err) - require.Equal(t, expected, res) + require.Equal(t, info.Authorities[i], auth) } } func TestEpochState_GetStartSlotForEpoch(t *testing.T) { s := newEpochStateFromGenesis(t) - info := &types.EpochData{ + info := &types.EpochDataRaw{ Randomness: [32]byte{77}, } - err := s.SetEpochData(2, info) + err := s.SetEpochDataRaw(2, info) require.NoError(t, err) - info = &types.EpochData{ + info = &types.EpochDataRaw{ Randomness: [32]byte{77}, } - err = s.SetEpochData(3, info) + err = s.SetEpochDataRaw(3, info) require.NoError(t, err) start, err := s.GetStartSlotForEpoch(0) @@ -405,10 +401,8 @@ func TestStoreAndFinalizeBabeNextEpochData(t *testing.T) { } else { require.NoError(t, err) - expected, err := expectedNextEpochData.ToEpochData() - require.NoError(t, err) - - gotNextEpochData, err := epochState.GetEpochData(tt.finalizeEpoch, nil) + expected := expectedNextEpochData.ToEpochDataRaw() + gotNextEpochData, err := epochState.GetEpochDataRaw(tt.finalizeEpoch, nil) require.NoError(t, err) require.Equal(t, expected, gotNextEpochData) diff --git a/dot/types/consensus_digest.go b/dot/types/consensus_digest.go index 9cb061e325..d6719c3b91 100644 --- a/dot/types/consensus_digest.go +++ b/dot/types/consensus_digest.go @@ -102,16 +102,11 @@ func (d NextEpochData) String() string { //skipcq: GO-W1029 } // ToEpochData returns the NextEpochData as EpochData -func (d *NextEpochData) ToEpochData() (*EpochData, error) { //skipcq: GO-W1029 - auths, err := BABEAuthorityRawToAuthority(d.Authorities) - if err != nil { - return nil, err - } - - return &EpochData{ - Authorities: auths, +func (d *NextEpochData) ToEpochDataRaw() *EpochDataRaw { + return &EpochDataRaw{ + Authorities: d.Authorities, Randomness: d.Randomness, - }, nil + } } // BABEOnDisabled represents a GRANDPA authority being disabled diff --git a/lib/babe/babe.go b/lib/babe/babe.go index 0ef35b8244..a7aa8d3c19 100644 --- a/lib/babe/babe.go +++ b/lib/babe/babe.go @@ -258,12 +258,8 @@ func (b *Service) Stop() error { } // Authorities returns the current BABE authorities -func (b *Service) Authorities() []types.Authority { - auths := make([]types.Authority, len(b.epochHandler.epochData.authorities)) - for i, auth := range b.epochHandler.epochData.authorities { - auths[i] = *auth.DeepCopy() - } - return auths +func (b *Service) AuthoritiesRaw() []types.AuthorityRaw { + return b.epochHandler.epochData.authorities } // IsStopped returns true if the service is stopped (ie not producing blocks) @@ -271,7 +267,7 @@ func (b *Service) IsStopped() bool { return b.ctx.Err() != nil } -func (b *Service) getAuthorityIndex(Authorities []types.Authority) (uint32, error) { +func (b *Service) getAuthorityIndex(Authorities []types.AuthorityRaw) (uint32, error) { if !b.authority { return 0, ErrNotAuthority } @@ -279,7 +275,7 @@ func (b *Service) getAuthorityIndex(Authorities []types.Authority) (uint32, erro pub := b.keypair.Public() for i, auth := range Authorities { - if bytes.Equal(pub.Encode(), auth.Key.Encode()) { + if bytes.Equal(pub.Encode(), auth.Key[:]) { return uint32(i), nil } } diff --git a/lib/babe/babe_integration_test.go b/lib/babe/babe_integration_test.go index 43a216e445..1a2c2f303e 100644 --- a/lib/babe/babe_integration_test.go +++ b/lib/babe/babe_integration_test.go @@ -64,9 +64,9 @@ func TestService_GetAuthorityIndex(t *testing.T) { pubA := kpA.Public().(*sr25519.PublicKey) pubB := kpB.Public().(*sr25519.PublicKey) - authData := []types.Authority{ - {Key: pubA, Weight: 1}, - {Key: pubB, Weight: 1}, + authData := []types.AuthorityRaw{ + {Key: pubA.AsBytes(), Weight: 1}, + {Key: pubB.AsBytes(), Weight: 1}, } bs := &Service{ diff --git a/lib/babe/crypto.go b/lib/babe/crypto.go index 63830f149c..9458c82459 100644 --- a/lib/babe/crypto.go +++ b/lib/babe/crypto.go @@ -94,7 +94,7 @@ func checkPrimaryThreshold(randomness Randomness, func claimSecondarySlotVRF(randomness Randomness, slot, epoch uint64, - authorities []types.Authority, + authorities []types.AuthorityRaw, keypair *sr25519.Keypair, authorityIndex uint32, ) (*VrfOutputAndProof, error) { @@ -123,8 +123,8 @@ func claimSecondarySlotVRF(randomness Randomness, }, nil } -func claimSecondarySlotPlain(randomness Randomness, slot uint64, authorities []types.Authority, authorityIndex uint32, -) error { +func claimSecondarySlotPlain(randomness Randomness, slot uint64, + authorities []types.AuthorityRaw, authorityIndex uint32) error { secondarySlotAuthor, err := getSecondarySlotAuthor(slot, len(authorities), randomness) if err != nil { return fmt.Errorf("cannot get secondary slot author: %w", err) diff --git a/lib/babe/epoch.go b/lib/babe/epoch.go index 7cf51873be..69b8493b2b 100644 --- a/lib/babe/epoch.go +++ b/lib/babe/epoch.go @@ -95,7 +95,7 @@ func (b *Service) getEpochData(epoch uint64, bestBlock *types.Header) (*epochDat return epochData, nil } - currEpochData, err := b.epochState.GetEpochData(epoch, bestBlock) + currEpochData, err := b.epochState.GetEpochDataRaw(epoch, bestBlock) if err != nil { return nil, fmt.Errorf("cannot get epoch data for epoch %d: %w", epoch, err) } @@ -127,13 +127,13 @@ func (b *Service) getEpochData(epoch uint64, bestBlock *types.Header) (*epochDat func (b *Service) getLatestEpochData() (resEpochData *epochData, error error) { resEpochData = &epochData{} - epochData, err := b.epochState.GetLatestEpochData() + epochDataRaw, err := b.epochState.GetLatestEpochDataRaw() if err != nil { return nil, fmt.Errorf("cannot get latest epoch data: %w", err) } - resEpochData.randomness = epochData.Randomness - resEpochData.authorities = epochData.Authorities + resEpochData.randomness = epochDataRaw.Randomness + resEpochData.authorities = epochDataRaw.Authorities configData, err := b.epochState.GetLatestConfigData() if err != nil { diff --git a/lib/babe/epoch_handler_integration_test.go b/lib/babe/epoch_handler_integration_test.go index bb8eac33a5..f1c7d98774 100644 --- a/lib/babe/epoch_handler_integration_test.go +++ b/lib/babe/epoch_handler_integration_test.go @@ -24,8 +24,11 @@ func TestEpochHandler_run_shouldReturnAfterContextCancel(t *testing.T) { epochData := &epochData{ threshold: scale.MaxUint128, authorityIndex: authorityIndex, - authorities: []types.Authority{ - *types.NewAuthority(aliceKeyPair.Public(), 1), + authorities: []types.AuthorityRaw{ + { + Key: [32]byte(aliceKeyPair.Public().Encode()), + Weight: 1, + }, }, } @@ -66,8 +69,11 @@ func TestEpochHandler_run(t *testing.T) { epochData := &epochData{ threshold: scale.MaxUint128, authorityIndex: authorityIndex, - authorities: []types.Authority{ - *types.NewAuthority(aliceKeyPair.Public(), 1), + authorities: []types.AuthorityRaw{ + { + Key: [32]byte(aliceKeyPair.Public().Encode()), + Weight: 1, + }, }, } diff --git a/lib/babe/epoch_integration_test.go b/lib/babe/epoch_integration_test.go index 6cdd6a8946..5094ae0374 100644 --- a/lib/babe/epoch_integration_test.go +++ b/lib/babe/epoch_integration_test.go @@ -42,15 +42,15 @@ func TestInitiateEpoch_Epoch1(t *testing.T) { state.AddBlocksToState(t, babeService.blockState.(*state.BlockState), 1, false) // epoch 1, check that genesis EpochData and ConfigData was properly set - auth := types.Authority{ - Key: babeService.keypair.Public().(*sr25519.PublicKey), + auth := types.AuthorityRaw{ + Key: babeService.keypair.Public().(*sr25519.PublicKey).AsBytes(), Weight: 1, } - data, err := babeService.epochState.GetEpochData(0, nil) + data, err := babeService.epochState.GetEpochDataRaw(0, nil) require.NoError(t, err) - data.Authorities = []types.Authority{auth} - err = babeService.epochState.(*state.EpochState).SetEpochData(1, data) + data.Authorities = []types.AuthorityRaw{auth} + err = babeService.epochState.(*state.EpochState).SetEpochDataRaw(1, data) require.NoError(t, err) ed, err := babeService.initiateEpoch(1) @@ -58,7 +58,7 @@ func TestInitiateEpoch_Epoch1(t *testing.T) { expected := &epochData{ randomness: [32]byte{}, - authorities: []types.Authority{auth}, + authorities: []types.AuthorityRaw{auth}, authorityIndex: 0, threshold: ed.threshold, } @@ -67,20 +67,16 @@ func TestInitiateEpoch_Epoch1(t *testing.T) { require.Equal(t, expected.threshold, ed.threshold) for i, auth := range ed.authorities { - expAuth, err := expected.authorities[i].Encode() - require.NoError(t, err) - res, err := auth.Encode() - require.NoError(t, err) - require.Equal(t, expAuth, res) + require.Equal(t, expected.authorities[i], auth) } // for epoch 2, set EpochData but not ConfigData - edata := &types.EpochData{ + edata := &types.EpochDataRaw{ Authorities: ed.authorities, Randomness: [32]byte{9}, } - err = babeService.epochState.(*state.EpochState).SetEpochData(2, edata) + err = babeService.epochState.(*state.EpochState).SetEpochDataRaw(2, edata) require.NoError(t, err) expected = &epochData{ @@ -97,20 +93,16 @@ func TestInitiateEpoch_Epoch1(t *testing.T) { require.Equal(t, expected.threshold, ed.threshold) for i, auth := range ed.authorities { - expAuth, err := expected.authorities[i].Encode() - require.NoError(t, err) - res, err := auth.Encode() - require.NoError(t, err) - require.Equal(t, expAuth, res) + require.Equal(t, expected.authorities[i], auth) } // for epoch 3, set EpochData and ConfigData - edata = &types.EpochData{ + edata = &types.EpochDataRaw{ Authorities: ed.authorities, Randomness: [32]byte{9}, } - err = babeService.epochState.(*state.EpochState).SetEpochData(3, edata) + err = babeService.epochState.(*state.EpochState).SetEpochDataRaw(3, edata) require.NoError(t, err) cdata := &types.ConfigData{ @@ -158,12 +150,11 @@ func TestService_getLatestEpochData_genesis(t *testing.T) { latestEpochData, err := service.getLatestEpochData() require.NoError(t, err) - auths, err := types.BABEAuthorityRawToAuthority(genesisCfg.GenesisAuthorities) - require.NoError(t, err) - threshold, err := CalculateThreshold(genesisCfg.C1, genesisCfg.C2, len(auths)) + + threshold, err := CalculateThreshold(genesisCfg.C1, genesisCfg.C2, len(genesisCfg.GenesisAuthorities)) require.NoError(t, err) - require.Equal(t, auths, latestEpochData.authorities) + require.Equal(t, genesisCfg.GenesisAuthorities, latestEpochData.authorities) require.Equal(t, threshold, latestEpochData.threshold) require.Equal(t, genesisCfg.Randomness, latestEpochData.randomness) } @@ -175,14 +166,11 @@ func TestService_getLatestEpochData_epochData(t *testing.T) { err := epochState.SetCurrentEpoch(1) require.NoError(t, err) - auths, err := types.BABEAuthorityRawToAuthority(genesisCfg.GenesisAuthorities) - require.NoError(t, err) - - data := &types.EpochData{ - Authorities: auths, + data := &types.EpochDataRaw{ + Authorities: genesisCfg.GenesisAuthorities, Randomness: [types.RandomnessLength]byte{99, 88, 77}, } - err = epochState.SetEpochData(1, data) + err = epochState.SetEpochDataRaw(1, data) require.NoError(t, err) ed, err := service.getLatestEpochData() @@ -201,14 +189,11 @@ func TestService_getLatestEpochData_configData(t *testing.T) { err := epochState.SetCurrentEpoch(7) require.NoError(t, err) - auths, err := types.BABEAuthorityRawToAuthority(genesisCfg.GenesisAuthorities) - require.NoError(t, err) - - data := &types.EpochData{ - Authorities: auths, + data := &types.EpochDataRaw{ + Authorities: genesisCfg.GenesisAuthorities, Randomness: [types.RandomnessLength]byte{99, 88, 77}, } - err = epochState.SetEpochData(7, data) + err = epochState.SetEpochDataRaw(7, data) require.NoError(t, err) cfgData := &types.ConfigData{ diff --git a/lib/babe/epoch_test.go b/lib/babe/epoch_test.go index d8d9f20d2c..2aae08d6f7 100644 --- a/lib/babe/epoch_test.go +++ b/lib/babe/epoch_test.go @@ -73,9 +73,9 @@ func TestBabeService_checkAndSetFirstSlot(t *testing.T) { func TestBabeService_getEpochDataAndStartSlot(t *testing.T) { kp := keyring.Alice().(*sr25519.Keypair) authority := types.NewAuthority(kp.Public(), uint64(1)) - testEpochData := &types.EpochData{ + testEpochData := &types.EpochDataRaw{ Randomness: [32]byte{1}, - Authorities: []types.Authority{*authority}, + Authorities: []types.AuthorityRaw{*authority.ToRaw()}, } testConfigData := &types.ConfigData{ @@ -88,9 +88,11 @@ func TestBabeService_getEpochDataAndStartSlot(t *testing.T) { C2: 2, } - testEpochDataEpoch0 := &types.EpochData{ - Randomness: [32]byte{9}, - Authorities: []types.Authority{*authority}, + testEpochDataEpoch0 := &types.EpochDataRaw{ + Randomness: [32]byte{9}, + Authorities: []types.AuthorityRaw{ + *authority.ToRaw(), + }, } threshold0, err := CalculateThreshold(testConfigData.C1, testConfigData.C2, 1) @@ -111,7 +113,7 @@ func TestBabeService_getEpochDataAndStartSlot(t *testing.T) { service: func(ctrl *gomock.Controller) *Service { mockEpochState := NewMockEpochState(ctrl) - mockEpochState.EXPECT().GetLatestEpochData().Return(testEpochDataEpoch0, nil) + mockEpochState.EXPECT().GetLatestEpochDataRaw().Return(testEpochDataEpoch0, nil) mockEpochState.EXPECT().GetLatestConfigData().Return(testConfigData, nil) return &Service{ @@ -134,7 +136,7 @@ func TestBabeService_getEpochDataAndStartSlot(t *testing.T) { service: func(ctrl *gomock.Controller) *Service { mockEpochState := NewMockEpochState(ctrl) - mockEpochState.EXPECT().GetEpochData(uint64(1), nil).Return(testEpochData, nil) + mockEpochState.EXPECT().GetEpochDataRaw(uint64(1), nil).Return(testEpochData, nil) mockEpochState.EXPECT().GetConfigData(uint64(1), nil).Return(testConfigData, nil) return &Service{ @@ -157,7 +159,7 @@ func TestBabeService_getEpochDataAndStartSlot(t *testing.T) { service: func(ctrl *gomock.Controller) *Service { mockEpochState := NewMockEpochState(ctrl) - mockEpochState.EXPECT().GetEpochData(uint64(1), nil).Return(testEpochData, nil) + mockEpochState.EXPECT().GetEpochDataRaw(uint64(1), nil).Return(testEpochData, nil) mockEpochState.EXPECT().GetConfigData(uint64(1), nil).Return(testLatestConfigData, nil) return &Service{ diff --git a/lib/babe/mock_state_test.go b/lib/babe/mock_state_test.go index c7f2984d64..cc609ec52d 100644 --- a/lib/babe/mock_state_test.go +++ b/lib/babe/mock_state_test.go @@ -473,19 +473,19 @@ func (mr *MockEpochStateMockRecorder) GetCurrentEpoch() *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetCurrentEpoch", reflect.TypeOf((*MockEpochState)(nil).GetCurrentEpoch)) } -// GetEpochData mocks base method. -func (m *MockEpochState) GetEpochData(arg0 uint64, arg1 *types.Header) (*types.EpochData, error) { +// GetEpochDataRaw mocks base method. +func (m *MockEpochState) GetEpochDataRaw(arg0 uint64, arg1 *types.Header) (*types.EpochDataRaw, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetEpochData", arg0, arg1) - ret0, _ := ret[0].(*types.EpochData) + ret := m.ctrl.Call(m, "GetEpochDataRaw", arg0, arg1) + ret0, _ := ret[0].(*types.EpochDataRaw) ret1, _ := ret[1].(error) return ret0, ret1 } -// GetEpochData indicates an expected call of GetEpochData. -func (mr *MockEpochStateMockRecorder) GetEpochData(arg0, arg1 any) *gomock.Call { +// GetEpochDataRaw indicates an expected call of GetEpochDataRaw. +func (mr *MockEpochStateMockRecorder) GetEpochDataRaw(arg0, arg1 any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetEpochData", reflect.TypeOf((*MockEpochState)(nil).GetEpochData), arg0, arg1) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetEpochDataRaw", reflect.TypeOf((*MockEpochState)(nil).GetEpochDataRaw), arg0, arg1) } // GetEpochForBlock mocks base method. @@ -533,19 +533,19 @@ func (mr *MockEpochStateMockRecorder) GetLatestConfigData() *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetLatestConfigData", reflect.TypeOf((*MockEpochState)(nil).GetLatestConfigData)) } -// GetLatestEpochData mocks base method. -func (m *MockEpochState) GetLatestEpochData() (*types.EpochData, error) { +// GetLatestEpochDataRaw mocks base method. +func (m *MockEpochState) GetLatestEpochDataRaw() (*types.EpochDataRaw, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetLatestEpochData") - ret0, _ := ret[0].(*types.EpochData) + ret := m.ctrl.Call(m, "GetLatestEpochDataRaw") + ret0, _ := ret[0].(*types.EpochDataRaw) ret1, _ := ret[1].(error) return ret0, ret1 } -// GetLatestEpochData indicates an expected call of GetLatestEpochData. -func (mr *MockEpochStateMockRecorder) GetLatestEpochData() *gomock.Call { +// GetLatestEpochDataRaw indicates an expected call of GetLatestEpochDataRaw. +func (mr *MockEpochStateMockRecorder) GetLatestEpochDataRaw() *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetLatestEpochData", reflect.TypeOf((*MockEpochState)(nil).GetLatestEpochData)) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetLatestEpochDataRaw", reflect.TypeOf((*MockEpochState)(nil).GetLatestEpochDataRaw)) } // GetSlotDuration mocks base method. @@ -592,20 +592,6 @@ func (mr *MockEpochStateMockRecorder) SetCurrentEpoch(arg0 any) *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetCurrentEpoch", reflect.TypeOf((*MockEpochState)(nil).SetCurrentEpoch), arg0) } -// SetEpochData mocks base method. -func (m *MockEpochState) SetEpochData(arg0 uint64, arg1 *types.EpochData) error { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "SetEpochData", arg0, arg1) - ret0, _ := ret[0].(error) - return ret0 -} - -// SetEpochData indicates an expected call of SetEpochData. -func (mr *MockEpochStateMockRecorder) SetEpochData(arg0, arg1 any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetEpochData", reflect.TypeOf((*MockEpochState)(nil).SetEpochData), arg0, arg1) -} - // SetFirstSlot mocks base method. func (m *MockEpochState) SetFirstSlot(arg0 uint64) error { m.ctrl.T.Helper() diff --git a/lib/babe/state.go b/lib/babe/state.go index 7652d0f2bc..47de36a930 100644 --- a/lib/babe/state.go +++ b/lib/babe/state.go @@ -61,16 +61,15 @@ type EpochState interface { GetSlotDuration() (time.Duration, error) SetCurrentEpoch(epoch uint64) error GetCurrentEpoch() (uint64, error) - SetEpochData(epoch uint64, info *types.EpochData) error - GetEpochData(epoch uint64, header *types.Header) (*types.EpochData, error) + GetEpochDataRaw(epoch uint64, header *types.Header) (*types.EpochDataRaw, error) GetConfigData(epoch uint64, header *types.Header) (*types.ConfigData, error) GetLatestConfigData() (*types.ConfigData, error) GetStartSlotForEpoch(epoch uint64) (uint64, error) GetEpochForBlock(header *types.Header) (uint64, error) SetFirstSlot(slot uint64) error - GetLatestEpochData() (*types.EpochData, error) + GetLatestEpochDataRaw() (*types.EpochDataRaw, error) SkipVerify(*types.Header) (bool, error) } diff --git a/lib/babe/types.go b/lib/babe/types.go index accea21c49..02457ea083 100644 --- a/lib/babe/types.go +++ b/lib/babe/types.go @@ -58,7 +58,7 @@ func (d Authorities) String() string { type epochData struct { randomness Randomness authorityIndex uint32 - authorities []types.Authority + authorities []types.AuthorityRaw threshold *scale.Uint128 allowedSlots types.AllowedSlots } diff --git a/lib/babe/verify.go b/lib/babe/verify.go index c66022e4ca..8f4841eb04 100644 --- a/lib/babe/verify.go +++ b/lib/babe/verify.go @@ -20,7 +20,7 @@ var errEmptyKeyOwnershipProof = errors.New("key ownership proof is nil") // verifierInfo contains the information needed to verify blocks // it remains the same for an epoch type verifierInfo struct { - authorities []types.Authority + authorities []types.AuthorityRaw randomness Randomness threshold *scale.Uint128 secondarySlots bool @@ -195,7 +195,7 @@ func (v *VerificationManager) VerifyBlock(header *types.Header) error { } func (v *VerificationManager) getVerifierInfo(epoch uint64, header *types.Header) (*verifierInfo, error) { - epochData, err := v.epochState.GetEpochData(epoch, header) + epochData, err := v.epochState.GetEpochDataRaw(epoch, header) if err != nil { return nil, fmt.Errorf("failed to get epoch data for epoch %d: %w", epoch, err) } @@ -223,7 +223,7 @@ type verifier struct { blockState BlockState slotState SlotState epoch uint64 - authorities []types.Authority + authorities []types.AuthorityRaw randomness Randomness threshold *scale.Uint128 secondarySlots bool @@ -294,7 +294,11 @@ func (b *verifier) verifyAuthorshipRight(header *types.Header) error { authIdx = d.AuthorityIndex } - authorPub := b.authorities[authIdx].Key + authority := new(types.Authority) + err = authority.FromRawSr25519(&b.authorities[authIdx]) + if err != nil { + return fmt.Errorf("from raw sr25519: %w", err) + } // remove seal before verifying signature h := types.NewDigest() @@ -331,7 +335,7 @@ func (b *verifier) verifyAuthorshipRight(header *types.Header) error { return err } - ok, err = authorPub.Verify(hash[:], seal.Data) + ok, err = authority.Key.Verify(hash[:], seal.Data) if err != nil { return err } @@ -396,7 +400,7 @@ func (b *verifier) verifyBlockEquivocation(header *types.Header) (bool, error) { } slotNow := getCurrentSlot(b.slotDuration) - signer := types.AuthorityID(b.authorities[authorityIndex].ToRaw().Key) + signer := b.authorities[authorityIndex].Key equivocationProof, err := b.slotState.CheckEquivocation(slotNow, slotNumber, header, signer) if err != nil { @@ -449,9 +453,8 @@ func (b *verifier) verifyPreRuntimeDigest(digest *types.PreRuntimeDigest) (scale ok = false break } - pub := b.authorities[d.AuthorityIndex].Key - - pk, err := sr25519.NewPublicKey(pub.Encode()) + authority := b.authorities[d.AuthorityIndex] + pk, err := sr25519.NewPublicKey(authority.Key[:]) if err != nil { return nil, err } @@ -487,9 +490,8 @@ func (b *verifier) verifyPreRuntimeDigest(digest *types.PreRuntimeDigest) (scale func (b *verifier) verifyPrimarySlotWinner(authorityIndex uint32, slot uint64, vrfOutput [sr25519.VRFOutputLength]byte, vrfProof [sr25519.VRFProofLength]byte) (bool, error) { - pub := b.authorities[authorityIndex].Key - - pk, err := sr25519.NewPublicKey(pub.Encode()) + authority := b.authorities[authorityIndex] + pk, err := sr25519.NewPublicKey(authority.Key[:]) if err != nil { return false, err } @@ -511,10 +513,10 @@ func (b *verifier) verifyPrimarySlotWinner(authorityIndex uint32, // validate VRF proof logger.Tracef("verifyPrimarySlotWinner authority index %d, "+ - "public key %s, randomness 0x%x, slot %d, epoch %d, "+ + "public key 0x%x, randomness 0x%x, slot %d, epoch %d, "+ "output 0x%x and proof 0x%x", authorityIndex, - pub.Hex(), b.randomness, slot, b.epoch, + authority.Key[:], b.randomness, slot, b.epoch, vrfOutput, vrfProof[:]) t := makeTranscript(b.randomness, slot, b.epoch) diff --git a/lib/babe/verify_integration_test.go b/lib/babe/verify_integration_test.go index 5f6e76a5e6..480731817d 100644 --- a/lib/babe/verify_integration_test.go +++ b/lib/babe/verify_integration_test.go @@ -236,9 +236,9 @@ func TestVerificationManager_VerifyBlock_FutureEpoch(t *testing.T) { require.NoError(t, err) const futureEpoch = uint64(2) - err = babeService.epochState.SetEpochData(futureEpoch, &types.EpochData{ - Authorities: []types.Authority{{ - Key: keyring.Alice().(*sr25519.Keypair).Public(), + err = babeService.epochState.(*state.EpochState).SetEpochDataRaw(futureEpoch, &types.EpochDataRaw{ + Authorities: []types.AuthorityRaw{{ + Key: [32]byte(keyring.Alice().(*sr25519.Keypair).Public().Encode()), }}, }) require.NoError(t, err) @@ -286,9 +286,9 @@ func TestVerificationManager_VerifyBlock_MultipleEpochs(t *testing.T) { require.NoError(t, err) const futureEpoch = uint64(2) - err = babeService.epochState.SetEpochData(futureEpoch, &types.EpochData{ - Authorities: []types.Authority{{ - Key: keyring.Alice().(*sr25519.Keypair).Public(), + err = babeService.epochState.(*state.EpochState).SetEpochDataRaw(futureEpoch, &types.EpochDataRaw{ + Authorities: []types.AuthorityRaw{{ + Key: [32]byte(keyring.Alice().(*sr25519.Keypair).Public().Encode()), }}, }) require.NoError(t, err) @@ -664,13 +664,8 @@ func TestVerifyForkBlocksWithRespectiveEpochData(t *testing.T) { require.NoError(t, err) require.Equal(t, len(authorities[3:]), len(verifierInfo.authorities)) - rawAuthorities := make([]types.AuthorityRaw, len(verifierInfo.authorities)) + require.ElementsMatch(t, authorities[3:], verifierInfo.authorities) - for i, auth := range verifierInfo.authorities { - rawAuthorities[i] = *auth.ToRaw() - } - - require.ElementsMatch(t, authorities[3:], rawAuthorities) require.True(t, verifierInfo.secondarySlots) require.Equal(t, expectedThreshold, verifierInfo.threshold) } @@ -686,14 +681,9 @@ func TestVerifyForkBlocksWithRespectiveEpochData(t *testing.T) { require.NoError(t, err) require.Equal(t, len(authorities[6:]), len(verifierInfo.authorities)) - rawAuthorities := make([]types.AuthorityRaw, len(verifierInfo.authorities)) - - for i, auth := range verifierInfo.authorities { - rawAuthorities[i] = *auth.ToRaw() - } - // should keep the original authorities - require.ElementsMatch(t, authorities[6:], rawAuthorities) + require.ElementsMatch(t, authorities[6:], verifierInfo.authorities) + require.True(t, verifierInfo.secondarySlots) require.Equal(t, expectedThreshold, verifierInfo.threshold) } @@ -719,14 +709,9 @@ func TestVerifyForkBlocksWithRespectiveEpochData(t *testing.T) { require.NoError(t, err) require.Equal(t, len(authorities[6:]), len(verifierInfo.authorities)) - rawAuthorities := make([]types.AuthorityRaw, len(verifierInfo.authorities)) - - for i, auth := range verifierInfo.authorities { - rawAuthorities[i] = *auth.ToRaw() - } - // should keep the original authorities - require.ElementsMatch(t, authorities[6:], rawAuthorities) + require.ElementsMatch(t, authorities[6:], verifierInfo.authorities) + require.True(t, verifierInfo.secondarySlots) require.Equal(t, expectedThreshold, verifierInfo.threshold) } diff --git a/lib/babe/verify_test.go b/lib/babe/verify_test.go index e91f54ea08..a70879fe3d 100644 --- a/lib/babe/verify_test.go +++ b/lib/babe/verify_test.go @@ -75,7 +75,7 @@ func newTestVerifier(kp *sr25519.Keypair, blockState BlockState, slotState SlotS threshold *scale.Uint128, secSlots bool) *verifier { authority := types.NewAuthority(kp.Public(), uint64(1)) info := &verifierInfo{ - authorities: []types.Authority{*authority, *authority}, + authorities: []types.AuthorityRaw{*authority.ToRaw(), *authority.ToRaw()}, randomness: Randomness{}, threshold: threshold, secondarySlots: secSlots, @@ -221,12 +221,12 @@ func Test_verifier_verifyPrimarySlotWinner(t *testing.T) { auth := types.NewAuthority(kp.Public(), uint64(1)) vi := &verifierInfo{ - authorities: []types.Authority{*auth}, + authorities: []types.AuthorityRaw{*auth.ToRaw()}, threshold: &scale.Uint128{}, } vi1 := &verifierInfo{ - authorities: []types.Authority{*auth}, + authorities: []types.AuthorityRaw{*auth.ToRaw()}, threshold: scale.MaxUint128, } @@ -315,7 +315,7 @@ func Test_verifier_verifyPreRuntimeDigest(t *testing.T) { auth := types.NewAuthority(kp.Public(), uint64(1)) vi := &verifierInfo{ - authorities: []types.Authority{*auth, *auth}, + authorities: []types.AuthorityRaw{*auth.ToRaw(), *auth.ToRaw()}, threshold: scale.MaxUint128, } @@ -328,7 +328,7 @@ func Test_verifier_verifyPreRuntimeDigest(t *testing.T) { // Above threshold case vi1 := &verifierInfo{ - authorities: []types.Authority{*auth, *auth}, + authorities: []types.AuthorityRaw{*auth.ToRaw(), *auth.ToRaw()}, threshold: &scale.Uint128{}, } @@ -352,12 +352,12 @@ func Test_verifier_verifyPreRuntimeDigest(t *testing.T) { authVRFSec := types.NewAuthority(kp.Public(), uint64(1)) viVRFSec := &verifierInfo{ - authorities: []types.Authority{*authVRFSec, *authVRFSec}, + authorities: []types.AuthorityRaw{*authVRFSec.ToRaw(), *authVRFSec.ToRaw()}, threshold: scale.MaxUint128, } viVRFSec2 := &verifierInfo{ - authorities: []types.Authority{*authVRFSec, *authVRFSec}, + authorities: []types.AuthorityRaw{*authVRFSec.ToRaw(), *authVRFSec.ToRaw()}, threshold: scale.MaxUint128, secondarySlots: true, } @@ -369,12 +369,12 @@ func Test_verifier_verifyPreRuntimeDigest(t *testing.T) { authSec := types.NewAuthority(kp.Public(), uint64(1)) viSec := &verifierInfo{ - authorities: []types.Authority{*authSec, *authSec}, + authorities: []types.AuthorityRaw{*authSec.ToRaw(), *authSec.ToRaw()}, threshold: scale.MaxUint128, } viSec2 := &verifierInfo{ - authorities: []types.Authority{*authSec, *authSec}, + authorities: []types.AuthorityRaw{*authSec.ToRaw(), *authSec.ToRaw()}, threshold: scale.MaxUint128, secondarySlots: true, } @@ -730,7 +730,7 @@ func Test_verifyBlockEquivocation(t *testing.T) { wantErr: types.ErrNoFirstPreDigest, buildVerifier: func(t *testing.T) *verifier { return &verifier{ - authorities: []types.Authority{}, + authorities: []types.AuthorityRaw{}, } }, }, @@ -740,7 +740,7 @@ func Test_verifyBlockEquivocation(t *testing.T) { wantErr: ErrAuthIndexOutOfBound, buildVerifier: func(t *testing.T) *verifier { return &verifier{ - authorities: []types.Authority{}, + authorities: []types.AuthorityRaw{}, } }, }, @@ -763,9 +763,9 @@ func Test_verifyBlockEquivocation(t *testing.T) { Return(nil, slotStateMockErr) return &verifier{ - authorities: []types.Authority{ + authorities: []types.AuthorityRaw{ { - Key: kp.Public(), + Key: [32]byte(kp.Public().Encode()), Weight: 1, }, }, @@ -792,9 +792,9 @@ func Test_verifyBlockEquivocation(t *testing.T) { Return(nil, nil) return &verifier{ - authorities: []types.Authority{ + authorities: []types.AuthorityRaw{ { - Key: kp.Public(), + Key: [32]byte(kp.Public().Encode()), Weight: 1, }, }, @@ -848,9 +848,9 @@ func Test_verifyBlockEquivocation(t *testing.T) { mockBlockState.EXPECT().GetRuntime(defaultHeader.Hash()).Return(mockRuntimeInstance, nil) return &verifier{ - authorities: []types.Authority{ + authorities: []types.AuthorityRaw{ { - Key: kp.Public(), + Key: [32]byte(kp.Public().Encode()), Weight: 1, }, }, @@ -893,9 +893,9 @@ func Test_verifyBlockEquivocation(t *testing.T) { mockBlockState.EXPECT().GetRuntime(defaultHeader.Hash()).Return(nil, getRuntimeErr) return &verifier{ - authorities: []types.Authority{ + authorities: []types.AuthorityRaw{ { - Key: kp.Public(), + Key: [32]byte(kp.Public().Encode()), Weight: 1, }, }, @@ -933,7 +933,7 @@ func Test_verifier_submitAndReportEquivocation(t *testing.T) { auth := types.NewAuthority(keyPair.Public(), uint64(1)) vi := &verifierInfo{ - authorities: []types.Authority{*auth, *auth}, + authorities: []types.AuthorityRaw{*auth.ToRaw(), *auth.ToRaw()}, threshold: scale.MaxUint128, } @@ -976,7 +976,7 @@ func Test_verifier_submitAndReportEquivocation(t *testing.T) { secondHeader := newTestHeader(t, *preRuntimeDigest2) - offenderPublicKey := verifier.authorities[authorityIndex].ToRaw().Key + offenderPublicKey := verifier.authorities[authorityIndex].Key keyOwnershipProof := testKeyOwnershipProof mockRuntime := mocks.NewMockInstance(ctrl) @@ -1071,7 +1071,7 @@ func Test_verifier_verifyAuthorshipRightEquivocatory(t *testing.T) { mockBlockState.EXPECT().GetRuntime(header.Hash()).Return(mockRuntime, nil) auth := types.NewAuthority(kp.Public(), uint64(1)) info := &verifierInfo{ - authorities: []types.Authority{*auth, *auth}, + authorities: []types.AuthorityRaw{*auth.ToRaw(), *auth.ToRaw()}, threshold: scale.MaxUint128, } @@ -1132,7 +1132,7 @@ func Test_verifier_verifyAuthorshipRightEquivocatory(t *testing.T) { mockBlockState.EXPECT().GetRuntime(header.Hash()).Return(mockRuntime, nil) auth := types.NewAuthority(kp.Public(), uint64(1)) info := &verifierInfo{ - authorities: []types.Authority{*auth, *auth}, + authorities: []types.AuthorityRaw{*auth.ToRaw(), *auth.ToRaw()}, threshold: scale.MaxUint128, secondarySlots: true, randomness: Randomness{}, @@ -1203,7 +1203,7 @@ func Test_verifier_verifyAuthorshipRightEquivocatory(t *testing.T) { auth := types.NewAuthority(kp.Public(), uint64(1)) info := &verifierInfo{ - authorities: []types.Authority{*auth, *auth}, + authorities: []types.AuthorityRaw{*auth.ToRaw(), *auth.ToRaw()}, threshold: scale.MaxUint128, secondarySlots: true, randomness: Randomness{}, @@ -1236,19 +1236,19 @@ func TestVerificationManager_getVerifierInfo(t *testing.T) { testHeader := types.NewEmptyHeader() - mockEpochStateGetErr.EXPECT().GetEpochData(uint64(0), testHeader).Return(nil, state.ErrEpochNotInMemory) + mockEpochStateGetErr.EXPECT().GetEpochDataRaw(uint64(0), testHeader).Return(nil, state.ErrEpochNotInMemory) - mockEpochStateHasErr.EXPECT().GetEpochData(uint64(0), testHeader).Return(&types.EpochData{}, nil) + mockEpochStateHasErr.EXPECT().GetEpochDataRaw(uint64(0), testHeader).Return(&types.EpochDataRaw{}, nil) mockEpochStateHasErr.EXPECT().GetConfigData(uint64(0), testHeader).Return(&types.ConfigData{}, state.ErrConfigNotFound) - mockEpochStateThresholdErr.EXPECT().GetEpochData(uint64(0), testHeader).Return(&types.EpochData{}, nil) + mockEpochStateThresholdErr.EXPECT().GetEpochDataRaw(uint64(0), testHeader).Return(&types.EpochDataRaw{}, nil) mockEpochStateThresholdErr.EXPECT().GetConfigData(uint64(0), testHeader). Return(&types.ConfigData{ C1: 3, C2: 1, }, nil) - mockEpochStateOk.EXPECT().GetEpochData(uint64(0), testHeader).Return(&types.EpochData{}, nil) + mockEpochStateOk.EXPECT().GetEpochDataRaw(uint64(0), testHeader).Return(&types.EpochDataRaw{}, nil) mockEpochStateOk.EXPECT().GetConfigData(uint64(0), testHeader). Return(&types.ConfigData{ C1: 1, @@ -1345,16 +1345,16 @@ func TestVerificationManager_VerifyBlock(t *testing.T) { mockEpochStateSkipVerifyErr.EXPECT().GetEpochForBlock(testBlockHeaderEmpty).Return(uint64(1), nil) errTestGetEpochData := errors.New("test get epoch data error") - mockEpochStateSkipVerifyErr.EXPECT().GetEpochData(uint64(1), testBlockHeaderEmpty).Return(nil, errTestGetEpochData) + mockEpochStateSkipVerifyErr.EXPECT().GetEpochDataRaw(uint64(1), testBlockHeaderEmpty).Return(nil, errTestGetEpochData) errTestSkipVerify := errors.New("test skip verify error") mockEpochStateSkipVerifyErr.EXPECT().SkipVerify(testBlockHeaderEmpty).Return(false, errTestSkipVerify) mockEpochStateSkipVerifyTrue.EXPECT().GetEpochForBlock(testBlockHeaderEmpty).Return(uint64(1), nil) - mockEpochStateSkipVerifyTrue.EXPECT().GetEpochData(uint64(1), testBlockHeaderEmpty).Return(nil, errTestGetEpochData) + mockEpochStateSkipVerifyTrue.EXPECT().GetEpochDataRaw(uint64(1), testBlockHeaderEmpty).Return(nil, errTestGetEpochData) mockEpochStateSkipVerifyTrue.EXPECT().SkipVerify(testBlockHeaderEmpty).Return(true, nil) mockEpochStateGetVerifierInfoErr.EXPECT().GetEpochForBlock(testBlockHeaderEmpty).Return(uint64(1), nil) - mockEpochStateGetVerifierInfoErr.EXPECT().GetEpochData(uint64(1), testBlockHeaderEmpty). + mockEpochStateGetVerifierInfoErr.EXPECT().GetEpochDataRaw(uint64(1), testBlockHeaderEmpty). Return(nil, errTestGetEpochData) mockEpochStateGetVerifierInfoErr.EXPECT().SkipVerify(testBlockHeaderEmpty).Return(false, nil) @@ -1376,7 +1376,7 @@ func TestVerificationManager_VerifyBlock(t *testing.T) { authority := types.NewAuthority(kp.Public(), uint64(1)) info := &verifierInfo{ - authorities: []types.Authority{*authority, *authority}, + authorities: []types.AuthorityRaw{*authority.ToRaw(), *authority.ToRaw()}, threshold: scale.MaxUint128, secondarySlots: true, } @@ -1488,7 +1488,9 @@ func TestVerificationManager_SetOnDisabled(t *testing.T) { mockEpochStateGetEpochDataErr.EXPECT().GetEpochForBlock(types.NewEmptyHeader()).Return(uint64(0), nil) errTestGetEpochData := errors.New("test get epoch data error") - mockEpochStateGetEpochDataErr.EXPECT().GetEpochData(uint64(0), types.NewEmptyHeader()).Return(nil, errTestGetEpochData) + mockEpochStateGetEpochDataErr.EXPECT(). + GetEpochDataRaw(uint64(0), types.NewEmptyHeader()). + Return(nil, errTestGetEpochData) mockEpochStateIndexLenErr.EXPECT().GetEpochForBlock(types.NewEmptyHeader()).Return(uint64(2), nil) @@ -1508,7 +1510,7 @@ func TestVerificationManager_SetOnDisabled(t *testing.T) { authority := types.NewAuthority(kp.Public(), uint64(1)) info := &verifierInfo{ - authorities: []types.Authority{*authority, *authority}, + authorities: []types.AuthorityRaw{*authority.ToRaw(), *authority.ToRaw()}, threshold: scale.MaxUint128, secondarySlots: true, }