stacks-network / stacks-core

The Stacks blockchain implementation
https://docs.stacks.co
GNU General Public License v3.0
3.01k stars 667 forks source link

[Stacks Node] Automatically deduce fees for `satoshis_per_byte` in the config file via a side-car service #4073

Open jcnelson opened 11 months ago

jcnelson commented 11 months ago

N.B. I'm just copying the text of a reply by @AcrossFireX into a new issue. His original text is below.


In order to make best use of the PR that would mitigate this issue, we need a system of determining what the appropriate fee is and also when to make an update to the config file so this does not need to be manually done by miners each step of the way as fees change. This can be done in a few steps that can be done by a script run periodically within cron.

  1. Make an API request to a destination to get the latest fee estimation, this may be an electrum server or alternative endpoint that has the appropriate data.
  2. Store that result as a variable
  3. Use sed in bash to update the miner config file to have the appropriate value.

Once those are done, the manual process of updating is complete and the miner should not have to do anything to keep up to date with fee market dynamics.

Here is an example script that does this (this may need to be modified for your particular scenario).

#!/bin/bash
#REPLACE THIS PATH WITH YOUR MINER CONFIG FILE
MINER_CONFIG=/var/tmp/config

fee_estimate=`curl https://api.blockcypher.com/v1/btc/main | grep high_fee_per_kb | awk -F ':' '{print $2}' | cut -d',' -f 1 | xargs`

sed -i "s/satoshis_per_byte =.*/satoshis_per_byte = ${fee_estimate}/g" $MINER_CONFIG
echo "fee estimate updated"

Users may want to modify the endpoint used for fee estimates to use their own node and also may want to add additional logic to maybe only update the fees if its a significant enough change from what they already had set, but this may be helpful nonetheless

Originally posted by @AcrossfireX in https://github.com/stacks-network/stacks-core/issues/4047#issuecomment-1816890800

tippenein commented 11 months ago
#!/bin/bash
MINER_CONFIG="<Path to your config>"

if [ ! -f "$MINER_CONFIG" ]; then
    echo "Error: File not found at $MINER_CONFIG"
    exit 1
fi

fee_estimate=$(curl https://api.blockcypher.com/v1/btc/main | grep high_fee_per_kb | awk -F ':' '{print $2}' | cut -d',' -f 1 | xargs)

echo "Fee Estimate: ${fee_estimate}"
echo "Miner Config Path: ${MINER_CONFIG}"

sed -i -e "s|satoshis_per_byte*=.*|satoshis_per_byte = ${fee_estimate}|g" "$MINER_CONFIG"
echo "fee estimate updated"

This works fine for me. I had to give sed the -e flag, and mess with the | vs / but it works.

I'm curious what the goal of this issue is broadly. Is it a documentation task to let people know they can set this up with cron themselves? Or is it for a greater, more integrated solution within the miners themselves?

ldiego08 commented 11 months ago

Is it a hard requirement for this to be a script? I understand a script is far easier, but having to set it up through cron doesn't sound too convenient DX-wise. A CLI command with a scheduled job could be more appropriate (and better for logging.) Perhaps a new command into blockstack_cli.rs or a separate config CLI like stacks-config --watch-fees.

AcrossfireX commented 11 months ago

My initial goal of this issue was just to close the loop on the fact that even though we now will have the ability to automatically update miner fees when the configuration is changed as described in Issue #4047, there is no way to determine automatically what those fees should be and update the configuration file. To better represent the issue I just wrote a script that could fill the gap that people could use. Maybe it would be best to just include this as part of the documentation if it has to be implemented separately by miners, but if someone has a better idea of how to integrate this into existing setups I think that would obviously be better. By no means does it need to be a script IMO @ldiego08

jcnelson commented 11 months ago

Made this script a little bit more robust: https://github.com/stacks-network/stacks-core/pull/4077

jcnelson commented 11 months ago

@tippenein @AcrossfireX @ldiego08 The idea is that the miner would run the side-car alongside their miner (e.g. in the same VM, container, pod, whatever) and it would continuously determine the new fee rate and write the new value to the config file, so the miner would automatically pick up the appropriate fee rate. Each miner can do what they want (and sophisticated miners will likely want something in-house anyway), but this side-car just needs to be powerful enough to make this happen in a reliable manner.