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

feat: add referral set spam stats to core API #9758

Merged
merged 1 commit into from
Oct 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@
- [9664](https://github.com/vegaprotocol/vega/issues/9664) - Handle pagination of release request with github.
- [9681](https://github.com/vegaprotocol/vega/issues/9681) - Move referral set reward factor to the referral set stats events
- [9708](https://github.com/vegaprotocol/vega/issues/9708) - Use the correct transaction hash when submitting orders through the `nullblockchain`
- [9755](https://github.com/vegaprotocol/vega/issues/9755) - Add referral program spam statistics to `GetSpamStatistics` core API.
- [409](https://github.com/vegaprotocol/OctoberACs/issues/409) - Add integration test for team rewards `0056-REWA-106`
- [410](https://github.com/vegaprotocol/OctoberACs/issues/410) - Add integration test for team rewards `0056-REWA-107`
- [411](https://github.com/vegaprotocol/OctoberACs/issues/411) - Add integration test for team rewards `0056-REWA-108`
Expand Down
3 changes: 3 additions & 0 deletions core/api/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -702,6 +702,9 @@ func (s *coreService) GetSpamStatistics(ctx context.Context, req *protoapi.GetSp
spamStats.Proposals = defaultStats
spamStats.IssueSignatures = defaultStats
spamStats.Transfers = defaultStats
spamStats.CreateReferralSet = defaultStats
spamStats.UpdateReferralSet = defaultStats
spamStats.ApplyReferralCode = defaultStats
spamStats.Votes = &protoapi.VoteSpamStatistics{
Statistics: []*protoapi.VoteSpamStatistic{},
MaxForEpoch: math.MaxUint64,
Expand Down
2 changes: 1 addition & 1 deletion core/protocol/all_services.go
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ func newServices(
svcs.snapshotEngine.AddProviders(svcs.spam)

pow := pow.New(svcs.log, svcs.conf.PoW, svcs.timeService)
if svcs.conf.Blockchain.ChainProvider == blockchain.ProviderNullChain && !svcs.conf.Blockchain.Null.SpamProtection {
if svcs.conf.Blockchain.ChainProvider == blockchain.ProviderNullChain {
pow.DisableVerification()
}
svcs.pow = pow
Expand Down
6 changes: 6 additions & 0 deletions core/spam/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,12 @@ func (e *Engine) GetSpamStatistics(partyID string) *protoapi.SpamStatistics {
stats.IssueSignatures = policy.GetSpamStats(partyID)
case txn.VoteCommand:
stats.Votes = policy.GetVoteSpamStats(partyID)
case txn.CreateReferralSetCommand:
stats.CreateReferralSet = policy.GetSpamStats(partyID)
case txn.UpdateReferralSetCommand:
stats.UpdateReferralSet = policy.GetSpamStats(partyID)
case txn.ApplyReferralCodeCommand:
stats.ApplyReferralCode = policy.GetSpamStats(partyID)
default:
continue
}
Expand Down
22 changes: 14 additions & 8 deletions protos/sources/vega/api/v1/core.proto
Original file line number Diff line number Diff line change
Expand Up @@ -434,22 +434,28 @@ message PoWStatistic {

// Complete spam statistics captured for a given party
message SpamStatistics {
// Statistics for proposal transactions made by the party
// Statistics for proposal transactions made by the party.
SpamStatistic proposals = 1;
// Statistics for delegation transactions made by the party
// Statistics for delegation transactions made by the party.
SpamStatistic delegations = 2;
// Statistics for transfer transactions made by the party
// Statistics for transfer transactions made by the party.
SpamStatistic transfers = 3;
// Statistics for node announcement transactions made by the party
// Statistics for node announcement transactions made by the party.
SpamStatistic node_announcements = 4;
// Statistics for proposal votes made by the party
// Statistics for proposal votes made by the party.
VoteSpamStatistics votes = 5;
// Statistics for proof of work difficulty observed per block for the party
// Statistics for proof of work difficulty observed per block for the party.
PoWStatistic pow = 6;
// Statistics for multisig signatures issued for the party
// Statistics for multisig signatures issued for the party.
SpamStatistic issue_signatures = 7;
// Epoch in which these statistics apply to
// Epoch in which these statistics apply to.
uint64 epoch_seq = 8;
// Statistics for transactions made by the party to create referral sets.
SpamStatistic create_referral_set = 9;
// Statistics for transactions made by the party to update referral sets.
SpamStatistic update_referral_set = 10;
// Statistics for transactions made by the party to apply referral codes.
SpamStatistic apply_referral_code = 11;
}

// Response containing all the spam statistics of a party for the current epoch
Expand Down
266 changes: 155 additions & 111 deletions protos/vega/api/v1/core.pb.go

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions wallet/api/node/adapters/grpc_adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ func (c *GRPCAdapter) SpamStatistics(ctx context.Context, party string) (nodetyp
Transfers: toSpamStatistic(r.Statistics.Transfers),
NodeAnnouncements: toSpamStatistic(r.Statistics.NodeAnnouncements),
IssuesSignatures: toSpamStatistic(r.Statistics.IssueSignatures),
CreateReferralSet: toSpamStatistic(r.Statistics.CreateReferralSet),
UpdateReferralSet: toSpamStatistic(r.Statistics.UpdateReferralSet),
ApplyReferralCode: toSpamStatistic(r.Statistics.ApplyReferralCode),
Votes: &nodetypes.VoteSpamStatistics{
Proposals: proposals,
MaxForEpoch: r.Statistics.Votes.MaxForEpoch,
Expand Down
3 changes: 3 additions & 0 deletions wallet/api/node/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ type SpamStatistics struct {
Transfers *SpamStatistic
NodeAnnouncements *SpamStatistic
IssuesSignatures *SpamStatistic
CreateReferralSet *SpamStatistic
UpdateReferralSet *SpamStatistic
ApplyReferralCode *SpamStatistic
Votes *VoteSpamStatistics
PoW *PoWStatistics
}
Expand Down
9 changes: 9 additions & 0 deletions wallet/api/spam/spam.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,15 @@ func (s *Handler) CheckSubmission(req *walletpb.SubmitTransactionRequest, newSta
case *walletpb.SubmitTransactionRequest_IssueSignatures:
s.merge(stats.IssuesSignatures, newStats.IssuesSignatures)
return s.checkTxn(stats.IssuesSignatures)
case *walletpb.SubmitTransactionRequest_CreateReferralSet:
s.merge(stats.CreateReferralSet, newStats.CreateReferralSet)
return s.checkTxn(stats.CreateReferralSet)
case *walletpb.SubmitTransactionRequest_UpdateReferralSet:
s.merge(stats.UpdateReferralSet, newStats.UpdateReferralSet)
return s.checkTxn(stats.UpdateReferralSet)
case *walletpb.SubmitTransactionRequest_ApplyReferralCode:
s.merge(stats.ApplyReferralCode, newStats.ApplyReferralCode)
return s.checkTxn(stats.ApplyReferralCode)
case *walletpb.SubmitTransactionRequest_VoteSubmission:
s.mergeVotes(stats.Votes, newStats.Votes)
return s.checkVote(cmd.VoteSubmission.ProposalId, stats.Votes)
Expand Down
28 changes: 28 additions & 0 deletions wallet/service/service_v1_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,10 @@ func testCheckTransactionSucceeds(t *testing.T) {
Transfers: &api.SpamStatistic{},
Delegations: &api.SpamStatistic{},
NodeAnnouncements: &api.SpamStatistic{},
IssueSignatures: &api.SpamStatistic{},
CreateReferralSet: &api.SpamStatistic{},
UpdateReferralSet: &api.SpamStatistic{},
ApplyReferralCode: &api.SpamStatistic{},
Votes: &api.VoteSpamStatistics{},
Pow: &api.PoWStatistic{
BlockStates: []*api.PoWBlockState{},
Expand Down Expand Up @@ -676,6 +680,10 @@ func testCheckTransactionWithRejectedTransactionSucceeds(t *testing.T) {
Transfers: &api.SpamStatistic{},
Delegations: &api.SpamStatistic{},
NodeAnnouncements: &api.SpamStatistic{},
IssueSignatures: &api.SpamStatistic{},
CreateReferralSet: &api.SpamStatistic{},
UpdateReferralSet: &api.SpamStatistic{},
ApplyReferralCode: &api.SpamStatistic{},
Votes: &api.VoteSpamStatistics{},
Pow: &api.PoWStatistic{
BlockStates: []*api.PoWBlockState{},
Expand Down Expand Up @@ -726,6 +734,10 @@ func testCheckTransactionWithFailedTransactionFails(t *testing.T) {
Transfers: &api.SpamStatistic{},
Delegations: &api.SpamStatistic{},
NodeAnnouncements: &api.SpamStatistic{},
IssueSignatures: &api.SpamStatistic{},
CreateReferralSet: &api.SpamStatistic{},
UpdateReferralSet: &api.SpamStatistic{},
ApplyReferralCode: &api.SpamStatistic{},
Votes: &api.VoteSpamStatistics{},
Pow: &api.PoWStatistic{
BlockStates: []*api.PoWBlockState{},
Expand Down Expand Up @@ -767,6 +779,10 @@ func testAcceptSigningTransactionSucceeds(t *testing.T) {
Transfers: &api.SpamStatistic{},
Delegations: &api.SpamStatistic{},
NodeAnnouncements: &api.SpamStatistic{},
IssueSignatures: &api.SpamStatistic{},
CreateReferralSet: &api.SpamStatistic{},
UpdateReferralSet: &api.SpamStatistic{},
ApplyReferralCode: &api.SpamStatistic{},
Votes: &api.VoteSpamStatistics{},
Pow: &api.PoWStatistic{
BlockStates: []*api.PoWBlockState{},
Expand Down Expand Up @@ -843,6 +859,10 @@ func testFailedTransactionSigningFails(t *testing.T) {
Transfers: &api.SpamStatistic{},
Delegations: &api.SpamStatistic{},
NodeAnnouncements: &api.SpamStatistic{},
IssueSignatures: &api.SpamStatistic{},
CreateReferralSet: &api.SpamStatistic{},
UpdateReferralSet: &api.SpamStatistic{},
ApplyReferralCode: &api.SpamStatistic{},
Votes: &api.VoteSpamStatistics{},
Pow: &api.PoWStatistic{
BlockStates: []*api.PoWBlockState{},
Expand Down Expand Up @@ -929,6 +949,10 @@ func testAcceptSigningTransactionFailsSpam(t *testing.T) {
Transfers: &api.SpamStatistic{},
Delegations: &api.SpamStatistic{},
NodeAnnouncements: &api.SpamStatistic{},
IssueSignatures: &api.SpamStatistic{},
CreateReferralSet: &api.SpamStatistic{},
UpdateReferralSet: &api.SpamStatistic{},
ApplyReferralCode: &api.SpamStatistic{},
Votes: &api.VoteSpamStatistics{},
Pow: &api.PoWStatistic{
BlockStates: []*api.PoWBlockState{},
Expand Down Expand Up @@ -1135,6 +1159,10 @@ func TestEmptyChainIDFromNetworkFails(t *testing.T) {
Transfers: &api.SpamStatistic{},
Delegations: &api.SpamStatistic{},
NodeAnnouncements: &api.SpamStatistic{},
IssueSignatures: &api.SpamStatistic{},
CreateReferralSet: &api.SpamStatistic{},
UpdateReferralSet: &api.SpamStatistic{},
ApplyReferralCode: &api.SpamStatistic{},
Votes: &api.VoteSpamStatistics{},
Pow: &api.PoWStatistic{
BlockStates: []*api.PoWBlockState{},
Expand Down
4 changes: 4 additions & 0 deletions wallet/service/v1/endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -1097,6 +1097,10 @@ func convertSpamStatistics(r *api.GetSpamStatisticsResponse) *nodetypes.SpamStat
Delegations: toSpamStatistic(r.Statistics.Delegations),
Transfers: toSpamStatistic(r.Statistics.Transfers),
NodeAnnouncements: toSpamStatistic(r.Statistics.NodeAnnouncements),
IssuesSignatures: toSpamStatistic(r.Statistics.IssueSignatures),
CreateReferralSet: toSpamStatistic(r.Statistics.CreateReferralSet),
UpdateReferralSet: toSpamStatistic(r.Statistics.UpdateReferralSet),
ApplyReferralCode: toSpamStatistic(r.Statistics.ApplyReferralCode),
Votes: &nodetypes.VoteSpamStatistics{
Proposals: proposals,
MaxForEpoch: r.Statistics.Votes.MaxForEpoch,
Expand Down
Loading