Skip to content

Commit

Permalink
Merge pull request #2808 from rsksmart/rename-release-values
Browse files Browse the repository at this point in the history
Rename variables related to release amounts. Indicate satoshis or weis
  • Loading branch information
marcos-iov authored Oct 17, 2024
2 parents e17da01 + 177fb91 commit 41cc91a
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 35 deletions.
44 changes: 22 additions & 22 deletions rskj-core/src/main/java/co/rsk/peg/BridgeSupport.java
Original file line number Diff line number Diff line change
Expand Up @@ -840,33 +840,33 @@ public void releaseBtc(Transaction rskTx) throws IOException {
}

private void refundAndEmitRejectEvent(
co.rsk.core.Coin releaseRequestedValue,
co.rsk.core.Coin releaseRequestedValueInWeis,
RskAddress senderAddress,
RejectedPegoutReason reason
) {
logger.trace(
"[refundAndEmitRejectEvent] Executing a refund of {} to {}. Reason: {}",
releaseRequestedValue,
"[refundAndEmitRejectEvent] Executing a refund of {} weis to {}. Reason: {}",
releaseRequestedValueInWeis,
senderAddress,
reason
);

// Prior to RSKIP427, the value was converted to BTC before doing the refund
// This could cause the original value to be rounded down to fit in satoshis value
co.rsk.core.Coin refundValue = activations.isActive(RSKIP427) ?
releaseRequestedValue :
co.rsk.core.Coin.fromBitcoin(releaseRequestedValue.toBitcoin());
releaseRequestedValueInWeis :
co.rsk.core.Coin.fromBitcoin(releaseRequestedValueInWeis.toBitcoin());

rskRepository.transfer(
PrecompiledContracts.BRIDGE_ADDR,
senderAddress,
refundValue
);
emitRejectEvent(releaseRequestedValue, senderAddress, reason);
emitRejectEvent(releaseRequestedValueInWeis, senderAddress, reason);
}

private void emitRejectEvent(co.rsk.core.Coin value, RskAddress senderAddress, RejectedPegoutReason reason) {
eventLogger.logReleaseBtcRequestRejected(senderAddress, value, reason);
private void emitRejectEvent(co.rsk.core.Coin releaseRequestedValueInWeis, RskAddress senderAddress, RejectedPegoutReason reason) {
eventLogger.logReleaseBtcRequestRejected(senderAddress, releaseRequestedValueInWeis, reason);
}

/**
Expand All @@ -875,11 +875,11 @@ private void emitRejectEvent(co.rsk.core.Coin value, RskAddress senderAddress, R
* to be processed later.
*
* @param destinationAddress the destination BTC address.
* @param releaseRequestedValue the amount of RBTC requested to be released.
* @param releaseRequestedValueInWeis the amount of RBTC requested to be released, represented in weis
* @throws IOException if there is an error getting the release request queue from storage
*/
private void requestRelease(Address destinationAddress, co.rsk.core.Coin releaseRequestedValue, Transaction rskTx) throws IOException {
Coin valueToRelease = releaseRequestedValue.toBitcoin();
private void requestRelease(Address destinationAddress, co.rsk.core.Coin releaseRequestedValueInWeis, Transaction rskTx) throws IOException {
Coin valueToReleaseInSatoshis = releaseRequestedValueInWeis.toBitcoin();
Optional<RejectedPegoutReason> optionalRejectedPegoutReason = Optional.empty();
if (activations.isActive(RSKIP219)) {
int pegoutSize = getRegularPegoutTxSize(activations, getActiveFederation());
Expand All @@ -897,11 +897,11 @@ private void requestRelease(Address destinationAddress, co.rsk.core.Coin release
.divide(100)
); // add the gap

// The pegout releaseRequestedValue should be greater or equals than the max of these two values
// The pegout releaseRequestedValueInWeis should be greater or equals than the max of these two values
Coin minValue = Coin.valueOf(Math.max(bridgeConstants.getMinimumPegoutTxValue().value, requireFundsForFee.value));

// Since Iris the peg-out the rule is that the minimum is inclusive
if (valueToRelease.isLessThan(minValue)) {
if (valueToReleaseInSatoshis.isLessThan(minValue)) {
optionalRejectedPegoutReason = Optional.of(
Objects.equals(minValue, requireFundsForFee) ?
RejectedPegoutReason.FEE_ABOVE_VALUE:
Expand All @@ -910,46 +910,46 @@ private void requestRelease(Address destinationAddress, co.rsk.core.Coin release
}
} else {
// For legacy peg-outs the rule stated that the minimum was exclusive
if (!valueToRelease.isGreaterThan(bridgeConstants.getLegacyMinimumPegoutTxValue())) {
if (!valueToReleaseInSatoshis.isGreaterThan(bridgeConstants.getLegacyMinimumPegoutTxValue())) {
optionalRejectedPegoutReason = Optional.of(RejectedPegoutReason.LOW_AMOUNT);
}
}

if (optionalRejectedPegoutReason.isPresent()) {
logger.warn(
"[requestRelease] releaseBtc ignored. To {}. Tx {}. Value {}. Reason: {}",
"[requestRelease] releaseBtc ignored. To {}. Tx {}. Value {} weis. Reason: {}",
destinationAddress,
rskTx,
releaseRequestedValue,
releaseRequestedValueInWeis,
optionalRejectedPegoutReason.get()
);
if (activations.isActive(ConsensusRule.RSKIP185)) {
refundAndEmitRejectEvent(
releaseRequestedValue,
releaseRequestedValueInWeis,
rskTx.getSender(signatureCache),
optionalRejectedPegoutReason.get()
);
}
} else {
if (activations.isActive(ConsensusRule.RSKIP146)) {
provider.getReleaseRequestQueue().add(destinationAddress, valueToRelease, rskTx.getHash());
provider.getReleaseRequestQueue().add(destinationAddress, valueToReleaseInSatoshis, rskTx.getHash());
} else {
provider.getReleaseRequestQueue().add(destinationAddress, valueToRelease);
provider.getReleaseRequestQueue().add(destinationAddress, valueToReleaseInSatoshis);
}

RskAddress sender = rskTx.getSender(signatureCache);
if (activations.isActive(ConsensusRule.RSKIP185)) {
eventLogger.logReleaseBtcRequestReceived(
sender,
destinationAddress,
releaseRequestedValue
releaseRequestedValueInWeis
);
}
logger.info(
"[requestRelease] releaseBtc successful to {}. Tx {}. Value {}.",
"[requestRelease] releaseBtc successful to {}. Tx {}. Value {} weis.",
destinationAddress,
rskTx,
releaseRequestedValue
releaseRequestedValueInWeis
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ default void logUnrefundablePegin(BtcTransaction btcTx, UnrefundablePeginReason
throw new UnsupportedOperationException();
}

default void logReleaseBtcRequestReceived(RskAddress sender, Address btcDestinationAddress, co.rsk.core.Coin amount) {
default void logReleaseBtcRequestReceived(RskAddress sender, Address btcDestinationAddress, co.rsk.core.Coin amountInWeis) {
throw new UnsupportedOperationException();
}

default void logReleaseBtcRequestRejected(RskAddress sender, co.rsk.core.Coin amount, RejectedPegoutReason reason) {
default void logReleaseBtcRequestRejected(RskAddress sender, co.rsk.core.Coin amountInWeis, RejectedPegoutReason reason) {
throw new UnsupportedOperationException();
}

Expand Down
22 changes: 11 additions & 11 deletions rskj-core/src/main/java/co/rsk/peg/utils/BridgeEventLoggerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -192,45 +192,45 @@ public void logUnrefundablePegin(BtcTransaction btcTx, UnrefundablePeginReason r
}

@Override
public void logReleaseBtcRequestReceived(RskAddress sender, Address btcDestinationAddress, co.rsk.core.Coin amount) {
public void logReleaseBtcRequestReceived(RskAddress sender, Address btcDestinationAddress, co.rsk.core.Coin amountInWeis) {
if (activations.isActive(ConsensusRule.RSKIP326)) {
logReleaseBtcRequestReceived(sender.toHexString(), btcDestinationAddress.toString(), amount);
logReleaseBtcRequestReceived(sender.toHexString(), btcDestinationAddress.toString(), amountInWeis);
} else {
logReleaseBtcRequestReceived(sender.toHexString(), btcDestinationAddress.getHash160(), amount.toBitcoin());
logReleaseBtcRequestReceived(sender.toHexString(), btcDestinationAddress.getHash160(), amountInWeis.toBitcoin());
}
}

private void logReleaseBtcRequestReceived(String sender, byte[] btcDestinationAddress, Coin amount) {
private void logReleaseBtcRequestReceived(String sender, byte[] btcDestinationAddress, Coin amountInSatoshis) {
CallTransaction.Function event = BridgeEvents.RELEASE_REQUEST_RECEIVED_LEGACY.getEvent();
byte[][] encodedTopicsInBytes = event.encodeEventTopics(sender);
List<DataWord> encodedTopics = LogInfo.byteArrayToList(encodedTopicsInBytes);

byte[] encodedData = event.encodeEventData(btcDestinationAddress, amount.getValue());
byte[] encodedData = event.encodeEventData(btcDestinationAddress, amountInSatoshis.getValue());

this.logs.add(new LogInfo(BRIDGE_CONTRACT_ADDRESS, encodedTopics, encodedData));
}

private void logReleaseBtcRequestReceived(String sender, String btcDestinationAddress, co.rsk.core.Coin amount) {
private void logReleaseBtcRequestReceived(String sender, String btcDestinationAddress, co.rsk.core.Coin amountInWeis) {
CallTransaction.Function event = BridgeEvents.RELEASE_REQUEST_RECEIVED.getEvent();
byte[][] encodedTopicsInBytes = event.encodeEventTopics(sender);
List<DataWord> encodedTopics = LogInfo.byteArrayToList(encodedTopicsInBytes);

byte[] encodedData = activations.isActive(ConsensusRule.RSKIP427) ?
event.encodeEventData(btcDestinationAddress, amount.asBigInteger()) :
event.encodeEventData(btcDestinationAddress, amount.toBitcoin().getValue());
event.encodeEventData(btcDestinationAddress, amountInWeis.asBigInteger()) :
event.encodeEventData(btcDestinationAddress, amountInWeis.toBitcoin().getValue());

this.logs.add(new LogInfo(BRIDGE_CONTRACT_ADDRESS, encodedTopics, encodedData));
}

@Override
public void logReleaseBtcRequestRejected(RskAddress sender, co.rsk.core.Coin amount, RejectedPegoutReason reason) {
public void logReleaseBtcRequestRejected(RskAddress sender, co.rsk.core.Coin amountInWeis, RejectedPegoutReason reason) {
CallTransaction.Function event = BridgeEvents.RELEASE_REQUEST_REJECTED.getEvent();
byte[][] encodedTopicsInBytes = event.encodeEventTopics(sender.toHexString());
List<DataWord> encodedTopics = LogInfo.byteArrayToList(encodedTopicsInBytes);

byte[] encodedData = activations.isActive(ConsensusRule.RSKIP427) ?
event.encodeEventData(amount.asBigInteger(), reason.getValue()) :
event.encodeEventData(amount.toBitcoin().getValue(), reason.getValue());
event.encodeEventData(amountInWeis.asBigInteger(), reason.getValue()) :
event.encodeEventData(amountInWeis.toBitcoin().getValue(), reason.getValue());

this.logs.add(new LogInfo(BRIDGE_CONTRACT_ADDRESS, encodedTopics, encodedData));
}
Expand Down

0 comments on commit 41cc91a

Please sign in to comment.