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

[Merged by Bors] - v2alpha1 malfeasance API #6353

Closed
wants to merge 18 commits into from
Closed
39 changes: 39 additions & 0 deletions activation/malfeasance.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"context"
"errors"
"fmt"
"strconv"

"github.com/prometheus/client_golang/prometheus"
"github.com/spacemeshos/post/shared"
Expand Down Expand Up @@ -44,6 +45,19 @@
}
}

func (mh *MalfeasanceHandler) Info(data wire.ProofData) (map[string]string, error) {
ap, ok := data.(*wire.AtxProof)
if !ok {
return nil, errors.New("wrong message type for multiple ATXs")

Check warning on line 51 in activation/malfeasance.go

View check run for this annotation

Codecov / codecov/patch

activation/malfeasance.go#L48-L51

Added lines #L48 - L51 were not covered by tests
}
return map[string]string{
"atx1": ap.Messages[0].InnerMsg.MsgHash.String(),
"atx2": ap.Messages[1].InnerMsg.MsgHash.String(),
"publish_epoch": strconv.FormatUint(uint64(ap.Messages[0].InnerMsg.PublishEpoch), 10),
"smesher_id": ap.Messages[0].SmesherID.String(),
}, nil

Check warning on line 58 in activation/malfeasance.go

View check run for this annotation

Codecov / codecov/patch

activation/malfeasance.go#L53-L58

Added lines #L53 - L58 were not covered by tests
}

func (mh *MalfeasanceHandler) Validate(ctx context.Context, data wire.ProofData) (types.NodeID, error) {
ap, ok := data.(*wire.AtxProof)
if !ok {
Expand Down Expand Up @@ -109,6 +123,18 @@
}
}

func (mh *InvalidPostIndexHandler) Info(data wire.ProofData) (map[string]string, error) {
pp, ok := data.(*wire.InvalidPostIndexProof)
if !ok {
return nil, errors.New("wrong message type for invalid post index")

Check warning on line 129 in activation/malfeasance.go

View check run for this annotation

Codecov / codecov/patch

activation/malfeasance.go#L126-L129

Added lines #L126 - L129 were not covered by tests
}
return map[string]string{
"atx": pp.Atx.ID().String(),
"index": strconv.FormatUint(uint64(pp.InvalidIdx), 10),
"smesher_id": pp.Atx.SmesherID.String(),
}, nil

Check warning on line 135 in activation/malfeasance.go

View check run for this annotation

Codecov / codecov/patch

activation/malfeasance.go#L131-L135

Added lines #L131 - L135 were not covered by tests
}

func (mh *InvalidPostIndexHandler) Validate(ctx context.Context, data wire.ProofData) (types.NodeID, error) {
proof, ok := data.(*wire.InvalidPostIndexProof)
if !ok {
Expand Down Expand Up @@ -174,6 +200,19 @@
}
}

func (mh *InvalidPrevATXHandler) Info(data wire.ProofData) (map[string]string, error) {
pp, ok := data.(*wire.InvalidPrevATXProof)
if !ok {
return nil, errors.New("wrong message type for invalid previous ATX")

Check warning on line 206 in activation/malfeasance.go

View check run for this annotation

Codecov / codecov/patch

activation/malfeasance.go#L203-L206

Added lines #L203 - L206 were not covered by tests
}
return map[string]string{
"atx1": pp.Atx1.ID().String(),
"atx2": pp.Atx2.ID().String(),
"prev_atx": pp.Atx1.PrevATXID.String(),
"smesher_id": pp.Atx1.SmesherID.String(),
}, nil

Check warning on line 213 in activation/malfeasance.go

View check run for this annotation

Codecov / codecov/patch

activation/malfeasance.go#L208-L213

Added lines #L208 - L213 were not covered by tests
}

func (mh *InvalidPrevATXHandler) Validate(ctx context.Context, data wire.ProofData) (types.NodeID, error) {
proof, ok := data.(*wire.InvalidPrevATXProof)
if !ok {
Expand Down
5 changes: 4 additions & 1 deletion api/grpcserver/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ const (
TransactionV2Alpha1 Service = "transaction_v2alpha1"
TransactionStreamV2Alpha1 Service = "transaction_stream_v2alpha1"
AccountV2Alpha1 Service = "account_v2alpha1"
MalfeasanceV2Alpha1 Service = "malfeasance_v2alpha1"
MalfeasanceStreamV2Alpha1 Service = "malfeasance_stream_v2alpha1"
)

// DefaultConfig defines the default configuration options for api.
Expand All @@ -57,12 +59,13 @@ func DefaultConfig() Config {
PublicServices: []Service{
GlobalState, Mesh, Transaction, Node, Activation, ActivationV2Alpha1,
RewardV2Alpha1, NetworkV2Alpha1, NodeV2Alpha1, LayerV2Alpha1, TransactionV2Alpha1,
AccountV2Alpha1,
AccountV2Alpha1, MalfeasanceV2Alpha1,
},
PublicListener: "0.0.0.0:9092",
PrivateServices: []Service{
Admin, Smesher, Debug, ActivationStreamV2Alpha1,
RewardStreamV2Alpha1, LayerStreamV2Alpha1, TransactionStreamV2Alpha1,
MalfeasanceStreamV2Alpha1,
},
PrivateListener: "127.0.0.1:9093",
PostServices: []Service{Post, PostInfo},
Expand Down
4 changes: 2 additions & 2 deletions api/grpcserver/globalstate_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func TestGlobalStateService(t *testing.T) {

_, err := c.AccountDataQuery(ctx, &pb.AccountDataQueryRequest{})
require.Error(t, err)
require.Contains(t, err.Error(), "`Filter` must be provided")
require.ErrorContains(t, err, "`Filter` must be provided")
})
t.Run("AccountDataQuery_MissingFlags", func(t *testing.T) {
t.Parallel()
Expand All @@ -91,7 +91,7 @@ func TestGlobalStateService(t *testing.T) {
},
})
require.Error(t, err)
require.Contains(t, err.Error(), "`Filter.AccountMeshDataFlags` must set at least one")
require.ErrorContains(t, err, "`Filter.AccountMeshDataFlags` must set at least one")
})
t.Run("AccountDataQuery_BadOffset", func(t *testing.T) {
t.Parallel()
Expand Down
Loading
Loading