Skip to content

Commit 8a31b57

Browse files
authored
Fix eligibility check for banned/suspended nodes (#439)
* Handle eligibility banned/suspended * fix banned condition * add banned/suspended until date * fix condition
1 parent 15ab812 commit 8a31b57

2 files changed

Lines changed: 42 additions & 17 deletions

File tree

src/components/node-details/eligibility.tsx

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import Card from '@/components/card/card';
22
import { Node } from '@/types/nodes';
3+
import { formatDateTime } from '@/utils/formatters';
34
import ErrorOutlineIcon from '@mui/icons-material/ErrorOutline';
45
import HighlightOffIcon from '@mui/icons-material/HighlightOff';
56
import VerifiedIcon from '@mui/icons-material/Verified';
@@ -11,11 +12,13 @@ type EligibilityProps = {
1112
};
1213

1314
const Eligibility = ({ isAdmin, node }: EligibilityProps) => {
14-
const { banReason, eligibilityCauseStr } = node;
15-
const verified = !!node.latestBenchmarkResults;
15+
const now = Date.now();
16+
const isBanned = node.banned || (node.bannedUntil && now < node.bannedUntil);
17+
const isSuspended = node.suspendedUntil && now < node.suspendedUntil;
18+
const isVerified = !!node.latestBenchmarkResults && !isBanned && !isSuspended;
1619

17-
// [All roles] Verified and not banned
18-
if (verified && !node.banned) {
20+
// [All roles] Verified and NOT Banned / Suspended
21+
if (isVerified) {
1922
return (
2023
<Card direction="column" padding="sm" radius="md" shadow="success" spacing="sm" variant="success">
2124
<div className={styles.header}>
@@ -28,23 +31,42 @@ const Eligibility = ({ isAdmin, node }: EligibilityProps) => {
2831
}
2932

3033
if (isAdmin) {
31-
// [Admins] Banned
32-
if (node.banned) {
34+
const suspensionDate = (
35+
<>
36+
{node.bannedUntil ? (
37+
<div className={styles.reason}>
38+
<strong className="alignSelfStart">Banned until:</strong>{' '}
39+
<span>{formatDateTime(node.bannedUntil / 1000)}</span>
40+
</div>
41+
) : null}
42+
{node.suspendedUntil ? (
43+
<div className={styles.reason}>
44+
<strong className="alignSelfStart">Suspended until:</strong>{' '}
45+
<span>{formatDateTime(node.suspendedUntil / 1000)}</span>
46+
</div>
47+
) : null}
48+
</>
49+
);
50+
51+
// [Admins] Banned / Suspended
52+
if (isBanned || isSuspended) {
3353
return (
3454
<Card direction="column" padding="sm" radius="md" shadow="error" spacing="sm" variant="error">
3555
<div className={styles.header}>
3656
<HighlightOffIcon className={styles.icon} />
3757
<h3>Banned</h3>
3858
</div>
3959
<div>This node is excluded from all operations and rewards</div>
60+
{suspensionDate}
4061
<div className={styles.reason}>
41-
<strong className="alignSelfStart">Reason:</strong> <span>{banReason ?? 'Unknown'}</span>
62+
<strong className="alignSelfStart">Reason:</strong>{' '}
63+
<span>{node.banReason || node.eligibilityCauseStr || 'Unknown'}</span>
4264
</div>
4365
</Card>
4466
);
4567
}
4668

47-
// [Admins] Non-eligible
69+
// [Admins] NOT Eligible
4870
if (!node.eligible) {
4971
return (
5072
<Card direction="column" padding="sm" radius="md" shadow="warning" spacing="sm" variant="warning">
@@ -53,29 +75,31 @@ const Eligibility = ({ isAdmin, node }: EligibilityProps) => {
5375
<h3>Not eligible</h3>
5476
</div>
5577
<div>This node is active, but not eligible for rewards</div>
78+
{suspensionDate}
5679
<div className={styles.reason}>
57-
<strong className="alignSelfStart">Reason:</strong> <span>{eligibilityCauseStr ?? 'Unknown'}</span>
80+
<strong className="alignSelfStart">Reason:</strong> <span>{node.eligibilityCauseStr || 'Unknown'}</span>
5881
</div>
5982
</Card>
6083
);
6184
}
6285

63-
// [Admins] Not verified
86+
// [Admins] NOT Verified
6487
return (
6588
<Card direction="column" padding="sm" radius="md" shadow="warning" spacing="sm" variant="warning">
6689
<div className={styles.header}>
6790
<ErrorOutlineIcon className={styles.icon} />
6891
<h3>Not verified</h3>
6992
</div>
7093
<div>This node is active, but not verified via benchmark</div>
94+
{suspensionDate}
7195
<div className={styles.reason}>
72-
<strong className="alignSelfStart">Reason:</strong> <span>{eligibilityCauseStr ?? 'Unknown'}</span>
96+
<strong className="alignSelfStart">Reason:</strong> <span>{node.eligibilityCauseStr || 'Unknown'}</span>
7397
</div>
7498
</Card>
7599
);
76100
}
77101

78-
// [Non-admins] Not verified
102+
// [Non-admins] NOT Verified
79103
return (
80104
<Card direction="column" padding="sm" radius="md" shadow="warning" spacing="sm" variant="warning">
81105
<div className={styles.header}>

src/types/nodes.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ export type NodeBanInfo = {
2121

2222
export type Node = {
2323
allowedAdmins?: string[];
24+
banned: boolean;
25+
bannedAt?: number;
26+
bannedUntil?: number;
27+
banReason?: string;
2428
cpus: CPU[];
2529
currentAddrs?: string[];
2630
eligible?: boolean;
@@ -58,14 +62,11 @@ export type Node = {
5862
};
5963
provider?: Array<{ network: string }>;
6064
region: string;
65+
supportedStorage: any;
66+
suspendedUntil?: number;
6167
totalJobs: number;
6268
totalRevenue: number;
6369
version?: string;
64-
supportedStorage: any;
65-
banned: boolean;
66-
banReason: string;
67-
bannedAt: number;
68-
bannedUntil: number;
6970
};
7071

7172
type GPU = {

0 commit comments

Comments
 (0)