Skip to content

Commit

Permalink
OG-932: Fix private preferred relay event lookup (#904)
Browse files Browse the repository at this point in the history
* OG-932: Fix private preferred relay event lookup

* Fix: Initial reputation is below throttle so all Paymasters start as throttled

* Update deployment process

1. Remove ABI from generated 'gsn-networks.json' file as unnecessary
2. Add non-optional fields to sample 'gsn-relay-config.json'
3. Print to console a link to our new Relay Server Regsitration Web Tool

* Remove empty types require
  • Loading branch information
forshtat authored Sep 18, 2022
1 parent 42aeef3 commit ba78fa3
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 31 deletions.
2 changes: 2 additions & 0 deletions dockers/config-sample/gsn-relay-config.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{
"url": "https://<your relay server public URL>",
"workdir": "./app/data",
"relayHubAddress": "<deployed relay hub>",
"managerStakeTokenAddress": "<erc20 token address for staking>",
"ownerAddress": "<address of owner account>",
Expand Down
1 change: 0 additions & 1 deletion packages/common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
"@metamask/eth-sig-util": "^4.0.1",
"@types/bn.js": "^5.1.0",
"@types/semver": "^7.3.4",
"@types/web3": "1.2.2",
"axios": "^0.21.1",
"bn.js": "^5.2.0",
"bignumber.js": "^9.0.2",
Expand Down
3 changes: 2 additions & 1 deletion packages/deployer/src/deployUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,8 @@ export async function printRelayInfo (hre: HardhatRuntimeEnvironment): Promise<v
maxFeePerGas: 1e12,
ethereumNodeUrl: network.url
}, null, 2)))
console.log(chalk.white('Relayer register:'))
console.log(chalk.white('Register your Relay Server:'))
console.log(chalk.grey('Go to https://relays.opengsn.org/ and register your relay server with the web app, or use the following CLI command:'))
console.log(chalk.grey(`gsn relayer-register -m $SECRET --network ${network.url} --relayUrl https://${hre.hardhatArguments.network}.v3.opengsn.org/v3 --token ${stakingTokenAddress} --stake ${stakingTokenValue} --wrap`))
}

Expand Down
29 changes: 14 additions & 15 deletions packages/deployer/src/exportTask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,22 @@ task('export', 'Export all GSN-deployed networks')
const exportNetworks = require(tmpExportFile)
// export is an hash of arrays { 3: [ { chainId: 3, ... } ] }
const networks = Object.keys(exportNetworks).reduce((set, chainId) => {
let globalChainInfo = globalChainList[chainId]
const globalChainInfo = globalChainList[chainId]
if (globalChainInfo == null) {
if (chainId === '421612') {
// special case... nitro doesn't appear in the global list.
globalChainInfo = {
name: 'Arbitrum Nitro Devnet'
}
} else {
throw new Error(`Chain ${chainId} not found in ${chainListUrl}`)
}
throw new Error(`Chain ${chainId} not found in ${chainListUrl}`)
}
const chainArray = exportNetworks[chainId].map((chain: any) => ({
title: globalChainInfo.name,
symbol: globalChainInfo.nativeCurrency?.symbol,
explorer: globalChainInfo.explorers?.[0].url,
...chain
}))
const chainArray = exportNetworks[chainId].map((chain: any) => {
const ret = {
title: globalChainInfo.name,
symbol: globalChainInfo.nativeCurrency?.symbol,
explorer: globalChainInfo.explorers?.[0].url,
...chain
}
for (const contract of Object.values(ret.contracts)) {
delete (contract as any).abi
}
return ret
})
return {
...set,
[chainId]: chainArray
Expand Down
20 changes: 13 additions & 7 deletions packages/dev/test/provider/KnownRelaysManager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,13 +171,17 @@ contract('KnownRelaysManager', function (
assert.equal(actual[3], activeRelayServerRegistered)
})

it('should not contain relay managers from chain with valid relay URL',
it('should not contain relay managers from chain with invalid relay URL',
async function () {
const id = (await snapshot()).result
const relayRegistrar = await RelayRegistrar.at(await relayHub.getRelayRegistrar())
const knownRelaysManager = new KnownRelaysManager(contractInteractor, logger, config)
let infos = await knownRelaysManager.getRelayInfoForManagers()
const actual = infos.map(info => info.relayManager)
await knownRelaysManager.refresh()
let infos = await knownRelaysManager.getRelaysShuffledForTransaction()
assert.equal(infos[0].length, 0)
assert.equal(infos[1].length, 4)
assert.equal(infos[2].length, 0)
const actual = infos[1].map((info: any) => info.relayManager)
assert.equal(actual.length, 4)
// creating garbage registrations and breaking accounts' roles in other tests - only testing if URL valid here
await stake(testToken, stakeManager, relayHub, workerRelayWorkersAdded, owner)
Expand All @@ -189,10 +193,12 @@ contract('KnownRelaysManager', function (
await relayRegistrar.registerRelayServer(relayHub.address, splitRelayUrlForRegistrar(''), { from: workerRelayWorkersAdded })
await relayRegistrar.registerRelayServer(relayHub.address, splitRelayUrlForRegistrar('invalid'), { from: workerTransactionRelayed })
await relayRegistrar.registerRelayServer(relayHub.address, splitRelayUrlForRegistrar('https://www.example.com'), { from: workerNotActive })
infos = await knownRelaysManager.getRelayInfoForManagers()
assert.equal(infos.length, 5)
assert.equal(infos[4].relayManager, workerNotActive)
assert.equal(infos[4].relayUrl, 'https://www.example.com')
await knownRelaysManager.refresh()
infos = await knownRelaysManager.getRelaysShuffledForTransaction()
assert.equal(infos[1].length, 5)
const exampleCom = infos[1].find(it => it.relayUrl === 'https://www.example.com')
assert.isNotNull(exampleCom)
assert.equal((exampleCom as any).relayManager, workerNotActive)
// undo all garbage registrations
await revert(id)
})
Expand Down
14 changes: 8 additions & 6 deletions packages/provider/src/KnownRelaysManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,8 @@ export class KnownRelaysManager {
}

async getRelayInfoForManagers (): Promise<RegistrarRelayInfo[]> {
let relayInfos: RegistrarRelayInfo[] = await this.contractInteractor.getRegisteredRelays()
const relayInfos: RegistrarRelayInfo[] = await this.contractInteractor.getRegisteredRelays()
this.logger.info(`fetchRelaysAdded: found ${relayInfos.length} relays`)
const queriedRelaysSize = relayInfos.length
relayInfos = relayInfos.filter(it => validateRelayUrl(it.relayUrl))
if (relayInfos.length < queriedRelaysSize) {
this.logger.info(`fetchRelaysAdded: filtered out ${queriedRelaysSize - relayInfos.length} relays without a public URL or a public URL that is not valid`)
}

const blacklistFilteredRelayInfos = relayInfos.filter((info: RegistrarRelayInfo) => {
const isHostBlacklisted = this.config.blacklistedRelays.find(relay => info.relayUrl.toLowerCase().includes(relay.toLowerCase())) != null
Expand Down Expand Up @@ -91,6 +86,13 @@ export class KnownRelaysManager {
})
sortedRelays[1] = shuffle(relaysWithoutFailures)
sortedRelays[2] = shuffle(relaysWithFailures)
for (let i = 0; i < sortedRelays.length; i++) {
const queriedRelaysSize = sortedRelays[i].length
sortedRelays[i] = sortedRelays[i].filter(it => validateRelayUrl(it.relayUrl))
if (sortedRelays[i].length < queriedRelaysSize) {
this.logger.info(`getRelaysShuffledForTransaction (${i}): filtered out ${queriedRelaysSize - sortedRelays[i].length} relays without a public URL or a public URL that is not valid`)
}
}
return sortedRelays
}

Expand Down
2 changes: 1 addition & 1 deletion packages/relay/src/ReputationManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export interface ReputationManagerConfiguration {
}

const defaultReputationConfig: ReputationManagerConfiguration = {
initialReputation: 3,
initialReputation: 6,
maximumReputation: 100,
throttleReputation: 5,
throttleDelayMs: 60000,
Expand Down

0 comments on commit ba78fa3

Please sign in to comment.