Skip to content
This repository has been archived by the owner on Oct 4, 2023. It is now read-only.

Commit

Permalink
Remove CN fallbacks (#71)
Browse files Browse the repository at this point in the history
* Remove CN fallbacks

* Update .env.prod

* Fix env vars
  • Loading branch information
raymondjacobson authored Oct 22, 2020
1 parent 10b2db2 commit 303359e
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 95 deletions.
12 changes: 5 additions & 7 deletions .env/.env.prod
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ REACT_APP_REGISTRY_ADDRESS=0xC611C82150b56E6e4Ec5973AcAbA8835Dd0d75A2
REACT_APP_WEB3_PROVIDER_URL=https://poa-gateway.audius.co,https://core.poa.network
REACT_APP_WEB3_NETWORK_ID=99

REACT_APP_ETH_REGISTRY_ADDRESS=0x095284A8237b275aBB96E8587e60ed76983BE6A5
REACT_APP_ETH_PROVIDER_URL=https://eth-ropsten.alchemyapi.io/v2/Cfba0ddjnI3WUXr2V_85dAaIPm_a6CSx,https://eth-ropsten.alchemyapi.io/v2/LHMVUibmgdZO59CqVYJrsFss2vtSyxAV
REACT_APP_ETH_NETWORK_ID=3
REACT_APP_ETH_TOKEN_ADDRESS=0xF0A4A438821d21e37150e9916569De7c156E898F
REACT_APP_ETH_REGISTRY_ADDRESS=0xd976d3b4f4e22a238c1A736b6612D22f17b6f64C
REACT_APP_ETH_PROVIDER_URL=https://eth-mainnet.alchemyapi.io/v2/iSnek4T02BFCUEkcPGKo0eEY1aWLJgxF,https://eth-mainnet.alchemyapi.io/v2/qSUBgXJpg5Vj75otrSHFXCh7YCqaiOhX,https://eth-mainnet.alchemyapi.io/v2/eaVcvbYPXbDYMl8tVhU9fJTdDQEuV-BZ
REACT_APP_ETH_NETWORK_ID=1
REACT_APP_ETH_TOKEN_ADDRESS=0x18aAA7115705e8be94bfFEBDE57Af9BFc265B998
REACT_APP_ETH_OWNER_WALLET=0xC7310a03e930DD659E15305ed7e1F5Df0F0426C5
REACT_APP_COMSTOCK_URL=
REACT_APP_COMSTOCK_URL=https://comstock.audius.co
REACT_APP_CLAIM_DISTRIBUTION_CONTRACT_ADDRESS=

REACT_APP_CACHE_PRUNE_MIN=250
Expand All @@ -30,9 +30,7 @@ REACT_APP_NOTIFICATION_URL=https://download.audius.co/whatsnew
REACT_APP_SCHEME=audius

REACT_APP_EXPLORE_CONTENT_URL=https://download.audius.co/static-resources/explore-content.json
REACT_APP_CREATOR_NODE_FALLBACKS=https://usermetadata.audius.co,https://creatornode.audius.co,https://creatornode2.audius.co,https://creatornode3.audius.co
REACT_APP_DISCOVERY_PROVIDER_FALLBACKS=https://discoveryprovider.audius.co,https://discoveryprovider2.audius.co,https://discoveryprovider3.audius.co
REACT_APP_S3_SERVICE_PROVIDER_OVERRIDE_URL=https://download.audius.co/static-resources/service-providers-production.json

REACT_APP_SENTRY_DSN=https://e26d2b01488f4b538ea235de6466c40a@sentry.io/1457231

Expand Down
4 changes: 1 addition & 3 deletions .env/.env.staging
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ REACT_APP_REGISTRY_ADDRESS=0x793373aBF96583d5eb71a15d86fFE732CD04D452
REACT_APP_WEB3_PROVIDER_URL=https://poa-gateway.staging.audius.co,https://sokol.poa.network/
REACT_APP_WEB3_NETWORK_ID=77

REACT_APP_ETH_REGISTRY_ADDRESS=0xE4D37F2dA0a2953f801c23e036D924595eE6d0c1
REACT_APP_ETH_REGISTRY_ADDRESS=0xe39b1cA04fc06c416c4eaBd188Cb1330b8FED781
REACT_APP_ETH_PROVIDER_URL=https://eth-ropsten.alchemyapi.io/v2/Y-vE_LXNPnKsbnmaXxAre7t_xI-PA6KU,https://eth-ropsten.alchemyapi.io/v2/sydBoAxCidDdGK2kX4HuSb0ZzcmesZmt
REACT_APP_ETH_NETWORK_ID=3
REACT_APP_ETH_TOKEN_ADDRESS=0x74f24429ec3708fc21381e017194A5711E93B751
Expand All @@ -28,9 +28,7 @@ REACT_APP_REACHABILITY_URL=https://general-admission.staging.audius.co/204
REACT_APP_SCHEME=audius

REACT_APP_EXPLORE_CONTENT_URL=https://download.staging.audius.co/static-resources/explore-content.json
REACT_APP_CREATOR_NODE_FALLBACKS=https://usermetadata.staging.audius.co,https://creatornode.staging.audius.co,https://creatornode2.staging.audius.co,https://creatornode3.staging.audius.co
REACT_APP_DISCOVERY_PROVIDER_FALLBACKS=https://discoveryprovider.staging.audius.co,https://discoveryprovider2.staging.audius.co,https://discoveryprovider3.staging.audius.co
REACT_APP_S3_SERVICE_PROVIDER_OVERRIDE_URL=https://download.audius.co/static-resources/service-providers-staging.json

REACT_APP_SENTRY_DSN=https://4b15a7a2f2e2459997408b39a0c4942c@sentry.io/1851611

Expand Down
12 changes: 6 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"version": "0.21.25",
"private": true,
"dependencies": {
"@audius/libs": "1.0.3",
"@audius/libs": "1.0.4",
"@audius/stems": "0.2.11",
"@optimizely/optimizely-sdk": "^4.0.0",
"@reduxjs/toolkit": "^1.3.2",
Expand Down
100 changes: 22 additions & 78 deletions src/services/AudiusBackend.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,6 @@ const DISCOVERY_PROVIDER_FALLBACKS = process.env
.REACT_APP_DISCOVERY_PROVIDER_FALLBACKS
? new Set(process.env.REACT_APP_DISCOVERY_PROVIDER_FALLBACKS.split(','))
: null
let CREATOR_NODE_FALLBACKS = process.env.REACT_APP_CREATOR_NODE_FALLBACKS
? new Set(process.env.REACT_APP_CREATOR_NODE_FALLBACKS.split(','))
: null
let CREATOR_NODE_GATEWAY_WHITELIST = process.env
.REACT_APP_CREATOR_NODE_FALLBACKS
? new Set(
process.env.REACT_APP_CREATOR_NODE_FALLBACKS.split(',').map(
node => `${node}/ipfs/`
)
)
: null
const S3_SERVICE_PROVIDER_OVERRIDE_URL =
process.env.REACT_APP_S3_SERVICE_PROVIDER_OVERRIDE_URL

const NATIVE_MOBILE = process.env.REACT_APP_NATIVE_MOBILE
const AUDIUS_ORIGIN = `${process.env.REACT_APP_PUBLIC_PROTOCOL}//${process.env.REACT_APP_PUBLIC_HOSTNAME}`
Expand Down Expand Up @@ -186,22 +173,12 @@ const processSearchResults = async ({

export const fetchCID = async (cid, creatorNodeGateways = [], cache = true) => {
await waitForLibsInit()
let allGateways
if (creatorNodeGateways.length === 0) {
allGateways = [...CREATOR_NODE_GATEWAY_WHITELIST]
} else {
allGateways = creatorNodeGateways
}
if (CREATOR_NODE_GATEWAY_WHITELIST) {
allGateways = allGateways.filter(gateway =>
CREATOR_NODE_GATEWAY_WHITELIST.has(gateway)
)
}
if (CIDCache.has(cid)) {
return CIDCache.get(cid)
}
try {
const image = await audiusLibs.File.fetchCID(cid, allGateways, () => {})
const image = await audiusLibs.File.fetchCID(
cid,
creatorNodeGateways,
() => {}
)
const url = URL.createObjectURL(image.data)
if (cache) CIDCache.add(cid, url)
return url
Expand Down Expand Up @@ -257,32 +234,29 @@ const preloadImage = async url => {
}

const fetchImageCID = async (cid, creatorNodeGateways = [], cache = true) => {
let allGateways = []
const primary = creatorNodeGateways[0]
if (primary) {
const rest = new Set(CREATOR_NODE_GATEWAY_WHITELIST)
rest.delete(primary)
allGateways = [primary, ...rest]
} else {
allGateways = [...CREATOR_NODE_GATEWAY_WHITELIST]
}

if (CIDCache.has(cid)) {
return CIDCache.get(cid)
}

// Attempt to fetch/load the image using the first creator node gateway
const firstImageUrl = `${allGateways[0]}${cid}`
const preloadedImageUrl = await preloadImage(firstImageUrl)
const primary = creatorNodeGateways[0]
if (primary) {
// Attempt to fetch/load the image using the first creator node gateway
const firstImageUrl = `${primary}${cid}`
const preloadedImageUrl = await preloadImage(firstImageUrl)

// If the image is loaded, add to cache and return
if (preloadedImageUrl && cache) CIDCache.add(cid, preloadedImageUrl)
if (preloadedImageUrl) return preloadedImageUrl
// If the image is loaded, add to cache and return
if (preloadedImageUrl && cache) CIDCache.add(cid, preloadedImageUrl)
if (preloadedImageUrl) return preloadedImageUrl
}

await waitForLibsInit()
// Else, race fetching of the image from all gateways & return the image url blob
try {
const image = await audiusLibs.File.fetchCID(cid, allGateways, () => {})
const image = await audiusLibs.File.fetchCID(
cid,
creatorNodeGateways,
() => {}
)
const url = URL.createObjectURL(image.data)
if (cache) CIDCache.add(cid, url)
return url
Expand Down Expand Up @@ -411,33 +385,6 @@ class AudiusBackend {
Utils = libsUtils
SanityChecks = libsSanityChecks

// get SP overrides from S3
let resp
if (S3_SERVICE_PROVIDER_OVERRIDE_URL) {
try {
resp = await Promise.race([
// this fetch returns a promise
(await fetch(S3_SERVICE_PROVIDER_OVERRIDE_URL)).json(),
Utils.wait(1000)
])
} catch (e) {
// do nothing here
}
}

// apply overrides to default whitelist values
if (resp && resp.data) {
const { creatorNodeWhitelist } = resp.data

// these whitelists are already defined, just override with values from s3
CREATOR_NODE_FALLBACKS = creatorNodeWhitelist
? new Set(creatorNodeWhitelist.split(','))
: null
CREATOR_NODE_GATEWAY_WHITELIST = creatorNodeWhitelist
? new Set(creatorNodeWhitelist.split(',').map(node => `${node}/ipfs/`))
: null
}

// initialize libs
let libsError = null
const { web3Error, web3Config } = await AudiusBackend.getWeb3Config()
Expand Down Expand Up @@ -465,7 +412,7 @@ class AudiusBackend {
window.dispatchEvent(event)

const sanityChecks = new SanityChecks(audiusLibs)
sanityChecks.run(CREATOR_NODE_FALLBACKS)
sanityChecks.run()
} catch (err) {
libsError = err.message
}
Expand Down Expand Up @@ -564,15 +511,12 @@ class AudiusBackend {

static async autoSelectCreatorNodes() {
return audiusLibs.ServiceProvider.autoSelectCreatorNodes(
/* numberOfNodes */ 3,
CREATOR_NODE_FALLBACKS
/* numberOfNodes */ 3
)
}

static async getSelectableCreatorNodes() {
return audiusLibs.ServiceProvider.getSelectableCreatorNodes(
CREATOR_NODE_FALLBACKS
)
return audiusLibs.ServiceProvider.getSelectableCreatorNodes()
}

static async getAccount(fromSource = false) {
Expand Down

0 comments on commit 303359e

Please sign in to comment.