Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve fee handling #5826

Merged
merged 10 commits into from
Nov 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 50 additions & 8 deletions core/src/main/java/bisq/core/filter/Filter.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,13 @@ public final class Filter implements ProtectedStoragePayload, ExpirablePayload {
// See ProofOfWorkTest for more info.
private final int powDifficulty;

// Added at v 1.8.0
// BSQ fee gets updated in proposals repo (e.g. https://github.com/bisq-network/proposals/issues/345)
private final long makerFeeBtc;
private final long takerFeeBtc;
private final long makerFeeBsq;
private final long takerFeeBsq;

// After we have created the signature from the filter data we clone it and apply the signature
static Filter cloneWithSig(Filter filter, String signatureAsBase64) {
return new Filter(filter.getBannedOfferIds(),
Expand Down Expand Up @@ -140,7 +147,11 @@ static Filter cloneWithSig(Filter filter, String signatureAsBase64) {
filter.isDisableMempoolValidation(),
filter.isDisableApi(),
filter.isDisablePowMessage(),
filter.getPowDifficulty());
filter.getPowDifficulty(),
filter.getMakerFeeBtc(),
filter.getTakerFeeBtc(),
filter.getMakerFeeBsq(),
filter.getTakerFeeBsq());
}

// Used for signature verification as we created the sig without the signatureAsBase64 field we set it to null again
Expand Down Expand Up @@ -174,7 +185,11 @@ static Filter cloneWithoutSig(Filter filter) {
filter.isDisableMempoolValidation(),
filter.isDisableApi(),
filter.isDisablePowMessage(),
filter.getPowDifficulty());
filter.getPowDifficulty(),
filter.getMakerFeeBtc(),
filter.getTakerFeeBtc(),
filter.getMakerFeeBsq(),
filter.getTakerFeeBsq());
}

public Filter(List<String> bannedOfferIds,
Expand Down Expand Up @@ -203,7 +218,11 @@ public Filter(List<String> bannedOfferIds,
boolean disableMempoolValidation,
boolean disableApi,
boolean disablePowMessage,
int powDifficulty) {
int powDifficulty,
long makerFeeBtc,
long takerFeeBtc,
long makerFeeBsq,
long takerFeeBsq) {
this(bannedOfferIds,
nodeAddressesBannedFromTrading,
bannedPaymentAccounts,
Expand Down Expand Up @@ -233,7 +252,11 @@ public Filter(List<String> bannedOfferIds,
disableMempoolValidation,
disableApi,
disablePowMessage,
powDifficulty);
powDifficulty,
makerFeeBtc,
takerFeeBtc,
makerFeeBsq,
takerFeeBsq);
}


Expand Down Expand Up @@ -271,7 +294,11 @@ public Filter(List<String> bannedOfferIds,
boolean disableMempoolValidation,
boolean disableApi,
boolean disablePowMessage,
int powDifficulty) {
int powDifficulty,
long makerFeeBtc,
long takerFeeBtc,
long makerFeeBsq,
long takerFeeBsq) {
this.bannedOfferIds = bannedOfferIds;
this.nodeAddressesBannedFromTrading = nodeAddressesBannedFromTrading;
this.bannedPaymentAccounts = bannedPaymentAccounts;
Expand Down Expand Up @@ -302,6 +329,10 @@ public Filter(List<String> bannedOfferIds,
this.disableApi = disableApi;
this.disablePowMessage = disablePowMessage;
this.powDifficulty = powDifficulty;
this.makerFeeBtc = makerFeeBtc;
this.takerFeeBtc = takerFeeBtc;
this.makerFeeBsq = makerFeeBsq;
this.takerFeeBsq = takerFeeBsq;

// ownerPubKeyBytes can be null when called from tests
if (ownerPubKeyBytes != null) {
Expand Down Expand Up @@ -344,7 +375,11 @@ public protobuf.StoragePayload toProtoMessage() {
.setDisableMempoolValidation(disableMempoolValidation)
.setDisableApi(disableApi)
.setDisablePowMessage(disablePowMessage)
.setPowDifficulty(powDifficulty);
.setPowDifficulty(powDifficulty)
.setMakerFeeBtc(makerFeeBtc)
.setTakerFeeBtc(takerFeeBtc)
.setMakerFeeBsq(makerFeeBsq)
.setTakerFeeBsq(takerFeeBsq);

Optional.ofNullable(signatureAsBase64).ifPresent(builder::setSignatureAsBase64);
Optional.ofNullable(extraDataMap).ifPresent(builder::putAllExtraData);
Expand All @@ -357,7 +392,6 @@ public static Filter fromProto(protobuf.Filter proto) {
.map(PaymentAccountFilter::fromProto)
.collect(Collectors.toList());


return new Filter(ProtoUtil.protocolStringListToList(proto.getBannedOfferIdsList()),
ProtoUtil.protocolStringListToList(proto.getNodeAddressesBannedFromTradingList()),
bannedPaymentAccountsList,
Expand Down Expand Up @@ -387,7 +421,11 @@ public static Filter fromProto(protobuf.Filter proto) {
proto.getDisableMempoolValidation(),
proto.getDisableApi(),
proto.getDisablePowMessage(),
proto.getPowDifficulty()
proto.getPowDifficulty(),
proto.getMakerFeeBtc(),
proto.getTakerFeeBtc(),
proto.getMakerFeeBsq(),
proto.getTakerFeeBsq()
);
}

Expand Down Expand Up @@ -435,6 +473,10 @@ public String toString() {
",\n disableApi=" + disableApi +
",\n disablePowMessage=" + disablePowMessage +
",\n powDifficulty=" + powDifficulty +
",\n makerFeeBtc=" + makerFeeBtc +
",\n takerFeeBtc=" + takerFeeBtc +
",\n makerFeeBsq=" + makerFeeBsq +
",\n takerFeeBsq=" + takerFeeBsq +
"\n}";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public boolean canRequestBeMade(OfferPayload offerPayload) {

public void validateOfferMakerTx(OfferPayload offerPayload, Consumer<TxValidator> resultHandler) {
validateOfferMakerTx(new TxValidator(daoStateService, offerPayload.getOfferFeePaymentTxId(), Coin.valueOf(offerPayload.getAmount()),
offerPayload.isCurrencyForMakerFeeBtc()), resultHandler);
offerPayload.isCurrencyForMakerFeeBtc(), offerPayload.getBlockHeightAtOfferCreation(), filterManager), resultHandler);
}

public void validateOfferMakerTx(TxValidator txValidator, Consumer<TxValidator> resultHandler) {
Expand All @@ -107,7 +107,7 @@ public void validateOfferMakerTx(TxValidator txValidator, Consumer<TxValidator>

public void validateOfferTakerTx(Trade trade, Consumer<TxValidator> resultHandler) {
validateOfferTakerTx(new TxValidator(daoStateService, trade.getTakerFeeTxId(), trade.getAmount(),
trade.isCurrencyForTakerFeeBtc()), resultHandler);
trade.isCurrencyForTakerFeeBtc(), filterManager), resultHandler);
}

public void validateOfferTakerTx(TxValidator txValidator, Consumer<TxValidator> resultHandler) {
Expand All @@ -120,7 +120,7 @@ public void validateOfferTakerTx(TxValidator txValidator, Consumer<TxValidator>
}

public void checkTxIsConfirmed(String txId, Consumer<TxValidator> resultHandler) {
TxValidator txValidator = new TxValidator(daoStateService, txId);
TxValidator txValidator = new TxValidator(daoStateService, txId, filterManager);
if (!isServiceSupported()) {
UserThread.runAfter(() -> resultHandler.accept(txValidator.endResult("mempool request not supported, bypassing", true)), 1);
return;
Expand Down
Loading