-
Notifications
You must be signed in to change notification settings - Fork 16
feat(toolkit): monitor on SR votes #105
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
Open
warku123
wants to merge
9
commits into
tronprotocol:develop
Choose a base branch
from
warku123:Slack_SR_post
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
2a40e61
Add go SR check
warku123 8bea3b4
add docker config
warku123 e1adb27
change go version
warku123 27203f8
Update URL to account name
warku123 f4d8bb1
Change output format
warku123 0bb37bf
Delete previous vote output
warku123 9ef9e76
Add sr change check
warku123 2cc3203
Add the readme
warku123 730864d
Add log directory and also log file
warku123 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| # Slack SR Monitor Configuration | ||
|
|
||
| # The Slack Webhook URL for sending notifications | ||
| SLACK_WEBHOOK=your_slack_webhook_url_here | ||
|
|
||
| # The Tron node API endpoint | ||
| # Default: https://api.trongrid.io | ||
| TRON_NODE=https://api.trongrid.io |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| .env | ||
| slack_sr_monitor | ||
| logs/ | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| # Build stage | ||
| FROM golang:1.25-alpine AS builder | ||
|
|
||
| WORKDIR /app | ||
|
|
||
| # Install dependencies | ||
| COPY go.mod go.sum ./ | ||
| RUN go mod download | ||
|
|
||
| # Copy source code | ||
| COPY . . | ||
|
|
||
| # Build the application | ||
| RUN CGO_ENABLED=0 GOOS=linux go build -o slack_sr_monitor main.go | ||
|
|
||
| # Final stage | ||
| FROM alpine:latest | ||
|
|
||
| RUN apk --no-cache add ca-certificates tzdata | ||
|
|
||
| WORKDIR /root/ | ||
|
|
||
| # Create logs directory | ||
| RUN mkdir -p logs | ||
|
|
||
| # Copy the binary from builder | ||
| COPY --from=builder /app/slack_sr_monitor . | ||
|
|
||
| # Command to run | ||
| CMD ["./slack_sr_monitor"] | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| ## Slack SR Monitor Tool | ||
| The Slack SR Monitor tool is designed to monitor TRON Super Representatives (SRs) and notify a Slack channel after every maintenance period. | ||
| It automatically tracks vote changes and detects replacements in the top 27 SR positions, providing a clear and formatted report. | ||
|
|
||
| ### Build and Run the monitor | ||
| To run the monitor tool, you can choose between native Go execution or Docker deployment. | ||
|
|
||
| #### Native Go Execution | ||
| Make sure you have Go 1.25+ installed. | ||
| ```shell | ||
| # enter the directory | ||
| cd tools/slack_sr_monitor | ||
| # install dependencies | ||
| go mod tidy | ||
| # run the tool | ||
| go run main.go | ||
| ``` | ||
|
|
||
| #### Docker Deployment | ||
| We provide a Docker-based deployment for easier management in production environments. | ||
| ```shell | ||
| # build and start the container | ||
| docker-compose up -d --build | ||
| # check logs | ||
| docker logs -f slack-sr-monitor | ||
| ``` | ||
|
|
||
| ### Configuration | ||
| All configurations are managed via environment variables or a `.env` file in the project root. Please refer to [.env.example](./.env.example) as an example. | ||
|
|
||
| - `SLACK_WEBHOOK`: The Slack Incoming Webhook URL used to send notifications. | ||
| - `TRON_NODE`: The TRON node HTTP API endpoint (e.g., `http://https://api.trongrid.io`). Default is Trongrid. | ||
|
|
||
| ### Key Features | ||
|
|
||
| #### SR vote monitor | ||
| Use `/wallet/getpaginatednowwitnesslist` to get the top **28** real-time votes, also the SR address and URL. | ||
|
|
||
| #### Dynamic Scheduling | ||
| Instead of a fixed interval, the tool queries `/wallet/getnextmaintenancetime` to calculate the exact wait time. It triggers the report **1 minute** after each maintenance period begins to ensure data consistency. | ||
|
|
||
| #### Parallel Data Acquisition | ||
| The tool uses Go routines to fetch `account_name` for all 28 witnesses in parallel from the `/wallet/getaccount` interface, significantly reducing the collection time. | ||
|
|
||
| #### Vote Change Tracking | ||
| The tool maintains an in-memory snapshot of the previous period's votes. It calculates the `Change` for each SR: | ||
| ```text | ||
| *1. Poloniex* | ||
| Current: `3,228,089,488` Change: `+89,488` | ||
| ``` | ||
|
|
||
| #### Top 27 Replacement Detection | ||
| After each report, it compares the current Top 27 list with the previous one and highlights any changes: | ||
| ```text | ||
| SR Replacement Detected: | ||
| >:inbox_tray: *Entered:* New_SR_Name | ||
| >:outbox_tray: *Left:* Old_SR_Name | ||
| ``` | ||
| If no changes occur, it displays `Top 27 SRs remain unchanged.` | ||
|
|
||
| ### Notifications | ||
|
|
||
| This monitor only support java-tron node v4.8.1+, because of the API it used. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| services: | ||
| slack-sr-monitor: | ||
| build: . | ||
| container_name: slack-sr-monitor | ||
| restart: always | ||
| environment: | ||
| - SLACK_WEBHOOK=${SLACK_WEBHOOK} | ||
| - TRON_NODE=${TRON_NODE:-https://api.trongrid.io} | ||
| volumes: | ||
| - ./logs:/root/logs | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| module github.com/tronprotocol/tron-docker/tools/slack_sr_monitor | ||
|
|
||
| go 1.25.5 | ||
|
|
||
| require github.com/joho/godotenv v1.5.1 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0= | ||
| github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4= |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please check the security of this package
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This package is the de-facto standard for environment variable management in the Go community (10k+ Stars), repo: https://github.com/joho/godotenv. Its logic is minimal and transparent (reading local files only).
I've scanned the project using the official Go vulnerability tool
govulncheck, and no vulnerabilities were detected in this package.