Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
9120681
chore: use ethers for ethereum-storage
benjlevesque Mar 26, 2021
b71a42a
retry mechanism & integration
benjlevesque Apr 7, 2021
17e269a
smart-contract-manager tests
benjlevesque Apr 7, 2021
7d300a4
wallet
benjlevesque Apr 7, 2021
314c9f3
layers
benjlevesque Apr 7, 2021
def4881
more web3 clean
benjlevesque Apr 7, 2021
6454888
ethers 5.4.1
benjlevesque Jul 8, 2021
8ea690e
fix tests
benjlevesque Aug 19, 2021
9bdf188
attempt runInBand
benjlevesque Aug 19, 2021
ff6608f
remove test helpers
benjlevesque Aug 19, 2021
9ec6af5
chai
benjlevesque Sep 22, 2021
2f8b580
ts 4.4.3, ethers 5.4.7, test fixes
benjlevesque Sep 22, 2021
5c50646
ts 4.4.3
benjlevesque Sep 22, 2021
eca3d98
fix test
benjlevesque Sep 22, 2021
f9b8e37
fix
benjlevesque Sep 22, 2021
e81cb67
Merge branch 'master' into eth-storage-ethers
benjlevesque Oct 22, 2021
584a82d
fix wrong merge
benjlevesque Oct 22, 2021
4806916
try ethers 5.5.1
benjlevesque Oct 22, 2021
1028ec8
fix integration tests
benjlevesque Oct 22, 2021
33e6dee
chore: ws lib <= 7.4.6
yomarion Oct 22, 2021
028a22a
4.4.4
benjlevesque Oct 22, 2021
a237c8c
feat: enable custom TheGraph client options (#643)
benjlevesque Oct 22, 2021
515da56
fix(http-data-access): do not throw in setTimeout (#644)
alexandre-abrioux Oct 22, 2021
617ba0e
chore: typescript 4.4.4 (#647)
benjlevesque Oct 22, 2021
6c652c1
Merge branch 'master' into eth-storage-ethers
benjlevesque Oct 22, 2021
fc7c43a
forgot 1 package
benjlevesque Oct 22, 2021
d95173d
remove transactionPollingTimeout
benjlevesque Oct 22, 2021
dbcc8e2
wait for confirmation
benjlevesque Oct 22, 2021
9ba0ad9
wait for confirmation
benjlevesque Oct 22, 2021
743dad8
rewrite helper
benjlevesque Oct 22, 2021
05e10b8
Merge remote-tracking branch 'origin/master' into eth-storage-ethers
benjlevesque Dec 1, 2021
0e17c8e
Merge branch 'master' into eth-storage-ethers
benjlevesque Dec 2, 2021
e26c093
remove web3-utils
benjlevesque Dec 2, 2021
ba6eeb7
bump ganache
benjlevesque Dec 2, 2021
c80b5f6
Revert "bump ganache"
benjlevesque Dec 2, 2021
642886f
runInBand
benjlevesque Dec 2, 2021
e8d024f
remove runInBand
benjlevesque Dec 2, 2021
0e63f26
misc
benjlevesque Dec 2, 2021
84f953b
test fixes
benjlevesque Dec 2, 2021
4710326
revert gas price change
benjlevesque Dec 2, 2021
06808ab
comments
benjlevesque Dec 7, 2021
3bdc5ac
Merge remote-tracking branch 'origin/master' into eth-storage-ethers
benjlevesque Dec 7, 2021
ef05632
Merge branch 'master' into eth-storage-ethers
benjlevesque Dec 8, 2021
0041d4e
remove comment
benjlevesque Dec 7, 2021
6f63768
revert config change & fix type
benjlevesque Dec 9, 2021
43c4104
Merge branch 'master' into eth-storage-ethers
benjlevesque Dec 9, 2021
b391c45
increase timeout
benjlevesque Dec 9, 2021
cd0a4c9
Merge branch 'master' into eth-storage-ethers
alexandre-abrioux Dec 9, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,8 @@
"prettier": "2.2.1",
"remap-istanbul": "0.13.0",
"typescript": "4.4.4"
},
"resolutions": {
"**/ws": "<=7.4.6"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ export default class AnyToErc20ProxyPaymentNetwork extends Erc20FeeProxyPaymentN
if (!currenciesWithConversionOracles[network]) {
throw Error(`network ${network} not supported`);
}
const supportedErc20: string[] = currenciesWithConversionOracles[network][RequestLogicTypes.CURRENCY.ERC20];
const supportedErc20: string[] =
currenciesWithConversionOracles[network][RequestLogicTypes.CURRENCY.ERC20];

for (const address of creationParameters.acceptedTokens) {
if (!supportedErc20.includes(address.toLowerCase())) {
Expand Down
8 changes: 4 additions & 4 deletions packages/docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@
"gen:code2md": "aurelius 'docs/**/*'"
},
"dependencies": {
"@docusaurus/core": "2.0.0-alpha.72",
"@docusaurus/preset-classic": "2.0.0-alpha.72",
"@docusaurus/theme-live-codeblock": "2.0.0-alpha.72",
"@docusaurus/utils": "2.0.0-alpha.72",
"@docusaurus/core": "2.0.0-beta.3",
"@docusaurus/preset-classic": "2.0.0-beta.3",
"@docusaurus/theme-live-codeblock": "2.0.0-beta.3",
"@docusaurus/utils": "2.0.0-beta.3",
"@metamask/contract-metadata": "1.25.0",
"@requestnetwork/payment-processor": "0.37.0",
"@requestnetwork/request-client.js": "0.39.0",
Expand Down
7 changes: 1 addition & 6 deletions packages/ethereum-storage/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,9 @@
"keyv": "4.0.3",
"shelljs": "0.8.4",
"tslib": "2.3.1",
"web3-eth": "1.3.6",
"web3-utils": "1.3.6",
"yargs": "16.2.0"
},
"devDependencies": {
"@openzeppelin/test-helpers": "0.5.6",
"@truffle/hdwallet-provider": "1.2.3",
"@types/bluebird": "3.5.33",
"@types/jest": "26.0.13",
"@types/keyv": "3.1.1",
Expand All @@ -69,8 +65,7 @@
"source-map-support": "0.5.19",
"ts-jest": "26.3.0",
"ts-node": "9.0.0",
"typescript": "4.4.4",
"web3-providers-http": "1.3.6"
"typescript": "4.4.4"
},
"gitHead": "6155223cfce769e48ccae480c510b35b4f54b4d0"
}
30 changes: 10 additions & 20 deletions packages/ethereum-storage/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,15 @@ import { BigNumber } from 'ethers';

// This contains default values used to use Ethereum Network and IPFS
// if information are not provided by the user
const config: any = {
const defaultNode: StorageTypes.IIpfsGatewayConnection = {
host: 'localhost',
port: 5001,
protocol: StorageTypes.IpfsGatewayProtocol.HTTP,
timeout: 30000,
};
const config = {
ethereum: {
default: 'private',
default: 'private' as const,
gasPriceDefault: '100000000000',
maxRetries: 5,
nodeUrlDefault: {
Expand All @@ -16,26 +22,17 @@ const config: any = {
},
retryDelay: 0,
safeGasPriceLimit: '500000000000',
transactionPollingTimeout: 300,
},
ipfs: {
defaultNode: {
host: 'localhost',
port: 5001,
protocol: 'http',
timeout: 30000,
},
defaultNode,
errorHandling: {
delayBetweenRetries: 500,
maxRetries: 3,
},
expectedBootstrapNodes: [
'/dns4/ipfs-bootstrap.request.network/tcp/4001/ipfs/QmaSrBXFBaupfeGMTuigswtKtsthbVaSonurjTV967Fdxx',

'/dns4/ipfs-bootstrap-2.request.network/tcp/4001/ipfs/QmYdcSoVNU1axgSnkRAyHtwsKiSvFHXeVvRonGCAV9LVEj',

'/dns4/ipfs-2.request.network/tcp/4001/ipfs/QmPBPgTDVjveRu6KjGVMYixkCSgGtVyV8aUe6wGQeLZFVd',

'/dns4/ipfs-survival.request.network/tcp/4001/ipfs/Qmb6a5DH45k8JwLdLVZUhRhv1rnANpsbXjtsH41esGhNCh',
],
maxIpfsReadRetry: 1,
Expand Down Expand Up @@ -69,7 +66,7 @@ export function getDefaultEthereumProvider(): string {
* @returns the url to connect to the network
*/
export function getDefaultEthereumProviderTimeout(): number {
return config.ethereum.nodeUrlDefault[config.ethereum.default].timeout;
return config.ethereum.nodeUrlDefault.private.timeout;
}

/**
Expand Down Expand Up @@ -160,10 +157,3 @@ export function getIpfsExpectedBootstrapNodes(): string[] {
export function getMaxIpfsReadRetry(): number {
return config.ipfs.maxIpfsReadRetry;
}

/**
* Retrieve from config the amount of time to wait before a transaction is considered failed
*/
export function getTransactionPollingTimeout(): number {
return config.ethereum.transactionPollingTimeout;
}
24 changes: 10 additions & 14 deletions packages/ethereum-storage/src/ethereum-blocks.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { LogTypes, StorageTypes } from '@requestnetwork/types';
import Utils from '@requestnetwork/utils';
import { providers } from 'ethers';

/**
* Manages every info linked to the ethereum blocks (blockNumber, blockTimestamp, confirmations ... )
*/
export default class EthereumBlocks {
// 'web3-eth' object
public eth: any;
public provider: providers.Provider;

/**
* Gets last block number
Expand Down Expand Up @@ -43,26 +43,22 @@ export default class EthereumBlocks {

/**
* Constructor
* @param eth eth object from web3
* @param provider eth object from web3
* @param firstSignificantBlockNumber all the block before this one will be ignored
* @param getLastBlockNumberMinDelay the minimum delay to wait between fetches of lastBlockNumber
*/
public constructor(
eth: any,
provider: providers.Provider,
firstSignificantBlockNumber: number,
retryDelay: number,
maxRetries: number,
getLastBlockNumberMinDelay = 0,
logger?: LogTypes.ILogger,
) {
this.eth = eth;

this.provider = provider;
this.firstSignificantBlockNumber = firstSignificantBlockNumber;

this.getLastBlockNumberMinDelay = getLastBlockNumberMinDelay;

this.logger = logger || new Utils.SimpleLogger();

// Get retry parameter values from config
this.retryDelay = retryDelay;
this.maxRetries = maxRetries;
Expand All @@ -73,7 +69,7 @@ export default class EthereumBlocks {
Utils.retry(
() => {
this.logger.debug(`Getting last block number`, ['ethereum', 'ethereum-blocks']);
return this.eth.getBlockNumber();
return this.provider.getBlockNumber();
},
{
maxRetries: this.maxRetries,
Expand All @@ -97,7 +93,7 @@ export default class EthereumBlocks {

// if we don't know the information, let's get it
// Use Utils.retry to rerun if getBlock fails
const block = await Utils.retry((bn: number) => this.eth.getBlock(bn), {
const block = await Utils.retry((bn: number) => this.provider.getBlock(bn), {
maxRetries: this.maxRetries,
retryDelay: this.retryDelay,
})(blockNumber);
Expand Down Expand Up @@ -193,9 +189,9 @@ export default class EthereumBlocks {
* @param blockNumber The block number
* @returns An Ethereum block
*/
public async getBlock(blockNumber: number | string): Promise<any> {
return Utils.retry(this.eth.getBlock, {
context: this.eth,
public async getBlock(blockNumber: number | string): Promise<providers.Block> {
return Utils.retry(this.provider.getBlock, {
context: this.provider,
maxRetries: this.maxRetries,
retryDelay: this.retryDelay,
})(blockNumber);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,11 @@ async function getIpfsContent(

// Check if the declared size is higher or equal to the size of the actual file
// If the declared size is higher, it's not considered as a problem since it means the hash submitter has paid a bigger fee than he had to
if (!ipfsObject || ipfsObject.ipfsSize > contentSizeDeclared) {
if (
!ipfsObject ||
Number.isNaN(contentSizeDeclared) ||
ipfsObject.ipfsSize > contentSizeDeclared
) {
logger.info(`Incorrect declared size for hash: ${ethereumEntry.hash}`, ['ipfs']);

// No need to retry to find this hash
Expand Down
10 changes: 4 additions & 6 deletions packages/ethereum-storage/src/ethereum-storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ export default class EthereumStorage implements StorageTypes.IStorage {
*/
public constructor(
externalBufferUrl: string,
ipfsGatewayConnection?: StorageTypes.IIpfsGatewayConnection,
web3Connection?: StorageTypes.IWeb3Connection,
ipfsGatewayConnection: StorageTypes.IIpfsGatewayConnection,
web3Connection: StorageTypes.IWeb3Connection,
{
getLastBlockNumberDelay,
logger,
Expand Down Expand Up @@ -120,7 +120,7 @@ export default class EthereumStorage implements StorageTypes.IStorage {
try {
await this.smartContractManager.checkWeb3ProviderConnection(WEB3_PROVIDER_TIMEOUT);
} catch (error) {
throw Error(`Ethereum node is not accessible: ${error}`);
throw new Error(`Ethereum node is not accessible: ${error}`);
}

// check if contracts are deployed on ethereum
Expand Down Expand Up @@ -380,9 +380,7 @@ export default class EthereumStorage implements StorageTypes.IStorage {
public async getData(
options?: StorageTypes.ITimestampBoundaries,
): Promise<StorageTypes.IEntriesWithLastTimestamp> {
const contentDataIdAndMeta = await this.getContentAndDataId(options);

return contentDataIdAndMeta;
return this.getContentAndDataId(options);
}

/**
Expand Down
Loading