From 3e178f5923c19cad9f733a3e8cc8afa37c5f269b Mon Sep 17 00:00:00 2001 From: Naman Garg <0708ng@gmail.com> Date: Sun, 9 Jun 2024 17:55:08 +0530 Subject: [PATCH 01/10] chore(demo): add status --- bolt-web-demo/frontend/src/app/page.tsx | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/bolt-web-demo/frontend/src/app/page.tsx b/bolt-web-demo/frontend/src/app/page.tsx index 6c88f8cd5..b6bf73c97 100644 --- a/bolt-web-demo/frontend/src/app/page.tsx +++ b/bolt-web-demo/frontend/src/app/page.tsx @@ -140,6 +140,10 @@ export default function Home() { setEvents((prev) => [event, ...prev]); } + const getStatusClass = (status: boolean) => { + return status ? 'bg-green-500' : 'bg-yellow-500'; + }; + return (
@@ -232,11 +236,24 @@ export default function Home() { )}
-

Event logs

+

Status

- This is the list of events received from the server. +
    +
  • + Preconfirmation received: + +
  • +
  • + Preconfirmation included: + +
  • +
  • Preconfirmation finalized : {time === 0 ? "false" : "true"}
  • +
+
+
+

Event logs

    {events.map((message, index) => ( From a931e2c6cb7efc5ecf9247877e012571747d5731 Mon Sep 17 00:00:00 2001 From: Naman Garg <0708ng@gmail.com> Date: Sun, 9 Jun 2024 18:00:53 +0530 Subject: [PATCH 02/10] misc: fix --- bolt-web-demo/frontend/src/app/page.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bolt-web-demo/frontend/src/app/page.tsx b/bolt-web-demo/frontend/src/app/page.tsx index b6bf73c97..e4442b7b1 100644 --- a/bolt-web-demo/frontend/src/app/page.tsx +++ b/bolt-web-demo/frontend/src/app/page.tsx @@ -236,7 +236,7 @@ export default function Home() { )}
    -

    Status

    +

    Status

    • @@ -247,7 +247,7 @@ export default function Home() { Preconfirmation included:
    • -
    • Preconfirmation finalized : {time === 0 ? "false" : "true"}
    • +
    • Preconfirmation finalized:
    From 1131cc80b4c6c305c2996b5030de3477bad9cbb0 Mon Sep 17 00:00:00 2001 From: nicolas <48695862+merklefruit@users.noreply.github.com> Date: Sun, 9 Jun 2024 15:10:29 +0200 Subject: [PATCH 03/10] feat: updated frontend --- bolt-web-demo/backend/src/server.ts | 15 +- bolt-web-demo/frontend/src/app/page.tsx | 222 ++++++++++++++++-------- 2 files changed, 150 insertions(+), 87 deletions(-) diff --git a/bolt-web-demo/backend/src/server.ts b/bolt-web-demo/backend/src/server.ts index 8cdd24b13..3830dfa35 100644 --- a/bolt-web-demo/backend/src/server.ts +++ b/bolt-web-demo/backend/src/server.ts @@ -129,7 +129,7 @@ async function sendDevnetEvents() { sendDevnetEvents(); })(); -// Poll for the slot number until we reach slot 128 +// Poll for the latest slot number (async () => { let beaconClientUrl = DEVNET_ENDPOINTS?.[EventType.BEACON_CLIENT_URL_FOUND]; @@ -138,23 +138,14 @@ async function sendDevnetEvents() { beaconClientUrl = DEVNET_ENDPOINTS?.[EventType.BEACON_CLIENT_URL_FOUND]; } - LATEST_SLOT = await getSlot(beaconClientUrl); - while (LATEST_SLOT <= 128) { + while (true) { LATEST_SLOT = await getSlot(beaconClientUrl); - await new Promise((resolve) => setTimeout(resolve, 1000)); - io.emit("new-event", { type: EventType.NEW_SLOT, message: LATEST_SLOT, timestamp: new Date().toISOString(), }); - } - if (LATEST_SLOT > 128) { - io.emit("new-event", { - type: EventType.NEW_SLOT, - message: 128, - timestamp: new Date().toISOString(), - }); + await new Promise((resolve) => setTimeout(resolve, 1000)); } })(); diff --git a/bolt-web-demo/frontend/src/app/page.tsx b/bolt-web-demo/frontend/src/app/page.tsx index e4442b7b1..2ba3e4e4d 100644 --- a/bolt-web-demo/frontend/src/app/page.tsx +++ b/bolt-web-demo/frontend/src/app/page.tsx @@ -21,17 +21,22 @@ export const SERVER_URL = "http://localhost:3001"; export default function Home() { const [events, setEvents] = useState>([]); - const [preconfSent, setPreconfSent] = useState(false); - const [preconfSlot, setPreconfSlot] = useState(-1); - const [preconfIncluded, setPreconfIncluded] = useState(false); - - const [timerActive, setTimerActive] = useState(false); - const [time, setTime] = useState(0); - - const [newSlotNumber, setNewSlotNumber] = useState(-1); - const [beaconClientUrl, setBeaconClientUrl] = useState(""); - const [providerUrl, setProviderUrl] = useState(""); - const [explorerUrl, setExplorerUrl] = useState(""); + const [preconfSent, setPreconfSent] = useState(false); + const [preconfSlot, setPreconfSlot] = useState(-1); + const [preconfIncluded, setPreconfIncluded] = useState(false); + const [preconfFinalized, setPreconfFinalized] = useState(false); + + const [preconfTimerActive, setPreconfTimerActive] = useState(false); + const [preconfTime, setPreconfTime] = useState(0); + const [inclusionTimerActive, setInclusionTimerActive] = useState(false); + const [inclusionTime, setInclusionTime] = useState(0); + const [finalizationTimerActive, setFinalizationTimerActive] = useState(false); + const [finalizationTime, setFinalizationTime] = useState(0); + + const [newSlotNumber, setNewSlotNumber] = useState(-1); + const [beaconClientUrl, setBeaconClientUrl] = useState(""); + const [providerUrl, setProviderUrl] = useState(""); + const [explorerUrl, setExplorerUrl] = useState(""); useEffect(() => { fetch(`${SERVER_URL}/retry-port-events`); @@ -77,12 +82,25 @@ export default function Home() { event.message.toLowerCase().includes("verified merkle proof for tx") ) { setPreconfIncluded(true); + setInclusionTimerActive(false); dispatchEvent({ message: `Preconfirmed transaction included at slot ${preconfSlot}`, link: `${explorerUrl}/slot/${preconfSlot}`, timestamp: new Date().toISOString(), }); } + + if (event.type === EventType.NEW_SLOT) { + const slot = Number(event.message); + if (slot === preconfSlot + 64) { + setPreconfFinalized(true); + setFinalizationTimerActive(false); + dispatchEvent({ + message: `Preconfirmed transaction finalized at slot ${slot}`, + timestamp: new Date().toISOString(), + }); + } + } }); return () => { @@ -93,22 +111,57 @@ export default function Home() { useEffect(() => { let interval: any = null; - if (timerActive) { + if (preconfTimerActive) { + interval = setInterval(() => { + setPreconfTime((prev) => prev + 2); + }, 2); + } else { + clearInterval(interval); + } + + return () => clearInterval(interval); + }, [preconfTimerActive]); + + useEffect(() => { + let interval: any = null; + + if (inclusionTimerActive) { + interval = setInterval(() => { + setInclusionTime((prev) => prev + 2); + }, 2); + } else { + clearInterval(interval); + } + + return () => clearInterval(interval); + }, [inclusionTimerActive]); + + useEffect(() => { + let interval: any = null; + + if (finalizationTimerActive) { interval = setInterval(() => { - setTime((prev) => prev + 2); + setFinalizationTime((prev) => prev + 2); }, 2); } else { clearInterval(interval); } return () => clearInterval(interval); - }, [timerActive]); + }, [finalizationTimerActive]); async function sendPreconfirmation() { // Reset state setEvents([]); setPreconfSent(true); setPreconfIncluded(false); + setPreconfFinalized(false); + setPreconfTime(0); + setInclusionTime(0); + setFinalizationTime(0); + setPreconfTimerActive(false); + setInclusionTimerActive(false); + setFinalizationTimerActive(false); try { const { payload, txHash } = await createPreconfPayload(providerUrl); @@ -120,16 +173,18 @@ export default function Home() { // 1. POST preconfirmation. // The preconfirmation is considered valid as soon as the server responds with a 200 status code. - setTime(0); - setTimerActive(true); + setPreconfTimerActive(true); + setInclusionTimerActive(true); + setFinalizationTimerActive(true); + const res = await fetch(`${SERVER_URL}/preconfirmation`, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(payload), }); if (res.status === 200) { - console.log("Preconfirmation successful"); - setTimerActive(false); + console.log("Preconfirmation response was successful"); + setPreconfTimerActive(false); } } catch (e) { console.error(e); @@ -141,7 +196,8 @@ export default function Home() { } const getStatusClass = (status: boolean) => { - return status ? 'bg-green-500' : 'bg-yellow-500'; + const base = "h-4 w-4 border border-gray-800 rounded-full "; + return base + (status ? "bg-green-500" : "bg-yellow-500"); }; return ( @@ -198,7 +254,9 @@ export default function Home() { {beaconClientUrl && providerUrl ? (
    -

    Step 1: send a transactions eligible for pre-confirmation

    +

    + Step 1: send a transactions eligible for pre-confirmation +

    By clicking this button you will create a transaction and send it as a preconfirmation request to the BOLT sidecar of the @@ -218,65 +276,79 @@ export default function Home() {
    {preconfSent && ( -
    -

    - Step 2: wait for proposers to issue the preconfirmation response -

    - - The transaction will be processed by BOLT and you will - receive a preconfirmation for inclusion in the next block. - - -
    -

    - Waiting for preconfirmation. Time elapsed: {time}ms + <> +

    +

    + Step 2: wait for proposers to issue the preconfirmation + response

    + + The transaction will be processed by BOLT and you will + receive a preconfirmation for inclusion in the next block. +
    -
    - )} -
    -

    Status

    - -
      -
    • - Preconfirmation received: - -
    • -
    • - Preconfirmation included: - -
    • -
    • Preconfirmation finalized:
    • -
    -
    -
    - -
    -

    Event logs

    - -
      - {events.map((message, index) => ( -
    • - {parseDateToMs(message.timestamp)} - {" | "} - {message.message.toString()} - {message.link && ( - - {" "} - [link] - - )} +
      +

      Status

      +
        +
      • + Preconfirmation received: + + {preconfTime}ms
      • - ))} -
      - -
      +
    • + + Preconfirmed transaction included in a block : + + + {inclusionTime}ms +
    • +
    • + + Inclusion block finalized (2 epochs after inclusion): + + + {finalizationTime}ms +
    • +
    +
    + +
    +

    Event logs

    + +
      + {events.map((message, index) => ( +
    • + {parseDateToMs(message.timestamp)} + {" | "} + {message.message.toString()} + {message.link && ( + + {" "} + [link] + + )} +
    • + ))} +
    +
    +
    + + )}
    ) : (
    From 30386faccd81546e825f5577eca610f7c68a126d Mon Sep 17 00:00:00 2001 From: nicolas <48695862+merklefruit@users.noreply.github.com> Date: Sun, 9 Jun 2024 15:11:19 +0200 Subject: [PATCH 04/10] chore: copy --- bolt-web-demo/frontend/src/app/page.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bolt-web-demo/frontend/src/app/page.tsx b/bolt-web-demo/frontend/src/app/page.tsx index 2ba3e4e4d..df414c501 100644 --- a/bolt-web-demo/frontend/src/app/page.tsx +++ b/bolt-web-demo/frontend/src/app/page.tsx @@ -255,7 +255,7 @@ export default function Home() {

    - Step 1: send a transactions eligible for pre-confirmation + Step 1: send a transactions eligible for preconfirmation

    By clicking this button you will create a transaction and send From 671c58af79497ee3fdc10ae7b6878bce75000243 Mon Sep 17 00:00:00 2001 From: nicolas <48695862+merklefruit@users.noreply.github.com> Date: Sun, 9 Jun 2024 15:11:36 +0200 Subject: [PATCH 05/10] chore: typo --- bolt-web-demo/frontend/src/app/page.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bolt-web-demo/frontend/src/app/page.tsx b/bolt-web-demo/frontend/src/app/page.tsx index df414c501..3c4f61f48 100644 --- a/bolt-web-demo/frontend/src/app/page.tsx +++ b/bolt-web-demo/frontend/src/app/page.tsx @@ -255,7 +255,7 @@ export default function Home() {

    - Step 1: send a transactions eligible for preconfirmation + Step 1: send a transaction eligible for preconfirmation

    By clicking this button you will create a transaction and send From 2992eafabb274e23d108a96f656937adec2c4f4f Mon Sep 17 00:00:00 2001 From: nicolas <48695862+merklefruit@users.noreply.github.com> Date: Sun, 9 Jun 2024 15:22:21 +0200 Subject: [PATCH 06/10] chore: addressed team review --- bolt-web-demo/frontend/src/app/page.tsx | 76 +++++++++++++------------ 1 file changed, 39 insertions(+), 37 deletions(-) diff --git a/bolt-web-demo/frontend/src/app/page.tsx b/bolt-web-demo/frontend/src/app/page.tsx index 3c4f61f48..96f13ab83 100644 --- a/bolt-web-demo/frontend/src/app/page.tsx +++ b/bolt-web-demo/frontend/src/app/page.tsx @@ -253,9 +253,45 @@ export default function Home() {
    {beaconClientUrl && providerUrl ? (
    + {preconfSent && ( +
    +

    Status

    +
      +
    • + Transaction preconfirmed: + + {preconfTime}ms +
    • +
    • + + Transaction confirmed (included in a block): + + + {inclusionTime / 1000}s +
    • +
    • + + Transaction finalized (2 epochs after inclusion): + + + {finalizationTime / 1000}s +
    • +
    +
    + )} +

    - Step 1: send a transaction eligible for preconfirmation + Step 1: Send a transaction eligible for preconfirmation

    By clicking this button you will create a transaction and send @@ -279,7 +315,7 @@ export default function Home() { <>

    - Step 2: wait for proposers to issue the preconfirmation + Step 2: Wait for proposers to issue the preconfirmation response

    @@ -288,45 +324,11 @@ export default function Home() {
    -
    -

    Status

    -
      -
    • - Preconfirmation received: - - {preconfTime}ms -
    • -
    • - - Preconfirmed transaction included in a block : - - - {inclusionTime}ms -
    • -
    • - - Inclusion block finalized (2 epochs after inclusion): - - - {finalizationTime}ms -
    • -
    -
    -

    Event logs

      - {events.map((message, index) => ( + {[...events].reverse().map((message, index) => (
    • {parseDateToMs(message.timestamp)} {" | "} From bef67d8ff3491b3e5c9ecd8030155624cf2ad478 Mon Sep 17 00:00:00 2001 From: Jonas Bostoen Date: Sun, 9 Jun 2024 17:06:02 +0200 Subject: [PATCH 07/10] feat: some demo changes --- bolt-web-demo/frontend/src/app/page.tsx | 2 +- builder/builder/builder.go | 7 +++++-- builder/builder/relay.go | 5 ++--- mev-boost-relay/services/api/service.go | 2 ++ mev-boost/server/service.go | 4 ++++ 5 files changed, 14 insertions(+), 6 deletions(-) diff --git a/bolt-web-demo/frontend/src/app/page.tsx b/bolt-web-demo/frontend/src/app/page.tsx index 96f13ab83..d16021d29 100644 --- a/bolt-web-demo/frontend/src/app/page.tsx +++ b/bolt-web-demo/frontend/src/app/page.tsx @@ -223,7 +223,7 @@ export default function Home() { width={20} height={20} /> -

      – v0.1.0

      +

      – v0.1.0-alpha

    diff --git a/builder/builder/builder.go b/builder/builder/builder.go index 3af7b9c50..cac225f93 100644 --- a/builder/builder/builder.go +++ b/builder/builder/builder.go @@ -405,7 +405,10 @@ func (b *Builder) subscribeToRelayForConstraints(relayBaseEndpoint, authHeader s // Update the slot constraints in the cache b.constraintsCache.Put(constraint.Message.Slot, slotConstraints) + + EmitBoltDemoEvent(fmt.Sprintf("Received constraint from relay for slot %d, stored in cache (path: %s)", constraint.Message.Slot, SubscribeConstraintsPath)) } + } return nil @@ -456,6 +459,7 @@ func (b *Builder) onSealedBlock(opts SubmitBlockOpts, constraints types.HashToCo var versionedBlockRequestWithPreconfsProofs *common.VersionedSubmitBlockRequestWithProofs if len(constraints) > 0 { + EmitBoltDemoEvent(fmt.Sprintf("sealing block %d with %d constraints", opts.Block.Number(), len(constraints))) log.Info(fmt.Sprintf("[BOLT]: Sealing block with %d preconfirmed transactions for block %d", len(constraints), opts.Block.Number())) payloadTransactions := opts.Block.Transactions() @@ -529,8 +533,7 @@ func (b *Builder) onSealedBlock(opts SubmitBlockOpts, constraints types.HashToCo timeForProofs := time.Since(timeStart) // BOLT: send event to web demo - message := fmt.Sprintf("created %d merkle proofs for block %d in %v", len(constraints), opts.Block.Number(), timeForProofs) - EmitBoltDemoEvent(message) + EmitBoltDemoEvent(fmt.Sprintf("created %d merkle proofs for block %d in %v", len(constraints), opts.Block.Number(), timeForProofs)) versionedBlockRequestWithPreconfsProofs = &common.VersionedSubmitBlockRequestWithProofs{ Inner: versionedBlockRequest, diff --git a/builder/builder/relay.go b/builder/builder/relay.go index 07be6ffb1..f4d2f7df2 100644 --- a/builder/builder/relay.go +++ b/builder/builder/relay.go @@ -199,9 +199,8 @@ func (r *RemoteRelay) SubmitBlockWithProofs(msg *common.VersionedSubmitBlockRequ // BOLT: send event to web demo if len(msg.Proofs) > 0 { - slot, _ := msg.Inner.Slot() - message := fmt.Sprintf("sending bid to relay with %d constraints for slot %d", len(msg.Proofs), slot) - EmitBoltDemoEvent(message) + number, _ := msg.Inner.BlockNumber() + EmitBoltDemoEvent(fmt.Sprintf("sending block %d with proofs to relay (path: %s)", number, "/relay/v1/builder/blocks_with_proofs")) } switch msg.Inner.Version { diff --git a/mev-boost-relay/services/api/service.go b/mev-boost-relay/services/api/service.go index 727c252f2..3164f4b65 100644 --- a/mev-boost-relay/services/api/service.go +++ b/mev-boost-relay/services/api/service.go @@ -1870,6 +1870,8 @@ func (api *RelayAPI) handleSubmitConstraints(w http.ResponseWriter, req *http.Re log.Infof("Added %d constraints for slot %d and broadcasted %d to channels", len(*payload), message.Slot, len(api.constraintsConsumers)) } + EmitBoltDemoEvent(fmt.Sprintf("received %d valid constraints, sending to builders... (path: %s)", len(*payload), req.URL.Path)) + // respond to the HTTP request api.RespondOK(w, nil) } diff --git a/mev-boost/server/service.go b/mev-boost/server/service.go index 0ce504210..fdd18e118 100644 --- a/mev-boost/server/service.go +++ b/mev-boost/server/service.go @@ -446,6 +446,8 @@ func (m *BoostService) handleSubmitConstraint(w http.ResponseWriter, req *http.R "ua": ua, }) + path := req.URL.Path + log.Info("submitConstraint") payload := BatchedSignedConstraints{} @@ -474,6 +476,8 @@ func (m *BoostService) handleSubmitConstraint(w http.ResponseWriter, req *http.R relayRespCh := make(chan error, len(m.relays)) + EmitBoltDemoEvent(fmt.Sprintf("received %d constraints, forwarding to Bolt relays... (path: %s)", len(payload), path)) + for _, relay := range m.relays { go func(relay RelayEntry) { url := relay.GetURI(pathSubmitConstraint) From 3976cfd1f222c5e1163658e70c68e92bbbafc875 Mon Sep 17 00:00:00 2001 From: Jonas Bostoen Date: Sun, 9 Jun 2024 17:07:27 +0200 Subject: [PATCH 08/10] feat: some demo changes --- builder/builder/builder.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/builder/builder/builder.go b/builder/builder/builder.go index cac225f93..c77418bac 100644 --- a/builder/builder/builder.go +++ b/builder/builder/builder.go @@ -390,6 +390,8 @@ func (b *Builder) subscribeToRelayForConstraints(relayBaseEndpoint, authHeader s continue } + EmitBoltDemoEvent(fmt.Sprintf("Received constraint from relay for slot %d, stored in cache (path: %s)", constraint.Message.Slot, SubscribeConstraintsPath)) + // For every constraint, we need to check if it has already been seen for the associated slot slotConstraints, _ := b.constraintsCache.Get(constraint.Message.Slot) if len(slotConstraints) == 0 { @@ -406,7 +408,6 @@ func (b *Builder) subscribeToRelayForConstraints(relayBaseEndpoint, authHeader s // Update the slot constraints in the cache b.constraintsCache.Put(constraint.Message.Slot, slotConstraints) - EmitBoltDemoEvent(fmt.Sprintf("Received constraint from relay for slot %d, stored in cache (path: %s)", constraint.Message.Slot, SubscribeConstraintsPath)) } } From 7fa843d605c44cba2d39d1a8b63da3ace62f4a3d Mon Sep 17 00:00:00 2001 From: nicolas <48695862+merklefruit@users.noreply.github.com> Date: Sun, 9 Jun 2024 17:51:27 +0200 Subject: [PATCH 09/10] chore: stop filtering duplicate events (will fix not shown events, but probably will show some duplicates now) --- bolt-web-demo/backend/src/server.ts | 21 +++++++++++++-------- bolt-web-demo/frontend/src/app/page.tsx | 7 ++----- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/bolt-web-demo/backend/src/server.ts b/bolt-web-demo/backend/src/server.ts index 3830dfa35..a799f9aa8 100644 --- a/bolt-web-demo/backend/src/server.ts +++ b/bolt-web-demo/backend/src/server.ts @@ -29,16 +29,21 @@ app.post("/events", (req, res) => { const { message } = req.body; if (!message) { + console.error("No message provided"); res.status(400).send("No message provided"); } else { - // Remove time measurements from the message - const messageWithoutMeasurements = message.replace(/ in .+$/g, ""); - // Deduplicate events - if (EVENTS_SET.has(messageWithoutMeasurements)) { - res.status(200).send("OK"); - return; - } - EVENTS_SET.add(messageWithoutMeasurements); + // // Remove time measurements from the message + // const messageWithoutMeasurements = message.replace(/ in .+$/g, ""); + // // Deduplicate events + // if (EVENTS_SET.has(messageWithoutMeasurements)) { + // console.warn( + // "Duplicate event received, discarding:", + // messageWithoutMeasurements + // ); + // res.status(200).send("OK"); + // return; + // } + // EVENTS_SET.add(messageWithoutMeasurements); // Broadcast the message to all connected WebSocket clients io.emit("new-event", { message, timestamp: new Date().toISOString() }); diff --git a/bolt-web-demo/frontend/src/app/page.tsx b/bolt-web-demo/frontend/src/app/page.tsx index d16021d29..b2d063ca4 100644 --- a/bolt-web-demo/frontend/src/app/page.tsx +++ b/bolt-web-demo/frontend/src/app/page.tsx @@ -49,7 +49,7 @@ export default function Home() { const newSocket = io(SERVER_URL, { autoConnect: true }); newSocket.on("new-event", (event: Event) => { - console.debug("Event from server:", event); + console.info("Event from server:", event); // If the event has a special type, handle it differently switch (event.type) { @@ -159,9 +159,6 @@ export default function Home() { setPreconfTime(0); setInclusionTime(0); setFinalizationTime(0); - setPreconfTimerActive(false); - setInclusionTimerActive(false); - setFinalizationTimerActive(false); try { const { payload, txHash } = await createPreconfPayload(providerUrl); @@ -223,7 +220,7 @@ export default function Home() { width={20} height={20} /> -

    – v0.1.0-alpha

    +

    – v0.1.0

    From 067b6681633bb63efe5dd57b51e270d5379005dc Mon Sep 17 00:00:00 2001 From: nicolas <48695862+merklefruit@users.noreply.github.com> Date: Sun, 9 Jun 2024 20:42:34 +0200 Subject: [PATCH 10/10] chore: fixed finalization time --- bolt-web-demo/frontend/src/app/page.tsx | 32 ++++++++++++------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/bolt-web-demo/frontend/src/app/page.tsx b/bolt-web-demo/frontend/src/app/page.tsx index b2d063ca4..3b1ff65e0 100644 --- a/bolt-web-demo/frontend/src/app/page.tsx +++ b/bolt-web-demo/frontend/src/app/page.tsx @@ -51,6 +51,18 @@ export default function Home() { newSocket.on("new-event", (event: Event) => { console.info("Event from server:", event); + if (event.type === EventType.NEW_SLOT) { + const slot = Number(event.message); + if (slot === preconfSlot + 64) { + setPreconfFinalized(true); + setFinalizationTimerActive(false); + dispatchEvent({ + message: `Preconfirmed transaction finalized at slot ${slot}`, + timestamp: new Date().toISOString(), + }); + } + } + // If the event has a special type, handle it differently switch (event.type) { case EventType.BEACON_CLIENT_URL_FOUND: @@ -89,18 +101,6 @@ export default function Home() { timestamp: new Date().toISOString(), }); } - - if (event.type === EventType.NEW_SLOT) { - const slot = Number(event.message); - if (slot === preconfSlot + 64) { - setPreconfFinalized(true); - setFinalizationTimerActive(false); - dispatchEvent({ - message: `Preconfirmed transaction finalized at slot ${slot}`, - timestamp: new Date().toISOString(), - }); - } - } }); return () => { @@ -127,8 +127,8 @@ export default function Home() { if (inclusionTimerActive) { interval = setInterval(() => { - setInclusionTime((prev) => prev + 2); - }, 2); + setInclusionTime((prev) => prev + 10); + }, 10); } else { clearInterval(interval); } @@ -141,8 +141,8 @@ export default function Home() { if (finalizationTimerActive) { interval = setInterval(() => { - setFinalizationTime((prev) => prev + 2); - }, 2); + setFinalizationTime((prev) => prev + 30); + }, 30); } else { clearInterval(interval); }