Skip to content

Feat: Implemented High-Frequency Contract Calls detection#159

Open
Chongai-Cli wants to merge 1 commit into
MD-Creative-Production:mainfrom
Chongai-Cli:contract
Open

Feat: Implemented High-Frequency Contract Calls detection#159
Chongai-Cli wants to merge 1 commit into
MD-Creative-Production:mainfrom
Chongai-Cli:contract

Conversation

@Chongai-Cli

Copy link
Copy Markdown

Description

Here's what was built:

4 files created, 1 modified:

apps/backend/src/modules/detection/contracts/
├── interfaces/
│ └── spike-detection.interface.ts ←
SpikeDetectionConfig, ContractActivityRecord,
SpikeAlert
├── spike-detection.service.ts ← core
logic
├── spike-detection.module.ts ← NestJS
module
└── spike-detection.service.spec.ts ← 13 unit
tests

apps/backend/src/app.module.ts ←
SpikeDetectionModule registered

How it works:

The service uses a dual rolling window for baseline
comparison — a "current" window and an equally-sized
"previous" window:

|← baseline window →|← current window →|
now - 2×windowMs now - windowMs now

When recordTransaction(address, timestamp) is
called, it compares the current window count against
the baseline:

  • Below minBaselineCount (default 5) → no alert
    (suppresses noise during cold start)
  • currentCount / baselineCount < multiplierThreshold
    (default 3×) → no alert
  • ≥ 3× → medium, ≥ 5× → high, ≥ 10× → critical
    SpikeAlert

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • [ x] New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Related Issues

Fixes #150
Related to #

Changes Made

Testing

  • [ x] I have tested these changes locally
  • [ x] Tests pass locally (npm run test)
  • [ x] Linting passes (npm run lint)
  • [ x] Code is formatted (npm run format)
  • [x ] TypeScript builds successfully (npm run build)

Checklist

  • [x ] My code follows the style guidelines of this project
  • [ x] I have performed a self-review of my own code
  • [ x] I have commented my code, particularly in hard-to-understand areas
  • [ x] I have made corresponding changes to the documentation
  • [x ] My changes generate no new warnings or errors
  • [ x] I have added tests that prove my fix is effective or that my feature works
  • [ x] New and existing unit tests passed with my changes

Screenshots (if applicable)

Additional Context

@mijinummi

Copy link
Copy Markdown
Collaborator

Hello @Chongai-Cli , thank you for your contribution, please kindly fix the git workflow failures? Thanks for your usual cooperation, looking forward to work with you on this project for more issues

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Detect High-Frequency Contract Calls

2 participants