Skip to content

Commit

Permalink
Merge pull request #5420 from ghubstan/01-update-txfee
Browse files Browse the repository at this point in the history
Adjust to changing minimum tx fee rates
  • Loading branch information
sqrrm authored Apr 20, 2021
2 parents de8213a + 2308afb commit 12a9fcc
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import static bisq.apitest.Scaffold.BitcoinCoreApp.bitcoind;
import static bisq.apitest.config.BisqAppConfig.alicedaemon;
import static bisq.apitest.config.BisqAppConfig.seednode;
import static bisq.common.config.BaseCurrencyNetwork.BTC_DAO_REGTEST;
import static java.lang.String.format;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
Expand Down Expand Up @@ -56,22 +55,25 @@ public void testGetTxFeeRate(final TestInfo testInfo) {
@Test
@Order(2)
public void testSetInvalidTxFeeRateShouldThrowException(final TestInfo testInfo) {
var currentTxFeeRateInfo = TxFeeRateInfo.fromProto(aliceClient.getTxFeeRate());
Throwable exception = assertThrows(StatusRuntimeException.class, () ->
aliceClient.setTxFeeRate(10));
String expectedExceptionMessage =
format("UNKNOWN: tx fee rate preference must be >= %d sats/byte",
BTC_DAO_REGTEST.getDefaultMinFeePerVbyte());
currentTxFeeRateInfo.getMinFeeServiceRate());
assertEquals(expectedExceptionMessage, exception.getMessage());
}

@Test
@Order(3)
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);

assertTrue(txFeeRateInfo.isUseCustomTxFeeRate());
assertEquals(15, txFeeRateInfo.getCustomTxFeeRate());
assertEquals(customFeeRate, txFeeRateInfo.getCustomTxFeeRate());
assertTrue(txFeeRateInfo.getFeeServiceRate() > 0);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public class WalletTest extends MethodTest {
@BeforeAll
public static void setUp() {
startSupportingApps(true,
true,
false,
bitcoind,
seednode,
arbdaemon,
Expand Down
10 changes: 6 additions & 4 deletions cli/src/main/java/bisq/cli/CurrencyFormat.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,14 @@ public static String formatBsqAmount(long bsqSats) {

public static String formatTxFeeRateInfo(TxFeeRateInfo txFeeRateInfo) {
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.getFeeServiceRate()));
formatFeeSatoshis(txFeeRateInfo.getFeeServiceRate()),
formatFeeSatoshis(txFeeRateInfo.getMinFeeServiceRate()));
else
return format("tx fee rate: %s sats/byte",
formatFeeSatoshis(txFeeRateInfo.getFeeServiceRate()));
return format("tx fee rate: %s sats/byte, min tx fee rate: %s sats/byte",
formatFeeSatoshis(txFeeRateInfo.getFeeServiceRate()),
formatFeeSatoshis(txFeeRateInfo.getMinFeeServiceRate()));
}

public static String formatAmountRange(long minAmount, long amount) {
Expand Down
6 changes: 2 additions & 4 deletions core/src/main/java/bisq/core/api/CoreWalletsService.java
Original file line number Diff line number Diff line change
Expand Up @@ -373,10 +373,7 @@ public void onFailure(Throwable t) {

void setTxFeeRatePreference(long txFeeRate,
ResultHandler resultHandler) {
long minFeePerVbyte = BTC_DAO_REGTEST.getDefaultMinFeePerVbyte();
// TODO Replace line above with line below, after commit
// c33ac1b9834fb9f7f14e553d09776f94efc9d13d is merged.
// long minFeePerVbyte = feeService.getMinFeePerVByte();
long minFeePerVbyte = feeService.getMinFeePerVByte();
if (txFeeRate < minFeePerVbyte)
throw new IllegalStateException(
format("tx fee rate preference must be >= %d sats/byte", minFeePerVbyte));
Expand All @@ -396,6 +393,7 @@ TxFeeRateInfo getMostRecentTxFeeRateInfo() {
return new TxFeeRateInfo(
preferences.isUseCustomWithdrawalTxFee(),
preferences.getWithdrawalTxFeeInVbytes(),
feeService.getMinFeePerVByte(),
feeService.getTxFeePerVbyte().value,
feeService.getLastRequest());
}
Expand Down
6 changes: 6 additions & 0 deletions core/src/main/java/bisq/core/api/model/TxFeeRateInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,18 @@ public class TxFeeRateInfo implements Payload {

private final boolean useCustomTxFeeRate;
private final long customTxFeeRate;
private final long minFeeServiceRate;
private final long feeServiceRate;
private final long lastFeeServiceRequestTs;

public TxFeeRateInfo(boolean useCustomTxFeeRate,
long customTxFeeRate,
long minFeeServiceRate,
long feeServiceRate,
long lastFeeServiceRequestTs) {
this.useCustomTxFeeRate = useCustomTxFeeRate;
this.customTxFeeRate = customTxFeeRate;
this.minFeeServiceRate = minFeeServiceRate;
this.feeServiceRate = feeServiceRate;
this.lastFeeServiceRequestTs = lastFeeServiceRequestTs;
}
Expand All @@ -50,6 +53,7 @@ public bisq.proto.grpc.TxFeeRateInfo toProtoMessage() {
return bisq.proto.grpc.TxFeeRateInfo.newBuilder()
.setUseCustomTxFeeRate(useCustomTxFeeRate)
.setCustomTxFeeRate(customTxFeeRate)
.setMinFeeServiceRate(minFeeServiceRate)
.setFeeServiceRate(feeServiceRate)
.setLastFeeServiceRequestTs(lastFeeServiceRequestTs)
.build();
Expand All @@ -59,6 +63,7 @@ public bisq.proto.grpc.TxFeeRateInfo toProtoMessage() {
public static TxFeeRateInfo fromProto(bisq.proto.grpc.TxFeeRateInfo proto) {
return new TxFeeRateInfo(proto.getUseCustomTxFeeRate(),
proto.getCustomTxFeeRate(),
proto.getMinFeeServiceRate(),
proto.getFeeServiceRate(),
proto.getLastFeeServiceRequestTs());
}
Expand All @@ -68,6 +73,7 @@ public String toString() {
return "TxFeeRateInfo{" + "\n" +
" useCustomTxFeeRate=" + useCustomTxFeeRate + "\n" +
", customTxFeeRate=" + customTxFeeRate + " sats/byte" + "\n" +
", minFeeServiceRate=" + minFeeServiceRate + " sats/byte" + "\n" +
", feeServiceRate=" + feeServiceRate + " sats/byte" + "\n" +
", lastFeeServiceRequestTs=" + lastFeeServiceRequestTs + "\n" +
'}';
Expand Down
1 change: 1 addition & 0 deletions proto/src/main/proto/grpc.proto
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,7 @@ message TxFeeRateInfo {
uint64 customTxFeeRate = 2;
uint64 feeServiceRate = 3;
uint64 lastFeeServiceRequestTs = 4;
uint64 minFeeServiceRate = 5;
}

message TxInfo {
Expand Down

0 comments on commit 12a9fcc

Please sign in to comment.