Skip to content
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

Fabo/sdk 0.26.1-rc1 #1515

Merged
merged 46 commits into from
Nov 17, 2018
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
af1aefc
Merge remote-tracking branch 'origin/fabo/local-net' into fabo/sdk-0.…
faboweb Nov 1, 2018
ab7d000
change init local testnet to latest SDK
Nov 1, 2018
4ed2629
working initialising
Nov 1, 2018
a5110ee
WIP: Implement HTTPS support for Gaia Lite.
Nov 2, 2018
ccf25dd
using working commit
Nov 5, 2018
07b457c
updated to latest
Nov 5, 2018
4a3d5c9
working node start
Nov 5, 2018
7fbfd67
Merge remote-tracking branch 'origin/david/1346-HTTPS' into fabo/sdk-…
faboweb Nov 5, 2018
c44752b
working https
Nov 5, 2018
8d1e8c7
remove decimals fix
Nov 5, 2018
d78a7e9
fixed some tests related to updating
Nov 5, 2018
6b8e959
correctly map unbonding delegations and txs
Nov 5, 2018
9fdcefd
pipe init
Nov 5, 2018
db0c47d
clear all data on overwrite
Nov 5, 2018
4a13224
go to 0.26-rc0
Nov 8, 2018
e8db09a
Fix a bunch of tests in lcdClient.spec.
Nov 9, 2018
5235cd8
most tests fixed
Nov 12, 2018
f79de8b
fixed last test in main
Nov 13, 2018
059e769
tests all passing
Nov 13, 2018
8aed8dc
working e2e test start
Nov 14, 2018
37e215b
declaring validators works
Nov 14, 2018
4b2db72
all e2e tests passed
Nov 14, 2018
c057b92
comments
Nov 14, 2018
ced3b46
linted
Nov 14, 2018
10a5cef
Merge remote-tracking branch 'origin/develop' into fabo/sdk-0.25.0
Nov 16, 2018
c4642fb
refactor
Nov 16, 2018
2c29168
refactors
Nov 16, 2018
72fabaa
reverted to axios proxy
Nov 16, 2018
e198f28
fixed refactor issues
Nov 16, 2018
f81da31
fixed refactor issues
Nov 16, 2018
f4f363e
Merge branch 'fabo/sdk-0.25.0' of https://github.com/cosmos/voyager i…
Nov 16, 2018
402c137
linted
Nov 16, 2018
16992b4
skip using url for communicating lcdPort
Nov 16, 2018
2e4af2b
removed ratTo when not needed
Nov 16, 2018
6685143
added catching
Nov 16, 2018
ed72c2a
added logging
Nov 16, 2018
1e703fc
fix ubuntu running
Nov 16, 2018
8a2b981
fixed e2e test (passing wrong dir to tests)
Nov 16, 2018
e0bb0a2
fixed coverage issues in lcdclient
Nov 16, 2018
9123e21
added test for axios proxy
Nov 16, 2018
ca6cb6e
Update app/src/renderer/connectors/lcdClient.js
NodeGuy Nov 16, 2018
b5db553
Update tasks/gaia.js
NodeGuy Nov 16, 2018
a7aae14
Update test/e2e/launch.js
NodeGuy Nov 17, 2018
0bdf122
implemented comments
Nov 17, 2018
117c788
fixed test
Nov 17, 2018
da99f94
Update lcdClient.js
fedekunze Nov 17, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
171 changes: 127 additions & 44 deletions app/src/main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
const assert = require(`assert`)
let { app, BrowserWindow, ipcMain } = require(`electron`)
let fs = require(`fs-extra`)
const https = require(`https`)
let { join, relative } = require(`path`)
let childProcess = require(`child_process`)
let semver = require(`semver`)
let Raven = require(`raven`)
const readline = require(`readline`)
let axios = require(`axios`)
const userHome = require(`user-home`)

let pkg = require(`../../../package.json`)
let addMenu = require(`./menu.js`)
Expand Down Expand Up @@ -203,6 +206,17 @@ function startProcess(name, args, env) {
}
child.stdout.on(`data`, data => !shuttingDown && log(`${name}: ${data}`))
child.stderr.on(`data`, data => !shuttingDown && log(`${name}: ${data}`))

// Make stdout more useful by emitting a line at a time.
readline.createInterface({ input: child.stdout }).on(`line`, line => {
child.stdout.emit(`line`, line)
})

// Make stderr more useful by emitting a line at a time.
readline.createInterface({ input: child.stderr }).on(`line`, line => {
child.stderr.emit(`line`, line)
})

child.on(
`exit`,
code => !shuttingDown && log(`${name} exited with code ${code}`)
Expand Down Expand Up @@ -256,7 +270,6 @@ async function startLCD(home, nodeURL) {
log(`startLCD`, home)
let child = startProcess(LCD_BINARY_NAME, [
`rest-server`,
`--insecure`,
`--laddr`,
`tcp://localhost:${LCD_PORT}`,
`--home`,
Expand All @@ -270,27 +283,19 @@ async function startLCD(home, nodeURL) {
])
logProcess(child, join(home, `lcd.log`))

child.stderr.on(`data`, error => {
child.stdout.once(`line`, async line => {
const certPath = /\(cert: "(.+?)"/.exec(line)[1]
resolve({ ca: fs.readFileSync(certPath, `utf8`), process: child })
})

child.stderr.on(`line`, error => {
let errorMessage = `The gaiacli rest-server (LCD) experienced an error:\n${error.toString(
`utf8`
)}`.substr(0, 1000)
lcdStarted
? handleCrash(errorMessage) // if fails later
: reject(errorMessage) // if fails immediatly
})

// poll until LCD is started
let client = LcdClient(axios, `http://localhost:${LCD_PORT}`)
while (true) {
try {
await client.keys.values()
break // request succeeded
} catch (err) {
await sleep(1000)
}
}
lcdStarted = true
resolve(child)
})
}

Expand Down Expand Up @@ -434,20 +439,9 @@ Object.entries(eventHandlers).forEach(([event, handler]) => {
ipcMain.on(event, handler)
})

// query version of the used SDK via LCD
async function getNodeVersion(nodeURL) {
let versionURL = `${nodeURL}/node_version`
let nodeVersion = await axios
.get(versionURL, { timeout: 3000 })
.then(res => res.data)
.then(fullversion => fullversion.split(`-`)[0])

return nodeVersion
}

// test an actual node version against the expected one and flag the node if incompatible
async function testNodeVersion(nodeURL, expectedGaiaVersion) {
let nodeVersion = await getNodeVersion(nodeURL)
async function testNodeVersion(client, expectedGaiaVersion) {
let nodeVersion = (await client.nodeVersion()).split(`-`)[0]
let semverDiff = semver.diff(nodeVersion, expectedGaiaVersion)
if (semverDiff === `patch` || semverDiff === null) {
return { compatible: true, nodeVersion }
Expand All @@ -456,20 +450,48 @@ async function testNodeVersion(nodeURL, expectedGaiaVersion) {
return { compatible: false, nodeVersion }
}

// Proxy requests to Axios through the main process because we need
// Node.js in order to support self-signed TLS certificates.
faboweb marked this conversation as resolved.
Show resolved Hide resolved
const AxiosListener = axios => {
return async (event, id, options) => {
let response

try {
response = {
value: await axios(options)
}
} catch (exception) {
response = { exception }
}

event.sender.send(`Axios/${id}`, response)
}
}

// check if our node is reachable and the SDK version is compatible with the local one
async function pickAndConnect() {
let nodeURL = config.node_lcd
connecting = true
let gaiaLite

try {
await connect(nodeURL)
gaiaLite = await connect(nodeURL)
} catch (err) {
handleCrash(err)
return
}

const axiosInstance = axios.create({
httpsAgent: new https.Agent({ ca: gaiaLite.ca })
})

let compatible, nodeVersion
try {
const out = await testNodeVersion(config.node_lcd, expectedGaiaCliVersion)
const out = await testNodeVersion(
LcdClient(axiosInstance, config.node_lcd),
expectedGaiaCliVersion
)

compatible = out.compatible
nodeVersion = out.nodeVersion
} catch (err) {
Expand All @@ -491,27 +513,27 @@ async function pickAndConnect() {
return
}

return nodeURL
ipcMain.removeAllListeners(`Axios`)
ipcMain.on(`Axios`, AxiosListener(axiosInstance))
}

async function connect() {
log(`starting gaia rest server with nodeURL ${config.node_lcd}`)
try {
lcdProcess = await startLCD(lcdHome, config.node_rpc)
log(`gaia rest server ready`)

afterBooted(() => {
log(`Signaling connected node`)
mainWindow.webContents.send(`connected`, {
lcdURL: config.node_lcd,
rpcURL: config.node_rpc
})

const gaiaLite = await startLCD(lcdHome, config.node_rpc)
lcdProcess = gaiaLite.process
log(`gaia rest server ready`)

afterBooted(() => {
log(`Signaling connected node`)
mainWindow.webContents.send(`connected`, {
lcdURL: config.node_lcd,
rpcURL: config.node_rpc
})
} catch (err) {
throw err
}
})

connecting = false
return gaiaLite
}

async function reconnect() {
Expand Down Expand Up @@ -582,6 +604,63 @@ const checkGaiaCompatibility = async gaiacliVersionPath => {
}
}

const initLCD = async lcdHome => {
log(`initialising the LCD config dir`)
await new Promise((resolve, reject) => {
const NODE_BINARY_NAME = WIN ? `gaiad.exe` : `gaiad`
const tempNodeDir = join(lcdHome, `.temp_node_home`)

const child = startProcess(NODE_BINARY_NAME, [
`init`,
`--home`,
tempNodeDir,
`--home-client`,
lcdHome,
`--name`,
`default`
])

child.stdin.write(`1234567890\n`)

child.on(`exit`, code => {
if (code === 0) {
resolve()
} else {
reject()
}

fs.remove(tempNodeDir)
})
})

log(`deleting forced default account`)
// initLCD always needs to create one key, we don't want to confuse
// the user with this key, so we throw it away
await deleteKey(`default`, `1234567890`, lcdHome)
}

const deleteKey = (name, password, lcdHome) => {
return new Promise((resolve, reject) => {
const child = startProcess(LCD_BINARY_NAME, [
`keys`,
`delete`,
name,
`--home`,
lcdHome
])

child.stdin.write(`${password}\n`)

child.on(`exit`, code => {
if (code === 0) {
resolve()
} else {
reject()
}
})
})
}

async function main() {
// we only enable error collection after users opted in
Raven.config(``, { captureUnhandledRejections: false }).install()
Expand Down Expand Up @@ -642,6 +721,10 @@ async function main() {
fs.writeFileSync(appVersionPath, pkg.version)
}

if (!fs.existsSync(lcdHome)) {
await initLCD(lcdHome)
}

await checkGaiaCompatibility(gaiacliVersionPath)

// read chainId from genesis.json
Expand Down
6 changes: 2 additions & 4 deletions app/src/renderer/components/wallet/PageTransactions.vue
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,10 @@ export default {
let unbondingDelegation = this.delegation.unbondingDelegations[
tx.validator_addr
]
// TODO hack, use creation_height when https://github.com/cosmos/cosmos-sdk/issues/2314 is resolved
if (
unbondingDelegation &&
new Date(unbondingDelegation.min_time).getTime() -
new Date(copiedTransaction.time).getTime() ===
0
unbondingDelegation.creation_height ===
String(copiedTransaction.height)
)
copiedTransaction.unbondingDelegation = unbondingDelegation
}
Expand Down
24 changes: 17 additions & 7 deletions app/src/renderer/connectors/lcdClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const Client = (axios, localLcdURL, remoteLcdURL) => {
async function request(method, path, data, useRemote) {
const url = useRemote ? remoteLcdURL : localLcdURL
return (await axios[method.toLowerCase()](url + path, data)).data
return (await axios({ data, method, url: url + path })).data
}

// returns an async function which makes a request for the given
Expand All @@ -23,9 +23,7 @@ const Client = (axios, localLcdURL, remoteLcdURL) => {
if (Array.isArray(args)) {
args = args.join(`/`)
}
if (method === `DELETE`) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I remember that the DELETE requests needed to have this nested data structure. Did you test if any DELETE requests works like this?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I tried to but I'm unable to start Voyager on this branch.

I deleted the above code because the behavior changed when I called Axios using axios({method: 'delete', ...}) instead of axios.delete(... and this change was necessary to make the tests pass again. At least one of the tests was the contract test keys.delete against a real HTTP server so it's likely that any other delete requests will work this way as well.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cool, just wanted to make sure

data = { data }
}

return request(method, `${prefix}/${args}${suffix}`, data, useRemote)
}
}
Expand Down Expand Up @@ -64,6 +62,8 @@ const Client = (axios, localLcdURL, remoteLcdURL) => {
return keys.values().then(() => true, () => false)
},

nodeVersion: req(`GET`, `/node_version`),

// tx
postTx: req(`POST`, `/tx`),

Expand Down Expand Up @@ -95,8 +95,18 @@ const Client = (axios, localLcdURL, remoteLcdURL) => {
/* ============ STAKE ============ */

// Get all delegations information from a delegator
getDelegator: function(addr) {
return req(`GET`, `/stake/delegators/${addr}`, true)()
getDelegations: function(addr) {
return req(`GET`, `/stake/delegators/${addr}/delegations`, true)()
},
getUndelegations: function(addr) {
return req(
`GET`,
`/stake/delegators/${addr}/unbonding_delegations`,
true
)()
},
getRedelegations: function(addr) {
return req(`GET`, `/stake/delegators/${addr}/redelegations`, true)()
},
// Get all txs from a delegator
getDelegatorTxs: function(addr, types) {
Expand Down Expand Up @@ -154,7 +164,7 @@ const Client = (axios, localLcdURL, remoteLcdURL) => {
/* ============ Slashing ============ */

queryValidatorSigningInfo: function(pubKey) {
return req(`GET`, `/slashing/signing_info/${pubKey}`, true)()
return req(`GET`, `/slashing/validators/${pubKey}/signing_info`, true)()
},

/* ============ Governance ============ */
Expand Down
Loading