Skip to content

Commit a393310

Browse files
chore(randomnness-service): self review
1 parent 9d32090 commit a393310

5 files changed

Lines changed: 3 additions & 175 deletions

File tree

packages/contracts/src/test/RandomCommitment.t.sol

Lines changed: 0 additions & 129 deletions
This file was deleted.

packages/randomness-service/src/CustomGasEstimator.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ export class CustomGasEstimator extends GasEstimator {
1212
transaction: Transaction,
1313
): Promise<Result<bigint, EstimateGasErrorCause>> {
1414
if (transaction.functionName === "postCommitment") {
15-
return ok(100000n)
15+
return ok(50000n)
1616
}
1717
if (transaction.functionName === "revealValue") {
18-
return ok(200000n)
18+
return ok(100000n)
1919
}
2020

2121
return this.simulateTransactionForGas(transactionManager, transaction)

packages/randomness-service/src/DrandService.ts

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -52,26 +52,6 @@ export class DrandService {
5252
return ok(data)
5353
}
5454

55-
public async getLatestDrandBeacon(): Promise<Result<DrandBeacon, DrandError>> {
56-
const url = `${env.EVM_DRAND_URL}/rounds/latest`
57-
58-
const response = await ResultAsync.fromPromise(fetch(url), unknownToError)
59-
60-
if (response.isErr()) {
61-
return err(DrandError.NetworkError)
62-
}
63-
64-
const dataRaw = await response.value.json()
65-
66-
const parsed = drandBeaconSchema.safeParse(dataRaw)
67-
68-
if (!parsed.success) {
69-
return err(DrandError.InvalidResponse)
70-
}
71-
72-
return ok(parsed.data)
73-
}
74-
7555
public currentRound(): bigint {
7656
const currentTimestamp = nowInSeconds()
7757
const currentRound = Math.floor(

packages/randomness-service/src/index.ts

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { nowInSeconds, sleep } from "@happychain/common"
1+
import { sleep } from "@happychain/common"
22
import { TransactionManager, TransactionStatus, TxmHookType } from "@happychain/transaction-manager"
33
import type { LatestBlock, Transaction } from "@happychain/transaction-manager"
44
import { abis } from "./ABI/random.js"
@@ -60,11 +60,7 @@ class RandomnessService {
6060
const now = Date.now()
6161
const nextDrandBeaconTimestamp =
6262
Math.ceil((now - drandGenesisTimestampMs) / periodMs) * periodMs + drandGenesisTimestampMs
63-
console.log("nextDrandBeaconTimestamp", nextDrandBeaconTimestamp)
64-
console.log("now", now)
6563
await sleep(nextDrandBeaconTimestamp - now)
66-
console.log("Awaked on", Date.now())
67-
6864
setInterval(async () => {
6965
await this.handleNewDrandBeacons()
7066
}, Number(env.EVM_DRAND_PERIOD_SECONDS) * 1000)
@@ -145,34 +141,16 @@ class RandomnessService {
145141

146142
private async handleNewDrandBeacons() {
147143
const currentRound = this.drandService.currentRound()
148-
const latestDrandBeacon = await this.drandService.getLatestDrandBeacon()
149-
150-
if (latestDrandBeacon.isErr()) {
151-
return
152-
}
153-
154-
console.log("currentRound", currentRound)
155-
console.log("Now in seconds", nowInSeconds())
156-
console.log("latestDrandBeacon", latestDrandBeacon.value.round)
157-
console.log(
158-
"LATEST BEACON EXPECTED TIMESTAMP",
159-
(latestDrandBeacon.value.round - 1) * Number(env.EVM_DRAND_PERIOD_SECONDS) +
160-
Number(env.EVM_DRAND_GENESIS_TIMESTAMP_SECONDS),
161-
)
162144

163145
const oldestDrand = this.drandRepository.getOldestDrandRound() ?? env.EVM_DRAND_START_ROUND
164146

165147
const drandGaps = this.drandRepository.findRoundGapsInRange(oldestDrand, currentRound)
166148

167-
console.log("drandGaps", drandGaps)
168-
169149
await Promise.all(
170150
drandGaps.map(async (round) => {
171151
let drandBeacon = await this.drandService.getDrandBeacon(round)
172-
console.log("returned beacon", drandBeacon)
173152
if (drandBeacon.isErr()) {
174153
if (drandBeacon.error === DrandError.TooEarly) {
175-
console.log("Too early, waiting 1 second")
176154
await sleep(1000)
177155
drandBeacon = await this.drandService.getDrandBeacon(round)
178156

packages/transaction-manager/lib/TxMonitor.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,6 @@ export class TxMonitor {
130130
})
131131
: undefined
132132

133-
console.log("traceResult", traceResult)
134133
if (!traceResult || traceResult.isErr()) {
135134
if (receipt.gasUsed === attempt.gas) {
136135
return await this.handleOutOfGasTransaction(transaction)

0 commit comments

Comments
 (0)