-
Notifications
You must be signed in to change notification settings - Fork 109
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support forked deployments #1283
Draft
area
wants to merge
6
commits into
develop
Choose a base branch
from
maint/forked-deployment
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
5259b56
Add script to deploy new versions to (QA) forked chain
area e977a8a
First attempt at forked miner
area 4f88a05
Reputation query pass-through
area ff7cfc1
Forward upstream reputation errors correctly
area 5969aee
Add comments to deployToForkedChain
area 57a3b81
Update pnpm-lock
area File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
const hre = require("hardhat"); | ||
const path = require("path"); | ||
const express = require("express"); | ||
const axios = require("axios") | ||
|
||
const { argv } = require("yargs") | ||
.option('privateKey', {string:true}) | ||
.option('colonyNetworkAddress', {string:true}) | ||
.option('minerAddress', {string:true}) | ||
.option('providerAddress', {type: "array", default: []}); | ||
// const ethers = require("ethers"); | ||
|
||
const {ethers} = hre; | ||
|
||
const ReputationMinerClient = require("../ReputationMinerClient"); | ||
const { ConsoleAdapter, TruffleLoader } = require("../../package-utils"); | ||
|
||
const { | ||
minerAddress, | ||
privateKey, | ||
colonyNetworkAddress, | ||
dbPath, | ||
syncFrom, | ||
auto, | ||
oracle, | ||
exitOnError, | ||
oraclePort, | ||
processingDelay, | ||
} = argv; | ||
|
||
const loader = new TruffleLoader({ | ||
contractRoot: path.resolve(__dirname, "..", "..", "..", "artifacts", "contracts") | ||
}); | ||
|
||
const provider = new ethers.providers.StaticJsonRpcProvider("http://localhost:8545"); | ||
const adapterObject = new ConsoleAdapter(); | ||
|
||
const client = new ReputationMinerClient({ | ||
loader, | ||
minerAddress, | ||
privateKey, | ||
provider, | ||
useJsTree: true, | ||
dbPath, | ||
auto, | ||
oracle, | ||
exitOnError, | ||
adapter: adapterObject, | ||
oraclePort: 3001, | ||
processingDelay | ||
}); | ||
|
||
async function main() { | ||
await client.initialise(colonyNetworkAddress, syncFrom); | ||
client._miner.realWallet = await ethers.getImpersonatedSigner(minerAddress); | ||
|
||
if (oracle) { | ||
// Start a forked oracle. This will query our local node, and if that fails, query upstream. | ||
|
||
this._app = express(); | ||
|
||
this._app.use(function(req, res, next) { | ||
res.header("Access-Control-Allow-Origin", "*"); | ||
next(); | ||
}); | ||
|
||
this._app.get("/favicon.ico", (req, res) => { | ||
res.status(204).end(); | ||
}); | ||
|
||
this._app.get("/", (req, res) => { | ||
res.status(204).end(); | ||
}); | ||
|
||
|
||
this._app.get("*", async (req, res) => { | ||
|
||
try { | ||
const { data } = await axios.get(`http://localhost:${3001}/${req.originalUrl}`); | ||
res.send(data); | ||
} catch (e) { | ||
console.log('Local reputation request failed, trying upstream URL:'); | ||
// If the local oracle fails, query the upstream oracle. | ||
console.log(`${process.env.REPUTATION_URL}/${req.originalUrl}`) | ||
try { | ||
|
||
const { data } = await axios({ | ||
url: `${process.env.REPUTATION_URL}/${req.originalUrl}`, | ||
}); | ||
|
||
res.send(data); | ||
} catch (e2) { | ||
console.log('Upstream reputation request failed, forwarding result'); | ||
res.status(e2.response.status).send(await e2.response.data); | ||
} | ||
} | ||
}); | ||
|
||
|
||
this._app.listen(oraclePort || 3000, () => { | ||
console.log(`Forked (pass-through) oracle listening on port ${oraclePort || 3000}`); | ||
}); | ||
} | ||
} | ||
|
||
main(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason you don't use
globals
here?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't being run from inside hardhat, so I don't think it exists?