From a3b1059fe0797bd4c7742238162684aeae4e5db1 Mon Sep 17 00:00:00 2001 From: Qweder93 Date: Thu, 7 Jan 2021 21:17:46 +0200 Subject: [PATCH] multinode/console: list node updated with total earned Change-Id: I53a6ebd98acb7741f60d61178451575e7677c730 --- multinode/nodes/nodes.go | 1 + multinode/nodes/service.go | 7 + private/multinodepb/multinode.pb.go | 252 ++++++++++++++++++++++------ private/multinodepb/multinode.proto | 12 ++ storagenode/multinode/payout.go | 53 ++++++ storagenode/payout/payout.go | 2 + storagenode/storagenodedb/payout.go | 31 ++++ 7 files changed, 307 insertions(+), 51 deletions(-) create mode 100644 storagenode/multinode/payout.go diff --git a/multinode/nodes/nodes.go b/multinode/nodes/nodes.go index 3f952d615..4ac86d907 100644 --- a/multinode/nodes/nodes.go +++ b/multinode/nodes/nodes.go @@ -49,6 +49,7 @@ type NodeInfo struct { DiskSpaceUsed int64 DiskSpaceLeft int64 BandwidthUsed int64 + TotalEarned int64 } // NodeInfoSatellite contains satellite specific node internal state. diff --git a/multinode/nodes/service.go b/multinode/nodes/service.go index 038a9ba63..fcf64866b 100644 --- a/multinode/nodes/service.go +++ b/multinode/nodes/service.go @@ -111,6 +111,7 @@ func (service *Service) ListInfos(ctx context.Context) (_ []NodeInfo, err error) nodeClient := multinodepb.NewDRPCNodeClient(conn) storageClient := multinodepb.NewDRPCStorageClient(conn) bandwidthClient := multinodepb.NewDRPCBandwidthClient(conn) + payoutClient := multinodepb.NewDRPCPayoutClient(conn) header := &multinodepb.RequestHeader{ ApiKey: node.APISecret, @@ -131,6 +132,11 @@ func (service *Service) ListInfos(ctx context.Context) (_ []NodeInfo, err error) return NodeInfo{}, Error.Wrap(err) } + earned, err := payoutClient.Earned(ctx, &multinodepb.EarnedRequest{Header: header}) + if err != nil { + return NodeInfo{}, Error.Wrap(err) + } + bandwidthSummaryRequest := &multinodepb.BandwidthMonthSummaryRequest{ Header: header, } @@ -147,6 +153,7 @@ func (service *Service) ListInfos(ctx context.Context) (_ []NodeInfo, err error) DiskSpaceUsed: diskSpace.GetUsedPieces() + diskSpace.GetUsedTrash(), DiskSpaceLeft: diskSpace.GetAvailable(), BandwidthUsed: bandwidthSummary.GetUsed(), + TotalEarned: earned.Total, }, nil }() if err != nil { diff --git a/private/multinodepb/multinode.pb.go b/private/multinodepb/multinode.pb.go index a1495548e..93780a6f0 100644 --- a/private/multinodepb/multinode.pb.go +++ b/private/multinodepb/multinode.pb.go @@ -24,7 +24,7 @@ var _ = time.Kitchen // is compatible with the proto package it is being compiled against. // A compilation error at this line likely means your copy of the // proto package needs to be updated. -const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package +const _ = proto.GoGoProtoPackageIsVersion2 // please upgrade the proto package type RequestHeader struct { ApiKey []byte `protobuf:"bytes,1,opt,name=api_key,json=apiKey,proto3" json:"api_key,omitempty"` @@ -692,6 +692,82 @@ func (m *TrustedSatellitesResponse_NodeURL) GetAddress() string { return "" } +type EarnedRequest struct { + Header *RequestHeader `protobuf:"bytes,1,opt,name=header,proto3" json:"header,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *EarnedRequest) Reset() { *m = EarnedRequest{} } +func (m *EarnedRequest) String() string { return proto.CompactTextString(m) } +func (*EarnedRequest) ProtoMessage() {} +func (*EarnedRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_9a45fd79b06f3a1b, []int{13} +} +func (m *EarnedRequest) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_EarnedRequest.Unmarshal(m, b) +} +func (m *EarnedRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_EarnedRequest.Marshal(b, m, deterministic) +} +func (m *EarnedRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_EarnedRequest.Merge(m, src) +} +func (m *EarnedRequest) XXX_Size() int { + return xxx_messageInfo_EarnedRequest.Size(m) +} +func (m *EarnedRequest) XXX_DiscardUnknown() { + xxx_messageInfo_EarnedRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_EarnedRequest proto.InternalMessageInfo + +func (m *EarnedRequest) GetHeader() *RequestHeader { + if m != nil { + return m.Header + } + return nil +} + +type EarnedResponse struct { + Total int64 `protobuf:"varint,1,opt,name=total,proto3" json:"total,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *EarnedResponse) Reset() { *m = EarnedResponse{} } +func (m *EarnedResponse) String() string { return proto.CompactTextString(m) } +func (*EarnedResponse) ProtoMessage() {} +func (*EarnedResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_9a45fd79b06f3a1b, []int{14} +} +func (m *EarnedResponse) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_EarnedResponse.Unmarshal(m, b) +} +func (m *EarnedResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_EarnedResponse.Marshal(b, m, deterministic) +} +func (m *EarnedResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_EarnedResponse.Merge(m, src) +} +func (m *EarnedResponse) XXX_Size() int { + return xxx_messageInfo_EarnedResponse.Size(m) +} +func (m *EarnedResponse) XXX_DiscardUnknown() { + xxx_messageInfo_EarnedResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_EarnedResponse proto.InternalMessageInfo + +func (m *EarnedResponse) GetTotal() int64 { + if m != nil { + return m.Total + } + return 0 +} + func init() { proto.RegisterType((*RequestHeader)(nil), "multinode.RequestHeader") proto.RegisterType((*DiskSpaceRequest)(nil), "multinode.DiskSpaceRequest") @@ -709,61 +785,66 @@ func init() { proto.RegisterType((*TrustedSatellitesRequest)(nil), "multinode.TrustedSatellitesRequest") proto.RegisterType((*TrustedSatellitesResponse)(nil), "multinode.TrustedSatellitesResponse") proto.RegisterType((*TrustedSatellitesResponse_NodeURL)(nil), "multinode.TrustedSatellitesResponse.NodeURL") + proto.RegisterType((*EarnedRequest)(nil), "multinode.EarnedRequest") + proto.RegisterType((*EarnedResponse)(nil), "multinode.EarnedResponse") } func init() { proto.RegisterFile("multinode.proto", fileDescriptor_9a45fd79b06f3a1b) } var fileDescriptor_9a45fd79b06f3a1b = []byte{ - // 776 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x54, 0xd1, 0x6e, 0xe3, 0x44, - 0x14, 0xc5, 0x6d, 0xe2, 0x34, 0x37, 0xa1, 0x6d, 0x06, 0x24, 0x5c, 0x93, 0x34, 0x95, 0x5b, 0xa9, - 0x41, 0x20, 0x07, 0xd2, 0x27, 0x24, 0x1e, 0x20, 0x54, 0xa5, 0x11, 0x01, 0x8a, 0x53, 0x78, 0x00, - 0xa9, 0xd1, 0x24, 0x9e, 0x26, 0xa6, 0x8e, 0xc7, 0x78, 0xc6, 0x81, 0xfe, 0x05, 0x7f, 0x84, 0xf6, - 0x65, 0xb5, 0xdf, 0xb0, 0x0f, 0xdd, 0xcf, 0xd8, 0xd7, 0x95, 0x67, 0x26, 0x8e, 0xd3, 0x26, 0xd9, - 0x55, 0xf6, 0xcd, 0x73, 0xee, 0xb9, 0xe7, 0x5c, 0xdf, 0xb9, 0x73, 0x61, 0x6f, 0x12, 0xfb, 0xdc, - 0x0b, 0xa8, 0x4b, 0xec, 0x30, 0xa2, 0x9c, 0xa2, 0x62, 0x0a, 0x98, 0x30, 0xa2, 0x23, 0x2a, 0x61, - 0xb3, 0x3e, 0xa2, 0x74, 0xe4, 0x93, 0xa6, 0x38, 0x0d, 0xe2, 0xdb, 0x26, 0xf7, 0x26, 0x84, 0x71, - 0x3c, 0x09, 0x25, 0xc1, 0x6a, 0xc0, 0x87, 0x0e, 0xf9, 0x3b, 0x26, 0x8c, 0x5f, 0x12, 0xec, 0x92, - 0x08, 0x7d, 0x02, 0x05, 0x1c, 0x7a, 0xfd, 0x3b, 0x72, 0x6f, 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x79, 0xb8, 0x2a, 0xac, - 0xd4, 0x3a, 0x00, 0xf3, 0xf9, 0x47, 0xd5, 0x15, 0xcf, 0x42, 0x6a, 0xd5, 0xd6, 0x3e, 0x1a, 0x74, - 0x03, 0x95, 0x27, 0xc3, 0x82, 0x8e, 0xd7, 0x8f, 0x92, 0x14, 0x3e, 0x79, 0x97, 0x79, 0x6b, 0x9f, - 0xfc, 0x61, 0x31, 0x4e, 0xa3, 0xbf, 0x6c, 0x8f, 0x36, 0xc5, 0x47, 0x33, 0x8c, 0xbc, 0x29, 0xe6, - 0xa4, 0x99, 0x66, 0x87, 0x83, 0x81, 0x2e, 0x56, 0xdc, 0xd9, 0x9b, 0x00, 0x00, 0x00, 0xff, 0xff, - 0x0a, 0x7f, 0x78, 0x13, 0xdb, 0x07, 0x00, 0x00, + // 825 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x54, 0xd1, 0x6e, 0xeb, 0x44, + 0x10, 0xc5, 0x6d, 0xe2, 0xdc, 0x4c, 0x72, 0xdb, 0x9b, 0xe5, 0x4a, 0xb8, 0x26, 0xb9, 0xa9, 0xdc, + 0x8a, 0x06, 0x81, 0x1c, 0x48, 0x9f, 0x90, 0x40, 0xa2, 0xa1, 0xb4, 0x8d, 0x08, 0x50, 0x9c, 0xc2, + 0x03, 0x48, 0x8d, 0x36, 0xf1, 0x36, 0x31, 0x75, 0xbc, 0xc6, 0xbb, 0x0e, 0xe4, 0x2f, 0xf8, 0x23, + 0xc4, 0x0b, 0xe2, 0x1b, 0x78, 0x28, 0x9f, 0xc1, 0x2b, 0xf2, 0xee, 0xc6, 0x71, 0xda, 0x24, 0xa0, + 0xdc, 0x37, 0xcf, 0xcc, 0x99, 0x73, 0xd6, 0xb3, 0xb3, 0x07, 0xf6, 0x27, 0xb1, 0xcf, 0xbd, 0x80, + 0xba, 0xc4, 0x0e, 0x23, 0xca, 0x29, 0x2a, 0xa6, 0x09, 0x13, 0x46, 0x74, 0x44, 0x65, 0xda, 0xac, + 0x8f, 0x28, 0x1d, 0xf9, 0xa4, 0x29, 0xa2, 0x41, 0x7c, 0xd7, 0xe4, 0xde, 0x84, 0x30, 0x8e, 0x27, + 0xa1, 0x04, 0x58, 0x0d, 0x78, 0xee, 0x90, 0x9f, 0x62, 0xc2, 0xf8, 0x15, 0xc1, 0x2e, 0x89, 0xd0, + 0x5b, 0x50, 0xc0, 0xa1, 0xd7, 0xbf, 0x27, 0x33, 0x43, 0x3b, 0xd4, 0x1a, 0x65, 0x47, 0xc7, 0xa1, + 0xf7, 0x05, 0x99, 0x59, 0xe7, 0xf0, 0xe2, 0xdc, 0x63, 0xf7, 0xbd, 0x10, 0x0f, 0x89, 0x6a, 0x41, + 0x1f, 0x80, 0x3e, 0x16, 0x6d, 0x02, 0x5b, 0x6a, 0x19, 0xf6, 0xe2, 0x5c, 0x4b, 0xb4, 0x8e, 0xc2, + 0x59, 0xbf, 0x69, 0x50, 0xc9, 0xd0, 0xb0, 0x90, 0x06, 0x8c, 0xa0, 0x2a, 0x14, 0xb1, 0xef, 0xd3, + 0x21, 0xe6, 0xc4, 0x15, 0x54, 0xbb, 0xce, 0x22, 0x81, 0xea, 0x50, 0x8a, 0x19, 0x71, 0xfb, 0xa1, + 0x47, 0x86, 0x84, 0x19, 0x3b, 0xa2, 0x0e, 0x49, 0xea, 0x5a, 0x64, 0x50, 0x0d, 0x44, 0xd4, 0xe7, + 0x11, 0x66, 0x63, 0x63, 0x57, 0xf6, 0x27, 0x99, 0x9b, 0x24, 0x81, 0x10, 0xe4, 0xee, 0x22, 0x42, + 0x8c, 0x9c, 0x28, 0x88, 0x6f, 0xa1, 0x38, 0xc5, 0x9e, 0x8f, 0x07, 0x3e, 0x31, 0xf2, 0x4a, 0x71, + 0x9e, 0x40, 0x26, 0x3c, 0xa3, 0x53, 0x12, 0x25, 0x14, 0x86, 0x2e, 0x8a, 0x69, 0x6c, 0x5d,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@ func (x *drpcNodeTrustedSatellitesStream) SendAndClose(m *TrustedSatellitesRespo return x.CloseSend() } +type DRPCPayoutClient interface { + DRPCConn() drpc.Conn + + Earned(ctx context.Context, in *EarnedRequest) (*EarnedResponse, error) +} + +type drpcPayoutClient struct { + cc drpc.Conn +} + +func NewDRPCPayoutClient(cc drpc.Conn) DRPCPayoutClient { + return &drpcPayoutClient{cc} +} + +func (c *drpcPayoutClient) DRPCConn() drpc.Conn { return c.cc } + +func (c *drpcPayoutClient) Earned(ctx context.Context, in *EarnedRequest) (*EarnedResponse, error) { + out := new(EarnedResponse) + err := c.cc.Invoke(ctx, "/multinode.Payout/Earned", in, out) + if err != nil { + return nil, err + } + return out, nil +} + +type DRPCPayoutServer interface { + Earned(context.Context, *EarnedRequest) (*EarnedResponse, error) +} + +type DRPCPayoutDescription struct{} + +func (DRPCPayoutDescription) NumMethods() int { return 1 } + +func (DRPCPayoutDescription) Method(n int) (string, drpc.Receiver, interface{}, bool) { + switch n { + case 0: + return "/multinode.Payout/Earned", + func(srv interface{}, ctx context.Context, in1, in2 interface{}) (drpc.Message, error) { + return srv.(DRPCPayoutServer). + Earned( + ctx, + in1.(*EarnedRequest), + ) + }, DRPCPayoutServer.Earned, true + default: + return "", nil, nil, false + } +} + +func DRPCRegisterPayout(mux drpc.Mux, impl DRPCPayoutServer) error { + return mux.Register(impl, DRPCPayoutDescription{}) +} + +type DRPCPayout_EarnedStream interface { + drpc.Stream + SendAndClose(*EarnedResponse) error +} + +type drpcPayoutEarnedStream struct { + drpc.Stream +} + +func (x *drpcPayoutEarnedStream) SendAndClose(m *EarnedResponse) error { + if err := x.MsgSend(m); err != nil { + return err + } + return x.CloseSend() +} + // --- DRPC END --- diff --git a/private/multinodepb/multinode.proto b/private/multinodepb/multinode.proto index b72365db0..90c5dc906 100644 --- a/private/multinodepb/multinode.proto +++ b/private/multinodepb/multinode.proto @@ -95,3 +95,15 @@ message TrustedSatellitesResponse { repeated NodeURL trusted_satellites = 1; } + +service Payout { + rpc Earned(EarnedRequest) returns (EarnedResponse); +} + +message EarnedRequest { + RequestHeader header = 1; +} + +message EarnedResponse { + int64 total = 1; +} diff --git a/storagenode/multinode/payout.go b/storagenode/multinode/payout.go new file mode 100644 index 000000000..bf6bdd433 --- /dev/null +++ b/storagenode/multinode/payout.go @@ -0,0 +1,53 @@ +// Copyright (C) 2021 Storj Labs, Inc. +// See LICENSE for copying information. + +package multinode + +import ( + "context" + + "go.uber.org/zap" + + "storj.io/common/rpc/rpcstatus" + "storj.io/storj/private/multinodepb" + "storj.io/storj/storagenode/apikeys" + "storj.io/storj/storagenode/payout" +) + +var _ multinodepb.DRPCPayoutServer = (*PayoutEndpoint)(nil) + +// PayoutEndpoint implements multinode payout endpoint. +// +// architecture: Endpoint +type PayoutEndpoint struct { + log *zap.Logger + apiKeys *apikeys.Service + db payout.DB +} + +// NewPayoutEndpoint creates new multinode payout endpoint. +func NewPayoutEndpoint(log *zap.Logger, apiKeys *apikeys.Service, db payout.DB) *PayoutEndpoint { + return &PayoutEndpoint{ + log: log, + apiKeys: apiKeys, + db: db, + } +} + +// Earned returns total earned amount. +func (payout *PayoutEndpoint) Earned(ctx context.Context, req *multinodepb.EarnedRequest) (_ *multinodepb.EarnedResponse, err error) { + defer mon.Task()(&ctx)(&err) + + if err = authenticate(ctx, payout.apiKeys, req.GetHeader()); err != nil { + return nil, rpcstatus.Wrap(rpcstatus.Unauthenticated, err) + } + + earned, err := payout.db.GetTotalEarned(ctx) + if err != nil { + return nil, rpcstatus.Wrap(rpcstatus.Internal, err) + } + + return &multinodepb.EarnedResponse{ + Total: earned, + }, nil +} diff --git a/storagenode/payout/payout.go b/storagenode/payout/payout.go index d64b456d8..b60584a30 100644 --- a/storagenode/payout/payout.go +++ b/storagenode/payout/payout.go @@ -34,6 +34,8 @@ type DB interface { StorePayment(ctx context.Context, payment Payment) error // GetReceipt retrieves receipt for specific satellite and period. GetReceipt(ctx context.Context, satelliteID storj.NodeID, period string) (string, error) + // GetTotalEarned returns total earned amount of node from all paystubs. + GetTotalEarned(ctx context.Context) (_ int64, err error) } // ErrNoPayStubForPeriod represents errors from the payout database. diff --git a/storagenode/storagenodedb/payout.go b/storagenode/storagenodedb/payout.go index f30d3abb5..e9cdd7935 100644 --- a/storagenode/storagenodedb/payout.go +++ b/storagenode/storagenodedb/payout.go @@ -393,3 +393,34 @@ func (db *payoutDB) GetReceipt(ctx context.Context, satelliteID storj.NodeID, pe return receipt, nil } + +// GetTotalEarned returns total earned value for node from all paystubs. +func (db *payoutDB) GetTotalEarned(ctx context.Context) (_ int64, err error) { + defer mon.Task()(&ctx)(&err) + + query := `SELECT comp_at_rest, comp_get, comp_get_repair, comp_get_audit FROM paystubs` + + rows, err := db.QueryContext(ctx, query) + if err != nil { + return 0, err + } + + defer func() { err = errs.Combine(err, rows.Close()) }() + + var totalEarned int64 + for rows.Next() { + var compAtRest, compGet, compGetRepair, compGetAudit int64 + + err := rows.Scan(&compAtRest, &compGet, &compGetRepair, &compGetAudit) + if err != nil { + return 0, ErrPayout.Wrap(err) + } + + totalEarned += compGetAudit + compGet + compGetRepair + compAtRest + } + if err = rows.Err(); err != nil { + return 0, ErrPayout.Wrap(err) + } + + return totalEarned, nil +}