From b07b875e2cd6aa1474f5ae99e1b0a2feed4839a2 Mon Sep 17 00:00:00 2001 From: Lautaro Dragan Date: Wed, 5 Jun 2019 19:12:02 -0300 Subject: [PATCH] feat: configurable fixed fee rate (#944) --- src/BlockchainWriter/BlockchainWriter.ts | 1 - src/BlockchainWriter/Controller.ts | 10 +++++++++- src/BlockchainWriter/index.ts | 1 + src/Configuration.ts | 2 ++ src/app.ts | 1 + src/index.ts | 12 +++++++++++- typings/bitcoin-core.d.ts | 3 ++- 7 files changed, 26 insertions(+), 4 deletions(-) diff --git a/src/BlockchainWriter/BlockchainWriter.ts b/src/BlockchainWriter/BlockchainWriter.ts index 6f03fbe4..95a0e14a 100644 --- a/src/BlockchainWriter/BlockchainWriter.ts +++ b/src/BlockchainWriter/BlockchainWriter.ts @@ -43,7 +43,6 @@ export class BlockchainWriter { const db = await this.mongoClient.db() const blockchainWriterCollection: Collection = db.collection('blockchainWriter') - const blockchainInfoCollection: Collection = db.collection('blockchainInfo') const exchangesMessaging = pick(['poetAnchorDownloaded', 'claimsDownloaded'], this.configuration.exchanges) diff --git a/src/BlockchainWriter/Controller.ts b/src/BlockchainWriter/Controller.ts index 2ebe64e5..29ee6bfd 100644 --- a/src/BlockchainWriter/Controller.ts +++ b/src/BlockchainWriter/Controller.ts @@ -16,6 +16,7 @@ export interface ControllerConfiguration { readonly poetVersion: number readonly maximumTransactionAgeInBlocks: number readonly bitcoinFeeEstimateMode: 'CONSERVATIVE' | 'ECONOMICAL' + readonly bitcoinFeeRate: number } export const convertLightBlockToEntry = (lightBlock: LightBlock): Entry => ({ @@ -149,6 +150,7 @@ export class Controller { private anchorData = async (data: string) => { const { bitcoinCore } = this + const { bitcoinFeeEstimateMode, bitcoinFeeRate } = this.configuration const logger = this.logger.child({ method: 'anchorData' }) const rawTransaction = await bitcoinCore.createRawTransaction([], { data }) @@ -160,14 +162,20 @@ export class Controller { 'Got rawTransaction from Bitcoin Core', ) + const fundRawTransactionOptions = { + estimate_mode: bitcoinFeeRate === undefined ? bitcoinFeeEstimateMode : undefined, + feeRate: bitcoinFeeRate, + } + const fundedTransaction = await bitcoinCore.fundRawTransaction( rawTransaction, - { estimate_mode: this.configuration.bitcoinFeeEstimateMode }, + fundRawTransactionOptions, ).catch(translateFundTransactionError) logger.trace( { fundedTransaction, + fundRawTransactionOptions, }, 'Got fundedTransaction from Bitcoin Core', ) diff --git a/src/BlockchainWriter/index.ts b/src/BlockchainWriter/index.ts index 3cf62144..1a78672d 100644 --- a/src/BlockchainWriter/index.ts +++ b/src/BlockchainWriter/index.ts @@ -34,6 +34,7 @@ const blockchainWriter = new BlockchainWriter({ bitcoinUsername: configuration.bitcoinUsername, bitcoinPassword: configuration.bitcoinPassword, bitcoinFeeEstimateMode: configuration.bitcoinFeeEstimateMode, + bitcoinFeeRate: configuration.bitcoinFeeRate, exchanges: { anchorNextHashRequest: configuration.exchangeAnchorNextHashRequest, ipfsHashTxId: configuration.exchangeIpfsHashTxId, diff --git a/src/Configuration.ts b/src/Configuration.ts index 35c7f601..d66939c0 100644 --- a/src/Configuration.ts +++ b/src/Configuration.ts @@ -42,6 +42,7 @@ export interface Configuration extends LoggingConfiguration, BitcoinRPCConfigura readonly uploadClaimMaxAttempts: number readonly bitcoinFeeEstimateMode: 'CONSERVATIVE' | 'ECONOMICAL' + readonly bitcoinFeeRate: number } export interface LoggingConfiguration { @@ -103,6 +104,7 @@ export const DefaultConfiguration: Configuration = { purgeStaleTransactionsIntervalInSeconds: 600, maximumTransactionAgeInBlocks: 25, bitcoinFeeEstimateMode: 'CONSERVATIVE', + bitcoinFeeRate: undefined, healthIntervalInSeconds: 30, lowWalletBalanceInBitcoin: 1, diff --git a/src/app.ts b/src/app.ts index 9a3bf871..3f00ce3f 100644 --- a/src/app.ts +++ b/src/app.ts @@ -185,6 +185,7 @@ export async function app(localVars: any = {}) { bitcoinUsername: configuration.bitcoinUsername, bitcoinPassword: configuration.bitcoinPassword, bitcoinFeeEstimateMode: configuration.bitcoinFeeEstimateMode, + bitcoinFeeRate: configuration.bitcoinFeeRate, exchanges: { anchorNextHashRequest: configuration.exchangeAnchorNextHashRequest, ipfsHashTxId: configuration.exchangeIpfsHashTxId, diff --git a/src/index.ts b/src/index.ts index 710c1952..4011860d 100644 --- a/src/index.ts +++ b/src/index.ts @@ -5,6 +5,16 @@ import * as Pino from 'pino' const logger: Pino.Logger = Pino() +process.on('unhandledRejection', (e) => { + logger.fatal('unhandledRejection', e) + process.exit() +}) + +process.on('uncaughtException', (e) => { + logger.fatal('uncaughtException', e) + process.exit() +}) + app() .then(server => process.on('SIGINT', () => server.stop())) - .catch(exception => logger.error({ exception }, 'server was unable to start')) + .catch(exception => logger.fatal({ exception }, 'server was unable to start')) diff --git a/typings/bitcoin-core.d.ts b/typings/bitcoin-core.d.ts index 8c40ddef..6350cdd0 100644 --- a/typings/bitcoin-core.d.ts +++ b/typings/bitcoin-core.d.ts @@ -65,7 +65,8 @@ declare module 'bitcoin-core' { } interface FundRawTransactionOptions { - readonly estimate_mode: EstimateMode + readonly estimate_mode?: EstimateMode + readonly feeRate?: number } interface FundRawTransactionResponse {