Skip to content

Commit 9dfb258

Browse files
improve: comment feedback
Signed-off-by: james-a-morris <[email protected]>
1 parent 7c51f6d commit 9dfb258

File tree

2 files changed

+7
-57
lines changed

2 files changed

+7
-57
lines changed

src/arch/svm/SpokeUtils.ts

+3-47
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ export function getTimeAt(_spokePool: unknown, _blockNumber: number): Promise<nu
3030
}
3131

3232
/**
33-
* Retrieves the chain time at a particular block.
33+
* Retrieves the chain time at a particular slot.
3434
* @note This should be the same as getTimeAt() but can differ in test. These two functions should be consolidated.
35-
* @returns The chain time at the specified block tag.
35+
* @returns The chain time at the specified slot.
3636
*/
37-
export async function getTimestampForBlock(provider: Provider, slotNumber: number): Promise<number> {
37+
export async function getTimestampForSlot(provider: Provider, slotNumber: number): Promise<number> {
3838
const block = await provider.getBlock(BigInt(slotNumber)).send();
3939
let timestamp: number;
4040
if (!block?.blockTime) {
@@ -67,50 +67,6 @@ export function getDepositIdAtBlock(_contract: unknown, _blockTag: number): Prom
6767
throw new Error("getDepositIdAtBlock: not implemented");
6868
}
6969

70-
/**
71-
* xxx todo
72-
*/
73-
export async function getSlotForBlock(
74-
provider: Provider,
75-
blockNumber: bigint,
76-
lowSlot: bigint,
77-
_highSlot?: bigint
78-
): Promise<bigint | undefined> {
79-
// @todo: Factor getBlock out to SlotFinder ??
80-
const getBlockNumber = async (slot: bigint): Promise<bigint> => {
81-
const block = await provider
82-
.getBlock(slot, { transactionDetails: "none", maxSupportedTransactionVersion: 0 })
83-
.send();
84-
return block?.blockHeight ?? BigInt(0); // @xxx Handle undefined here!
85-
};
86-
87-
let highSlot = _highSlot ?? (await provider.getSlot().send());
88-
const [blockLow = 0, blockHigh = 1_000_000_000] = await Promise.all([
89-
getBlockNumber(lowSlot),
90-
getBlockNumber(highSlot),
91-
]);
92-
93-
if (blockLow > blockNumber || blockHigh < blockNumber) {
94-
return undefined; // blockNumber did not occur within the specified block range.
95-
}
96-
97-
// Find the lowest slot number where blockHeight is greater than the requested blockNumber.
98-
do {
99-
const midSlot = (highSlot + lowSlot) / BigInt(2);
100-
const midBlock = await getBlockNumber(midSlot);
101-
102-
if (midBlock < blockNumber) {
103-
lowSlot = midSlot + BigInt(1);
104-
} else if (midBlock > blockNumber) {
105-
highSlot = midSlot + BigInt(1); // blockNumber occurred at or earlier than midBlock.
106-
} else {
107-
return midSlot;
108-
}
109-
} while (lowSlot <= highSlot);
110-
111-
return undefined;
112-
}
113-
11470
export function findDepositBlock(
11571
_spokePool: unknown,
11672
depositId: BigNumber,

src/clients/SpokePoolClient/SVMSpokePoolClient.ts

+4-10
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@ import {
55
SvmSpokeEventsClient,
66
unwrapEventData,
77
getFillDeadline,
8-
getTimestampForBlock,
8+
getTimestampForSlot,
99
getStatePda,
10-
getSlotForBlock,
1110
} from "../../arch/svm";
1211
import { FillStatus, RelayData, SortableEvent } from "../../interfaces";
1312
import {
@@ -132,7 +131,7 @@ export class SvmSpokePoolClient extends SpokePoolClient {
132131
);
133132
return events.map(
134133
(event): SortableEvent => ({
135-
transactionHash: event.signature.toLowerCase(),
134+
transactionHash: event.signature,
136135
blockNumber: Number(event.slot),
137136
transactionIndex: 0,
138137
logIndex: 0,
@@ -169,13 +168,8 @@ export class SvmSpokePoolClient extends SpokePoolClient {
169168
/**
170169
* Retrieves the timestamp for a given SVM slot number.
171170
*/
172-
public override async getTimestampForBlock(blockNumber: number): Promise<number> {
173-
const slot = await getSlotForBlock(this.rpc, BigInt(blockNumber), BigInt(this.deploymentBlock));
174-
if (!slot) {
175-
this.log("error", `SvmSpokePoolClient::getTimestampForBlock: could not get slot for block ${blockNumber}`);
176-
throw new Error(`SvmSpokePoolClient::getTimestampForBlock: could not get slot for block ${blockNumber}`);
177-
}
178-
return getTimestampForBlock(this.rpc, Number(slot));
171+
public override getTimestampForBlock(slot: number): Promise<number> {
172+
return getTimestampForSlot(this.rpc, slot);
179173
}
180174

181175
/**

0 commit comments

Comments
 (0)