Skip to content

Commit b07b875

Browse files
feat: configurable fixed fee rate (#944)
1 parent 296e7e0 commit b07b875

File tree

7 files changed

+26
-4
lines changed

7 files changed

+26
-4
lines changed

src/BlockchainWriter/BlockchainWriter.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ export class BlockchainWriter {
4343
const db = await this.mongoClient.db()
4444

4545
const blockchainWriterCollection: Collection = db.collection('blockchainWriter')
46-
const blockchainInfoCollection: Collection = db.collection('blockchainInfo')
4746

4847
const exchangesMessaging = pick(['poetAnchorDownloaded', 'claimsDownloaded'], this.configuration.exchanges)
4948

src/BlockchainWriter/Controller.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export interface ControllerConfiguration {
1616
readonly poetVersion: number
1717
readonly maximumTransactionAgeInBlocks: number
1818
readonly bitcoinFeeEstimateMode: 'CONSERVATIVE' | 'ECONOMICAL'
19+
readonly bitcoinFeeRate: number
1920
}
2021

2122
export const convertLightBlockToEntry = (lightBlock: LightBlock): Entry => ({
@@ -149,6 +150,7 @@ export class Controller {
149150

150151
private anchorData = async (data: string) => {
151152
const { bitcoinCore } = this
153+
const { bitcoinFeeEstimateMode, bitcoinFeeRate } = this.configuration
152154
const logger = this.logger.child({ method: 'anchorData' })
153155

154156
const rawTransaction = await bitcoinCore.createRawTransaction([], { data })
@@ -160,14 +162,20 @@ export class Controller {
160162
'Got rawTransaction from Bitcoin Core',
161163
)
162164

165+
const fundRawTransactionOptions = {
166+
estimate_mode: bitcoinFeeRate === undefined ? bitcoinFeeEstimateMode : undefined,
167+
feeRate: bitcoinFeeRate,
168+
}
169+
163170
const fundedTransaction = await bitcoinCore.fundRawTransaction(
164171
rawTransaction,
165-
{ estimate_mode: this.configuration.bitcoinFeeEstimateMode },
172+
fundRawTransactionOptions,
166173
).catch(translateFundTransactionError)
167174

168175
logger.trace(
169176
{
170177
fundedTransaction,
178+
fundRawTransactionOptions,
171179
},
172180
'Got fundedTransaction from Bitcoin Core',
173181
)

src/BlockchainWriter/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ const blockchainWriter = new BlockchainWriter({
3434
bitcoinUsername: configuration.bitcoinUsername,
3535
bitcoinPassword: configuration.bitcoinPassword,
3636
bitcoinFeeEstimateMode: configuration.bitcoinFeeEstimateMode,
37+
bitcoinFeeRate: configuration.bitcoinFeeRate,
3738
exchanges: {
3839
anchorNextHashRequest: configuration.exchangeAnchorNextHashRequest,
3940
ipfsHashTxId: configuration.exchangeIpfsHashTxId,

src/Configuration.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ export interface Configuration extends LoggingConfiguration, BitcoinRPCConfigura
4242
readonly uploadClaimMaxAttempts: number
4343

4444
readonly bitcoinFeeEstimateMode: 'CONSERVATIVE' | 'ECONOMICAL'
45+
readonly bitcoinFeeRate: number
4546
}
4647

4748
export interface LoggingConfiguration {
@@ -103,6 +104,7 @@ export const DefaultConfiguration: Configuration = {
103104
purgeStaleTransactionsIntervalInSeconds: 600,
104105
maximumTransactionAgeInBlocks: 25,
105106
bitcoinFeeEstimateMode: 'CONSERVATIVE',
107+
bitcoinFeeRate: undefined,
106108

107109
healthIntervalInSeconds: 30,
108110
lowWalletBalanceInBitcoin: 1,

src/app.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ export async function app(localVars: any = {}) {
185185
bitcoinUsername: configuration.bitcoinUsername,
186186
bitcoinPassword: configuration.bitcoinPassword,
187187
bitcoinFeeEstimateMode: configuration.bitcoinFeeEstimateMode,
188+
bitcoinFeeRate: configuration.bitcoinFeeRate,
188189
exchanges: {
189190
anchorNextHashRequest: configuration.exchangeAnchorNextHashRequest,
190191
ipfsHashTxId: configuration.exchangeIpfsHashTxId,

src/index.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,16 @@ import * as Pino from 'pino'
55

66
const logger: Pino.Logger = Pino()
77

8+
process.on('unhandledRejection', (e) => {
9+
logger.fatal('unhandledRejection', e)
10+
process.exit()
11+
})
12+
13+
process.on('uncaughtException', (e) => {
14+
logger.fatal('uncaughtException', e)
15+
process.exit()
16+
})
17+
818
app()
919
.then(server => process.on('SIGINT', () => server.stop()))
10-
.catch(exception => logger.error({ exception }, 'server was unable to start'))
20+
.catch(exception => logger.fatal({ exception }, 'server was unable to start'))

typings/bitcoin-core.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ declare module 'bitcoin-core' {
6565
}
6666

6767
interface FundRawTransactionOptions {
68-
readonly estimate_mode: EstimateMode
68+
readonly estimate_mode?: EstimateMode
69+
readonly feeRate?: number
6970
}
7071

7172
interface FundRawTransactionResponse {

0 commit comments

Comments
 (0)