Merge pull request #5420 from ghubstan/01-update-txfee

Adjust to changing minimum tx fee rates
This commit is contained in:
sqrrm 2021-04-20 11:51:09 +02:00 committed by GitHub
commit 12a9fcc1e0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 22 additions and 13 deletions

View file

@ -17,7 +17,6 @@ import org.junit.jupiter.api.TestMethodOrder;
import static bisq.apitest.Scaffold.BitcoinCoreApp.bitcoind; import static bisq.apitest.Scaffold.BitcoinCoreApp.bitcoind;
import static bisq.apitest.config.BisqAppConfig.alicedaemon; import static bisq.apitest.config.BisqAppConfig.alicedaemon;
import static bisq.apitest.config.BisqAppConfig.seednode; import static bisq.apitest.config.BisqAppConfig.seednode;
import static bisq.common.config.BaseCurrencyNetwork.BTC_DAO_REGTEST;
import static java.lang.String.format; import static java.lang.String.format;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertFalse;
@ -56,22 +55,25 @@ public class BtcTxFeeRateTest extends MethodTest {
@Test @Test
@Order(2) @Order(2)
public void testSetInvalidTxFeeRateShouldThrowException(final TestInfo testInfo) { public void testSetInvalidTxFeeRateShouldThrowException(final TestInfo testInfo) {
var currentTxFeeRateInfo = TxFeeRateInfo.fromProto(aliceClient.getTxFeeRate());
Throwable exception = assertThrows(StatusRuntimeException.class, () -> Throwable exception = assertThrows(StatusRuntimeException.class, () ->
aliceClient.setTxFeeRate(10)); aliceClient.setTxFeeRate(10));
String expectedExceptionMessage = String expectedExceptionMessage =
format("UNKNOWN: tx fee rate preference must be >= %d sats/byte", format("UNKNOWN: tx fee rate preference must be >= %d sats/byte",
BTC_DAO_REGTEST.getDefaultMinFeePerVbyte()); currentTxFeeRateInfo.getMinFeeServiceRate());
assertEquals(expectedExceptionMessage, exception.getMessage()); assertEquals(expectedExceptionMessage, exception.getMessage());
} }
@Test @Test
@Order(3) @Order(3)
public void testSetValidTxFeeRate(final TestInfo testInfo) { public void testSetValidTxFeeRate(final TestInfo testInfo) {
var txFeeRateInfo = TxFeeRateInfo.fromProto(aliceClient.setTxFeeRate(15)); var currentTxFeeRateInfo = TxFeeRateInfo.fromProto(aliceClient.getTxFeeRate());
var customFeeRate = currentTxFeeRateInfo.getMinFeeServiceRate() + 5;
var txFeeRateInfo = TxFeeRateInfo.fromProto(aliceClient.setTxFeeRate(customFeeRate));
log.debug("{} -> Fee rates with custom preference: {}", testName(testInfo), txFeeRateInfo); log.debug("{} -> Fee rates with custom preference: {}", testName(testInfo), txFeeRateInfo);
assertTrue(txFeeRateInfo.isUseCustomTxFeeRate()); assertTrue(txFeeRateInfo.isUseCustomTxFeeRate());
assertEquals(15, txFeeRateInfo.getCustomTxFeeRate()); assertEquals(customFeeRate, txFeeRateInfo.getCustomTxFeeRate());
assertTrue(txFeeRateInfo.getFeeServiceRate() > 0); assertTrue(txFeeRateInfo.getFeeServiceRate() > 0);
} }

View file

@ -52,7 +52,7 @@ public class WalletTest extends MethodTest {
@BeforeAll @BeforeAll
public static void setUp() { public static void setUp() {
startSupportingApps(true, startSupportingApps(true,
true, false,
bitcoind, bitcoind,
seednode, seednode,
arbdaemon, arbdaemon,

View file

@ -67,12 +67,14 @@ public class CurrencyFormat {
public static String formatTxFeeRateInfo(TxFeeRateInfo txFeeRateInfo) { public static String formatTxFeeRateInfo(TxFeeRateInfo txFeeRateInfo) {
if (txFeeRateInfo.getUseCustomTxFeeRate()) if (txFeeRateInfo.getUseCustomTxFeeRate())
return format("custom tx fee rate: %s sats/byte, network rate: %s sats/byte", return format("custom tx fee rate: %s sats/byte, network rate: %s sats/byte, min network rate: %s sats/byte",
formatFeeSatoshis(txFeeRateInfo.getCustomTxFeeRate()), formatFeeSatoshis(txFeeRateInfo.getCustomTxFeeRate()),
formatFeeSatoshis(txFeeRateInfo.getFeeServiceRate())); formatFeeSatoshis(txFeeRateInfo.getFeeServiceRate()),
formatFeeSatoshis(txFeeRateInfo.getMinFeeServiceRate()));
else else
return format("tx fee rate: %s sats/byte", return format("tx fee rate: %s sats/byte, min tx fee rate: %s sats/byte",
formatFeeSatoshis(txFeeRateInfo.getFeeServiceRate())); formatFeeSatoshis(txFeeRateInfo.getFeeServiceRate()),
formatFeeSatoshis(txFeeRateInfo.getMinFeeServiceRate()));
} }
public static String formatAmountRange(long minAmount, long amount) { public static String formatAmountRange(long minAmount, long amount) {

View file

@ -373,10 +373,7 @@ class CoreWalletsService {
void setTxFeeRatePreference(long txFeeRate, void setTxFeeRatePreference(long txFeeRate,
ResultHandler resultHandler) { ResultHandler resultHandler) {
long minFeePerVbyte = BTC_DAO_REGTEST.getDefaultMinFeePerVbyte(); long minFeePerVbyte = feeService.getMinFeePerVByte();
// TODO Replace line above with line below, after commit
// c33ac1b9834fb9f7f14e553d09776f94efc9d13d is merged.
// long minFeePerVbyte = feeService.getMinFeePerVByte();
if (txFeeRate < minFeePerVbyte) if (txFeeRate < minFeePerVbyte)
throw new IllegalStateException( throw new IllegalStateException(
format("tx fee rate preference must be >= %d sats/byte", minFeePerVbyte)); format("tx fee rate preference must be >= %d sats/byte", minFeePerVbyte));
@ -396,6 +393,7 @@ class CoreWalletsService {
return new TxFeeRateInfo( return new TxFeeRateInfo(
preferences.isUseCustomWithdrawalTxFee(), preferences.isUseCustomWithdrawalTxFee(),
preferences.getWithdrawalTxFeeInVbytes(), preferences.getWithdrawalTxFeeInVbytes(),
feeService.getMinFeePerVByte(),
feeService.getTxFeePerVbyte().value, feeService.getTxFeePerVbyte().value,
feeService.getLastRequest()); feeService.getLastRequest());
} }

View file

@ -28,15 +28,18 @@ public class TxFeeRateInfo implements Payload {
private final boolean useCustomTxFeeRate; private final boolean useCustomTxFeeRate;
private final long customTxFeeRate; private final long customTxFeeRate;
private final long minFeeServiceRate;
private final long feeServiceRate; private final long feeServiceRate;
private final long lastFeeServiceRequestTs; private final long lastFeeServiceRequestTs;
public TxFeeRateInfo(boolean useCustomTxFeeRate, public TxFeeRateInfo(boolean useCustomTxFeeRate,
long customTxFeeRate, long customTxFeeRate,
long minFeeServiceRate,
long feeServiceRate, long feeServiceRate,
long lastFeeServiceRequestTs) { long lastFeeServiceRequestTs) {
this.useCustomTxFeeRate = useCustomTxFeeRate; this.useCustomTxFeeRate = useCustomTxFeeRate;
this.customTxFeeRate = customTxFeeRate; this.customTxFeeRate = customTxFeeRate;
this.minFeeServiceRate = minFeeServiceRate;
this.feeServiceRate = feeServiceRate; this.feeServiceRate = feeServiceRate;
this.lastFeeServiceRequestTs = lastFeeServiceRequestTs; this.lastFeeServiceRequestTs = lastFeeServiceRequestTs;
} }
@ -50,6 +53,7 @@ public class TxFeeRateInfo implements Payload {
return bisq.proto.grpc.TxFeeRateInfo.newBuilder() return bisq.proto.grpc.TxFeeRateInfo.newBuilder()
.setUseCustomTxFeeRate(useCustomTxFeeRate) .setUseCustomTxFeeRate(useCustomTxFeeRate)
.setCustomTxFeeRate(customTxFeeRate) .setCustomTxFeeRate(customTxFeeRate)
.setMinFeeServiceRate(minFeeServiceRate)
.setFeeServiceRate(feeServiceRate) .setFeeServiceRate(feeServiceRate)
.setLastFeeServiceRequestTs(lastFeeServiceRequestTs) .setLastFeeServiceRequestTs(lastFeeServiceRequestTs)
.build(); .build();
@ -59,6 +63,7 @@ public class TxFeeRateInfo implements Payload {
public static TxFeeRateInfo fromProto(bisq.proto.grpc.TxFeeRateInfo proto) { public static TxFeeRateInfo fromProto(bisq.proto.grpc.TxFeeRateInfo proto) {
return new TxFeeRateInfo(proto.getUseCustomTxFeeRate(), return new TxFeeRateInfo(proto.getUseCustomTxFeeRate(),
proto.getCustomTxFeeRate(), proto.getCustomTxFeeRate(),
proto.getMinFeeServiceRate(),
proto.getFeeServiceRate(), proto.getFeeServiceRate(),
proto.getLastFeeServiceRequestTs()); proto.getLastFeeServiceRequestTs());
} }
@ -68,6 +73,7 @@ public class TxFeeRateInfo implements Payload {
return "TxFeeRateInfo{" + "\n" + return "TxFeeRateInfo{" + "\n" +
" useCustomTxFeeRate=" + useCustomTxFeeRate + "\n" + " useCustomTxFeeRate=" + useCustomTxFeeRate + "\n" +
", customTxFeeRate=" + customTxFeeRate + " sats/byte" + "\n" + ", customTxFeeRate=" + customTxFeeRate + " sats/byte" + "\n" +
", minFeeServiceRate=" + minFeeServiceRate + " sats/byte" + "\n" +
", feeServiceRate=" + feeServiceRate + " sats/byte" + "\n" + ", feeServiceRate=" + feeServiceRate + " sats/byte" + "\n" +
", lastFeeServiceRequestTs=" + lastFeeServiceRequestTs + "\n" + ", lastFeeServiceRequestTs=" + lastFeeServiceRequestTs + "\n" +
'}'; '}';

View file

@ -407,6 +407,7 @@ message TxFeeRateInfo {
uint64 customTxFeeRate = 2; uint64 customTxFeeRate = 2;
uint64 feeServiceRate = 3; uint64 feeServiceRate = 3;
uint64 lastFeeServiceRequestTs = 4; uint64 lastFeeServiceRequestTs = 4;
uint64 minFeeServiceRate = 5;
} }
message TxInfo { message TxInfo {