Skip to content

Commit

Permalink
fix backend, adjust bot
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobdcastro committed Jun 13, 2024
1 parent 411ae0a commit ab244bf
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 59 deletions.
2 changes: 1 addition & 1 deletion bot/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import axios from "axios";
const EVENTS_ENDPOINT = "http://localhost:8080/events";
const BEACON_API_BASE_URL = "http://18.199.195.154:32995";
const SLOT_DURATION = 12000; // 12 seconds
const TXN_PER_SLOT = 5;
const TXN_PER_SLOT = 20;

const getCurrentSlot = async () => {
const genesisRes = await axios.get(
Expand Down
2 changes: 1 addition & 1 deletion client/src/app/components/EpochRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import LookAheadToolTip from "./Lookahead";

const EpochRow = () => {
const data = useContext(ApiDataContext);
const slotIndex = data?.slot?.slotIndex - 1;
const slotIndex = data?.slot?.slotIndex;
const currentEpochProposers = data?.slot?.currentEpochProposers;

return (
Expand Down
37 changes: 19 additions & 18 deletions client/src/app/components/LogsDisplay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,13 @@ import {
import { Badge } from "@/components/ui/badge";
import { ApiDataContext } from "../page";

export const LogsDisplay = ({title}) => {
const data = useContext(ApiDataContext);

const preconfTxns = data?.preconfTxns;

export const LogsDisplay = ({ title, preconfTxns }) => {
return (
<div className='flex'>
<div className="flex">
<Card className="mt-4 h-full">
<CardHeader>
<h2 className="text-base font-semibold leading-6 mx-3 my-0 text-gray-200">
{title} Preconfirmations
{title} Preconfirmations
</h2>
</CardHeader>
<CardContent>
Expand All @@ -43,48 +39,53 @@ export const LogsDisplay = ({title}) => {
</TableRow>
</TableHeader>
<TableBody>
{preconfTxns
{preconfTxns && preconfTxns.length > 0
? preconfTxns.map((pre, index) => (
<TableRow key={index} className="border-zinc-800">
<TableCell
className={cn("bg-zinc-800 p-2", {
"bg-zinc-900": index % 2 === 0,
})}
>
{pre.timestamp ? new Date(pre.timestamp).toLocaleTimeString(): null}
{pre.timestamp
? new Date(pre.timestamp).toLocaleTimeString()
: null}
</TableCell>
<TableCell

className={cn("bg-zinc-800 p-2", {
"bg-zinc-900": index % 2 === 0,
})}
>
{pre.tx_hash}
</TableCell>
<TableCell
key={'previous' + index}
key={"previous" + index}
className={cn("bg-zinc-800 p-2", {
"bg-zinc-900": index % 2 === 0,
})}
>
{pre.slot}
</TableCell>
<TableCell

className={cn("bg-zinc-800 p-2", {
"bg-zinc-900": index % 2 === 0,
})}
>
<Badge variant="outline">
{pre.requested
? "Received"
: pre.preconfirmed
<Badge
variant="default"
className={cn({
"bg-blue-800": pre.preconfirmed,
"text-white": pre.preconfirmed,
})}
>
{pre.preconfirmed
? "Preconfirmed"
: pre.requested
? "Received"
: "Unknown"}
</Badge>
</TableCell>
<TableCell

className={cn("bg-zinc-800 p-2", {
"bg-zinc-900": index % 2 === 0,
})}
Expand All @@ -109,6 +110,6 @@ export const LogsDisplay = ({title}) => {
</Card>
</div>
);
}
};

export default LogsDisplay;
24 changes: 3 additions & 21 deletions client/src/app/components/PreconfBanner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,9 @@ const displayBrand = (item: IBuilder | IPreconf) => {
);
};

export default function PreconfBanner({ builder, preconf, title }) {
export default function PreconfBanner({ builder, preconf, title, slot }) {
const data = useContext(ApiDataContext);
const slotIndex = data?.slot?.slotIndex - 1;
const currentSlot = data?.slot?.currentSlot;
const currentEpochProposers = data?.slot?.currentEpochProposers;
console.log(data);

// console.log(data);
// console.log(currentEpochProposers);

// replace this with real mapping
// console.log(getNameByPubkey(proposerNames, '0x23'));
const slotIndex = data?.slot?.slotIndex || null;

return (
<>
Expand All @@ -34,16 +25,7 @@ export default function PreconfBanner({ builder, preconf, title }) {
{title}
</h3>
<dl className="grid grid-cols-1 gap-2 sm:grid-cols-2 mt-2">
<SquareCard
title="Slot"
value={
slotIndex > 0
? slotIndex
: slotIndex < 0
? "No previous slot"
: "Fetching..."
}
/>
<SquareCard title="Slot" value={slot || "Fetching..."} />
<SquareCard
title="Proposer"
value={
Expand Down
32 changes: 18 additions & 14 deletions client/src/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ export default function Home() {
// const { data } = useQuery<DataPayload>({
// queryKey: ["data", { slot: currentSlot }],
// queryFn: async () => {
// const { data } = await axios<DataPayload>({
// const { data } = await axios<{}>({
// method: "GET",
// url: process.env.NEXT_PUBLIC_PRECONF_DASHBOARD_API_BASE_URL + "/data",
// url: process.env.NEXT_PUBLIC_PRECONF_DASHBOARD_API_BASE_URL + "/epoch",
// });
// // console.log(data);
// setCurrentSlot(data?.slot.currentSlot);
Expand Down Expand Up @@ -62,26 +62,30 @@ export default function Home() {
<Navbar />
<MainContentWrapper>
<EpochRow />
<div className='flex gap-x-6 w-full lg:min-w-[1060px]'>
<div className='flex flex-col'>
<div className="flex gap-x-6 w-full lg:min-w-[1060px]">
<div className="flex flex-col">
<PreconfBanner
builder={currentBuilder}
preconf={currentPreconf}
slotIndex={data?.slot.slotIndex - 1}
title='Previous Slot Details'
title="Previous Slot Details"
slot={data?.slot?.currentSlot}
/>
<LogsDisplay
title="Previous Slot"
preconfTxns={data?.prevSlotPreconfTxns}
/>
<LogsDisplay title="Previous Slot" />
</div>
<div className='flex flex-col'>
<div className="flex flex-col">
<PreconfBanner
builder={currentBuilder}
preconf={currentPreconf}
slotIndex={data?.slot.slotIndex}
title='Current Slot Details'


/>
<LogsDisplay title="Current Slot" />
title="Current Slot Details"
slot={data?.slot?.currentSlot + 1}
/>
<LogsDisplay
title="Current Slot"
preconfTxns={data?.currentSlotPreconfTxns}
/>
</div>
</div>
</MainContentWrapper>
Expand Down
10 changes: 6 additions & 4 deletions client/src/interfaces/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ interface ConfirmedBlock {
interface DataPayload {
currentTimestampSeconds: number;
slot: SlotData;
preconfTxns: PreconfTransaction[];
confirmedBlock: ConfirmedBlock | null;
currentSlotPreconfTxns: PreconfTransaction[];
prevSlotPreconfTxns: PreconfTransaction[];
prevSlotConfirmedBlock: ConfirmedBlock | null;
}

export type { SlotData, PreconfTransaction, ConfirmedBlock, DataPayload };
Expand All @@ -52,6 +53,7 @@ export const placeholderDataPayload: DataPayload = {
slotIndex: 0,
currentEpochProposers: [],
},
preconfTxns: [],
confirmedBlock: null,
currentSlotPreconfTxns: [],
prevSlotPreconfTxns: [],
prevSlotConfirmedBlock: null,
};
23 changes: 23 additions & 0 deletions server/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,9 +275,32 @@ const notifyClients = async () => {
console.error("Error querying Redis:", error);
}

const epochRes = await axios.get(
BEACON_API_BASE_URL + "/eth/v1/beacon/genesis"
);
const genesisTimeSeconds = parseInt(epochRes.data.data.genesis_time);
const currentTimeSeconds = Math.floor(Date.now() / 1000);

const currentSlotCalculated = Math.floor(
(currentTimeSeconds - genesisTimeSeconds) / 12
);
const currentEpoch = Math.floor(currentSlotCalculated / 32);
const slotIndex = currentSlotCalculated % 32;

const proposerRes = await axios.get(
BEACON_API_BASE_URL + "/eth/v1/validator/duties/proposer/" + currentEpoch
);

data.currentSlotPreconfTxns = currentSlotPreconfTxns;
data.prevSlotPreconfTxns = prevSlotPreconfTxns;
data.prevSlotConfirmedBlock = prevSlotConfirmedBlock;
data.slot = {
genesisTimeSeconds,
currentEpoch,
currentSlot: currentSlotCalculated,
slotIndex,
currentEpochProposers: proposerRes.data.data,
};
} catch (error) {
console.error("Error during data processing:", error);
}
Expand Down

0 comments on commit ab244bf

Please sign in to comment.