less noisy logging
This commit is contained in:
parent
d9aecb68c2
commit
2a5f3b3ae6
|
@ -19,7 +19,7 @@ import {
|
|||
import FluxAggregator from "./FluxAggregator"
|
||||
import { AggregatorConfig, IAggregatorConfig } from "./schema"
|
||||
import { jsonReplacer, jsonReviver } from "./json"
|
||||
|
||||
import { log } from "./log"
|
||||
|
||||
interface OracleDeployInfo {
|
||||
pubkey: PublicKey
|
||||
|
@ -72,11 +72,7 @@ export class Deployer {
|
|||
}
|
||||
|
||||
async deployProgram() {
|
||||
if (this.state.programID) {
|
||||
console.log("program deployed")
|
||||
return
|
||||
}
|
||||
|
||||
if (!this.state.programID) {
|
||||
const programBinary = fs.readFileSync(FLUX_AGGREGATOR_SO)
|
||||
|
||||
console.log(`deploying ${FLUX_AGGREGATOR_SO}...`)
|
||||
|
@ -86,21 +82,30 @@ export class Deployer {
|
|||
this.state.programID = account.publicKey
|
||||
}
|
||||
|
||||
async createAggregators() {
|
||||
for (let key of Object.keys(this.setup.aggregators)) {
|
||||
const aggregatorSetup = this.setup.aggregators[key]
|
||||
log.info("Program deployed", {
|
||||
programID: this.state.programID.toBase58(),
|
||||
})
|
||||
}
|
||||
|
||||
let info = this.state.aggregators[key]
|
||||
async createAggregators() {
|
||||
for (let name of Object.keys(this.setup.aggregators)) {
|
||||
const aggregatorSetup = this.setup.aggregators[name]
|
||||
|
||||
let info = this.state.aggregators[name]
|
||||
if (!info) {
|
||||
this.state.aggregators[key] = await this.createAggregator(
|
||||
key,
|
||||
this.state.aggregators[name] = await this.createAggregator(
|
||||
name,
|
||||
aggregatorSetup
|
||||
)
|
||||
// get the value again to wrap it in proxy...
|
||||
info = this.state.aggregators[key]
|
||||
info = this.state.aggregators[name]
|
||||
}
|
||||
|
||||
console.log(`${key} aggregator deployed`)
|
||||
log.info("Aggregator deployed", {
|
||||
name,
|
||||
aggregator: info.pubkey.toBase58(),
|
||||
})
|
||||
|
||||
for (let oracleName of aggregatorSetup.oracles || []) {
|
||||
const oracleSetup = this.setup.oracles[oracleName]
|
||||
// TODO: check that key exists
|
||||
|
@ -110,7 +115,7 @@ export class Deployer {
|
|||
oinfo = await this.createOracle(info, oracleName, oracleSetup)
|
||||
info.oracles[oracleName] = oinfo
|
||||
}
|
||||
console.log(`${key} added oracle:`, oracleSetup.owner)
|
||||
log.info(`Oracle added`, { name, oracleName })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -59,7 +59,6 @@ export class PriceFeeder {
|
|||
}
|
||||
)
|
||||
|
||||
console.log("start price feeding:", name)
|
||||
submitter.start()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,14 +8,8 @@ import { sleep } from "./utils"
|
|||
import FluxAggregator from "./FluxAggregator"
|
||||
|
||||
import { createLogger, Logger } from "winston"
|
||||
import logger from "winston"
|
||||
logger.add(
|
||||
new logger.transports.Console({
|
||||
format: logger.format.simple(),
|
||||
level: "debug",
|
||||
})
|
||||
)
|
||||
|
||||
import { log } from "./log"
|
||||
import { IPriceFeed } from "./feeds"
|
||||
|
||||
// allow oracle to start a new round after this many slots. each slot is about 500ms
|
||||
|
@ -60,7 +54,7 @@ export class Submitter {
|
|||
this.aggregator.answerSubmissions
|
||||
)
|
||||
|
||||
this.logger = logger.child({
|
||||
this.logger = log.child({
|
||||
aggregator: this.aggregator.config.description,
|
||||
})
|
||||
|
||||
|
@ -142,15 +136,15 @@ export class Submitter {
|
|||
|
||||
// The round is stale. start a new round if possible, or wait for another
|
||||
// oracle to start
|
||||
this.logger.info("Starting a new round")
|
||||
const oracle = await Oracle.load(this.oraclePK)
|
||||
if (oracle.canStartNewRound(round.id)) {
|
||||
this.logger.info("Starting a new round")
|
||||
return this.submitCurrentValue(round.id.addn(1))
|
||||
}
|
||||
}
|
||||
|
||||
private async onAggregatorStateUpdate() {
|
||||
if (this.canSubmitToCurrentRound) {
|
||||
if (!this.canSubmitToCurrentRound) {
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -173,7 +167,7 @@ export class Submitter {
|
|||
return
|
||||
}
|
||||
|
||||
this.logger.info("submit", {
|
||||
this.logger.info("Submit value", {
|
||||
round: round.toString(),
|
||||
value: value.toString(),
|
||||
})
|
||||
|
@ -193,7 +187,7 @@ export class Submitter {
|
|||
})
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
this.logger.error("submit error", {
|
||||
this.logger.error("Submit error", {
|
||||
err: err.toString(),
|
||||
})
|
||||
}
|
||||
|
|
10
src/feeds.ts
10
src/feeds.ts
|
@ -2,6 +2,8 @@ import WebSocket from "ws"
|
|||
import EventEmitter from "events"
|
||||
import { eventsIter } from "./utils"
|
||||
|
||||
import { log } from "./log"
|
||||
|
||||
export const UPDATE = "UPDATE"
|
||||
|
||||
export interface IPrice {
|
||||
|
@ -22,7 +24,7 @@ export function coinbase(pair: string): IPriceFeed {
|
|||
// "btc:usd" => "BTC-USD"
|
||||
pair = pair.replace(":", "-").toUpperCase()
|
||||
ws.on("open", () => {
|
||||
console.log(`${pair} price feed connected`)
|
||||
log.debug(`price feed connected`, { pair })
|
||||
ws.send(
|
||||
JSON.stringify({
|
||||
type: "subscribe",
|
||||
|
@ -34,8 +36,10 @@ export function coinbase(pair: string): IPriceFeed {
|
|||
|
||||
ws.on("message", async (data) => {
|
||||
const json = JSON.parse(data)
|
||||
log.debug("price update", json)
|
||||
|
||||
if (!json || !json.price) {
|
||||
return console.log(data)
|
||||
return
|
||||
}
|
||||
const price: IPrice = {
|
||||
decimals: 2,
|
||||
|
@ -47,7 +51,7 @@ export function coinbase(pair: string): IPriceFeed {
|
|||
|
||||
ws.on("close", (err) => {
|
||||
// TODO: automatic reconnect
|
||||
console.error(`websocket closed: ${err}`)
|
||||
log.debug(`price feed closed`, { pair, err: err.toString() })
|
||||
process.exit(1)
|
||||
})
|
||||
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
import logger from "winston"
|
||||
import { format } from "winston"
|
||||
|
||||
logger.add(
|
||||
new logger.transports.Console({
|
||||
// format: logger.format.cli(),
|
||||
format: format.combine(format.cli(), format.simple()),
|
||||
level: process.env.LOG_LEVEL?.toLocaleLowerCase() || "info",
|
||||
})
|
||||
)
|
||||
|
||||
export const log = logger
|
|
@ -20,10 +20,7 @@ export function stateFromJSON<T extends Object>(
|
|||
const data = fs.readFileSync(filepath, "utf8")
|
||||
// TODO: support custom revive
|
||||
root = JSON.parse(data, opts.reviver as any)
|
||||
console.log(`Loaded state object: ${filepath}`)
|
||||
} catch (err) {
|
||||
console.log(`Init state object: ${filepath}`)
|
||||
}
|
||||
} catch (err) {}
|
||||
|
||||
function save() {
|
||||
// should be sync to avoid write races
|
||||
|
|
|
@ -38,7 +38,6 @@ export async function walletFromEnv(
|
|||
}
|
||||
|
||||
const wallet = await Wallet.fromMnemonic(mnemonic, conn)
|
||||
console.log("using wallet:", wallet.address)
|
||||
return wallet
|
||||
}
|
||||
|
||||
|
|
6
test.ts
6
test.ts
|
@ -3,11 +3,11 @@ dotenv.config()
|
|||
|
||||
import { AppContext, conn, network } from "./src/context"
|
||||
import { Deployer } from "./src/Deployer"
|
||||
import { coinbase } from "./src/feeds"
|
||||
import { log } from "./src/log"
|
||||
import { PriceFeeder } from "./src/PriceFeeder"
|
||||
|
||||
async function main() {
|
||||
|
||||
console.log({network})
|
||||
const setupFile = `config/setup.${network}.json`
|
||||
const deployFile = `deploy.${network}.json`
|
||||
const feederConfigFile = "feeder.json"
|
||||
|
@ -24,7 +24,7 @@ async function main() {
|
|||
|
||||
const feeder = new PriceFeeder(deployFile, feederConfigFile, oracleWallet)
|
||||
feeder.start()
|
||||
console.log("done")
|
||||
|
||||
return
|
||||
|
||||
// const spltoken = new SPLToken(adminWallet)
|
||||
|
|
Loading…
Reference in New Issue