Get Current Fee Percentiles returns empty array after mining a block with no transactions

I am working on updating Azle’s basic bitcoin example and I am noticing what seems to me to be an odd behavior with bitcoin_get_current_fee_percentiles.

We are working on the regtest network, so as per examples/rust/basic_bitcoin/src/basic_bitcoin/src/bitcoin_wallet.rs at 113f8b5a87b7bda116c16558c5da664eec9bb01f · dfinity/examples · GitHub the initial length is in fact 0 before there are any transactions. So that’s as I would expect.

After I add the first transaction (in block 102 for example) the length of the fee percentiles array does fill up to the full 101, but if I mine another block (103) and if that block has no transactions in it then the fee percentiles will reset back to a length of 0. Is that the expected behavior?

In summary, after I mine the block with the first transaction in it the current fee percentiles look like they have the right number of entries, and as long as I continue to mine blocks with transactions in them that continues to be the case, but as soon as I mine a block with no transactions in it it resets back to length 0.

1 Like

@bdemann Thanks for reporting. What you’re describing sounds like it could be a bug. Let me try to reproduce and get back to you.

1 Like

I was unable to reproduce the behavior you’re mentioning. Can you share the commands you’re using to generate blocks and at what point between those commands you’re creating the transaction?

1 Like

Actually, I believe I figured out the issue you’re running into. Do you mind applying this patch to dfx.json in the example project and see if it fixes your problem?

--- a/rust/basic_bitcoin/dfx.json
+++ b/rust/basic_bitcoin/dfx.json
@@ -16,6 +16,7 @@
   },
   "defaults": {
     "bitcoin": {
+      "canister_init_arg": "(record { stability_threshold = 1000 : nat; network = variant { regtest }; blocks_source = principal \"aaaaa-aa\"; fees = record { get_utxos_base = 0 : nat; get_utxos_cycles_per_ten_instructions = 0 : nat; get_utxos_maximum = 0 : nat; get_balance = 0 : nat; get_balance_maximum = 0 : nat; get_current_fee_percentiles = 0 : nat; get_current_fee_percentiles_maximum = 0 : nat;  send_transaction_base = 0 : nat; send_transaction_per_byte = 0 : nat; }; syncing = variant { enabled }; api_access = variant { enabled }; disable_api_if_not_fully_synced = variant { enabled }})",
       "enabled": true,
       "nodes": [
         "127.0.0.1:18444"
1 Like

That patch fixed it!

Good to know! We’ll fix this in newer versions of dfx. Thanks for reporting it.