Skip to content

Commit ce076a6

Browse files
[release] v0.0.11 (#119)
* v0.0.11 * use message received time * fix compile error * fix adjust time * fix lint * ignore skew with small absolute value * nit * avoid jumpy block time * add const * update wasm
1 parent 7dc774b commit ce076a6

11 files changed

Lines changed: 72 additions & 26 deletions

File tree

Cargo.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ members = [
88
resolver = "2"
99

1010
[workspace.dependencies]
11-
alto-client = { version = "0.0.10", path = "client" }
12-
alto-types = { version = "0.0.10", path = "types" }
11+
alto-client = { version = "0.0.11", path = "client" }
12+
alto-types = { version = "0.0.11", path = "types" }
1313
commonware-broadcast = { version = "0.0.54" }
1414
commonware-codec = { version = "0.0.54" }
1515
commonware-consensus = { version = "0.0.54" }

chain/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "alto-chain"
3-
version = "0.0.10"
3+
version = "0.0.11"
44
publish = true
55
edition = "2021"
66
license = "MIT OR Apache-2.0"

client/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "alto-client"
3-
version = "0.0.10"
3+
version = "0.0.11"
44
publish = true
55
edition = "2021"
66
license = "MIT OR Apache-2.0"

explorer/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "alto-explorer",
3-
"version": "0.0.10",
3+
"version": "0.0.11",
44
"private": true,
55
"dependencies": {
66
"@types/node": "^16.18.126",

explorer/src/App.tsx

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ const App: React.FC = () => {
9393
const handleSeedRef = useRef<typeof handleSeed>(null!);
9494
const handleNotarizedRef = useRef<typeof handleNotarization>(null!);
9595
const handleFinalizedRef = useRef<typeof handleFinalization>(null!);
96+
const adjustTimeRef = useRef(adjustTime);
9697
const isInitializedRef = useRef(false);
9798
const reconnectTimeoutRef = useRef<NodeJS.Timeout | null>(null);
9899

@@ -311,7 +312,7 @@ const App: React.FC = () => {
311312
});
312313
}, [lastObservedView, adjustTime]);
313314

314-
const handleNotarization = useCallback((notarized: NotarizedJs) => {
315+
const handleNotarization = useCallback((notarized: NotarizedJs, messageReceivedTime?: number) => {
315316
const view = notarized.proof.view;
316317
setViews((prevViews) => {
317318
const index = prevViews.findIndex((v) => v.view === view);
@@ -320,9 +321,10 @@ const App: React.FC = () => {
320321
if (index !== -1 && prevViews[index].status === "finalized") {
321322
return prevViews; // No changes needed, preserve finalized state
322323
}
323-
324324
let newViews = [...prevViews];
325-
const currentTime = adjustTime(Date.now());
325+
326+
// If messageReceivedTime is not provided, use the current time
327+
const currentTime = messageReceivedTime || adjustTime(Date.now());
326328

327329
// Calculate a reasonable start time using the block timestamp if available
328330
let calculatedStartTime = currentTime;
@@ -401,12 +403,14 @@ const App: React.FC = () => {
401403
});
402404
}, [adjustTime]);
403405

404-
const handleFinalization = useCallback((finalized: FinalizedJs) => {
406+
const handleFinalization = useCallback((finalized: FinalizedJs, messageReceivedTime?: number) => {
405407
const view = finalized.proof.view;
406408
setViews((prevViews) => {
407409
const index = prevViews.findIndex((v) => v.view === view);
408410
let newViews = [...prevViews];
409-
const currentTime = adjustTime(Date.now());
411+
412+
// If messageReceivedTime is not provided, use the current time
413+
const currentTime = messageReceivedTime || adjustTime(Date.now());
410414

411415
// Calculate a reasonable start time using the block timestamp if available
412416
let calculatedStartTime = currentTime;
@@ -516,6 +520,10 @@ const App: React.FC = () => {
516520
handleFinalizedRef.current = handleFinalization;
517521
}, [handleFinalization]);
518522

523+
useEffect(() => {
524+
adjustTimeRef.current = adjustTime;
525+
}, [adjustTime]);
526+
519527
// WebSocket connection management with fixed single-connection approach
520528
useEffect(() => {
521529
// If loading, don't start
@@ -573,6 +581,8 @@ const App: React.FC = () => {
573581
};
574582

575583
ws.onmessage = (event) => {
584+
// Capture timestamp as soon as we receive the message (not when it is verified)
585+
const messageReceivedTime = adjustTimeRef.current(Date.now());
576586
const data = new Uint8Array(event.data);
577587
const kind = data[0];
578588
const payload = data.slice(1);
@@ -584,11 +594,11 @@ const App: React.FC = () => {
584594
break;
585595
case 1: // Notarization
586596
const notarized = parse_notarized(PUBLIC_KEY, payload);
587-
if (notarized) handleNotarizedRef.current(notarized);
597+
if (notarized) handleNotarizedRef.current(notarized, messageReceivedTime);
588598
break;
589599
case 2: // Finalization
590600
const finalized = parse_finalized(PUBLIC_KEY, payload);
591-
if (finalized) handleFinalizedRef.current(finalized);
601+
if (finalized) handleFinalizedRef.current(finalized, messageReceivedTime);
592602
break;
593603
}
594604
};

explorer/src/StatsSection.tsx

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -125,14 +125,43 @@ const StatsSection: React.FC<StatsSectionProps> = ({ views, connectionError = fa
125125
.sort((a, b) => a.block.height - b.block.height);
126126

127127
const blockTimes: number[] = [];
128+
129+
// Group consecutive blocks to ensure we're only comparing truly adjacent blocks
130+
const consecutiveGroups: typeof viewsWithBlocks[] = [];
131+
let currentGroup: typeof viewsWithBlocks = [viewsWithBlocks[0]];
132+
128133
for (let i = 1; i < viewsWithBlocks.length; i++) {
129134
const currentBlock = viewsWithBlocks[i].block;
130-
const prevBlock = viewsWithBlocks[i - 1].block;
131-
if (currentBlock && prevBlock &&
132-
currentBlock.timestamp && prevBlock.timestamp &&
133-
currentBlock.height === prevBlock.height + 1) {
134-
const timeDiff = currentBlock.timestamp - prevBlock.timestamp;
135-
if (timeDiff > 0 && timeDiff < 10000) { // Filter out unreasonable values (>10s)
135+
const prevBlock = currentGroup[currentGroup.length - 1].block;
136+
137+
// If this block is consecutive to the last one in current group, add it
138+
if (currentBlock.height === prevBlock.height + 1) {
139+
currentGroup.push(viewsWithBlocks[i]);
140+
} else {
141+
// Start a new group if we have a gap
142+
if (currentGroup.length >= 2) {
143+
consecutiveGroups.push(currentGroup);
144+
}
145+
currentGroup = [viewsWithBlocks[i]];
146+
}
147+
}
148+
149+
// Don't forget the last group
150+
if (currentGroup.length >= 2) {
151+
consecutiveGroups.push(currentGroup);
152+
}
153+
154+
// Calculate block times only within consecutive groups
155+
for (const group of consecutiveGroups) {
156+
// Only process groups with at least 3 blocks for more reliable measurements
157+
if (group.length >= 3) {
158+
for (let i = 1; i < group.length; i++) {
159+
const currentBlock = group[i].block;
160+
const prevBlock = group[i - 1].block;
161+
162+
// Use raw block timestamps directly - DO NOT apply clock skew correction
163+
// Block timestamps come from the network itself, not browser time
164+
const timeDiff = currentBlock.timestamp - prevBlock.timestamp;
136165
blockTimes.push(timeDiff);
137166
}
138167
}
0 Bytes
Binary file not shown.

explorer/src/useClockSkew.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ const timeout = 3000;
99
// Interval to fetch server time (in milliseconds)
1010
const interval = 30000;
1111

12+
// Uncertainty bound for clock skew (in milliseconds)
13+
const uncertaintyBound = 35;
14+
1215
/**
1316
* Custom hook to detect clock skew between client and server
1417
* Runs once on mount and then every 30 seconds, using the latest successful measurement as the skew
@@ -68,10 +71,14 @@ export const useClockSkew = () => {
6871
// Calculate skew
6972
const adjustedLocalTime = localStartTime + networkLatency;
7073
const skew = adjustedLocalTime - serverTime;
71-
console.log('Local clock skew:', skew);
74+
75+
// If the clockSkew has an absolute value less than 35ms, make no adjustment
76+
// This is within the range of uncertainty on measurement
77+
const adjustedSkew = Math.abs(skew) < uncertaintyBound ? 0 : skew;
78+
console.log(`Measured clock skew: ${skew}ms (Applied clock skew: ${adjustedSkew}ms)`);
7279

7380
// Update state with the new skew
74-
setClockSkew(skew);
81+
setClockSkew(adjustedSkew);
7582
} catch (err) {
7683
console.error('Failed to fetch skew:', err);
7784
// Keep the previous skew if the request fails

inspector/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "alto-inspector"
3-
version = "0.0.10"
3+
version = "0.0.11"
44
publish = true
55
edition = "2021"
66
license = "MIT OR Apache-2.0"

0 commit comments

Comments
 (0)