Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gas optimisations #406

Merged
merged 1 commit into from
Oct 26, 2020
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
2 changes: 1 addition & 1 deletion src/balancer/PoolFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import jsonFactoryABI from '@oceanprotocol/contracts/artifacts/BFactory.json'
import { TransactionReceipt } from 'web3-core'

export class PoolFactory {
public GASLIMIT_DEFAULT = 5000000
public GASLIMIT_DEFAULT = 8000000
public web3: Web3 = null
public factoryABI: AbiItem | AbiItem[]
public factoryAddress: string
Expand Down
20 changes: 15 additions & 5 deletions src/datatokens/Datatokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,7 @@ export class DataTokens {
.createToken(metadataCacheUri, name, symbol, this.web3.utils.toWei(cap))
.send({
from: address,
gas: estGas + 1,
gasPrice: '3000000000'
gas: estGas + 1
})

let tokenAddress = null
Expand Down Expand Up @@ -167,8 +166,7 @@ export class DataTokens {
.mint(destAddress, this.web3.utils.toWei(amount))
.send({
from: address,
gas: estGas + 1,
gasPrice: '3000000000'
gas: estGas + 1
})

return trxReceipt
Expand Down Expand Up @@ -365,14 +363,26 @@ export class DataTokens {
})
if (!mpFeeAddress) mpFeeAddress = '0x0000000000000000000000000000000000000000'
try {
const estGas = await datatoken.methods
.startOrder(
consumer,
this.web3.utils.toWei(amount),
String(serviceId),
mpFeeAddress
)
.estimateGas(function (err, estGas) {
if (err) console.error(`ERROR: Datatokens : ${err}`)
return estGas
})

const trxReceipt = await datatoken.methods
.startOrder(
consumer,
this.web3.utils.toWei(amount),
String(serviceId),
mpFeeAddress
)
.send({ from: address, gas: 600000 })
.send({ from: address, gas: estGas + 1 })
return trxReceipt
} catch (e) {
this.logger.error(`ERROR: Failed to start order : ${e.message}`)
Expand Down
2 changes: 1 addition & 1 deletion src/exchange/FixedRateExchange.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export enum FixedRateCreateProgressStep {
ApprovingDatatoken
}

const DEFAULT_GAS_LIMIT = 300000
const DEFAULT_GAS_LIMIT = 1000000

export class OceanFixedRateExchange {
/** Ocean related functions */
Expand Down
33 changes: 27 additions & 6 deletions src/metadatacache/OnChainMetaDataCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { didZeroX, Logger } from '../utils'
// Using limited, compress-only version
// See https://github.com/LZMA-JS/LZMA-JS#but-i-dont-want-to-use-web-workers
import { LZMA } from 'lzma/src/lzma-c'

const DEFAULT_GAS_LIMIT = 1000000
/**
* Provides an interface with Metadata Cache.
* Metadata Cache provides an off-chain database store for metadata about data assets.
Expand Down Expand Up @@ -105,17 +105,24 @@ export class OnChainMetadataCache {
this.logger.error('ERROR: Missing DDOContract')
return null
}
let estGas
try {
/* const estGas = await this.DDOContract.methods
estGas = await this.DDOContract.methods
.create(didZeroX(did), flags, data)
.estimateGas(function (err, estGas) {
if (err) console.error('ERROR: OnChainMetadataCacheEstimateGas: ' + err)
if (err) {
// console.error('ERROR: OnChainMetadataCacheEstimateGas: ' + err)
return DEFAULT_GAS_LIMIT
}
return estGas
})
*/
} catch (e) {
estGas = DEFAULT_GAS_LIMIT
}
try {
const trxReceipt = await this.DDOContract.methods
.create(didZeroX(did), flags, data)
.send({ from: consumerAccount })
.send({ from: consumerAccount, gas: estGas + 1 })
return trxReceipt
} catch (e) {
this.logger.error(`ERROR: Failed to publish raw DDO : ${e.message}`)
Expand All @@ -141,10 +148,24 @@ export class OnChainMetadataCache {
this.logger.error('ERROR: Missing DDOContract')
return null
}
let estGas
try {
estGas = await this.DDOContract.methods
.update(didZeroX(did), flags, data)
.estimateGas(function (err, estGas) {
if (err) {
// console.error('ERROR: OnChainMetadataCacheEstimateGas: ' + err)
return DEFAULT_GAS_LIMIT
}
return estGas
})
} catch (e) {
estGas = DEFAULT_GAS_LIMIT
}
try {
const trxReceipt = await this.DDOContract.methods
.update(didZeroX(did), flags, data)
.send({ from: consumerAccount })
.send({ from: consumerAccount, gas: estGas + 1 })
return trxReceipt
} catch (e) {
this.logger.error(`ERROR: Failed to update raw DDO : ${e.message}`)
Expand Down