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

feat: configurable fixed fee rate #944

Merged
merged 3 commits into from
Jun 5, 2019
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
1 change: 0 additions & 1 deletion src/BlockchainWriter/BlockchainWriter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
10 changes: 9 additions & 1 deletion src/BlockchainWriter/Controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 => ({
Expand Down Expand Up @@ -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 })
Expand All @@ -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',
)
Expand Down
1 change: 1 addition & 0 deletions src/BlockchainWriter/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions src/Configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export interface Configuration extends LoggingConfiguration, BitcoinRPCConfigura
readonly uploadClaimMaxAttempts: number

readonly bitcoinFeeEstimateMode: 'CONSERVATIVE' | 'ECONOMICAL'
readonly bitcoinFeeRate: number
}

export interface LoggingConfiguration {
Expand Down Expand Up @@ -103,6 +104,7 @@ export const DefaultConfiguration: Configuration = {
purgeStaleTransactionsIntervalInSeconds: 600,
maximumTransactionAgeInBlocks: 25,
bitcoinFeeEstimateMode: 'CONSERVATIVE',
bitcoinFeeRate: undefined,

healthIntervalInSeconds: 30,
lowWalletBalanceInBitcoin: 1,
Expand Down
1 change: 1 addition & 0 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
12 changes: 11 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'))
3 changes: 2 additions & 1 deletion typings/bitcoin-core.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ declare module 'bitcoin-core' {
}

interface FundRawTransactionOptions {
readonly estimate_mode: EstimateMode
readonly estimate_mode?: EstimateMode
readonly feeRate?: number
}

interface FundRawTransactionResponse {
Expand Down