Skip to content

Commit 669366e

Browse files
committed
Remove types.ActivationTxHeader (#5895)
## Motivation It's redundant and could be replaced with `types.ActivationTx`.
1 parent 63dc6a8 commit 669366e

24 files changed

+257
-337
lines changed

activation/handler_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -640,7 +640,7 @@ func TestHandler_AtxWeight(t *testing.T) {
640640
atxHdlr.expectAtxV1(atx1, sig.NodeID(), func(o *atxHandleOpts) { o.poetLeaves = leaves })
641641
require.NoError(t, atxHdlr.HandleSyncedAtx(context.Background(), atx1.ID().Hash32(), peer, buf))
642642

643-
stored1, err := atxHdlr.cdb.GetAtxHeader(atx1.ID())
643+
stored1, err := atxHdlr.cdb.GetAtx(atx1.ID())
644644
require.NoError(t, err)
645645
require.Equal(t, uint64(0), stored1.BaseTickHeight)
646646
require.Equal(t, leaves/tickSize, stored1.TickCount)
@@ -655,7 +655,7 @@ func TestHandler_AtxWeight(t *testing.T) {
655655
atxHdlr.mockFetch.EXPECT().GetAtxs(gomock.Any(), []types.ATXID{atx1.ID()}, gomock.Any())
656656
require.NoError(t, atxHdlr.HandleSyncedAtx(context.Background(), atx2.ID().Hash32(), peer, buf))
657657

658-
stored2, err := atxHdlr.cdb.GetAtxHeader(atx2.ID())
658+
stored2, err := atxHdlr.cdb.GetAtx(atx2.ID())
659659
require.NoError(t, err)
660660
require.Equal(t, stored1.TickHeight(), stored2.BaseTickHeight)
661661
require.Equal(t, leaves/tickSize, stored2.TickCount)

activation/handler_v1.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ func (h *HandlerV1) storeAtx(
418418
}
419419

420420
added := h.cacheAtx(ctx, atx, *nonce)
421-
h.beacon.OnAtx(atx.ToHeader())
421+
h.beacon.OnAtx(atx)
422422
if added != nil {
423423
h.tortoise.OnAtx(atx.TargetEpoch(), atx.ID(), added)
424424
}
@@ -439,7 +439,7 @@ func (h *HandlerV1) processATX(
439439
return nil, fmt.Errorf("invalid atx signature: %w", errMalformedData)
440440
}
441441

442-
existing, _ := h.cdb.GetAtxHeader(watx.ID())
442+
existing, _ := h.cdb.GetAtx(watx.ID())
443443
if existing != nil {
444444
return nil, fmt.Errorf("%w atx %s", errKnownAtx, watx.ID())
445445
}
@@ -475,7 +475,7 @@ func (h *HandlerV1) processATX(
475475

476476
var baseTickHeight uint64
477477
if watx.PositioningATXID != h.goldenATXID {
478-
posAtx, err := h.cdb.GetAtxHeader(watx.PositioningATXID)
478+
posAtx, err := h.cdb.GetAtx(watx.PositioningATXID)
479479
if err != nil {
480480
return nil, fmt.Errorf("failed to get positioning atx %s: %w", watx.PositioningATXID, err)
481481
}

activation/handler_v1_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,7 @@ func TestHandlerV1_StoreAtx(t *testing.T) {
565565
vAtx := toAtx(t, watx)
566566
require.NoError(t, err)
567567

568-
atxHdlr.mbeacon.EXPECT().OnAtx(vAtx.ToHeader())
568+
atxHdlr.mbeacon.EXPECT().OnAtx(vAtx)
569569
atxHdlr.mtortoise.EXPECT().OnAtx(gomock.Any(), vAtx.ID(), gomock.Any())
570570
proof, err := atxHdlr.storeAtx(context.Background(), vAtx, watx.Signature)
571571
require.NoError(t, err)
@@ -585,13 +585,13 @@ func TestHandlerV1_StoreAtx(t *testing.T) {
585585
watx.Sign(sig)
586586
vAtx := toAtx(t, watx)
587587

588-
atxHdlr.mbeacon.EXPECT().OnAtx(vAtx.ToHeader())
588+
atxHdlr.mbeacon.EXPECT().OnAtx(vAtx)
589589
atxHdlr.mtortoise.EXPECT().OnAtx(gomock.Any(), vAtx.ID(), gomock.Any())
590590
proof, err := atxHdlr.storeAtx(context.Background(), vAtx, watx.Signature)
591591
require.NoError(t, err)
592592
require.Nil(t, proof)
593593

594-
atxHdlr.mbeacon.EXPECT().OnAtx(vAtx.ToHeader())
594+
atxHdlr.mbeacon.EXPECT().OnAtx(vAtx)
595595
// Note: tortoise is not informed about the same ATX again
596596
proof, err = atxHdlr.storeAtx(context.Background(), vAtx, watx.Signature)
597597
require.NoError(t, err)
@@ -605,7 +605,7 @@ func TestHandlerV1_StoreAtx(t *testing.T) {
605605
watx0.Sign(sig)
606606
vAtx0 := toAtx(t, watx0)
607607

608-
atxHdlr.mbeacon.EXPECT().OnAtx(vAtx0.ToHeader())
608+
atxHdlr.mbeacon.EXPECT().OnAtx(vAtx0)
609609
atxHdlr.mtortoise.EXPECT().OnAtx(gomock.Any(), vAtx0.ID(), gomock.Any())
610610

611611
proof, err := atxHdlr.storeAtx(context.Background(), vAtx0, watx0.Signature)
@@ -617,7 +617,7 @@ func TestHandlerV1_StoreAtx(t *testing.T) {
617617
watx1.Sign(sig)
618618
vAtx1 := toAtx(t, watx1)
619619

620-
atxHdlr.mbeacon.EXPECT().OnAtx(vAtx1.ToHeader())
620+
atxHdlr.mbeacon.EXPECT().OnAtx(vAtx1)
621621
atxHdlr.mtortoise.EXPECT().OnAtx(gomock.Any(), vAtx1.ID(), gomock.Any())
622622
atxHdlr.mtortoise.EXPECT().OnMalfeasance(sig.NodeID())
623623

@@ -651,7 +651,7 @@ func TestHandlerV1_StoreAtx(t *testing.T) {
651651
watx0.Sign(sig)
652652
vAtx0 := toAtx(t, watx0)
653653

654-
atxHdlr.mbeacon.EXPECT().OnAtx(vAtx0.ToHeader())
654+
atxHdlr.mbeacon.EXPECT().OnAtx(vAtx0)
655655
atxHdlr.mtortoise.EXPECT().OnAtx(gomock.Any(), vAtx0.ID(), gomock.Any())
656656

657657
proof, err := atxHdlr.storeAtx(context.Background(), vAtx0, watx0.Signature)

activation/interface.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import (
1818
//go:generate mockgen -typed -package=activation -destination=./mocks.go -source=./interface.go
1919

2020
type AtxReceiver interface {
21-
OnAtx(*types.ActivationTxHeader)
21+
OnAtx(*types.ActivationTx)
2222
}
2323

2424
type PostVerifier interface {
@@ -94,7 +94,7 @@ type syncer interface {
9494
}
9595

9696
type atxProvider interface {
97-
GetAtxHeader(id types.ATXID) (*types.ActivationTxHeader, error)
97+
GetAtx(id types.ATXID) (*types.ActivationTx, error)
9898
}
9999

100100
// PostSetupProvider defines the functionality required for Post setup.

activation/mocks.go

Lines changed: 16 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

activation/validation.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ func (v *Validator) InitialNIPostChallengeV1(
236236
}
237237
commitmentATXId := *challenge.CommitmentATXID
238238
if commitmentATXId != goldenATXID {
239-
commitmentAtx, err := atxs.GetAtxHeader(commitmentATXId)
239+
commitmentAtx, err := atxs.GetAtx(commitmentATXId)
240240
if err != nil {
241241
return &ErrAtxNotFound{Id: commitmentATXId, source: err}
242242
}
@@ -289,7 +289,7 @@ func (v *Validator) PositioningAtx(
289289
if id == goldenATXID {
290290
return nil
291291
}
292-
posAtx, err := atxs.GetAtxHeader(id)
292+
posAtx, err := atxs.GetAtx(id)
293293
if err != nil {
294294
return &ErrAtxNotFound{Id: id, source: err}
295295
}

activation/validation_test.go

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ func Test_Validation_InitialNIPostChallenge(t *testing.T) {
112112
}
113113

114114
atxProvider := NewMockatxProvider(ctrl)
115-
atxProvider.EXPECT().GetAtxHeader(commitmentAtxId).Return(&types.ActivationTxHeader{PublishEpoch: 1}, nil)
115+
atxProvider.EXPECT().GetAtx(commitmentAtxId).Return(&types.ActivationTx{PublishEpoch: 1}, nil)
116116

117117
err := v.InitialNIPostChallengeV1(&challenge, atxProvider, goldenATXID)
118118
require.NoError(t, err)
@@ -149,7 +149,7 @@ func Test_Validation_InitialNIPostChallenge(t *testing.T) {
149149
InitialPost: &wire.PostV1{},
150150
}
151151
atxProvider := NewMockatxProvider(ctrl)
152-
atxProvider.EXPECT().GetAtxHeader(commitmentAtxId).Return(&types.ActivationTxHeader{PublishEpoch: 2}, nil)
152+
atxProvider.EXPECT().GetAtx(commitmentAtxId).Return(&types.ActivationTx{PublishEpoch: 2}, nil)
153153

154154
err := v.InitialNIPostChallengeV1(&challenge, atxProvider, goldenATXID)
155155
require.EqualError(t, err, "challenge pubepoch (1) must be after commitment atx pubepoch (2)")
@@ -294,9 +294,7 @@ func Test_Validation_PositioningAtx(t *testing.T) {
294294
goldenAtxId := types.ATXID{9, 9, 9}
295295

296296
atxProvider := NewMockatxProvider(ctrl)
297-
atxProvider.EXPECT().GetAtxHeader(posAtxId).Return(&types.ActivationTxHeader{
298-
PublishEpoch: 1,
299-
}, nil)
297+
atxProvider.EXPECT().GetAtx(posAtxId).Return(&types.ActivationTx{PublishEpoch: 1}, nil)
300298

301299
err := v.PositioningAtx(posAtxId, atxProvider, goldenAtxId, 2)
302300
require.NoError(t, err)
@@ -331,7 +329,7 @@ func Test_Validation_PositioningAtx(t *testing.T) {
331329
goldenAtxId := types.ATXID{9, 9, 9}
332330

333331
atxProvider := NewMockatxProvider(ctrl)
334-
atxProvider.EXPECT().GetAtxHeader(posAtxId).Return(nil, errors.New("db error"))
332+
atxProvider.EXPECT().GetAtx(posAtxId).Return(nil, errors.New("db error"))
335333

336334
err := v.PositioningAtx(posAtxId, atxProvider, goldenAtxId, types.LayerID(1012).GetEpoch())
337335
require.ErrorIs(t, err, &ErrAtxNotFound{Id: posAtxId})
@@ -345,9 +343,7 @@ func Test_Validation_PositioningAtx(t *testing.T) {
345343
goldenAtxId := types.ATXID{9, 9, 9}
346344

347345
atxProvider := NewMockatxProvider(ctrl)
348-
atxProvider.EXPECT().GetAtxHeader(posAtxId).Return(&types.ActivationTxHeader{
349-
PublishEpoch: 5,
350-
}, nil)
346+
atxProvider.EXPECT().GetAtx(posAtxId).Return(&types.ActivationTx{PublishEpoch: 5}, nil)
351347

352348
err := v.PositioningAtx(posAtxId, atxProvider, goldenAtxId, 3)
353349
require.EqualError(t, err, "positioning atx epoch (5) must be before 3")
@@ -360,9 +356,7 @@ func Test_Validation_PositioningAtx(t *testing.T) {
360356
goldenAtxId := types.ATXID{9, 9, 9}
361357

362358
atxProvider := NewMockatxProvider(ctrl)
363-
atxProvider.EXPECT().GetAtxHeader(posAtxId).Return(&types.ActivationTxHeader{
364-
PublishEpoch: 1,
365-
}, nil)
359+
atxProvider.EXPECT().GetAtx(posAtxId).Return(&types.ActivationTx{PublishEpoch: 1}, nil)
366360

367361
err := v.PositioningAtx(posAtxId, atxProvider, goldenAtxId, 10)
368362
require.NoError(t, err)

api/grpcserver/activation_service.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func (s *activationService) Get(ctx context.Context, request *pb.GetRequest) (*p
5555
}
5656

5757
atxId := types.ATXID(types.BytesToHash(request.Id))
58-
atx, err := s.atxProvider.GetFullAtx(atxId)
58+
atx, err := s.atxProvider.GetAtx(atxId)
5959
if err != nil || atx == nil {
6060
ctxzap.Debug(ctx, "failed to get ATX",
6161
zap.Stringer("id", atxId),
@@ -91,7 +91,7 @@ func (s *activationService) Highest(ctx context.Context, req *emptypb.Empty) (*p
9191
},
9292
}, nil
9393
}
94-
atx, err := s.atxProvider.GetFullAtx(highest)
94+
atx, err := s.atxProvider.GetAtx(highest)
9595
if err != nil || atx == nil {
9696
return nil, status.Error(codes.NotFound, fmt.Sprintf("atx id %v not found: %v", highest, err.Error()))
9797
}

api/grpcserver/activation_service_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func Test_Highest_ReturnsMaxTickHeight(t *testing.T) {
5353
id := types.RandomATXID()
5454
atx.SetID(id)
5555
atxProvider.EXPECT().MaxHeightAtx().Return(id, nil)
56-
atxProvider.EXPECT().GetFullAtx(id).Return(&atx, nil)
56+
atxProvider.EXPECT().GetAtx(id).Return(&atx, nil)
5757

5858
response, err := activationService.Highest(context.Background(), &emptypb.Empty{})
5959
require.NoError(t, err)
@@ -82,7 +82,7 @@ func TestGet_AtxNotPresent(t *testing.T) {
8282
activationService := grpcserver.NewActivationService(atxProvider, types.ATXID{1})
8383

8484
id := types.RandomATXID()
85-
atxProvider.EXPECT().GetFullAtx(id).Return(nil, nil)
85+
atxProvider.EXPECT().GetAtx(id).Return(nil, nil)
8686

8787
_, err := activationService.Get(context.Background(), &pb.GetRequest{Id: id.Bytes()})
8888
require.Error(t, err)
@@ -95,7 +95,7 @@ func TestGet_AtxProviderReturnsFailure(t *testing.T) {
9595
activationService := grpcserver.NewActivationService(atxProvider, types.ATXID{1})
9696

9797
id := types.RandomATXID()
98-
atxProvider.EXPECT().GetFullAtx(id).Return(&types.ActivationTx{}, errors.New(""))
98+
atxProvider.EXPECT().GetAtx(id).Return(&types.ActivationTx{}, errors.New(""))
9999

100100
_, err := activationService.Get(context.Background(), &pb.GetRequest{Id: id.Bytes()})
101101
require.Error(t, err)
@@ -116,7 +116,7 @@ func TestGet_HappyPath(t *testing.T) {
116116
NumUnits: rand.Uint32(),
117117
}
118118
atx.SetID(id)
119-
atxProvider.EXPECT().GetFullAtx(id).Return(&atx, nil)
119+
atxProvider.EXPECT().GetAtx(id).Return(&atx, nil)
120120
atxProvider.EXPECT().GetMalfeasanceProof(gomock.Any()).Return(nil, sql.ErrNotFound)
121121

122122
response, err := activationService.Get(context.Background(), &pb.GetRequest{Id: id.Bytes()})
@@ -148,7 +148,7 @@ func TestGet_IdentityCanceled(t *testing.T) {
148148
SmesherID: smesher,
149149
}
150150
atx.SetID(id)
151-
atxProvider.EXPECT().GetFullAtx(id).Return(&atx, nil)
151+
atxProvider.EXPECT().GetAtx(id).Return(&atx, nil)
152152
atxProvider.EXPECT().GetMalfeasanceProof(smesher).Return(proof, nil)
153153

154154
response, err := activationService.Get(context.Background(), &pb.GetRequest{Id: id.Bytes()})

api/grpcserver/interface.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ type txValidator interface {
5353

5454
// atxProvider is used by ActivationService to get ATXes.
5555
type atxProvider interface {
56-
GetFullAtx(id types.ATXID) (*types.ActivationTx, error)
56+
GetAtx(id types.ATXID) (*types.ActivationTx, error)
5757
MaxHeightAtx() (types.ATXID, error)
5858
GetMalfeasanceProof(id types.NodeID) (*wire.MalfeasanceProof, error)
5959
}

0 commit comments

Comments
 (0)