Skip to content
This repository has been archived by the owner on Dec 5, 2021. It is now read-only.

Commit

Permalink
Support uploading a new state-dump.latest.json file to DTL. (#528)
Browse files Browse the repository at this point in the history
Also cleans up some debug messages and returns '500' error
rather than '400' on unhandled errors.

 Changes to be committed:
	modified:   ../packages/data-transport-layer/src/services/main/service.ts

Co-authored-by: CAPtheorem <[email protected]>
  • Loading branch information
mmontour1306 and CAPtheorem authored Sep 30, 2021
1 parent f8de6a0 commit a1662c3
Showing 1 changed file with 35 additions and 12 deletions.
47 changes: 35 additions & 12 deletions packages/data-transport-layer/src/services/main/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { Counter } from 'prom-client'
import express, { Request, Response } from 'express'
import bodyParser from 'body-parser'
import cors from 'cors'
import fs from 'fs'

export interface L1DataTransportServiceOptions {
nodeEnv: string
Expand Down Expand Up @@ -113,7 +114,7 @@ export class L1DataTransportService extends BaseService<L1DataTransportServiceOp

return res.json(aList)
} catch (e) {
return res.status(400).json({
return res.status(500).json({
error: e.toString(),
})
}
Expand All @@ -132,7 +133,7 @@ export class L1DataTransportService extends BaseService<L1DataTransportServiceOp

return res.json(aList)
} catch (e) {
return res.status(400).json({
return res.status(500).json({
error: e.toString(),
})
}
Expand Down Expand Up @@ -163,12 +164,12 @@ export class L1DataTransportService extends BaseService<L1DataTransportServiceOp
} else { throw e; }
}

this.logger.info("MMDBG Will store", rb)
this.logger.info("Will store new addresses.json", rb)
await this.state.db.put("address-list", JSON.stringify(rb))
this.logger.info("MMDBG Stored")
this.logger.info("Stored addresses.json")
return res.sendStatus(201).end()
} catch (e) {
return res.status(400).json({
return res.status(500).json({
error: e.toString(),
})
}
Expand All @@ -182,31 +183,53 @@ export class L1DataTransportService extends BaseService<L1DataTransportServiceOp
// As with the base list, we could add future restrictions on changing
// certain critical addresses. For now we allow anything.

this.logger.info("MMDBG Will store", rb)
this.logger.info("Will store new omgx-addr.json", rb)
await this.state.db.put("omgx-addr", JSON.stringify(rb))
this.logger.info("MMDBG Stored")
this.logger.info("Stored omgx-addr.json")
return res.sendStatus(201).end()
} catch (e) {
return res.status(400).json({
return res.status(500).json({
error: e.toString(),
})
}
})

this.state.addressRegistry['get']("/state-dump.latest.json", async (req, res) => {
try {
//const sd = await this.state.db.get("state-dump")
//return res.send()
return res.sendFile("/opt/optimism/packages/data-transport-layer/state-dumps/state-dump.latest.json")
} catch (e) {
return res.status(500).json({
error: e.toString(),
})
}
})

this.state.addressRegistry['put']("/state-dump.latest.json", async (req, res) => {
try {
this.logger.info("addressRegistry PUT request for state-dump file")

req.pipe(fs.createWriteStream("/opt/optimism/packages/data-transport-layer/state-dumps/state-dump.latest.json_TMP"))

await fs.rename(
"/opt/optimism/packages/data-transport-layer/state-dumps/state-dump.latest.json_TMP",
"/opt/optimism/packages/data-transport-layer/state-dumps/state-dump.latest.json",
(err) => { if (err) { throw err; } }
)

this.logger.info("Saved new state-dump.latest.json")
return res.sendStatus(201).end()

//return res.sendFile("/opt/optimism/packages/data-transport-layer/state-dumps/state-dump.latest.json")

} catch (e) {
return res.status(400).json({
return res.status(500).json({
error: e.toString(),
})
}
})

this.state.arServer = this.state.addressRegistry.listen(this.options.arPort,this.options.hostname)
this.logger.info("MMDBG addressRegistry server listening", {hostname:this.options.hostname, port:this.options.arPort})
this.logger.info("addressRegistry server listening", {hostname:this.options.hostname, port:this.options.arPort})

if (this.options.cfgAddressManager) {
this.logger.warn("Using legacy cfgAddressManager address")
Expand Down

0 comments on commit a1662c3

Please sign in to comment.