@@ -154,6 +154,44 @@ pub fn make_bitcoin_indexer(
154
154
burnchain_indexer
155
155
}
156
156
157
+ pub fn get_satoshis_per_byte ( config : & Config ) -> u64 {
158
+ match config. get_burnchain_config ( ) {
159
+ Ok ( s) => s. satoshis_per_byte ,
160
+ Err ( _) => {
161
+ info ! ( "No config found. Using previous configuration." ) ;
162
+ config. burnchain . satoshis_per_byte
163
+ }
164
+ }
165
+ }
166
+
167
+ #[ cfg( test) ]
168
+ mod tests {
169
+ use crate :: config:: DEFAULT_SATS_PER_VB ;
170
+
171
+ use super :: * ;
172
+ use std:: env:: temp_dir;
173
+ use std:: fs:: File ;
174
+ use std:: io:: Write ;
175
+
176
+ #[ test]
177
+ fn test_get_satoshis_per_byte ( ) {
178
+ let dir = temp_dir ( ) ;
179
+ let file_path = dir. as_path ( ) . join ( "config.toml" ) ;
180
+
181
+ let mut config = Config :: default ( ) ;
182
+
183
+ let satoshis_per_byte = get_satoshis_per_byte ( & config) ;
184
+ assert_eq ! ( satoshis_per_byte, DEFAULT_SATS_PER_VB ) ;
185
+
186
+ let mut file = File :: create ( & file_path) . unwrap ( ) ;
187
+ writeln ! ( file, "[burnchain]" ) . unwrap ( ) ;
188
+ writeln ! ( file, "satoshis_per_byte = 51" ) . unwrap ( ) ;
189
+ config. config_path = Some ( file_path. to_str ( ) . unwrap ( ) . to_string ( ) ) ;
190
+
191
+ assert_eq ! ( get_satoshis_per_byte( & config) , 51 ) ;
192
+ }
193
+ }
194
+
157
195
impl LeaderBlockCommitFees {
158
196
pub fn fees_from_previous_tx (
159
197
& self ,
@@ -182,7 +220,7 @@ impl LeaderBlockCommitFees {
182
220
let value_per_transfer = payload. burn_fee / number_of_transfers;
183
221
let sortition_fee = value_per_transfer * number_of_transfers;
184
222
let spent_in_attempts = 0 ;
185
- let fee_rate = config. burnchain . satoshis_per_byte ;
223
+ let fee_rate = get_satoshis_per_byte ( config) ;
186
224
let default_tx_size = config. burnchain . block_commit_tx_estimated_size ;
187
225
188
226
LeaderBlockCommitFees {
@@ -796,8 +834,9 @@ impl BitcoinRegtestController {
796
834
) -> Option < Transaction > {
797
835
let public_key = signer. get_public_key ( ) ;
798
836
799
- let btc_miner_fee = self . config . burnchain . leader_key_tx_estimated_size
800
- * self . config . burnchain . satoshis_per_byte ;
837
+ // reload the config to find satoshis_per_byte changes
838
+ let satoshis_per_byte = get_satoshis_per_byte ( & self . config ) ;
839
+ let btc_miner_fee = self . config . burnchain . leader_key_tx_estimated_size * satoshis_per_byte;
801
840
let budget_for_outputs = DUST_UTXO_LIMIT ;
802
841
let total_required = btc_miner_fee + budget_for_outputs;
803
842
@@ -825,7 +864,7 @@ impl BitcoinRegtestController {
825
864
826
865
tx. output = vec ! [ consensus_output] ;
827
866
828
- let fee_rate = self . config . burnchain . satoshis_per_byte ;
867
+ let fee_rate = satoshis_per_byte;
829
868
830
869
self . finalize_tx (
831
870
epoch_id,
@@ -919,7 +958,7 @@ impl BitcoinRegtestController {
919
958
) -> Option < Transaction > {
920
959
let public_key = signer. get_public_key ( ) ;
921
960
let max_tx_size = 230 ;
922
-
961
+ let satoshis_per_byte = get_satoshis_per_byte ( & self . config ) ;
923
962
let ( mut tx, mut utxos) = if let Some ( utxo) = utxo_to_use {
924
963
(
925
964
Transaction {
@@ -937,7 +976,7 @@ impl BitcoinRegtestController {
937
976
self . prepare_tx (
938
977
epoch_id,
939
978
& public_key,
940
- DUST_UTXO_LIMIT + max_tx_size * self . config . burnchain . satoshis_per_byte ,
979
+ DUST_UTXO_LIMIT + max_tx_size * satoshis_per_byte,
941
980
None ,
942
981
None ,
943
982
0 ,
@@ -965,13 +1004,14 @@ impl BitcoinRegtestController {
965
1004
. to_bitcoin_tx_out ( DUST_UTXO_LIMIT ) ,
966
1005
) ;
967
1006
1007
+ let satoshis_per_byte = get_satoshis_per_byte ( & self . config ) ;
968
1008
self . finalize_tx (
969
1009
epoch_id,
970
1010
& mut tx,
971
1011
DUST_UTXO_LIMIT ,
972
1012
0 ,
973
1013
max_tx_size,
974
- self . config . burnchain . satoshis_per_byte ,
1014
+ satoshis_per_byte,
975
1015
& mut utxos,
976
1016
signer,
977
1017
) ?;
@@ -1020,7 +1060,7 @@ impl BitcoinRegtestController {
1020
1060
self . prepare_tx (
1021
1061
epoch_id,
1022
1062
& public_key,
1023
- DUST_UTXO_LIMIT + max_tx_size * self . config . burnchain . satoshis_per_byte ,
1063
+ DUST_UTXO_LIMIT + max_tx_size * get_satoshis_per_byte ( & self . config ) ,
1024
1064
None ,
1025
1065
None ,
1026
1066
0 ,
@@ -1054,7 +1094,7 @@ impl BitcoinRegtestController {
1054
1094
DUST_UTXO_LIMIT ,
1055
1095
0 ,
1056
1096
max_tx_size,
1057
- self . config . burnchain . satoshis_per_byte ,
1097
+ get_satoshis_per_byte ( & self . config ) ,
1058
1098
& mut utxos,
1059
1099
signer,
1060
1100
) ?;
@@ -1089,7 +1129,7 @@ impl BitcoinRegtestController {
1089
1129
let public_key = signer. get_public_key ( ) ;
1090
1130
let max_tx_size = 280 ;
1091
1131
1092
- let output_amt = DUST_UTXO_LIMIT + max_tx_size * self . config . burnchain . satoshis_per_byte ;
1132
+ let output_amt = DUST_UTXO_LIMIT + max_tx_size * get_satoshis_per_byte ( & self . config ) ;
1093
1133
let ( mut tx, mut utxos) =
1094
1134
self . prepare_tx ( epoch_id, & public_key, output_amt, None , None , 0 ) ?;
1095
1135
@@ -1118,7 +1158,7 @@ impl BitcoinRegtestController {
1118
1158
output_amt,
1119
1159
0 ,
1120
1160
max_tx_size,
1121
- self . config . burnchain . satoshis_per_byte ,
1161
+ get_satoshis_per_byte ( & self . config ) ,
1122
1162
& mut utxos,
1123
1163
signer,
1124
1164
) ?;
@@ -1319,7 +1359,7 @@ impl BitcoinRegtestController {
1319
1359
1320
1360
// Stop as soon as the fee_rate is ${self.config.burnchain.max_rbf} percent higher, stop RBF
1321
1361
if ongoing_op. fees . fee_rate
1322
- > ( self . config . burnchain . satoshis_per_byte * self . config . burnchain . max_rbf / 100 )
1362
+ > ( get_satoshis_per_byte ( & self . config ) * self . config . burnchain . max_rbf / 100 )
1323
1363
{
1324
1364
warn ! (
1325
1365
"RBF'd block commits reached {}% satoshi per byte fee rate, not resubmitting" ,
0 commit comments