Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
9 changes: 9 additions & 0 deletions packages/ethereum-storage/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const config = {
retryDelay: 0,
safeGasPriceLimit: '500000000000',
transactionPollingTimeout: 300,
blockConfirmations: 2,
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this is ever used

Copy link
Member Author

@MantisClone MantisClone Mar 3, 2023

Choose a reason for hiding this comment

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

Fixed, see comment below. it's used now.

},
ipfs: {
defaultNode: {
Expand Down Expand Up @@ -85,6 +86,14 @@ export function getDefaultEthereumGasPrice(): BigNumber {
return BigNumber.from(process?.env?.GAS_PRICE_DEFAULT || config.ethereum.gasPriceDefault);
}

/**
* Retrieve from config the default number of block confirmations to wait before considering a transaction successful
* @returns the number of block confirmations
*/
export function getDefaultEthereumBlockConfirmations(): number {
Copy link
Contributor

Choose a reason for hiding this comment

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

same

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed. I called it as a fallback.

return config.ethereum.blockConfirmations;
}

/**
* Retrieve from config the time to wait between query retries
* @returns the query retry delay
Expand Down
17 changes: 14 additions & 3 deletions packages/ethereum-storage/src/ethereum-storage-ethers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { CurrencyTypes, LogTypes, StorageTypes } from '@requestnetwork/types';
import { requestHashSubmitterArtifact } from '@requestnetwork/smart-contracts';
import { EthereumTransactionSubmitter } from './ethereum-tx-submitter';
import { getCurrentTimestampInSecond, SimpleLogger } from '@requestnetwork/utils';
import { getDefaultEthereumBlockConfirmations } from './config';

export type GasDefinerProps = {
gasPriceMin?: BigNumber;
Expand All @@ -18,6 +19,7 @@ export type SubmitterProps = GasDefinerProps & {

type StorageProps = SubmitterProps & {
ipfsStorage: StorageTypes.IIpfsStorage;
blockConfirmations?: number;
};

export type StorageEventEmitter = TypedEmitter<{
Expand All @@ -31,12 +33,21 @@ export class EthereumStorageEthers implements StorageTypes.IStorageWrite {

private readonly network: CurrencyTypes.EvmChainName;
private readonly txSubmitter: EthereumTransactionSubmitter;

constructor({ network, signer, ipfsStorage, logger, gasPriceMin }: StorageProps) {
private readonly blockConfirmations: number | undefined;

constructor({
network,
signer,
ipfsStorage,
logger,
gasPriceMin,
blockConfirmations,
}: StorageProps) {
this.logger = logger || new SimpleLogger();
this.ipfsStorage = ipfsStorage;
this.network = network;
this.txSubmitter = new EthereumTransactionSubmitter({ network, signer, logger, gasPriceMin });
this.blockConfirmations = blockConfirmations;
}

async initialize(): Promise<void> {
Expand Down Expand Up @@ -75,7 +86,7 @@ export class EthereumStorageEthers implements StorageTypes.IStorageWrite {
this.logger.debug(`TX ${tx.hash} submitted, waiting for confirmation...`);

void tx
.wait()
.wait(this.blockConfirmations || getDefaultEthereumBlockConfirmations())
.then((receipt: providers.TransactionReceipt) => {
this.logger.debug(
`TX ${receipt.transactionHash} confirmed at block ${receipt.blockNumber}`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import { IConversionSettings } from '../../src/payment/settings';

/* eslint-disable @typescript-eslint/no-unused-expressions */
/* eslint-disable @typescript-eslint/await-thenable */
// eslint-disable-next-line no-magic-numbers
jest.setTimeout(10000);

const erc20ContractAddress = '0x9FBDa871d559710256a2502A2517b794B482Db40';
const feeAddress = '0xC5fdf4076b8F3A5357c5E395ab970B5B54098Fef';
Expand Down
6 changes: 6 additions & 0 deletions packages/request-node/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,9 @@ Default values correspond to the basic configuration used to run a server in a t
- `--headers` Custom headers to send with the API responses (as a stringified JSON object)
- Default value: `'{}'`
- Environment variable name: `$HEADERS`
`--blockConfirmations` The number of block confirmations to consider a transaction successful
- Default value: `2`
- Environment variable name: `$BLOCK_CONFIRMATIONS`
- `--lastBlockNumberDelay` The minimum delay between getLastBlockNumber calls to ethereum network
- Default value: `'10000'`
- Environment variable name: `$LAST_BLOCK_NUMBER_DELAY`
Expand Down Expand Up @@ -307,6 +310,9 @@ cd requestNetwork

#### 2. Install and build all the dependencies.

Install IPFS Kubo (go-ipfs)
https://docs.ipfs.tech/install/command-line/#install-ipfs-kubo

```bash
yarn install
yarn build
Expand Down
13 changes: 13 additions & 0 deletions packages/request-node/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const defaultValues: any = {
networkId: 0,
web3ProviderUrl: 'http://localhost:8545',
gasPriceMin: '1000000000', // one gwei
blockConfirmations: 2,
},
ipfs: {
host: 'localhost',
Expand Down Expand Up @@ -119,6 +120,18 @@ export function getGasPriceMin(): BigNumber | undefined {
return gasPriceMin && BigNumber.from(gasPriceMin);
}

/**
* Get the number of block confirmations to wait before considering a transaction successful
* @returns the number of block confirmations
*/
export function getBlockConfirmations(): number {
return (
(argv.blockConfirmations && Number(argv.blockConfirmations)) ||
(process.env.BLOCK_CONFIRMATIONS && Number(process.env.BLOCK_CONFIRMATIONS)) ||
defaultValues.ethereumStorage.ethereum.blockConfirmations
Copy link
Contributor

Choose a reason for hiding this comment

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

this is never set, see at the top of this file

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed.

);
}

/**
* Get host from command line argument, environment variables or default values to connect to IPFS gateway
* @returns the host of the IPFS gateway
Expand Down
1 change: 1 addition & 0 deletions packages/request-node/src/request/getStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export default class GetStatusHandler {
networkId: config.getStorageNetworkId(),
providerUrl,
retryDelay: config.getEthereumRetryDelay(),
blockConfirmations: config.getBlockConfirmations(),
},
ipfs: {
host: config.getIpfsHost(),
Expand Down
1 change: 1 addition & 0 deletions packages/request-node/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const startNode = async (): Promise<void> => {
IPFS timeout: ${config.getIpfsTimeout()}
Storage concurrency: ${config.getStorageConcurrency()}
Initialization storage path: ${config.getInitializationStorageFilePath()}
Storage block confirmations: ${config.getBlockConfirmations()}
`;

logger.info(serverMessage);
Expand Down
2 changes: 2 additions & 0 deletions packages/request-node/src/thegraph-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,14 @@ export class TheGraphRequestNode extends RequestNodeBase {
const signer = new NonceManager(wallet);
const ipfsStorage = getIpfsStorage(logger);
const gasPriceMin = config.getGasPriceMin();
const blockConfirmations = config.getBlockConfirmations();
const storage = new EthereumStorageEthers({
ipfsStorage,
signer,
network,
logger,
gasPriceMin,
blockConfirmations,
});
const dataAccess = new TheGraphDataAccess({
graphql: { url },
Expand Down