diff --git a/rskj-core/src/main/java/co/rsk/peg/BridgeSupport.java b/rskj-core/src/main/java/co/rsk/peg/BridgeSupport.java index 2471d5519ed..e558ca3d456 100644 --- a/rskj-core/src/main/java/co/rsk/peg/BridgeSupport.java +++ b/rskj-core/src/main/java/co/rsk/peg/BridgeSupport.java @@ -840,13 +840,13 @@ 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 ); @@ -854,19 +854,19 @@ private void refundAndEmitRejectEvent( // 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); } /** @@ -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 optionalRejectedPegoutReason = Optional.empty(); if (activations.isActive(RSKIP219)) { int pegoutSize = getRegularPegoutTxSize(activations, getActiveFederation()); @@ -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: @@ -910,31 +910,31 @@ 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); @@ -942,14 +942,14 @@ private void requestRelease(Address destinationAddress, co.rsk.core.Coin release 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 ); } } diff --git a/rskj-core/src/main/java/co/rsk/peg/utils/BridgeEventLogger.java b/rskj-core/src/main/java/co/rsk/peg/utils/BridgeEventLogger.java index 20df205ea00..25fd8f3b16e 100644 --- a/rskj-core/src/main/java/co/rsk/peg/utils/BridgeEventLogger.java +++ b/rskj-core/src/main/java/co/rsk/peg/utils/BridgeEventLogger.java @@ -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(); } diff --git a/rskj-core/src/main/java/co/rsk/peg/utils/BridgeEventLoggerImpl.java b/rskj-core/src/main/java/co/rsk/peg/utils/BridgeEventLoggerImpl.java index f86d6c65d27..6b7242b47f5 100644 --- a/rskj-core/src/main/java/co/rsk/peg/utils/BridgeEventLoggerImpl.java +++ b/rskj-core/src/main/java/co/rsk/peg/utils/BridgeEventLoggerImpl.java @@ -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 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 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 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)); }