Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
44 changes: 23 additions & 21 deletions src/app/routes/reshare-dkg/ceremony-section.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { Card, CardHeader } from "@/components/ui/card.tsx";
import { Text } from "@/components/ui/text.tsx";
import { Button } from "@/components/ui/button.tsx";
import { Alert, AlertDescription } from "@/components/ui/alert.tsx";
import { useRegisterValidatorContext } from "@/guard/register-validator-guard.tsx";
import { LuCheck, LuCopy } from "react-icons/lu";
import CeremonySummary from "@/app/routes/create-cluster/ceremony-summary.tsx";
import { useQuery } from "@tanstack/react-query";
Expand Down Expand Up @@ -126,23 +125,26 @@ const CeremonySection = ({
</Button>{" "}
on the machine hosting the DKG client
</Text>
<Alert variant="warning">
<AlertDescription>
Please ensure you run the provided command from the
directory containing the proofs.json file you wish to
reshare. For additional details, refer to our{" "}
<Button
as="a"
href="https://github.com/ssvlabs/ssv-keys/releases"
variant="link"
size="xl"
target="_blank"
>
documentation
</Button>{" "}
.
</AlertDescription>
</Alert>
{(reshareContext.proofsQuery.data?.validators || [])
.length > 20 && (
<Alert variant="warning">
<AlertDescription>
Please ensure you run the provided command from the
directory containing the proofs.json file you wish to
reshare. For additional details, refer to our{" "}
<Button
as="a"
href="https://github.com/ssvlabs/ssv-keys/releases"
variant="link"
size="xl"
target="_blank"
>
documentation
</Button>{" "}
.
</AlertDescription>
</Alert>
)}
</div>
)}
<div>
Expand All @@ -154,7 +156,7 @@ const CeremonySection = ({
<Button
size="sm"
onClick={() =>
(useRegisterValidatorContext.state.dkgCeremonyState.selectedOs =
(useBulkActionContext.state.dkgReshareState.selectedOs =
"windows")
}
className="font-bold text-xs h-auto py-1 px-4"
Expand All @@ -168,7 +170,7 @@ const CeremonySection = ({
size="sm"
className="font-bold text-xs h-auto py-1 px-4"
onClick={() =>
(useRegisterValidatorContext.state.dkgCeremonyState.selectedOs =
(useBulkActionContext.state.dkgReshareState.selectedOs =
"mac")
}
variant={selectedOs === "mac" ? "secondary" : "outline"}
Expand All @@ -179,7 +181,7 @@ const CeremonySection = ({
size="sm"
className="font-bold text-xs h-auto py-1 px-4"
onClick={() =>
(useRegisterValidatorContext.state.dkgCeremonyState.selectedOs =
(useBulkActionContext.state.dkgReshareState.selectedOs =
"linux")
}
variant={
Expand Down
2 changes: 1 addition & 1 deletion src/app/routes/reshare-dkg/reshare-dkg.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const ethereumSignatureRegex = /^(0x([0-9a-fA-F]{130}))+$/;
const addressValidationSchema = z
.string()
.refine((value: string) => isAddress(value), {
message: "Wrong address format",
message: "Invalid Ethereum address",
});

const schema = z.object({
Expand Down
43 changes: 25 additions & 18 deletions src/app/routes/reshare-dkg/upload-proofs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import { useNavigate } from "react-router-dom";
import { useBulkActionContext } from "@/guard/bulk-action-guard.tsx";
import { useRegisterValidatorContext } from "@/guard/register-validator-guard.tsx";
import { useEffect } from "react";

const UploadProofs = () => {
const navigate = useNavigate();
Expand All @@ -23,6 +24,28 @@
const context = useBulkActionContext();
const { operators, proofsQuery } = useReshareDkg();

const nextStep = () => {
state.dkgReshareState.operators = operators.map(({ operator }) => {
registerValidatorContext.state.selectedOperatorsIds = [
...registerValidatorContext.state.selectedOperatorsIds,
operator.id,
];
return operator;
});

navigate("select-operators");
};

useEffect(() => {
if (
!proofsQuery.isLoading &&
proofsQuery.isSuccess &&
proofsQuery.data?.validators.length === 1
) {
nextStep();
}
}, [proofsQuery.isLoading, proofsQuery.isSuccess]);

Check warning on line 47 in src/app/routes/reshare-dkg/upload-proofs.tsx

View workflow job for this annotation

GitHub Actions / lint

React Hook useEffect has missing dependencies: 'nextStep' and 'proofsQuery.data?.validators.length'. Either include them or remove the dependency array

Check warning on line 47 in src/app/routes/reshare-dkg/upload-proofs.tsx

View workflow job for this annotation

GitHub Actions / lint

React Hook useEffect has missing dependencies: 'nextStep' and 'proofsQuery.data?.validators.length'. Either include them or remove the dependency array

return (
<Container
variant="vertical"
Expand Down Expand Up @@ -112,27 +135,11 @@
))}
</div>
</div>
<Button
onClick={() => {
state.dkgReshareState.operators = operators.map(
({ operator }) => {
registerValidatorContext.state.selectedOperatorsIds = [
...registerValidatorContext.state.selectedOperatorsIds,
operator.id,
];
return operator;
},
);

navigate("select-operators");
}}
>
Next
</Button>
<Button onClick={nextStep}>Next</Button>
</div>
)}
</Card>
{proofsQuery.isSuccess && proofsQuery.data?.validators && (
{proofsQuery.isSuccess && proofsQuery.data?.validators.length > 1 && (
<Card className="flex-[1] h-full">
<ValidatorsBulkSummary
publicKeys={
Expand Down
15 changes: 14 additions & 1 deletion src/components/cluster/cluster-validators-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,19 @@ import {
} from "@/components/ui/dropdown-menu";
import { useNavigate } from "react-router-dom";
import { useCluster } from "@/hooks/cluster/use-cluster";
import { TbExternalLink, TbRefresh } from "react-icons/tb";
import { TbExternalLink, TbRefresh, TbRefreshDot } from "react-icons/tb";
import { useBulkActionContext } from "@/guard/bulk-action-guard";
import { Spacer } from "@/components/ui/spacer";
import { ValidatorStatusBadge } from "@/components/cluster/validator-status-badge";
import { useLocalStorage } from "react-use";

export const ClusterValidatorsList: FC<ComponentPropsWithoutRef<"div">> = ({
...props
}) => {
const navigate = useNavigate();
const cluster = useCluster();
const { validators, infiniteQuery } = useInfiniteClusterValidators();
const [enabled] = useLocalStorage("reshareFlowEnabled", false);

return (
<VirtualizedInfinityTable
Expand Down Expand Up @@ -119,6 +121,17 @@ export const ClusterValidatorsList: FC<ComponentPropsWithoutRef<"div">> = ({
<LuLogOut className="size-4" />
<span>Exit Validator</span>
</DropdownMenuItem>
{enabled && (
<>
<div className="h-9 flex items-center text-gray-500 text-xs font-semibold pl-[16px]">
DKG
</div>
<DropdownMenuItem onClick={() => navigate("reshare")}>
<TbRefreshDot className="size-4" />
<span>Reshare</span>
</DropdownMenuItem>
</>
)}
</Tooltip>
</DropdownMenuContent>
</DropdownMenu>
Expand Down
48 changes: 28 additions & 20 deletions src/hooks/use-validate-proofs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,24 @@ type ValidateProofsResult = {
validators: ProofsValidatorsType[];
};

const validateProofs = (proofs: Proof[] | Proof[][], address: Address) =>
proofs.every((proof: Proof | Proof[]) =>
Array.isArray(proof)
? proof.every(
(p: Proof) =>
toChecksumAddress(`0x${p.proof.owner}`) === address &&
p.proof.validator === proof[0].proof.validator,
)
: toChecksumAddress(`0x${proof.proof.owner}`) === address &&
proof.proof.validator === (proofs as Proof[])[0].proof.validator,
);
const validateProofs = (proofs: Proof[] | Proof[][], address: Address) => {
try {
return proofs.every((proof: Proof | Proof[]) =>
Array.isArray(proof)
? proof.every(
(p: Proof) =>
toChecksumAddress(`0x${p.proof.owner}`) === address &&
p.proof.validator === proof[0].proof.validator,
)
: toChecksumAddress(`0x${proof.proof.owner}`) === address &&
proof.proof.validator === (proofs as Proof[])[0].proof.validator,
);
} catch (e) {
throw new Error(
"The file you uploaded is incorrect, please upload proofs.json.",
);
}
};

export const useValidateProofs = (files: File[]) => {
const account = useAccount();
Expand All @@ -58,14 +65,12 @@ export const useValidateProofs = (files: File[]) => {
refetchOnWindowFocus: false,
refetchOnReconnect: false,
queryFn: async () => {
if (files.length === 0) {
throw new Error("No file uploaded.");
}

const file = files[0];

if (!file || file.type !== "application/json") {
throw new Error("Please upload a valid JSON file.");
throw new Error(
"The file you uploaded is incorrect, please upload proofs.json.",
);
}

if (!account.address) {
Expand All @@ -77,7 +82,9 @@ export const useValidateProofs = (files: File[]) => {
const json = JSON.parse(fileContent);
const isValid = validateProofs(json, account.address);
if (!isValid) {
throw new Error("Wrong proofs file.");
throw new Error(
"The file you uploaded is incorrect, please upload proofs.json.",
);
}
const allRegisteredValidators = await getAllValidators(
clusterHash || "",
Expand All @@ -91,9 +98,6 @@ export const useValidateProofs = (files: File[]) => {
if (
!allRegisteredValidators.data.includes(validatorPublicKey)
) {
if (!Array.isArray(proof)) {
throw new Error("No registered public keys found.");
}
return acc;
}
if (Array.isArray(proof)) {
Expand All @@ -115,6 +119,10 @@ export const useValidateProofs = (files: File[]) => {
),
),
);

if (!validators.length) {
throw new Error("No registered validators found.");
}
state.dkgReshareState.selectedValidatorsCount = validators.length;

return {
Expand Down
4 changes: 2 additions & 2 deletions src/lib/utils/keyshares.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,13 +160,13 @@ export const generateSSVKeysDockerCMD = ({
};

if (signatures) {
return `docker pull bloxstaking/ssv-dkg:v${version} && docker run --rm -v ${dynamicFullPath}:/data -it "bloxstaking/ssv-dkg:v2.1.0" init --operatorIDs ${operatorIds} ${
return `docker pull bloxstaking/ssv-dkg:v${version} && docker run --rm -v ${dynamicFullPath}:/data -it "bloxstaking/ssv-dkg:v${version}" init --operatorIDs ${operatorIds} ${
newOperators?.length
? `--newOperatorsIDs ${sortOperators(newOperators)
.map((op) => op.id)
.join(",")}`
: ""
} --withdrawAddress ${withdrawalAddress} --owner ${account} --nonce ${nonce} --network ${chainName} ${proofsString ? `--proofsString ${proofsString}` : "--proofsFilePath /data/proofs.json"} --operatorsInfo ${newOperators ? getOperatorsData([...operators, ...newOperators]) : getOperatorsData(operators)} --signatures ${signatures} --outputPath /output --logLevel info --logFormat json --logLevelFormat capitalColor --logFilePath /data/debug.log --tlsInsecure`;
}
return `docker pull bloxstaking/ssv-dkg:v2.1.0 && docker run --rm -v ${dynamicFullPath}:/data -it "bloxstaking/ssv-dkg:v2.1.0" init --owner ${account} --nonce ${nonce} --withdrawAddress ${withdrawalAddress} --operatorIDs ${operatorIds} --operatorsInfo ${getOperatorsData(sortedOperators)} --network ${chainName} --validators ${validatorsCount} --logFilePath /data/debug.log --outputPath /data`;
return `docker pull bloxstaking/ssv-dkg:v2.1.0 && docker run --rm -v ${dynamicFullPath}:/data -it "bloxstaking/ssv-dkg:v${version}" init --owner ${account} --nonce ${nonce} --withdrawAddress ${withdrawalAddress} --operatorIDs ${operatorIds} --operatorsInfo ${getOperatorsData(sortedOperators)} --network ${chainName} --validators ${validatorsCount} --logFilePath /data/debug.log --outputPath /data`;
};
Loading