From 1e8197f1738b001577d42e10f16dda99597c3ec6 Mon Sep 17 00:00:00 2001 From: Sarvesh Jain Date: Thu, 10 Oct 2019 19:41:41 +0530 Subject: [PATCH 01/18] Added command to deploy subgraph --- src/Directory.ts | 5 +- src/Graph/SubGraph.ts | 118 ++++++++++++++-------------------- src/Graph/SubGraphDeployer.ts | 76 ---------------------- src/bin/mosaic-start.ts | 14 +--- src/bin/mosaic-subgraph.ts | 52 +++++++++++++++ src/bin/mosaic.ts | 1 + 6 files changed, 104 insertions(+), 162 deletions(-) delete mode 100644 src/Graph/SubGraphDeployer.ts create mode 100755 src/bin/mosaic-subgraph.ts diff --git a/src/Directory.ts b/src/Directory.ts index 7b7d8d58..038fe116 100644 --- a/src/Directory.ts +++ b/src/Directory.ts @@ -78,18 +78,15 @@ export default class Directory { * * @param originChain * @param auxiliaryChain - * @param chainClient * @return */ public static getOriginSubGraphProjectDirSuffix( originChain: string, auxiliaryChain: string, - chainClient: string ): string { return path.join( originChain, - `origin-${chainClient}`, - 'subgraph', + 'origin-subgraph', auxiliaryChain, ); } diff --git a/src/Graph/SubGraph.ts b/src/Graph/SubGraph.ts index 31dce681..1a11f2e5 100644 --- a/src/Graph/SubGraph.ts +++ b/src/Graph/SubGraph.ts @@ -4,9 +4,12 @@ import Logger from '../Logger'; import Shell from '../Shell'; import Directory from '../Directory'; import MosaicConfig from '../Config/MosaicConfig'; -import GraphDescription from './GraphDescription'; import FileSystem from '../FileSystem '; +export enum SubGraphType { + ORIGIN = 'origin', + AUXILIARY = 'auxiliary', +} /** * Represents a sub graph. */ @@ -20,42 +23,38 @@ export default class SubGraph { /** To be used to determine which code is deployed. For example origin/auxiliary */ private readonly subGraphType: string; - /** Graph description to be used for this sub graph */ - private readonly graphDescription: GraphDescription; + /** Graph node rpc admin URL */ + private readonly graphRPCAdminURL: string; - /** - * enum defining origin sub graph type. - * @returns The prefix. - */ - public static get originSubGraphType(): string { - return 'origin'; - } + /** Graph node IPFS URL */ + private readonly graphIPFSURL: string; - /** - * enum defining auxiliary sub graph type. - * @returns The prefix. - */ - public static get auxiliarySubGraphType(): string { - return 'auxiliary'; - } + /** Mosaic config instance */ + private readonly mosaicConfig: MosaicConfig; /** * Constructor. - * @param {string} originChain - * @param {string} auxiliaryChain - * @param {string} subGraphType - * @param {GraphDescription} graphDescription + * @param originChain Origin chain identifier. + * @param auxiliaryChain Auxiliary chain identifier. + * @param subGraphType Subgraph type + * @param graphRPCAdminURL Graph node rpc admin URL. + * @param graphIPFSURL Graph node IPFS url. + * @param mosaicConfig Mosaic config instance. */ - constructor( + public constructor( originChain: string, auxiliaryChain: string, subGraphType: string, - graphDescription: GraphDescription, + graphRPCAdminURL: string, + graphIPFSURL: string, + mosaicConfig: MosaicConfig, ) { this.originChain = originChain; this.auxiliaryChain = auxiliaryChain; this.subGraphType = subGraphType; - this.graphDescription = graphDescription; + this.graphRPCAdminURL = graphRPCAdminURL; + this.graphIPFSURL = graphIPFSURL; + this.mosaicConfig = mosaicConfig; } /** @@ -63,11 +62,6 @@ export default class SubGraph { * @return */ public deploy(): {success: boolean; message: string} { - if (FileSystem.pathExistsSync(this.getSubGraphProjectDir)) { - // if subGraphProjectDir we would assume sub graph deployment was already complete - this.logInfo('Sub graph already exists. Skipping deployment'); - return { success: true, message: 'Sub graph already exists. Skipping deployment' }; - } this.copyCodeToTempDir(); this.installNodeModules(); this.writeSubGraphConfigFile(); @@ -77,24 +71,10 @@ export default class SubGraph { return createLocalResponse; } const deployLocalResponse = this.deployLocal(); - if (deployLocalResponse.success) { - this.copyToSubGraphProjectDir(); - } this.deleteCodeFromTempDir(); return deployLocalResponse; } - /** - * Directory in which we would persist code which was used for sub graph deployment. - * @return - */ - private get getSubGraphProjectDir(): string { - return path.join( - this.graphDescription.mosaicDir, - this.getSubGraphProjectDirSuffix, - ); - } - /** * Directory in which we would keep auto generated graph related code temporarily. * @return {string} @@ -111,11 +91,11 @@ export default class SubGraph { * @return {string} */ private get getSubGraphProjectDirSuffix(): string { - if (this.subGraphType === SubGraph.originSubGraphType) { + if (this.subGraphType === SubGraphType.ORIGIN + ) { return Directory.getOriginSubGraphProjectDirSuffix( this.originChain, this.auxiliaryChain, - this.graphDescription.ethereumClient ); } return Directory.getAuxiliarySubGraphProjectDirSuffix(this.originChain, this.auxiliaryChain); @@ -148,7 +128,8 @@ export default class SubGraph { private createLocal(): {success: boolean; message: string} { this.logInfo('attempting to create local graph'); try { - this.executeGraphCommand(`create --node http://localhost:${this.graphDescription.rpcAdminPort}/ ${this.name}`); + this.tryRemovingSubgraph(); + this.executeGraphCommand(`create --node ${this.graphRPCAdminURL}/ ${this.name}`); return { success: true, message: '' }; } catch (ex) { const message = this.extractMessageFromError(ex); @@ -157,6 +138,17 @@ export default class SubGraph { } } + /** + * This method tries to remove the subgraph if already deployed. + */ + private tryRemovingSubgraph() { + try { + this.executeGraphCommand(`remove --node ${this.graphRPCAdminURL}/ ${this.name}`); + } catch (e) { + this.logInfo('No subgraph exists, deploying for the first time.'); + } + } + /** * Copy auto generated code to a temp dir. */ @@ -173,7 +165,7 @@ export default class SubGraph { * Returns values for all template variables which need to be replaced in subgraph.yaml. */ private templateVariables(): object { - if (this.subGraphType === SubGraph.originSubGraphType) { + if (this.subGraphType === SubGraphType.ORIGIN) { return this.originChainTemplateVariables(); } return this.auxiliaryChainTemplateVariables(); @@ -184,22 +176,22 @@ export default class SubGraph { * @returns The prefix. */ private get name(): string { - if (this.subGraphType === SubGraph.originSubGraphType) { + if (this.subGraphType === SubGraphType.ORIGIN) { return `mosaic/origin-${this.auxiliaryChain}`; } return `mosaic/auxiliary-${this.auxiliaryChain}`; } /** - * Returns values for all template variables which need to be replaced in subgraph.yaml for origin subGraphType + * Returns values for all template variables which need to be replaced in + * subgraph.yaml for origin subGraphType. */ private originChainTemplateVariables(): object { - const mosaicConfig: MosaicConfig = MosaicConfig.fromChain(this.originChain); return { projectRoot: Directory.projectRoot, - ostComposerAddress: mosaicConfig.originChain.contractAddresses.ostComposerAddress, - eip20GatewayAddress: mosaicConfig.auxiliaryChains[this.auxiliaryChain].contractAddresses.origin.ostEIP20GatewayAddress, - anchorAddress: mosaicConfig.auxiliaryChains[this.auxiliaryChain].contractAddresses.origin.anchorAddress, + ostComposerAddress: this.mosaicConfig.originChain.contractAddresses.ostComposerAddress, + eip20GatewayAddress: this.mosaicConfig.auxiliaryChains[this.auxiliaryChain].contractAddresses.origin.ostEIP20GatewayAddress, + anchorAddress: this.mosaicConfig.auxiliaryChains[this.auxiliaryChain].contractAddresses.origin.anchorAddress, }; } @@ -207,8 +199,7 @@ export default class SubGraph { * Returns values for all template variables which need to be replaced in subgraph.yaml for auxiliary subGraphType */ private auxiliaryChainTemplateVariables(): object { - const mosaicConfig: MosaicConfig = MosaicConfig.fromChain(this.originChain); - const auxiliaryContractAddresses = mosaicConfig.auxiliaryChains[this.auxiliaryChain].contractAddresses.auxiliary; + const auxiliaryContractAddresses = this.mosaicConfig.auxiliaryChains[this.auxiliaryChain].contractAddresses.auxiliary; return { projectRoot: Directory.projectRoot, anchorAddress: auxiliaryContractAddresses.anchorAddress, @@ -225,14 +216,14 @@ export default class SubGraph { this.logInfo('attempting to deploy local graph'); try { this.executeGraphCommand( - `deploy --node http://localhost:${this.graphDescription.rpcAdminPort}/ --ipfs http://localhost:${this.graphDescription.ipfsPort} ${this.name}`, + `deploy --node ${this.graphRPCAdminURL}/ --ipfs ${this.graphIPFSURL} ${this.name}`, ); return { success: true, message: '' }; } catch (ex) { const message = this.extractMessageFromError(ex); this.logInfo(`deploy local graph failed with: ${message}`); this.logInfo('removing local graph'); - this.executeGraphCommand(`remove --node http://localhost:${this.graphDescription.rpcAdminPort}/ ${this.name}`); + this.executeGraphCommand(`remove --node ${this.graphRPCAdminURL}/ ${this.name}`); return { success: false, message }; } } @@ -253,23 +244,10 @@ export default class SubGraph { FileSystem.removeSync(this.getTempGraphInstallationDir); } - /** - * Persist auto generated code. - */ - private copyToSubGraphProjectDir(): void { - this.logInfo('persisting auto generated graph code'); - const subGraphProjectDir = this.getSubGraphProjectDir; - FileSystem.ensureDirSync(subGraphProjectDir); - FileSystem.copySync( - this.getTempGraphInstallationDir, - subGraphProjectDir, - ); - } /** * Extract message from error object. * @param error - * @return */ private extractMessageFromError(error: Error): string { const jsonErrorObject = JSON.parse(JSON.stringify(error)); diff --git a/src/Graph/SubGraphDeployer.ts b/src/Graph/SubGraphDeployer.ts deleted file mode 100644 index d1a27e40..00000000 --- a/src/Graph/SubGraphDeployer.ts +++ /dev/null @@ -1,76 +0,0 @@ -import GraphDescription from './GraphDescription'; -import SubGraph from './SubGraph'; -import MosaicConfig from '../Config/MosaicConfig'; -import Logger from '../Logger'; - -/** - * Has logic to determine list of sub graphs and deploy them (if required) - */ -export default class SubGraphDeployer { - /** This chain identifier identifies the origin chain. For example ropsten. */ - private readonly originChain: string; - - /** This chain identifier identifies the aux chain. For example 1407. */ - private readonly auxiliaryChain: string; - - /** graph description to be used for starting graph node. */ - private readonly graphDescription: GraphDescription; - - /** - * - * @param {GraphDescription} graphDescription - * @param {String} originChain : origin chain identifier - * @param {String} [auxiliaryChain] : auxiliary chain identifier (to be passed only if called for an auxiliary chain) - */ - public constructor(graphDescription: GraphDescription, originChain: string, auxiliaryChain: string) { - this.graphDescription = graphDescription; - this.originChain = originChain; - this.auxiliaryChain = auxiliaryChain; - } - - /** - * Start graph node - * @return {Promise} - */ - public deploy(): void { - if (this.auxiliaryChain) { - return this.deployAuxiliarySubGraph(); - } - return this.deployOriginSubGraphs(); - } - - /** - * deploy sub graphs with SubGraphType=origin for all auxiliary chains - * @return {Promise} - */ - private deployOriginSubGraphs(): void { - const subGraphType = SubGraph.originSubGraphType; - const mosaicConfig: MosaicConfig = MosaicConfig.fromChain(this.originChain); - for (const auxiliaryChain of Object.keys(mosaicConfig.auxiliaryChains)) { - Logger.info(`Starting Sub Graph Deployment for originChain: ${this.originChain} auxiliaryChain: ${auxiliaryChain} subGraphType: ${subGraphType}`); - const subGraph = new SubGraph( - this.originChain, - auxiliaryChain, - subGraphType, - this.graphDescription, - ); - subGraph.deploy(); - } - } - - /** - * - * @return {Promise} - */ - private deployAuxiliarySubGraph(): void { - const subGraphType = SubGraph.auxiliarySubGraphType; - Logger.info(`Starting Sub Graph Deployment for originChain: ${this.originChain} auxiliaryChain: ${this.auxiliaryChain} subGraphType: ${subGraphType}`); - const subGraph = new SubGraph( - this.originChain, - this.auxiliaryChain, - subGraphType, - this.graphDescription, - ); - subGraph.deploy(); - } -} diff --git a/src/bin/mosaic-start.ts b/src/bin/mosaic-start.ts index 13a92350..6cb04b73 100755 --- a/src/bin/mosaic-start.ts +++ b/src/bin/mosaic-start.ts @@ -6,7 +6,6 @@ import Node from '../Node/Node'; import NodeOptions from './NodeOptions'; import GraphOptions from './GraphOptions'; import GraphDescription from '../Graph/GraphDescription'; -import SubGraphDeployer from '../Graph/SubGraphDeployer'; import Graph from '../Graph/Graph'; import NodeDescription from '../Node/NodeDescription'; import DevChainOptions from './DevChainOptions'; @@ -65,7 +64,7 @@ mosaic .option('-u,--unlock ', 'a comma separated list of accounts that get unlocked in the node; you must use this together with --password') .option('-s,--password ', 'the path to the password file on your machine; you must use this together with --unlock') .option('-g,--withoutGraphNode', 'boolean flag which decides if graph node should be started') - .action((chain: string, options) => { + .action(async (chain: string, options) => { let chainInput = chain; let optionInput = Object.assign({}, options); if (!validateCLIOptions(chain, optionInput)) { @@ -108,16 +107,7 @@ mosaic graphDescription.ethereumRpcPort = rpcPort; graphDescription.ethereumClient = nodeDescription.client; - new Graph(graphDescription).start().then(() => { - let subGraphDeployer; - // options.origin passed only in case of starting an auxiliary chain - if (optionInput.origin) { - subGraphDeployer = new SubGraphDeployer(graphDescription, optionInput.origin, chainInput); - } else { - subGraphDeployer = new SubGraphDeployer(graphDescription, chainInput, null); - } - return subGraphDeployer.deploy(); - }); + await (new Graph(graphDescription).start()); } }) .parse(process.argv); diff --git a/src/bin/mosaic-subgraph.ts b/src/bin/mosaic-subgraph.ts new file mode 100755 index 00000000..ac4aec40 --- /dev/null +++ b/src/bin/mosaic-subgraph.ts @@ -0,0 +1,52 @@ +#!/usr/bin/env node + +import * as commander from 'commander'; + +import Logger from '../Logger'; +import MosaicConfig from '../Config/MosaicConfig'; +import SubGraph, {SubGraphType} from '../Graph/SubGraph'; + +const mosaic = commander + .arguments(' '); + +mosaic.option('-m,--mosaic-config ', 'Mosaic config absolute path'); +mosaic.option('-a,--auxiliary ', 'auxiliary chain identifier'); +mosaic.action( + async ( + originChain: string, + auxiliaryChain: string, + subgraphType: SubGraphType, + graphAdminRPC: string, + graphIPFS: string, + options, + ) => { + try { + let mosaicConfig; + if (options.mosaicConfig) { + mosaicConfig = MosaicConfig.fromFile(options.mosaicConfig); + } else if (MosaicConfig.exists(originChain)) { + mosaicConfig = MosaicConfig.fromChain(originChain); + } + + if (!mosaicConfig) { + console.error(`Mosaic config not found for chain ${originChain} on default location. Use --mosaic-config option to provide path.`); + process.exit(1); + } + + new SubGraph( + originChain, + auxiliaryChain, + subgraphType, + graphAdminRPC, + graphIPFS, + mosaicConfig, + ).deploy(); + } catch (error) { + Logger.error('error while executing mosaic libraries', {error: error.toString()}); + process.exit(1); + } + + process.exit(0); + }, +) + .parse(process.argv); diff --git a/src/bin/mosaic.ts b/src/bin/mosaic.ts index 19fbce7c..5eb416fb 100755 --- a/src/bin/mosaic.ts +++ b/src/bin/mosaic.ts @@ -13,4 +13,5 @@ mosaic .command('verify-chain ', 'Verifies an auxiliary chain.') .command('setup-redeem-pool ', 'Deploys redeem pool contract.') .command('setup-stake-pool ', 'Deploys stake pool contract.') + .command('subgraph ', 'Deploys mosaic subgraph on a graph node') .parse(process.argv); From 6443cd80392a8144c1307940b5b847dfc14f0647 Mon Sep 17 00:00:00 2001 From: Sarvesh Jain Date: Fri, 11 Oct 2019 13:56:40 +0530 Subject: [PATCH 02/18] Removed assertion of subgraph deployment as mosaic start no more deploys subgraph --- tests/smoke.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/smoke.sh b/tests/smoke.sh index 9942858b..63e5024f 100755 --- a/tests/smoke.sh +++ b/tests/smoke.sh @@ -116,18 +116,18 @@ info "Starting node one by one and verifying if all services for them are runnin start_auxiliary_node 1406 grep_try 1406 geth rpc_node_try 1406 -rpc_auxiliary_sub_graph_try 1406 +#rpc_auxiliary_sub_graph_try 1406 start_auxiliary_node 1407 grep_try 1407 geth rpc_node_try 1407 -rpc_auxiliary_sub_graph_try 1407 +#rpc_auxiliary_sub_graph_try 1407 start_origin_node ropsten geth grep_try ropsten geth rpc_node_try "0003" # Given like this as it is used for the port in `rpc_node_try`. -rpc_origin_sub_graph_try 1406 60003 -rpc_origin_sub_graph_try 1407 60003 +#rpc_origin_sub_graph_try 1406 60003 +#rpc_origin_sub_graph_try 1407 60003 # Stop and start some nodes and make sure they are or are not running. stop_node ropsten From 512520706ecd5bf3527abeedead6d6c60f6d0e48 Mon Sep 17 00:00:00 2001 From: Sarvesh Jain Date: Fri, 11 Oct 2019 19:45:52 +0530 Subject: [PATCH 03/18] Fixed smoke test and refactor code to plug token config --- src/Config/TokenAddresses.ts | 67 +++++++++++++++++++ src/Graph/SubGraph.ts | 26 +++---- src/bin/mosaic-subgraph.ts | 21 +++--- .../SubGraphDeployment/origin-verifier.ts | 6 +- tests/smoke.sh | 22 ++++-- 5 files changed, 114 insertions(+), 28 deletions(-) create mode 100644 src/Config/TokenAddresses.ts diff --git a/src/Config/TokenAddresses.ts b/src/Config/TokenAddresses.ts new file mode 100644 index 00000000..419d7f8b --- /dev/null +++ b/src/Config/TokenAddresses.ts @@ -0,0 +1,67 @@ +import MosaicConfig from './MosaicConfig'; + +/** + * This class represents set of addresses specific to a single token gateway. + */ +export default class TokenAddresses { + public readonly stakerProxyAddress: string; + + public readonly eip20GatewayAddress: string; + + public readonly anchorAddress: string; + + public readonly coAnchorAddress: string; + + public readonly eip20CoGatewayAddress: string; + + public readonly redeemPoolAddress: string; + + /** + * Constructor + * @param stakerProxyAddress Stakerproxy address. + * @param eip20GatewayAddress eip20Gateway address. + * @param anchorAddress anchor address. + * @param coAnchorAddress coanchor address. + * @param eip20CoGatewayAddress cogateway address. + * @param redeemPoolAddress redeem pool address. + */ + private constructor( + stakerProxyAddress: string, + eip20GatewayAddress: string, + anchorAddress: string, + coAnchorAddress: string, + eip20CoGatewayAddress: string, + redeemPoolAddress: string, + ) { + this.stakerProxyAddress = stakerProxyAddress; + this.eip20GatewayAddress = eip20GatewayAddress; + this.anchorAddress = anchorAddress; + this.coAnchorAddress = coAnchorAddress; + this.eip20CoGatewayAddress = eip20CoGatewayAddress; + this.redeemPoolAddress = redeemPoolAddress; + } + + + /** + * Create token address instance based on mosaic config. + * @param mosaicConfig Mosaic config object. + * @param auxiliaryChain aux chain identifier. + */ + public static fromMosaicConfig( + mosaicConfig: MosaicConfig, + auxiliaryChain: string, + ): TokenAddresses { + const auxiliaryContractAddresses = mosaicConfig.auxiliaryChains[auxiliaryChain] + .contractAddresses.auxiliary; + const originContractAddresses = mosaicConfig.auxiliaryChains[auxiliaryChain] + .contractAddresses.origin; + return new TokenAddresses( + mosaicConfig.originChain.contractAddresses.ostComposerAddress, + originContractAddresses.ostEIP20GatewayAddress, + originContractAddresses.anchorAddress, + auxiliaryContractAddresses.anchorAddress, + auxiliaryContractAddresses.ostEIP20CogatewayAddress, + auxiliaryContractAddresses.redeemPoolAddress, + ); + } +} diff --git a/src/Graph/SubGraph.ts b/src/Graph/SubGraph.ts index 1a11f2e5..d3f0590a 100644 --- a/src/Graph/SubGraph.ts +++ b/src/Graph/SubGraph.ts @@ -3,8 +3,8 @@ import * as mustache from 'mustache'; import Logger from '../Logger'; import Shell from '../Shell'; import Directory from '../Directory'; -import MosaicConfig from '../Config/MosaicConfig'; import FileSystem from '../FileSystem '; +import TokenAddresses from '../Config/TokenAddresses'; export enum SubGraphType { ORIGIN = 'origin', @@ -30,7 +30,7 @@ export default class SubGraph { private readonly graphIPFSURL: string; /** Mosaic config instance */ - private readonly mosaicConfig: MosaicConfig; + private readonly tokenAddresses: TokenAddresses; /** * Constructor. @@ -39,7 +39,7 @@ export default class SubGraph { * @param subGraphType Subgraph type * @param graphRPCAdminURL Graph node rpc admin URL. * @param graphIPFSURL Graph node IPFS url. - * @param mosaicConfig Mosaic config instance. + * @param tokenAddresses Token addresses instance. */ public constructor( originChain: string, @@ -47,14 +47,14 @@ export default class SubGraph { subGraphType: string, graphRPCAdminURL: string, graphIPFSURL: string, - mosaicConfig: MosaicConfig, + tokenAddresses: TokenAddresses, ) { this.originChain = originChain; this.auxiliaryChain = auxiliaryChain; this.subGraphType = subGraphType; this.graphRPCAdminURL = graphRPCAdminURL; this.graphIPFSURL = graphIPFSURL; - this.mosaicConfig = mosaicConfig; + this.tokenAddresses = tokenAddresses; } /** @@ -189,22 +189,22 @@ export default class SubGraph { private originChainTemplateVariables(): object { return { projectRoot: Directory.projectRoot, - ostComposerAddress: this.mosaicConfig.originChain.contractAddresses.ostComposerAddress, - eip20GatewayAddress: this.mosaicConfig.auxiliaryChains[this.auxiliaryChain].contractAddresses.origin.ostEIP20GatewayAddress, - anchorAddress: this.mosaicConfig.auxiliaryChains[this.auxiliaryChain].contractAddresses.origin.anchorAddress, + ostComposerAddress: this.tokenAddresses.stakerProxyAddress, + eip20GatewayAddress: this.tokenAddresses.eip20GatewayAddress, + anchorAddress: this.tokenAddresses.anchorAddress, }; } /** - * Returns values for all template variables which need to be replaced in subgraph.yaml for auxiliary subGraphType + * Returns values for all template variables which need to be replaced in + * subgraph.yaml for auxiliary subGraphType. */ private auxiliaryChainTemplateVariables(): object { - const auxiliaryContractAddresses = this.mosaicConfig.auxiliaryChains[this.auxiliaryChain].contractAddresses.auxiliary; return { projectRoot: Directory.projectRoot, - anchorAddress: auxiliaryContractAddresses.anchorAddress, - eip20CoGatewayAddress: auxiliaryContractAddresses.ostEIP20CogatewayAddress, - redeemPoolAddress: auxiliaryContractAddresses.redeemPoolAddress, + anchorAddress: this.tokenAddresses.coAnchorAddress, + eip20CoGatewayAddress: this.tokenAddresses.eip20CoGatewayAddress, + redeemPoolAddress: this.tokenAddresses.redeemPoolAddress, }; } diff --git a/src/bin/mosaic-subgraph.ts b/src/bin/mosaic-subgraph.ts index ac4aec40..b6c652f5 100755 --- a/src/bin/mosaic-subgraph.ts +++ b/src/bin/mosaic-subgraph.ts @@ -4,12 +4,14 @@ import * as commander from 'commander'; import Logger from '../Logger'; import MosaicConfig from '../Config/MosaicConfig'; -import SubGraph, {SubGraphType} from '../Graph/SubGraph'; +import SubGraph, { SubGraphType } from '../Graph/SubGraph'; +import TokenAddresses from '../Config/TokenAddresses'; const mosaic = commander .arguments(' '); mosaic.option('-m,--mosaic-config ', 'Mosaic config absolute path'); +mosaic.option('-t,--token-config ', 'Token config absolute path'); mosaic.option('-a,--auxiliary ', 'auxiliary chain identifier'); mosaic.action( async ( @@ -21,15 +23,18 @@ mosaic.action( options, ) => { try { - let mosaicConfig; + let tokenAddresses; + if (options.mosaicConfig) { - mosaicConfig = MosaicConfig.fromFile(options.mosaicConfig); + const mosaicConfig = MosaicConfig.fromFile(options.mosaicConfig); + tokenAddresses = TokenAddresses.fromMosaicConfig(mosaicConfig, auxiliaryChain); } else if (MosaicConfig.exists(originChain)) { - mosaicConfig = MosaicConfig.fromChain(originChain); + const mosaicConfig = MosaicConfig.fromChain(originChain); + tokenAddresses = TokenAddresses.fromMosaicConfig(mosaicConfig, auxiliaryChain); } - if (!mosaicConfig) { - console.error(`Mosaic config not found for chain ${originChain} on default location. Use --mosaic-config option to provide path.`); + if (!tokenAddresses) { + console.error('Mosaic config or token config not found . Use --mosaic-config or --token-config option to provide path.'); process.exit(1); } @@ -39,10 +44,10 @@ mosaic.action( subgraphType, graphAdminRPC, graphIPFS, - mosaicConfig, + tokenAddresses, ).deploy(); } catch (error) { - Logger.error('error while executing mosaic libraries', {error: error.toString()}); + Logger.error('error while executing mosaic libraries', { error: error.toString() }); process.exit(1); } diff --git a/tests/Graph/SubGraphDeployment/origin-verifier.ts b/tests/Graph/SubGraphDeployment/origin-verifier.ts index 4ff2e558..f7f887ae 100644 --- a/tests/Graph/SubGraphDeployment/origin-verifier.ts +++ b/tests/Graph/SubGraphDeployment/origin-verifier.ts @@ -20,9 +20,9 @@ mosaic.action( // Creates subscription client const subscriptionClient = new SubscriptionClient(wsEndPoint, { - reconnect: true, - }, - WebSocket); + reconnect: true, + }, + WebSocket); subscriptionClient.onConnected(() => { Logger.info(`Connected to sub graph: ${subGraphName}`); subscriptionClient.close(); diff --git a/tests/smoke.sh b/tests/smoke.sh index 63e5024f..593fc1e5 100755 --- a/tests/smoke.sh +++ b/tests/smoke.sh @@ -43,6 +43,16 @@ function stop_nodes { stop_node 1407 stop_node 1406 } +# Deploy subgraph +# $1 origin chain identifier +# $2 aux chain identifier +# $3 chain {origin, auxiliary} +# $4 graph admin rpc port +# $5 graph IPFS port +function deploy_subgraph { + info "Deploying origin subraph." + try_silent "./mosaic subgraph $1 $2 $3 http://localhost:$4 http://localhost:$5" +} # Tries a command without output. Errors if the command does not execute successfully. function try_silent { @@ -116,18 +126,22 @@ info "Starting node one by one and verifying if all services for them are runnin start_auxiliary_node 1406 grep_try 1406 geth rpc_node_try 1406 -#rpc_auxiliary_sub_graph_try 1406 +deploy_subgraph ropsten 1406 auxiliary 9426 6407 +rpc_auxiliary_sub_graph_try 1406 start_auxiliary_node 1407 grep_try 1407 geth rpc_node_try 1407 -#rpc_auxiliary_sub_graph_try 1407 +deploy_subgraph ropsten 1407 auxiliary 9427 6408 +rpc_auxiliary_sub_graph_try 1407 start_origin_node ropsten geth grep_try ropsten geth rpc_node_try "0003" # Given like this as it is used for the port in `rpc_node_try`. -#rpc_origin_sub_graph_try 1406 60003 -#rpc_origin_sub_graph_try 1407 60003 +deploy_subgraph ropsten 1406 origin 8023 5004 +deploy_subgraph ropsten 1407 origin 8023 5004 +rpc_origin_sub_graph_try 1406 60003 +rpc_origin_sub_graph_try 1407 60003 # Stop and start some nodes and make sure they are or are not running. stop_node ropsten From 3f8384bbe8377e9e779ac4136997b54cc11b6356 Mon Sep 17 00:00:00 2001 From: Sarvesh Jain Date: Tue, 15 Oct 2019 16:32:52 +0530 Subject: [PATCH 04/18] Added gateway addresses file. --- .gitignore | 3 +++ ...{TokenAddresses.ts => GatewayAddresses.ts} | 8 +++---- src/Graph/SubGraph.ts | 24 +++++++++---------- src/bin/mosaic-subgraph.ts | 14 +++++------ 4 files changed, 26 insertions(+), 23 deletions(-) rename src/Config/{TokenAddresses.ts => GatewayAddresses.ts} (92%) diff --git a/.gitignore b/.gitignore index 87a91730..449c1f0a 100644 --- a/.gitignore +++ b/.gitignore @@ -85,3 +85,6 @@ typings/ # next.js build output .next + +docker/chain_data/ +docker/configs/ diff --git a/src/Config/TokenAddresses.ts b/src/Config/GatewayAddresses.ts similarity index 92% rename from src/Config/TokenAddresses.ts rename to src/Config/GatewayAddresses.ts index de405263..fbe0e683 100644 --- a/src/Config/TokenAddresses.ts +++ b/src/Config/GatewayAddresses.ts @@ -1,9 +1,9 @@ import MosaicConfig from './MosaicConfig'; /** - * This class represents set of addresses specific to a single token gateway. + * This class represents set of addresses specific to a gateway pair. */ -export default class TokenAddresses { +export default class GatewayAddresses { public readonly stakePoolAddress: string; public readonly eip20GatewayAddress: string; @@ -50,12 +50,12 @@ export default class TokenAddresses { public static fromMosaicConfig( mosaicConfig: MosaicConfig, auxiliaryChain: string, - ): TokenAddresses { + ): GatewayAddresses { const auxiliaryContractAddresses = mosaicConfig.auxiliaryChains[auxiliaryChain] .contractAddresses.auxiliary; const originContractAddresses = mosaicConfig.auxiliaryChains[auxiliaryChain] .contractAddresses.origin; - return new TokenAddresses( + return new GatewayAddresses( mosaicConfig.originChain.contractAddresses.stakePoolAddress, originContractAddresses.eip20GatewayAddress, originContractAddresses.anchorAddress, diff --git a/src/Graph/SubGraph.ts b/src/Graph/SubGraph.ts index d1aac822..0b6331e5 100644 --- a/src/Graph/SubGraph.ts +++ b/src/Graph/SubGraph.ts @@ -4,7 +4,7 @@ import Logger from '../Logger'; import Shell from '../Shell'; import Directory from '../Directory'; import FileSystem from '../FileSystem '; -import TokenAddresses from '../Config/TokenAddresses'; +import GatewayAddresses from '../Config/GatewayAddresses'; export enum SubGraphType { ORIGIN = 'origin', @@ -29,8 +29,8 @@ export default class SubGraph { /** Graph node IPFS URL */ private readonly graphIPFSURL: string; - /** Mosaic config instance */ - private readonly tokenAddresses: TokenAddresses; + /** Gateway pair addresses */ + private readonly gatewayAddresses: GatewayAddresses; /** * Constructor. @@ -39,7 +39,7 @@ export default class SubGraph { * @param subGraphType Subgraph type * @param graphRPCAdminURL Graph node rpc admin URL. * @param graphIPFSURL Graph node IPFS url. - * @param tokenAddresses Token addresses instance. + * @param gatewayAddresses Gateway pair addresses. */ public constructor( originChain: string, @@ -47,14 +47,14 @@ export default class SubGraph { subGraphType: string, graphRPCAdminURL: string, graphIPFSURL: string, - tokenAddresses: TokenAddresses, + gatewayAddresses: GatewayAddresses, ) { this.originChain = originChain; this.auxiliaryChain = auxiliaryChain; this.subGraphType = subGraphType; this.graphRPCAdminURL = graphRPCAdminURL; this.graphIPFSURL = graphIPFSURL; - this.tokenAddresses = tokenAddresses; + this.gatewayAddresses = gatewayAddresses; } /** @@ -189,9 +189,9 @@ export default class SubGraph { private originChainTemplateVariables(): object { return { projectRoot: Directory.projectRoot, - stakePoolAddress: this.tokenAddresses.stakePoolAddress, - eip20GatewayAddress: this.tokenAddresses.eip20GatewayAddress, - anchorAddress: this.tokenAddresses.anchorAddress, + stakePoolAddress: this.gatewayAddresses.stakePoolAddress, + eip20GatewayAddress: this.gatewayAddresses.eip20GatewayAddress, + anchorAddress: this.gatewayAddresses.anchorAddress, }; } @@ -202,9 +202,9 @@ export default class SubGraph { private auxiliaryChainTemplateVariables(): object { return { projectRoot: Directory.projectRoot, - anchorAddress: this.tokenAddresses.coAnchorAddress, - eip20CoGatewayAddress: this.tokenAddresses.eip20CoGatewayAddress, - redeemPoolAddress: this.tokenAddresses.redeemPoolAddress, + anchorAddress: this.gatewayAddresses.coAnchorAddress, + eip20CoGatewayAddress: this.gatewayAddresses.eip20CoGatewayAddress, + redeemPoolAddress: this.gatewayAddresses.redeemPoolAddress, }; } diff --git a/src/bin/mosaic-subgraph.ts b/src/bin/mosaic-subgraph.ts index b6c652f5..f5e26303 100755 --- a/src/bin/mosaic-subgraph.ts +++ b/src/bin/mosaic-subgraph.ts @@ -5,13 +5,13 @@ import * as commander from 'commander'; import Logger from '../Logger'; import MosaicConfig from '../Config/MosaicConfig'; import SubGraph, { SubGraphType } from '../Graph/SubGraph'; -import TokenAddresses from '../Config/TokenAddresses'; +import GatewayAddresses from '../Config/GatewayAddresses'; const mosaic = commander .arguments(' '); mosaic.option('-m,--mosaic-config ', 'Mosaic config absolute path'); -mosaic.option('-t,--token-config ', 'Token config absolute path'); +mosaic.option('-t,--gateway-config ', 'Gateway config absolute path'); mosaic.option('-a,--auxiliary ', 'auxiliary chain identifier'); mosaic.action( async ( @@ -23,17 +23,17 @@ mosaic.action( options, ) => { try { - let tokenAddresses; + let gatewayAddresses; if (options.mosaicConfig) { const mosaicConfig = MosaicConfig.fromFile(options.mosaicConfig); - tokenAddresses = TokenAddresses.fromMosaicConfig(mosaicConfig, auxiliaryChain); + gatewayAddresses = GatewayAddresses.fromMosaicConfig(mosaicConfig, auxiliaryChain); } else if (MosaicConfig.exists(originChain)) { const mosaicConfig = MosaicConfig.fromChain(originChain); - tokenAddresses = TokenAddresses.fromMosaicConfig(mosaicConfig, auxiliaryChain); + gatewayAddresses = GatewayAddresses.fromMosaicConfig(mosaicConfig, auxiliaryChain); } - if (!tokenAddresses) { + if (!gatewayAddresses) { console.error('Mosaic config or token config not found . Use --mosaic-config or --token-config option to provide path.'); process.exit(1); } @@ -44,7 +44,7 @@ mosaic.action( subgraphType, graphAdminRPC, graphIPFS, - tokenAddresses, + gatewayAddresses, ).deploy(); } catch (error) { Logger.error('error while executing mosaic libraries', { error: error.toString() }); From 04db517e77f51ca2916a2e74a89f7cb7ddc0d392 Mon Sep 17 00:00:00 2001 From: Sarvesh Jain Date: Tue, 15 Oct 2019 17:16:05 +0530 Subject: [PATCH 05/18] Added support of gateway config --- README.md | 29 +++++++++++++++++++++++ src/Config/GatewayAddresses.ts | 32 ++++++++++++++++++++++++- src/bin/mosaic-subgraph.ts | 43 +++++++++++++++++++++++++++------- 3 files changed, 94 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index b5ffddaf..295d1987 100644 --- a/README.md +++ b/README.md @@ -182,6 +182,35 @@ Where: *Refer integration test of mosaic-create command to understand end to end flow.* +## Subgraph deployment +Subgraph command can be used to deploy mosaic subgraph. Subgraph by [thegraph](https://thegraph.com) protocol is used to index transactions and events by mosaic smart contract. + +#### Prerequisite: Below commands assumes the blockchain node and graph node is already running. You can use `mosaic start` command to start a node and graph node. + +##### Subgraph deployment for mosaic gateways: +Below command deploys subgraph of mosaic gateways. + +```bash +./mosaic subgraph +``` +**where:** +1. origin-chain-identifier: Origin chain identifier like ropsten, goerli, dev-origin +2.auxiliary-chain-identifier: Auxiliary chain ID like 1405, 1406, 1407 or 1000(dev-auxiliary). +3. Chain: Either`origin` or `auxiliary` chain. +4. admin-graph-rpc: RPC endpoint of graph node. +5. graph-ipfs: IPFS endpoint used by graph node. + +Optionally `--mosaic-config` option can be used to pass mosaic config otherwise command will search on default path. + +#### Subgraph deployment for any EIP20 gateways: +Below command deploys subgraph of any eip20gateway. +```bash +./mosaic subgraph --gateway-config +``` +**where:** +1. gateway-config: Path of gateway config. + +Optionally `gateway-address` option can be passed which will search gateway config on default path. ## Chain Verifier Chain verifier makes sure that newly created chain is being setup correctly. diff --git a/src/Config/GatewayAddresses.ts b/src/Config/GatewayAddresses.ts index fbe0e683..2ef8c652 100644 --- a/src/Config/GatewayAddresses.ts +++ b/src/Config/GatewayAddresses.ts @@ -1,4 +1,5 @@ import MosaicConfig from './MosaicConfig'; +import GatewayConfig from './GatewayConfig'; /** * This class represents set of addresses specific to a gateway pair. @@ -43,7 +44,7 @@ export default class GatewayAddresses { /** - * Create token address instance based on mosaic config. + * Create Gateway address instance based on mosaic config. * @param mosaicConfig Mosaic config object. * @param auxiliaryChain aux chain identifier. */ @@ -64,4 +65,33 @@ export default class GatewayAddresses { auxiliaryContractAddresses.redeemPoolAddress, ); } + + /** + * Creates gateway address instance from gateway config. + * @param gatewayConfig GatewayConfig instance. + */ + public static fromGatewayConfig( + gatewayConfig: GatewayConfig, + ): GatewayAddresses { + const { auxChainId } = gatewayConfig; + const stakePoolAddress = gatewayConfig.originContracts.stakePoolAddress + ? gatewayConfig.originContracts.stakePoolAddress + : gatewayConfig.mosaicConfig.originChain.contractAddresses.stakePoolAddress; + + const auxiliaryChain = gatewayConfig.mosaicConfig.auxiliaryChains[auxChainId]; + const auxiliaryContracts = auxiliaryChain.contractAddresses.auxiliary; + const redeemPool = gatewayConfig.auxiliaryContracts.redeemPoolAddress + ? gatewayConfig.auxiliaryContracts.redeemPoolAddress + : auxiliaryContracts.redeemPoolAddress; + + const originContracts = auxiliaryChain.contractAddresses.origin; + return new GatewayAddresses( + stakePoolAddress, + gatewayConfig.originContracts.eip20GatewayAddress, + originContracts.anchorAddress, + auxiliaryContracts.anchorAddress, + gatewayConfig.auxiliaryContracts.eip20CoGatewayAddress, + redeemPool, + ); + } } diff --git a/src/bin/mosaic-subgraph.ts b/src/bin/mosaic-subgraph.ts index f5e26303..ee9b162b 100755 --- a/src/bin/mosaic-subgraph.ts +++ b/src/bin/mosaic-subgraph.ts @@ -6,17 +6,19 @@ import Logger from '../Logger'; import MosaicConfig from '../Config/MosaicConfig'; import SubGraph, { SubGraphType } from '../Graph/SubGraph'; import GatewayAddresses from '../Config/GatewayAddresses'; +import GatewayConfig from '../Config/GatewayConfig'; const mosaic = commander .arguments(' '); -mosaic.option('-m,--mosaic-config ', 'Mosaic config absolute path'); -mosaic.option('-t,--gateway-config ', 'Gateway config absolute path'); -mosaic.option('-a,--auxiliary ', 'auxiliary chain identifier'); +mosaic.option('-m,--mosaic-config ', 'Mosaic config absolute path.'); +mosaic.option('-t,--gateway-config ', 'Gateway config absolute path.'); +mosaic.option('-a,--auxiliary ', 'auxiliary chain identifier.'); +mosaic.option('-g,--gateway-address ', 'gateway address of origin.'); mosaic.action( async ( originChain: string, - auxiliaryChain: string, + auxiliaryChain: number, subgraphType: SubGraphType, graphAdminRPC: string, graphIPFS: string, @@ -24,13 +26,36 @@ mosaic.action( ) => { try { let gatewayAddresses; + let gatewayConfig; + let mosaicConfig; + + if (options.gatewayConfig) { + gatewayConfig = GatewayConfig.fromFile(options.gatewayConfig); + } else if (options.gatewayAddress) { + gatewayConfig = GatewayConfig.fromChain( + originChain, + auxiliaryChain, + options.gatewayAddress, + ); + } if (options.mosaicConfig) { - const mosaicConfig = MosaicConfig.fromFile(options.mosaicConfig); - gatewayAddresses = GatewayAddresses.fromMosaicConfig(mosaicConfig, auxiliaryChain); + mosaicConfig = MosaicConfig.fromFile(options.mosaicConfig); } else if (MosaicConfig.exists(originChain)) { - const mosaicConfig = MosaicConfig.fromChain(originChain); - gatewayAddresses = GatewayAddresses.fromMosaicConfig(mosaicConfig, auxiliaryChain); + mosaicConfig = MosaicConfig.fromChain(originChain); + } + + if (gatewayConfig) { + if (auxiliaryChain !== gatewayConfig.auxChainId) { + console.error(`Auxiliary chain id in gateway config is ${gatewayConfig.auxChainId} but value passed is ${auxiliaryChain}`); + process.exit(1); + } + gatewayAddresses = GatewayAddresses.fromGatewayConfig(gatewayConfig); + } else if (mosaicConfig) { + gatewayAddresses = GatewayAddresses.fromMosaicConfig( + mosaicConfig, + auxiliaryChain.toString(), + ); } if (!gatewayAddresses) { @@ -40,7 +65,7 @@ mosaic.action( new SubGraph( originChain, - auxiliaryChain, + auxiliaryChain.toString(), subgraphType, graphAdminRPC, graphIPFS, From 57ac4930d0c154474282ab4d6cdc84d15d385640 Mon Sep 17 00:00:00 2001 From: Sarvesh Jain Date: Tue, 15 Oct 2019 17:17:58 +0530 Subject: [PATCH 06/18] Updated name of subgraph --- src/Graph/SubGraph.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Graph/SubGraph.ts b/src/Graph/SubGraph.ts index 0b6331e5..69492d0d 100644 --- a/src/Graph/SubGraph.ts +++ b/src/Graph/SubGraph.ts @@ -177,9 +177,9 @@ export default class SubGraph { */ private get name(): string { if (this.subGraphType === SubGraphType.ORIGIN) { - return `mosaic/origin-${this.auxiliaryChain}`; + return `mosaic/origin-${this.gatewayAddresses.eip20GatewayAddress}`; } - return `mosaic/auxiliary-${this.auxiliaryChain}`; + return `mosaic/auxiliary-${this.gatewayAddresses.eip20CoGatewayAddress}`; } /** From 61ac82e9e22787f01e211c0f9a32d3d754df8cf3 Mon Sep 17 00:00:00 2001 From: Sarvesh Jain Date: Tue, 15 Oct 2019 17:59:29 +0530 Subject: [PATCH 07/18] Revert "Updated name of subgraph" This reverts commit 57ac4930d0c154474282ab4d6cdc84d15d385640. --- src/Graph/SubGraph.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Graph/SubGraph.ts b/src/Graph/SubGraph.ts index 69492d0d..0b6331e5 100644 --- a/src/Graph/SubGraph.ts +++ b/src/Graph/SubGraph.ts @@ -177,9 +177,9 @@ export default class SubGraph { */ private get name(): string { if (this.subGraphType === SubGraphType.ORIGIN) { - return `mosaic/origin-${this.gatewayAddresses.eip20GatewayAddress}`; + return `mosaic/origin-${this.auxiliaryChain}`; } - return `mosaic/auxiliary-${this.gatewayAddresses.eip20CoGatewayAddress}`; + return `mosaic/auxiliary-${this.auxiliaryChain}`; } /** From 12ad1252bf57c3c4479464c284f7d5f11502043f Mon Sep 17 00:00:00 2001 From: Sarvesh Jain Date: Tue, 15 Oct 2019 18:41:34 +0530 Subject: [PATCH 08/18] Added dev chain subgraph deployment in smoke test --- tests/smoke.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/smoke.sh b/tests/smoke.sh index 593fc1e5..74a7908e 100755 --- a/tests/smoke.sh +++ b/tests/smoke.sh @@ -159,5 +159,10 @@ grep_fail ropsten geth start_origin_node ropsten parity grep_try ropsten parity +start_origin_node dev-origin geth +start_auxiliary_node dev-auxiliary geth +deploy_subgraph dev-origin 1000 origin 9535 6516 +deploy_subgraph dev-origin 1000 auxiliary 9020 6001 + # When done, stop all nodes. stop_nodes From ba8992df2de4686812c6d238dceb29c0812eb40c Mon Sep 17 00:00:00 2001 From: Sarvesh Jain Date: Tue, 15 Oct 2019 19:15:32 +0530 Subject: [PATCH 09/18] Corrected data type of aux chain in subgraph command --- src/bin/mosaic-subgraph.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/bin/mosaic-subgraph.ts b/src/bin/mosaic-subgraph.ts index ee9b162b..64be394d 100755 --- a/src/bin/mosaic-subgraph.ts +++ b/src/bin/mosaic-subgraph.ts @@ -18,7 +18,7 @@ mosaic.option('-g,--gateway-address ', 'gateway address of origin.'); mosaic.action( async ( originChain: string, - auxiliaryChain: number, + auxiliaryChain: string, subgraphType: SubGraphType, graphAdminRPC: string, graphIPFS: string, @@ -34,7 +34,7 @@ mosaic.action( } else if (options.gatewayAddress) { gatewayConfig = GatewayConfig.fromChain( originChain, - auxiliaryChain, + parseInt(auxiliaryChain), options.gatewayAddress, ); } @@ -46,7 +46,7 @@ mosaic.action( } if (gatewayConfig) { - if (auxiliaryChain !== gatewayConfig.auxChainId) { + if (parseInt(auxiliaryChain) !== gatewayConfig.auxChainId) { console.error(`Auxiliary chain id in gateway config is ${gatewayConfig.auxChainId} but value passed is ${auxiliaryChain}`); process.exit(1); } From dfbf7f862798f4f179f321e336fc698d320f0866 Mon Sep 17 00:00:00 2001 From: Sarvesh Jain Date: Tue, 15 Oct 2019 18:07:16 +0530 Subject: [PATCH 10/18] Update docker image version --- src/Node/GethNode.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Node/GethNode.ts b/src/Node/GethNode.ts index ad30487e..a86ff85f 100644 --- a/src/Node/GethNode.ts +++ b/src/Node/GethNode.ts @@ -5,7 +5,7 @@ import Shell from '../Shell'; import Directory from '../Directory'; import ChainInfo from './ChainInfo'; -const DEV_CHAIN_DOCKER = 'mosaicdao/dev-chains'; +const DEV_CHAIN_DOCKER = 'mosaicdao/dev-chains:1.0.0'; /** * Represents a geth node that runs in a docker container. */ From 9bf7362a82ab061ff7eb3ec9111d30c8bf990101 Mon Sep 17 00:00:00 2001 From: Sarvesh Jain Date: Tue, 15 Oct 2019 19:27:32 +0530 Subject: [PATCH 11/18] smoke test for subgraph deployment with gateway config --- tests/smoke.sh | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/tests/smoke.sh b/tests/smoke.sh index 74a7908e..d9296e8a 100755 --- a/tests/smoke.sh +++ b/tests/smoke.sh @@ -54,6 +54,19 @@ function deploy_subgraph { try_silent "./mosaic subgraph $1 $2 $3 http://localhost:$4 http://localhost:$5" } +# Deploy subgraph +# $1 origin chain identifier +# $2 aux chain identifier +# $3 chain {origin, auxiliary} +# $4 graph admin rpc port +# $5 graph IPFS port +# gateway config +function deploy_subgraph_gateway_config { + info "Deploying origin subraph." + try_silent "./mosaic subgraph $1 $2 $3 http://localhost:$4 http://localhost:$5 --gateway-config ~/.mosaic/$1/$2/$6.json" +} + + # Tries a command without output. Errors if the command does not execute successfully. function try_silent { eval $1 2>&1 || error "$2" @@ -161,8 +174,10 @@ grep_try ropsten parity start_origin_node dev-origin geth start_auxiliary_node dev-auxiliary geth -deploy_subgraph dev-origin 1000 origin 9535 6516 -deploy_subgraph dev-origin 1000 auxiliary 9020 6001 +deploy_subgraph_gateway_config dev-origin 1000 origin 9535 6516 0xae02c7b1c324a8d94a564bc8d713df89eae441fe +deploy_subgraph_gateway_config dev-origin 1000 auxiliary 9020 6001 0xae02c7b1c324a8d94a564bc8d713df89eae441fe +rpc_origin_sub_graph_try 1000 61515 +rpc_auxiliary_sub_graph_try 1000 # When done, stop all nodes. stop_nodes From cc36441350dac99c5225d8e0cf9db25b90bdbedf Mon Sep 17 00:00:00 2001 From: Sarvesh Jain Date: Wed, 16 Oct 2019 16:11:35 +0530 Subject: [PATCH 12/18] Dynamic name of subgraph --- src/Graph/SubGraph.ts | 4 ++-- src/bin/mosaic-setup-redeem-pool.ts | 2 +- src/bin/mosaic-setup-stake-pool.ts | 2 +- src/bin/mosaic-subgraph.ts | 4 ++-- .../SubGraphDeployment/auxiliary-verifier.ts | 16 ++++++++------ .../SubGraphDeployment/origin-verifier.ts | 8 ++++--- tests/smoke.sh | 22 ++++++++++--------- 7 files changed, 32 insertions(+), 26 deletions(-) diff --git a/src/Graph/SubGraph.ts b/src/Graph/SubGraph.ts index 0b6331e5..e12b5616 100644 --- a/src/Graph/SubGraph.ts +++ b/src/Graph/SubGraph.ts @@ -177,9 +177,9 @@ export default class SubGraph { */ private get name(): string { if (this.subGraphType === SubGraphType.ORIGIN) { - return `mosaic/origin-${this.auxiliaryChain}`; + return `mosaic/origin-${this.gatewayAddresses.eip20GatewayAddress.substr(2, 25)}`; } - return `mosaic/auxiliary-${this.auxiliaryChain}`; + return `mosaic/auxiliary-${this.gatewayAddresses.eip20CoGatewayAddress.substr(2, 22)}`; } /** diff --git a/src/bin/mosaic-setup-redeem-pool.ts b/src/bin/mosaic-setup-redeem-pool.ts index de717039..bed1468c 100644 --- a/src/bin/mosaic-setup-redeem-pool.ts +++ b/src/bin/mosaic-setup-redeem-pool.ts @@ -23,7 +23,7 @@ mosaic.action( organizationAdmin, ); } catch (error) { - Logger.error('error while executing mosaic libraries', {error: error.toString()}); + Logger.error('error while executing mosaic setup redeem pool', { error: error.toString() }); process.exit(1); } diff --git a/src/bin/mosaic-setup-stake-pool.ts b/src/bin/mosaic-setup-stake-pool.ts index afcddff2..acd03871 100755 --- a/src/bin/mosaic-setup-stake-pool.ts +++ b/src/bin/mosaic-setup-stake-pool.ts @@ -17,7 +17,7 @@ mosaic.action( try { await deployStakePool(chain, originWebsocket, deployer, organizationOwner, organizationAdmin); } catch (error) { - Logger.error('error while executing mosaic libraries', { error: error.toString() }); + Logger.error('error while executing mosaic setup stake pool', { error: error.toString() }); process.exit(1); } diff --git a/src/bin/mosaic-subgraph.ts b/src/bin/mosaic-subgraph.ts index 64be394d..72911d6b 100755 --- a/src/bin/mosaic-subgraph.ts +++ b/src/bin/mosaic-subgraph.ts @@ -47,7 +47,7 @@ mosaic.action( if (gatewayConfig) { if (parseInt(auxiliaryChain) !== gatewayConfig.auxChainId) { - console.error(`Auxiliary chain id in gateway config is ${gatewayConfig.auxChainId} but value passed is ${auxiliaryChain}`); + Logger.error(`Auxiliary chain id in gateway config is ${gatewayConfig.auxChainId} but value passed is ${auxiliaryChain}`); process.exit(1); } gatewayAddresses = GatewayAddresses.fromGatewayConfig(gatewayConfig); @@ -59,7 +59,7 @@ mosaic.action( } if (!gatewayAddresses) { - console.error('Mosaic config or token config not found . Use --mosaic-config or --token-config option to provide path.'); + Logger.error('Mosaic config or token config not found . Use --mosaic-config or --token-config option to provide path.'); process.exit(1); } diff --git a/tests/Graph/SubGraphDeployment/auxiliary-verifier.ts b/tests/Graph/SubGraphDeployment/auxiliary-verifier.ts index 286d3eac..ec1395ee 100644 --- a/tests/Graph/SubGraphDeployment/auxiliary-verifier.ts +++ b/tests/Graph/SubGraphDeployment/auxiliary-verifier.ts @@ -8,21 +8,23 @@ import Logger from '../../../src/Logger'; import WebSocket = require('ws'); const mosaic = commander - .arguments(' '); + .arguments(' '); mosaic.action( async ( - auxiliaryChainIdentifier: string, graphWsPort: string, + cogatewayAddress: string, ) => { - const subGraphName = `mosaic/auxiliary-${auxiliaryChainIdentifier}`; + const subGraphName = `mosaic/auxiliary-${cogatewayAddress.substr(2, 22)}`; + Logger.info(`subgraph name for verification ${subGraphName}`); + Logger.info(`graph ws port ${graphWsPort}`); const wsEndPoint = `ws://127.0.0.1:${graphWsPort}/subgraphs/name/${subGraphName}`; // Creates subscription client const subscriptionClient = new SubscriptionClient(wsEndPoint, { - reconnect: true, - }, - WebSocket); + reconnect: true, + }, + WebSocket); subscriptionClient.onConnected(() => { Logger.info(`Connected to sub graph: ${subGraphName}`); subscriptionClient.close(); @@ -35,4 +37,4 @@ mosaic.action( }); }, ) - .parse(process.argv); \ No newline at end of file + .parse(process.argv); diff --git a/tests/Graph/SubGraphDeployment/origin-verifier.ts b/tests/Graph/SubGraphDeployment/origin-verifier.ts index f7f887ae..7eafacc9 100644 --- a/tests/Graph/SubGraphDeployment/origin-verifier.ts +++ b/tests/Graph/SubGraphDeployment/origin-verifier.ts @@ -8,14 +8,16 @@ import Logger from '../../../src/Logger'; import WebSocket = require('ws'); const mosaic = commander - .arguments(' '); + .arguments(' { - const subGraphName = `mosaic/origin-${auxiliaryChainIdentifier}`; + const subGraphName = `mosaic/origin-${gatewayAddresses.substr(2, 25)}` + Logger.info(`subgraph name for verification ${subGraphName}`); + Logger.info(`graph ws port ${graphWsPort}`); const wsEndPoint = `ws://127.0.0.1:${graphWsPort}/subgraphs/name/${subGraphName}`; // Creates subscription client diff --git a/tests/smoke.sh b/tests/smoke.sh index d9296e8a..d0f9eff0 100755 --- a/tests/smoke.sh +++ b/tests/smoke.sh @@ -42,6 +42,8 @@ function stop_nodes { stop_node ropsten stop_node 1407 stop_node 1406 + stop_node dev-origin + stop_node dev-auxiliary } # Deploy subgraph # $1 origin chain identifier @@ -122,13 +124,13 @@ function rpc_node_try { } function rpc_origin_sub_graph_try { - info "Checking RPC connection to origin sub graph at port $2 on node for $1." - try_silent "./node_modules/.bin/ts-node tests/Graph/SubGraphDeployment/origin-verifier.ts $1 $2" "Origin sub graph at port $2 was expected to be deployed on $1, but wasn't." + info "Checking RPC connection to origin sub graph at port $1 on node for $2." + try_silent "./node_modules/.bin/ts-node tests/Graph/SubGraphDeployment/origin-verifier.ts $1 $2" "Origin sub graph at port $1 was expected to be deployed on $2, but wasn't." } function rpc_auxiliary_sub_graph_try { info "Checking RPC connection to auxiliary sub graph for $1 chain on node." - try_silent "./node_modules/.bin/ts-node tests/Graph/SubGraphDeployment/auxiliary-verifier.ts $1 6$1" "Auxiliary sub graph was expected to be deployed, but wasn't." + try_silent "./node_modules/.bin/ts-node tests/Graph/SubGraphDeployment/auxiliary-verifier.ts 6$1 $2" "Auxiliary sub graph was expected to be deployed, but wasn't." } # Making sure the mosaic command exists (we are in the right directory). @@ -140,21 +142,21 @@ start_auxiliary_node 1406 grep_try 1406 geth rpc_node_try 1406 deploy_subgraph ropsten 1406 auxiliary 9426 6407 -rpc_auxiliary_sub_graph_try 1406 +rpc_auxiliary_sub_graph_try 1406 0x02cffaa1e06c28021fff6b36d9e418a97b3de2fc start_auxiliary_node 1407 grep_try 1407 geth rpc_node_try 1407 deploy_subgraph ropsten 1407 auxiliary 9427 6408 -rpc_auxiliary_sub_graph_try 1407 +rpc_auxiliary_sub_graph_try 1407 0xf690624171fe06d02d2f4250bff17fe3b682ebd1 start_origin_node ropsten geth grep_try ropsten geth rpc_node_try "0003" # Given like this as it is used for the port in `rpc_node_try`. deploy_subgraph ropsten 1406 origin 8023 5004 deploy_subgraph ropsten 1407 origin 8023 5004 -rpc_origin_sub_graph_try 1406 60003 -rpc_origin_sub_graph_try 1407 60003 +rpc_origin_sub_graph_try 60003 0x04df90efbedf393361cdf498234af818da14f562 +rpc_origin_sub_graph_try 60003 0x31c8870c76390c5eb0d425799b5bd214a2600438 # Stop and start some nodes and make sure they are or are not running. stop_node ropsten @@ -172,12 +174,12 @@ grep_fail ropsten geth start_origin_node ropsten parity grep_try ropsten parity +# Deploy subgraph with gateway config start_origin_node dev-origin geth start_auxiliary_node dev-auxiliary geth deploy_subgraph_gateway_config dev-origin 1000 origin 9535 6516 0xae02c7b1c324a8d94a564bc8d713df89eae441fe deploy_subgraph_gateway_config dev-origin 1000 auxiliary 9020 6001 0xae02c7b1c324a8d94a564bc8d713df89eae441fe -rpc_origin_sub_graph_try 1000 61515 -rpc_auxiliary_sub_graph_try 1000 - +rpc_origin_sub_graph_try 61515 0xaE02C7b1C324A8D94A564bC8d713Df89eae441fe +rpc_auxiliary_sub_graph_try 1000 0xc6fF898ceBf631eFb58eEc7187E4c1f70AE8d943 # When done, stop all nodes. stop_nodes From e2dd7e6c7d98d99a27b32b04c289a7eb9b2a6018 Mon Sep 17 00:00:00 2001 From: Sarvesh Jain Date: Wed, 16 Oct 2019 19:39:20 +0530 Subject: [PATCH 13/18] Added variable in smoke test --- tests/smoke.sh | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/tests/smoke.sh b/tests/smoke.sh index d0f9eff0..2ce125fb 100755 --- a/tests/smoke.sh +++ b/tests/smoke.sh @@ -45,6 +45,7 @@ function stop_nodes { stop_node dev-origin stop_node dev-auxiliary } + # Deploy subgraph # $1 origin chain identifier # $2 aux chain identifier @@ -137,6 +138,23 @@ function rpc_auxiliary_sub_graph_try { try_silent "ls mosaic" "Script must be run from the mosaic chains root directory so that the required node modules are available." info "Starting node one by one and verifying if all services for them are running." +# 1406 config +GRAPH_ADMIN_RPC_1406=9426 +GRAPH_IPFS_1406=6407 +OST_COGATEWAY_ADDRESS_1406=0x02cffaa1e06c28021fff6b36d9e418a97b3de2fc + +# 1407 config +GRAPH_ADMIN_RPC_1407=9427 +GRAPH_IPFS_1407=6408 +OST_COGATEWAY_ADDRESS_1407=0xf690624171fe06d02d2f4250bff17fe3b682ebd1 + +# ropsten config +GRAPH_ADMIN_RPC_ROPSTEN=8023 +GRAPH_IPFS_ROPSTEN=5004 +GRAPH_WS_PORT_ROPSTEN=60003 +OST_GATEWAY_ADDRESS_ROPSTEN_1406=0x04df90efbedf393361cdf498234af818da14f562 +OST_GATEWAY_ADDRESS_ROPSTEN_1407=0x31c8870c76390c5eb0d425799b5bd214a2600438 + start_auxiliary_node 1406 grep_try 1406 geth @@ -174,6 +192,13 @@ grep_fail ropsten geth start_origin_node ropsten parity grep_try ropsten parity +# Dev chain config +GRAPH_ADMIN_RPC_DEV_ORIGIN=9535 +GRAPH_IPFS_DEV_ORIGIN=6516 +GRAPH_WS_PORT_DEV_ORIGIN=61515 +OST_GATEWAY_ADDRESS_DEV_ORIGIN_WETH=0xaE02C7b1C324A8D94A564bC8d713Df89eae441fe +OST_CO_GATEWAY_ADDRESS_DEV_ORIGIN_WETH=0xc6fF898ceBf631eFb58eEc7187E4c1f70AE8d943 + # Deploy subgraph with gateway config start_origin_node dev-origin geth start_auxiliary_node dev-auxiliary geth From 7656d1ad7d666911640194f41cc8b17321783444 Mon Sep 17 00:00:00 2001 From: Sarvesh Jain Date: Wed, 16 Oct 2019 19:55:57 +0530 Subject: [PATCH 14/18] Using variables in smoke test --- tests/smoke.sh | 41 ++++++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/tests/smoke.sh b/tests/smoke.sh index 2ce125fb..d7e482ce 100755 --- a/tests/smoke.sh +++ b/tests/smoke.sh @@ -155,26 +155,36 @@ GRAPH_WS_PORT_ROPSTEN=60003 OST_GATEWAY_ADDRESS_ROPSTEN_1406=0x04df90efbedf393361cdf498234af818da14f562 OST_GATEWAY_ADDRESS_ROPSTEN_1407=0x31c8870c76390c5eb0d425799b5bd214a2600438 +# Dev chain config +GRAPH_ADMIN_RPC_DEV_ORIGIN=9535 +GRAPH_IPFS_DEV_ORIGIN=6516 +GRAPH_WS_PORT_DEV_ORIGIN=61515 +OST_GATEWAY_ADDRESS_DEV_ORIGIN_WETH=0xaE02C7b1C324A8D94A564bC8d713Df89eae441fe +OST_CO_GATEWAY_ADDRESS_DEV_ORIGIN_WETH=0xc6fF898ceBf631eFb58eEc7187E4c1f70AE8d943 + +DEV_AUXILIARY_CHAIN_ID=1000 +GRAPH_ADMIN_RPC_DEV_AUXILIARY=9020 +GRAPH_IPFS_DEV_AUXILIARY=6001 start_auxiliary_node 1406 grep_try 1406 geth rpc_node_try 1406 -deploy_subgraph ropsten 1406 auxiliary 9426 6407 -rpc_auxiliary_sub_graph_try 1406 0x02cffaa1e06c28021fff6b36d9e418a97b3de2fc +deploy_subgraph ropsten 1406 auxiliary $GRAPH_ADMIN_RPC_1406 $GRAPH_IPFS_1406 +rpc_auxiliary_sub_graph_try 1406 $OST_COGATEWAY_ADDRESS_1406 start_auxiliary_node 1407 grep_try 1407 geth rpc_node_try 1407 -deploy_subgraph ropsten 1407 auxiliary 9427 6408 -rpc_auxiliary_sub_graph_try 1407 0xf690624171fe06d02d2f4250bff17fe3b682ebd1 +deploy_subgraph ropsten 1407 auxiliary $GRAPH_ADMIN_RPC_1407 $GRAPH_IPFS_1407 +rpc_auxiliary_sub_graph_try 1407 $OST_COGATEWAY_ADDRESS_1407 start_origin_node ropsten geth grep_try ropsten geth rpc_node_try "0003" # Given like this as it is used for the port in `rpc_node_try`. -deploy_subgraph ropsten 1406 origin 8023 5004 -deploy_subgraph ropsten 1407 origin 8023 5004 -rpc_origin_sub_graph_try 60003 0x04df90efbedf393361cdf498234af818da14f562 -rpc_origin_sub_graph_try 60003 0x31c8870c76390c5eb0d425799b5bd214a2600438 +deploy_subgraph ropsten 1406 origin $GRAPH_ADMIN_RPC_ROPSTEN $GRAPH_IPFS_ROPSTEN +deploy_subgraph ropsten 1407 origin $GRAPH_ADMIN_RPC_ROPSTEN $GRAPH_IPFS_ROPSTEN +rpc_origin_sub_graph_try $GRAPH_WS_PORT_ROPSTEN $OST_GATEWAY_ADDRESS_ROPSTEN_1406 +rpc_origin_sub_graph_try $GRAPH_WS_PORT_ROPSTEN $OST_GATEWAY_ADDRESS_ROPSTEN_1407 # Stop and start some nodes and make sure they are or are not running. stop_node ropsten @@ -192,19 +202,12 @@ grep_fail ropsten geth start_origin_node ropsten parity grep_try ropsten parity -# Dev chain config -GRAPH_ADMIN_RPC_DEV_ORIGIN=9535 -GRAPH_IPFS_DEV_ORIGIN=6516 -GRAPH_WS_PORT_DEV_ORIGIN=61515 -OST_GATEWAY_ADDRESS_DEV_ORIGIN_WETH=0xaE02C7b1C324A8D94A564bC8d713Df89eae441fe -OST_CO_GATEWAY_ADDRESS_DEV_ORIGIN_WETH=0xc6fF898ceBf631eFb58eEc7187E4c1f70AE8d943 - # Deploy subgraph with gateway config start_origin_node dev-origin geth start_auxiliary_node dev-auxiliary geth -deploy_subgraph_gateway_config dev-origin 1000 origin 9535 6516 0xae02c7b1c324a8d94a564bc8d713df89eae441fe -deploy_subgraph_gateway_config dev-origin 1000 auxiliary 9020 6001 0xae02c7b1c324a8d94a564bc8d713df89eae441fe -rpc_origin_sub_graph_try 61515 0xaE02C7b1C324A8D94A564bC8d713Df89eae441fe -rpc_auxiliary_sub_graph_try 1000 0xc6fF898ceBf631eFb58eEc7187E4c1f70AE8d943 +deploy_subgraph_gateway_config dev-origin $DEV_AUXILIARY_CHAIN_ID origin $GRAPH_ADMIN_RPC_DEV_ORIGIN $GRAPH_IPFS_DEV_ORIGIN OST_GATEWAY_ADDRESS_DEV_ORIGIN_WETH +deploy_subgraph_gateway_config dev-origin $DEV_AUXILIARY_CHAIN_ID auxiliary $GRAPH_ADMIN_RPC_DEV_AUXILIARY $GRAPH_IPFS_DEV_AUXILIARY $OST_GATEWAY_ADDRESS_DEV_ORIGIN_WETH +rpc_origin_sub_graph_try $GRAPH_WS_PORT_DEV_ORIGIN $OST_GATEWAY_ADDRESS_DEV_ORIGIN_WETH +rpc_auxiliary_sub_graph_try $DEV_AUXILIARY_CHAIN_ID $OST_CO_GATEWAY_ADDRESS_DEV_ORIGIN_WETH # When done, stop all nodes. stop_nodes From 432464014e8f1b3aff4b5371f5a89de4052fb73c Mon Sep 17 00:00:00 2001 From: Sarvesh Jain Date: Wed, 16 Oct 2019 19:57:51 +0530 Subject: [PATCH 15/18] PR feedback refacotring, typos and imporved documentation --- README.md | 6 +++--- src/Config/GatewayAddresses.ts | 9 +++------ src/Graph/SubGraph.ts | 28 ++++++++++++++-------------- src/bin/mosaic-subgraph.ts | 15 +++++++++------ 4 files changed, 29 insertions(+), 29 deletions(-) diff --git a/README.md b/README.md index 295d1987..0f0c2708 100644 --- a/README.md +++ b/README.md @@ -191,12 +191,12 @@ Subgraph command can be used to deploy mosaic subgraph. Subgraph by [thegraph](h Below command deploys subgraph of mosaic gateways. ```bash -./mosaic subgraph +./mosaic subgraph ``` **where:** 1. origin-chain-identifier: Origin chain identifier like ropsten, goerli, dev-origin -2.auxiliary-chain-identifier: Auxiliary chain ID like 1405, 1406, 1407 or 1000(dev-auxiliary). -3. Chain: Either`origin` or `auxiliary` chain. +2. auxiliary-chain-identifier: Auxiliary chain ID like 1405, 1406, 1407 or 1000(dev-auxiliary). +3. chainType: Either`origin` or `auxiliary` chain. 4. admin-graph-rpc: RPC endpoint of graph node. 5. graph-ipfs: IPFS endpoint used by graph node. diff --git a/src/Config/GatewayAddresses.ts b/src/Config/GatewayAddresses.ts index 2ef8c652..86f18110 100644 --- a/src/Config/GatewayAddresses.ts +++ b/src/Config/GatewayAddresses.ts @@ -19,7 +19,7 @@ export default class GatewayAddresses { /** * Constructor - * @param stakePoolAddress StakePool Address address. + * @param stakePoolAddress StakePool address. * @param eip20GatewayAddress eip20Gateway address. * @param anchorAddress anchor address. * @param coAnchorAddress coanchor address. @@ -42,7 +42,6 @@ export default class GatewayAddresses { this.redeemPoolAddress = redeemPoolAddress; } - /** * Create Gateway address instance based on mosaic config. * @param mosaicConfig Mosaic config object. @@ -75,14 +74,12 @@ export default class GatewayAddresses { ): GatewayAddresses { const { auxChainId } = gatewayConfig; const stakePoolAddress = gatewayConfig.originContracts.stakePoolAddress - ? gatewayConfig.originContracts.stakePoolAddress - : gatewayConfig.mosaicConfig.originChain.contractAddresses.stakePoolAddress; + || gatewayConfig.mosaicConfig.originChain.contractAddresses.stakePoolAddress; const auxiliaryChain = gatewayConfig.mosaicConfig.auxiliaryChains[auxChainId]; const auxiliaryContracts = auxiliaryChain.contractAddresses.auxiliary; const redeemPool = gatewayConfig.auxiliaryContracts.redeemPoolAddress - ? gatewayConfig.auxiliaryContracts.redeemPoolAddress - : auxiliaryContracts.redeemPoolAddress; + || auxiliaryContracts.redeemPoolAddress; const originContracts = auxiliaryChain.contractAddresses.origin; return new GatewayAddresses( diff --git a/src/Graph/SubGraph.ts b/src/Graph/SubGraph.ts index e12b5616..9f2c03a9 100644 --- a/src/Graph/SubGraph.ts +++ b/src/Graph/SubGraph.ts @@ -23,11 +23,11 @@ export default class SubGraph { /** To be used to determine which code is deployed. For example origin/auxiliary */ private readonly subGraphType: string; - /** Graph node rpc admin URL */ - private readonly graphRPCAdminURL: string; + /** Graph node rpc admin endpoint */ + private readonly graphRPCAdminEndPoint: string; - /** Graph node IPFS URL */ - private readonly graphIPFSURL: string; + /** Graph node IPFS endpoint */ + private readonly graphIPFSEndPoint: string; /** Gateway pair addresses */ private readonly gatewayAddresses: GatewayAddresses; @@ -37,23 +37,23 @@ export default class SubGraph { * @param originChain Origin chain identifier. * @param auxiliaryChain Auxiliary chain identifier. * @param subGraphType Subgraph type - * @param graphRPCAdminURL Graph node rpc admin URL. - * @param graphIPFSURL Graph node IPFS url. + * @param graphRPCAdminEndPoint Graph node rpc admin URL. + * @param graphIPFSEndPoint Graph node IPFS url. * @param gatewayAddresses Gateway pair addresses. */ public constructor( originChain: string, auxiliaryChain: string, subGraphType: string, - graphRPCAdminURL: string, - graphIPFSURL: string, + graphRPCAdminEndPoint: string, + graphIPFSEndPoint: string, gatewayAddresses: GatewayAddresses, ) { this.originChain = originChain; this.auxiliaryChain = auxiliaryChain; this.subGraphType = subGraphType; - this.graphRPCAdminURL = graphRPCAdminURL; - this.graphIPFSURL = graphIPFSURL; + this.graphRPCAdminEndPoint = graphRPCAdminEndPoint; + this.graphIPFSEndPoint = graphIPFSEndPoint; this.gatewayAddresses = gatewayAddresses; } @@ -129,7 +129,7 @@ export default class SubGraph { this.logInfo('attempting to create local graph'); try { this.tryRemovingSubgraph(); - this.executeGraphCommand(`create --node ${this.graphRPCAdminURL}/ ${this.name}`); + this.executeGraphCommand(`create --node ${this.graphRPCAdminEndPoint}/ ${this.name}`); return { success: true, message: '' }; } catch (ex) { const message = this.extractMessageFromError(ex); @@ -143,7 +143,7 @@ export default class SubGraph { */ private tryRemovingSubgraph() { try { - this.executeGraphCommand(`remove --node ${this.graphRPCAdminURL}/ ${this.name}`); + this.executeGraphCommand(`remove --node ${this.graphRPCAdminEndPoint}/ ${this.name}`); } catch (e) { this.logInfo('No subgraph exists, deploying for the first time.'); } @@ -216,14 +216,14 @@ export default class SubGraph { this.logInfo('attempting to deploy local graph'); try { this.executeGraphCommand( - `deploy --node ${this.graphRPCAdminURL}/ --ipfs ${this.graphIPFSURL} ${this.name}`, + `deploy --node ${this.graphRPCAdminEndPoint}/ --ipfs ${this.graphIPFSEndPoint} ${this.name}`, ); return { success: true, message: '' }; } catch (ex) { const message = this.extractMessageFromError(ex); this.logInfo(`deploy local graph failed with: ${message}`); this.logInfo('removing local graph'); - this.executeGraphCommand(`remove --node ${this.graphRPCAdminURL}/ ${this.name}`); + this.executeGraphCommand(`remove --node ${this.graphRPCAdminEndPoint}/ ${this.name}`); return { success: false, message }; } } diff --git a/src/bin/mosaic-subgraph.ts b/src/bin/mosaic-subgraph.ts index 72911d6b..a5be873d 100755 --- a/src/bin/mosaic-subgraph.ts +++ b/src/bin/mosaic-subgraph.ts @@ -13,7 +13,6 @@ const mosaic = commander mosaic.option('-m,--mosaic-config ', 'Mosaic config absolute path.'); mosaic.option('-t,--gateway-config ', 'Gateway config absolute path.'); -mosaic.option('-a,--auxiliary ', 'auxiliary chain identifier.'); mosaic.option('-g,--gateway-address ', 'gateway address of origin.'); mosaic.action( async ( @@ -25,9 +24,9 @@ mosaic.action( options, ) => { try { - let gatewayAddresses; - let gatewayConfig; - let mosaicConfig; + let gatewayAddresses: GatewayAddresses; + let gatewayConfig: GatewayConfig; + let mosaicConfig: MosaicConfig; if (options.gatewayConfig) { gatewayConfig = GatewayConfig.fromFile(options.gatewayConfig); @@ -52,6 +51,10 @@ mosaic.action( } gatewayAddresses = GatewayAddresses.fromGatewayConfig(gatewayConfig); } else if (mosaicConfig) { + if (mosaicConfig.originChain.chain !== originChain) { + Logger.error(`Origin chain id in mosaic config is ${mosaicConfig.originChain.chain} but received argument is ${originChain}`); + process.exit(1); + } gatewayAddresses = GatewayAddresses.fromMosaicConfig( mosaicConfig, auxiliaryChain.toString(), @@ -59,7 +62,7 @@ mosaic.action( } if (!gatewayAddresses) { - Logger.error('Mosaic config or token config not found . Use --mosaic-config or --token-config option to provide path.'); + Logger.error('Mosaic config or gateway config not found . Use --mosaic-config or --gateway-config option to provide path.'); process.exit(1); } @@ -72,7 +75,7 @@ mosaic.action( gatewayAddresses, ).deploy(); } catch (error) { - Logger.error('error while executing mosaic libraries', { error: error.toString() }); + Logger.error('error while executing mosaic subgraph command', { error: error.toString() }); process.exit(1); } From 7dabbe68daaf6f68e4ab0b6c4c9232a46b057429 Mon Sep 17 00:00:00 2001 From: Sarvesh Jain Date: Wed, 16 Oct 2019 20:04:51 +0530 Subject: [PATCH 16/18] Corrected smoke tests --- src/Graph/SubGraph.ts | 4 ++-- tests/smoke.sh | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Graph/SubGraph.ts b/src/Graph/SubGraph.ts index 9f2c03a9..12d31d94 100644 --- a/src/Graph/SubGraph.ts +++ b/src/Graph/SubGraph.ts @@ -37,8 +37,8 @@ export default class SubGraph { * @param originChain Origin chain identifier. * @param auxiliaryChain Auxiliary chain identifier. * @param subGraphType Subgraph type - * @param graphRPCAdminEndPoint Graph node rpc admin URL. - * @param graphIPFSEndPoint Graph node IPFS url. + * @param graphRPCAdminEndPoint Graph node rpc admin endpoint. + * @param graphIPFSEndPoint Graph node IPFS endpoint. * @param gatewayAddresses Gateway pair addresses. */ public constructor( diff --git a/tests/smoke.sh b/tests/smoke.sh index d7e482ce..964c5037 100755 --- a/tests/smoke.sh +++ b/tests/smoke.sh @@ -205,7 +205,7 @@ grep_try ropsten parity # Deploy subgraph with gateway config start_origin_node dev-origin geth start_auxiliary_node dev-auxiliary geth -deploy_subgraph_gateway_config dev-origin $DEV_AUXILIARY_CHAIN_ID origin $GRAPH_ADMIN_RPC_DEV_ORIGIN $GRAPH_IPFS_DEV_ORIGIN OST_GATEWAY_ADDRESS_DEV_ORIGIN_WETH +deploy_subgraph_gateway_config dev-origin $DEV_AUXILIARY_CHAIN_ID origin $GRAPH_ADMIN_RPC_DEV_ORIGIN $GRAPH_IPFS_DEV_ORIGIN $OST_GATEWAY_ADDRESS_DEV_ORIGIN_WETH deploy_subgraph_gateway_config dev-origin $DEV_AUXILIARY_CHAIN_ID auxiliary $GRAPH_ADMIN_RPC_DEV_AUXILIARY $GRAPH_IPFS_DEV_AUXILIARY $OST_GATEWAY_ADDRESS_DEV_ORIGIN_WETH rpc_origin_sub_graph_try $GRAPH_WS_PORT_DEV_ORIGIN $OST_GATEWAY_ADDRESS_DEV_ORIGIN_WETH rpc_auxiliary_sub_graph_try $DEV_AUXILIARY_CHAIN_ID $OST_CO_GATEWAY_ADDRESS_DEV_ORIGIN_WETH From f9830c545879e0adecdebb504ffe0d747c7239e7 Mon Sep 17 00:00:00 2001 From: Sarvesh Jain Date: Thu, 17 Oct 2019 12:42:09 +0530 Subject: [PATCH 17/18] Added log for file path --- src/Config/GatewayConfig.ts | 2 ++ src/Directory.ts | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Config/GatewayConfig.ts b/src/Config/GatewayConfig.ts index 2935ca17..bd651080 100644 --- a/src/Config/GatewayConfig.ts +++ b/src/Config/GatewayConfig.ts @@ -7,6 +7,7 @@ import { } from '../Exception'; import FileSystem from '../FileSystem '; import Directory from '../Directory'; +import Logger from "../Logger"; /* eslint-disable @typescript-eslint/no-var-requires */ const schema = require('./GatewayConfig.schema.json'); @@ -95,6 +96,7 @@ export default class GatewayConfig { public static fromChain(originChain: string, auxChainId: number, gatewayAddress: string): GatewayConfig { const filePath = Directory.getGatewayConfigPath(originChain, auxChainId, gatewayAddress); + Logger.info(`filepath for gateway config ${filePath}`); if (GatewayConfig.exists(filePath)) { const configObject = GatewayConfig.readConfigFromFile(filePath); return new GatewayConfig(configObject); diff --git a/src/Directory.ts b/src/Directory.ts index 562a449d..99d50e8f 100644 --- a/src/Directory.ts +++ b/src/Directory.ts @@ -172,12 +172,12 @@ export default class Directory { * @return Path of gateway config file. */ public static getGatewayConfigPath(originChain: string, auxChainId: number, gatewayAddress: string): - string { + string { return path.join( Directory.getDefaultMosaicDataDir, originChain, auxChainId.toString(), - gatewayAddress.toLowerCase()+'.json', + `${gatewayAddress.toLowerCase()}.json`, ); } } From e0bb4a84153d0d9daf7b48a8eb779584d5cdd6fa Mon Sep 17 00:00:00 2001 From: Sarvesh Jain Date: Thu, 17 Oct 2019 13:15:42 +0530 Subject: [PATCH 18/18] Converted gateway address to lower case --- tests/smoke.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/smoke.sh b/tests/smoke.sh index 964c5037..5f26cd4d 100755 --- a/tests/smoke.sh +++ b/tests/smoke.sh @@ -66,7 +66,7 @@ function deploy_subgraph { # gateway config function deploy_subgraph_gateway_config { info "Deploying origin subraph." - try_silent "./mosaic subgraph $1 $2 $3 http://localhost:$4 http://localhost:$5 --gateway-config ~/.mosaic/$1/$2/$6.json" + try_silent "./mosaic subgraph $1 $2 $3 http://localhost:$4 http://localhost:$5 --gateway-config ~/.mosaic/$1/$2/$( echo "$6" | tr -s '[:upper:]' '[:lower:]' ).json" }