From ba78fa34c359b97048b6d8cd529a021fef12af83 Mon Sep 17 00:00:00 2001 From: Alex Forshtat Date: Sun, 18 Sep 2022 16:41:35 +0200 Subject: [PATCH] OG-932: Fix private preferred relay event lookup (#904) * 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 --- dockers/config-sample/gsn-relay-config.json | 2 ++ packages/common/package.json | 1 - packages/deployer/src/deployUtils.ts | 3 +- packages/deployer/src/exportTask.ts | 29 +++++++++---------- .../test/provider/KnownRelaysManager.test.ts | 20 ++++++++----- packages/provider/src/KnownRelaysManager.ts | 14 +++++---- packages/relay/src/ReputationManager.ts | 2 +- 7 files changed, 40 insertions(+), 31 deletions(-) diff --git a/dockers/config-sample/gsn-relay-config.json b/dockers/config-sample/gsn-relay-config.json index f0db8a4d5..086b1a0bd 100644 --- a/dockers/config-sample/gsn-relay-config.json +++ b/dockers/config-sample/gsn-relay-config.json @@ -1,4 +1,6 @@ { + "url": "https://", + "workdir": "./app/data", "relayHubAddress": "", "managerStakeTokenAddress": "", "ownerAddress": "
", diff --git a/packages/common/package.json b/packages/common/package.json index 8cb6cddbf..44bedb462 100644 --- a/packages/common/package.json +++ b/packages/common/package.json @@ -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", diff --git a/packages/deployer/src/deployUtils.ts b/packages/deployer/src/deployUtils.ts index 7d50623e5..0720312b3 100644 --- a/packages/deployer/src/deployUtils.ts +++ b/packages/deployer/src/deployUtils.ts @@ -161,7 +161,8 @@ export async function printRelayInfo (hre: HardhatRuntimeEnvironment): Promise { - 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 diff --git a/packages/dev/test/provider/KnownRelaysManager.test.ts b/packages/dev/test/provider/KnownRelaysManager.test.ts index 8ac94baff..fa79e576b 100644 --- a/packages/dev/test/provider/KnownRelaysManager.test.ts +++ b/packages/dev/test/provider/KnownRelaysManager.test.ts @@ -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) @@ -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) }) diff --git a/packages/provider/src/KnownRelaysManager.ts b/packages/provider/src/KnownRelaysManager.ts index 1b8698124..65eaa38d6 100644 --- a/packages/provider/src/KnownRelaysManager.ts +++ b/packages/provider/src/KnownRelaysManager.ts @@ -49,13 +49,8 @@ export class KnownRelaysManager { } async getRelayInfoForManagers (): Promise { - 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 @@ -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 } diff --git a/packages/relay/src/ReputationManager.ts b/packages/relay/src/ReputationManager.ts index 6da6a21e4..7a380bef2 100644 --- a/packages/relay/src/ReputationManager.ts +++ b/packages/relay/src/ReputationManager.ts @@ -26,7 +26,7 @@ export interface ReputationManagerConfiguration { } const defaultReputationConfig: ReputationManagerConfiguration = { - initialReputation: 3, + initialReputation: 6, maximumReputation: 100, throttleReputation: 5, throttleDelayMs: 60000,