Skip to content

Conversation

@emizzle
Copy link
Collaborator

@emizzle emizzle commented Apr 30, 2018

  • added EmbarkJS.Storage.isAvailable and EmbarkJS.Messages.isAvailable() and underlying provider functions for Whisper, Orbit, IPFS, and Swarm so service availability can be checked from the DApp (@richard-ramos)
  • Finished swarm implementation in embarkjs plus cleanup
  • updated test app storage config to swarm to show swarm config option
  • added eth-lib to parse result of swarm text
  • added protocol to storage config (defaulting to "http")
  • selectively starts storage service depending on which one is configured in the storage config
  • run service check for ipfs/swarm prior to uploaded
  • added swarm methods for embarkjs
  • removed unneeded provider property.
  • add 'swarm' as a provider in the storage.config
  • update method for swarm service check

emizzle added 2 commits April 30, 2018 15:56
Adding swarm to embarkjs. WIP.

Add 'auto' setting for geth CORS and websockets origin

* 'auto' now supported for `rpcCorsDomain` and `wsOrigins` in the blockchain config.
* 'auto' set to the default value in blockchain config for test and demo apps.
test add config and contract and add test

addFileToPipeline test and registerBeforeDeploy with new arg

add more registers but generation one fails in run

WIP commit

Undo changes to test config.

Merge pull request #381 from embark-framework/features/cors-auto

Add 'auto' setting for geth CORS and websockets origin
fix a bug where upload cmd used plugin name

don't error if it's an empty dapp with no contracts yet

Merge pull request #383 from embark-framework/no_contracts

don't error if it's an empty dapp with no contracts yet
remove duplicated entry

force zepplein version for travis

Merge pull request #384 from embark-framework/chores/test-allpligin-apis

Small fixes for plugin APIs
intercept logs in the app itself - stopgap fix

Merge pull request #385 from embark-framework/console_logs_fix

intercept logs in the app itself - stopgap fix
* removed unneeded provider property.
* add 'swarm' as a provider in the storage.config
* update method for swarm service check

Merge branch 'develop' into features/add-swarm-to-embarkjs


More work to add swarm to embarkjs

* added eth-lib to parse result of swarm text
* changed "currentStorage" and "currentMessages" to "currentProvider" for consistency.
* added protocol to storage config
* selectively starts storage service depending on which one is configured in the storage config
* run service check for ipfs/swarm prior to uploaded
* added swarm methods for embarkjs

Updated code based on code review

check if testrpc is installed and warn if not

Merge pull request #386 from embark-framework/bug_fix/test-rpc-not-installed

check if testrpc is installed and warn if not
Removed timeout

Removed spacer

Merge pull request #382 from embark-framework/react-demo

Updating embark demo to use react instead of jquery
fix on contract add

Merge pull request #387 from embark-framework/bug_fix/new-contract-in-empty-dapp

Fix adding a contract
redeploy with right config on config change

fix tests

reset watchers after build to make sure files remain watch

Merge pull request #389 from embark-framework/bug_fix/file-changes-not-watched

Fix files not being watched
Merge pull request #388 from embark-framework/bug_fix/changing-contract-config

Redeploy with right config on config change
Added swarm support in embarkjs and isAvailable for messages/storage

* reverted currentProvider back to currentStorage and currentMessages
* added `EmbarkJS.Storage.isAvailable` and `EmbarkJS.Messages.isAvailable()` and underlying provider functions for Whisper, Orbit, IPFS, and Swarm
* Finished swarm implementation in embarkjs plus cleanup
* updated test app storage config to swarm to show swarm config option

Merge branch 'develop' into features/add-swarm-to-embarkjs
@emizzle emizzle changed the title Added swarm support in embarkjs and isAvailable for messages/storage Added swarm support in embarkj, isAvailable for messages/storage, swarm/ipfs checks Apr 30, 2018
@emizzle emizzle changed the title Added swarm support in embarkj, isAvailable for messages/storage, swarm/ipfs checks Added swarm support in embarkjs, isAvailable for messages/storage, swarm/ipfs checks Apr 30, 2018
@emizzle
Copy link
Collaborator Author

emizzle commented Apr 30, 2018

on the test app, run ../../bin/embark upload ipfs or ../../bin/embark upload swarm causes the following error:

/Users/emizzle/Code/__Github/embark/lib/core/engine.js:149
          self.watch.restart(); // Necessary because changing a file while it is writing can stop it from being watched
                     ^

TypeError: Cannot read property 'restart' of undefined
    at /Users/emizzle/Code/__Github/embark/lib/core/engine.js:149:22
    at /Users/emizzle/Code/__Github/embark/lib/pipeline/pipeline.js:155:11
    at /Users/emizzle/Code/__Github/embark/node_modules/async/dist/async.js:473:16
    at replenish (/Users/emizzle/Code/__Github/embark/node_modules/async/dist/async.js:993:25)
    at iterateeCallback (/Users/emizzle/Code/__Github/embark/node_modules/async/dist/async.js:983:17)
    at /Users/emizzle/Code/__Github/embark/node_modules/async/dist/async.js:958:16
    at /Users/emizzle/Code/__Github/embark/lib/pipeline/pipeline.js:150:13
    at /Users/emizzle/Code/__Github/embark/node_modules/async/dist/async.js:1126:9
    at /Users/emizzle/Code/__Github/embark/node_modules/async/dist/async.js:473:16
    at replenish (/Users/emizzle/Code/__Github/embark/node_modules/async/dist/async.js:993:25)
    at iterateeCallback (/Users/emizzle/Code/__Github/embark/node_modules/async/dist/async.js:983:17)
    at /Users/emizzle/Code/__Github/embark/node_modules/async/dist/async.js:958:16
    at /Users/emizzle/Code/__Github/embark/node_modules/async/dist/async.js:1123:13
    at /Users/emizzle/Code/__Github/embark/lib/pipeline/pipeline.js:180:16
    at /Users/emizzle/Code/__Github/embark/node_modules/async/dist/async.js:473:16
    at replenish (/Users/emizzle/Code/__Github/embark/node_modules/async/dist/async.js:993:25)
    at iterateeCallback (/Users/emizzle/Code/__Github/embark/node_modules/async/dist/async.js:983:17)
    at /Users/emizzle/Code/__Github/embark/node_modules/async/dist/async.js:958:16
    at /Users/emizzle/Code/__Github/embark/lib/pipeline/pipeline.js:174:9
    at /Users/emizzle/Code/__Github/embark/node_modules/async/dist/async.js:3096:16
    at replenish (/Users/emizzle/Code/__Github/embark/node_modules/async/dist/async.js:998:17)
    at /Users/emizzle/Code/__Github/embark/node_modules/async/dist/async.js:1002:9

Copy link
Collaborator

@jrainville jrainville left a comment

Choose a reason for hiding this comment

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

Mostly the same comment at multiple places about returning to prevent further code execution and also because it's cleaner. Otherwise, it's pretty gucci 👍

lib/index.js Outdated
return true;
}
});
if(!checkFn || typeof checkFn.fn !== 'function') callback();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Just code cleaning: You could just do:

if(!checkFn || typeof checkFn.fn !== 'function') {
  return callback();
}

That way, we don't need an else.

lib/index.js Outdated
if(!serviceCheckResult.status || serviceCheckResult.status === 'off'){
callback({message:`Cannot upload: ${platform} node is not running on http://${engine.config.storageConfig.host}:${engine.config.storageConfig.port}.`});
} else {
callback(null);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Again, you can use a return from the first one to remove the else. But mostly, no need to put null in the callback.

lib/index.js Outdated
callback();
}
}
else callback(null);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same thing as above.


__embarkIPFS.isAvailable = function(){
return new Promise((resolve) => {
if(!this.ipfsConnection) resolve(false);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Don't you need a return here to make sure we don't resolve twice (not sure if it is possible, but at least to prevent anymore code execution)

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ok, I tested and it does only take the first resolve, but it also does continue the code execution, so I think using a return would still be nice.

this.connectError = new Error(`Cannot connect to Swarm node on ${this.connectUrl}`);
this._getUrl = options.getUrl || `${this.connectUrl}/bzzr:/`;

var promise = new Promise((resolve, reject) => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

No need for the var. Just return new Promise((resolve, reject) => { ......

__embarkSwarm.saveText = function(text) {
return new Promise((resolve, reject) => {
this.isAvailable().then((isAvailable) => {
if(!isAvailable) reject(this.connectError);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Again return

__embarkSwarm.get = function(hash) {
return new Promise((resolve, reject) => {
this.isAvailable().then((isAvailable) => {
if(!isAvailable) reject(this.connectError);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Again return (sorry for copy-pasta, just want you to know all the spots 🤷‍♂️ )

reader.onloadend = (event) => {
var fileContent = new Uint8Array(event.target.result);
this.isAvailable().then((isAvailable) => {
if(!isAvailable) reject(this.connectError);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Again return


__embarkWhisperNewWeb3.isAvailable = function(){
return new Promise((resolve, reject) => {
if(!this.web3.shh) resolve(false);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Again return


__embarkWhisperOld.isAvailable = function(){
return new Promise((resolve, reject) => {
if(!this.web3) resolve(false);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Again return

@iurimatias
Copy link
Collaborator

@jrainville could you add the missing early returns please and then merge? @emizzle is currently traveling

Copy link
Collaborator

@jrainville jrainville left a comment

Choose a reason for hiding this comment

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

As far as I'm concerned, the code is good. I tested in the demo app and it worked ok. Sometimes, the image returned a 0 byte file, but could be swarm-gateways. However, upload swarm returns with a dir_hash of false (both in the demo app and test app) and I'm not sure why that is. @emizzle is there another step to configure?

@iurimatias iurimatias merged commit 0cffff0 into develop May 1, 2018
@emizzle
Copy link
Collaborator Author

emizzle commented May 2, 2018

Returning 0 byte files and returning a hash that 404's on the network are exactly the issues I was having with swarm. What does your storage.json look like @jrainville?

@jrainville
Copy link
Collaborator

I went back to IPFS after testing, but I had what you put in the test_app:

{
  "default": {
    "enabled": true,
    "available_providers": ["ipfs", "swarm"],
    "ipfs_bin": "ipfs",
    "provider": "ipfs",
    "host": "localhost",
    "port": 5001
  },
  "development": {
    "enabled": true,
    "provider": "swarm",
    "host": "swarm-gateways.net",
    "port": 80,
    "getUrl": "http://swarm-gateways.net/bzzr:/"
  },
  "livenet": {
    "enabled": true,
    "provider": "ipfs",
    "host": "ipfs.infura.io",
    "protocol": "https",
    "port": false,
    "getUrl": "https://ipfs.infura.io/ipfs/"
  }
}

@emizzle
Copy link
Collaborator Author

emizzle commented May 2, 2018

The config looks good. I just feel like Swarm is strangely unreliable. Mostly on localhost, getting a resource seemed to return a 200 but with 0 bytes. While swarm-gateways.net seems to 404 most often (and sometimes the resource will eventually become available). And other times, I'll get a CORS error when trying to get a resource. It's definitely flaky.

In saying that, I have never hit an issue with not getting a hash.

And even weirder, I swear sometimes it would seem to work better when running a local node, but using swarm-gateways.net. But that would never be 100% reliable either. Witch craft.

@jrainville jrainville deleted the features/add-swarm-to-embarkjs branch May 3, 2018 16:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants