Skip to content

Commit d0419f8

Browse files
committed
Rewording some logs and comments
1 parent bc7b5d5 commit d0419f8

File tree

4 files changed

+39
-42
lines changed

4 files changed

+39
-42
lines changed

src/main/java/co/rsk/federate/btcreleaseclient/BtcPegoutClient.java

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -216,8 +216,8 @@ public void onBlock(org.ethereum.core.Block block, List<TransactionReceipt> rece
216216
if (!isPegoutEnabled || nodeBlockProcessor.hasBetterBlockToSync()) {
217217
return;
218218
}
219-
// Pegout must be processed on an every-single-block basis,
220-
// since otherwise we could be missing pegout potentially mined
219+
// Pegout events must be processed on an every-single-block basis,
220+
// since otherwise we could be missing pegouts potentially mined
221221
// on what originally were side-chains and then turned into best-chains.
222222
Stream<LogInfo> transactionLogs = receipts.stream().map(TransactionReceipt::getLogInfoList).flatMap(Collection::stream);
223223
Stream<LogInfo> bridgeLogs = transactionLogs.filter(info -> Arrays.equals(info.getAddress(), PrecompiledContracts.BRIDGE_ADDR.getBytes()));
@@ -248,7 +248,7 @@ private BtcTransaction convertToBtcTxFromSolidityData(byte[] dataFromBtcReleaseT
248248

249249
protected void processPegouts(Set<Map.Entry<Keccak256, BtcTransaction>> pegouts) {
250250
try {
251-
logger.debug("[processPegout] Starting process with {} pegouts", pegouts.size());
251+
logger.debug("[processPegouts] Starting process with {} pegouts", pegouts.size());
252252
int version = signer.getVersionForKeyId(BTC_KEY_ID.getKeyId());
253253
// Get pegout information and store it in a new list
254254
List<PegoutCreationInformation> pegoutsReadyToSign = new ArrayList<>();
@@ -257,7 +257,7 @@ protected void processPegouts(Set<Map.Entry<Keccak256, BtcTransaction>> pegouts)
257257
tryGetPegoutInformation(version, pegout.getKey(), pegoutBtcTx)
258258
.ifPresent(pegoutsReadyToSign::add);
259259
}
260-
logger.debug("[processPegout] Going to sign {} pegouts", pegoutsReadyToSign.size());
260+
logger.debug("[processPegouts] Going to sign {} pegouts", pegoutsReadyToSign.size());
261261
// TODO: Sorting and then looping again is not efficient but we are making a compromise on performance here as we don't have that many pegouts
262262
// Sort descending
263263
pegoutsReadyToSign.sort((a, b) -> (int) (b.getPegoutCreationRskBlock().getNumber() - a.getPegoutCreationRskBlock().getNumber()));
@@ -266,9 +266,9 @@ protected void processPegouts(Set<Map.Entry<Keccak256, BtcTransaction>> pegouts)
266266
signConfirmedPegout(version, pegoutsReadyToSign.get(0));
267267
}
268268
} catch (Exception e) {
269-
logger.error("[processPegout] There was an error trying to process pegouts", e);
269+
logger.error("[processPegouts] There was an error trying to process pegouts", e);
270270
}
271-
logger.trace("[processPegout] Finished processing pegouts");
271+
logger.trace("[processPegouts] Finished processing pegouts");
272272
}
273273

274274
protected Optional<PegoutCreationInformation> tryGetPegoutInformation(
@@ -278,19 +278,19 @@ protected Optional<PegoutCreationInformation> tryGetPegoutInformation(
278278
) {
279279
try {
280280
// Discard transactions this fed already signed or cannot be signed by the observed federations
281-
logger.trace("[tryGetPegoutInformation] Validating if pegout btcTxHash {} can be signed by observed federations and " +
281+
logger.trace("[tryGetPegoutInformation] Validating if pegoutBtcTxHash {} can be signed by observed federations and " +
282282
"that it is not already signed by current fed", pegoutBtcTx.getHash());
283-
validateConfirmedPegoutCanBeSigned(pegoutBtcTx);
283+
validatePegoutBtcTxCanBeSigned(pegoutBtcTx);
284284

285285
// IMPORTANT: As per the current behaviour of the bridge, no pegout should have inputs to be signed
286286
// by different federations. Taking this into account, when removing the signatures from the tx new
287287
// scriptSigs are created that all spend from the same federation
288288
logger.trace("[tryGetPegoutInformation] Removing possible signatures from pegout btcTxHash {}", pegoutBtcTx.getHash());
289289
Federation spendingFed = getSpendingFederation(pegoutBtcTx);
290-
removeSignaturesFromPegoutBtxTx(pegoutBtcTx, spendingFed);
290+
removeSignaturesFromPegoutBtcTx(pegoutBtcTx, spendingFed);
291291
logger.trace("[tryGetPegoutInformation] pegout btcTxHash without signatures {}", pegoutBtcTx.getHash());
292292

293-
logger.trace("[tryGetPegoutInformation] Is tx in storage? {}", storageAccessor.hasBtcTxHash(pegoutBtcTx.getHash()));
293+
logger.trace("[tryGetPegoutInformation] Is pegout btc tx in storage? {}", storageAccessor.hasBtcTxHash(pegoutBtcTx.getHash()));
294294
// Try to get the pegoutCreationRskTxHash from the map in memory, and if not found then use pegoutConfirmationRskTxHash
295295
Keccak256 pegoutCreationRskTxHash = storageAccessor.hasBtcTxHash(pegoutBtcTx.getHash()) ?
296296
storageAccessor.getRskTxHash(pegoutBtcTx.getHash()) :
@@ -319,18 +319,18 @@ protected Optional<PegoutCreationInformation> tryGetPegoutInformation(
319319
return Optional.empty();
320320
}
321321

322-
protected void validateConfirmedPegoutCanBeSigned(BtcTransaction pegoutBtcTx) throws FederatorAlreadySignedException, FederationCantSignException {
322+
protected void validatePegoutBtcTxCanBeSigned(BtcTransaction pegoutBtcTx) throws FederatorAlreadySignedException, FederationCantSignException {
323323
try {
324324
BtcECKey federatorPublicKey = signer.getPublicKey(BTC_KEY_ID.getKeyId()).toBtcKey();
325-
logger.trace("[validateConfirmedPegoutCanBeSigned] Federator public key {}", federatorPublicKey);
325+
logger.trace("[validatePegoutBtcTxCanBeSigned] Federator public key {}", federatorPublicKey);
326326

327327
for (int inputIndex = 0; inputIndex < pegoutBtcTx.getInputs().size(); inputIndex++) {
328328
TransactionInput txIn = pegoutBtcTx.getInput(inputIndex);
329329
Script redeemScript = getRedeemScriptFromInput(txIn);
330330
Script standardRedeemScript = extractStandardRedeemScript(redeemScript);
331331

332332
// Check if input is not already signed by the current federator
333-
logger.trace("[validateConfirmedPegoutCanBeSigned] Checking if the input {} is not already signed by the current federator", inputIndex);
333+
logger.trace("[validatePegoutBtcTxCanBeSigned] Checking if the input {} is not already signed by the current federator", inputIndex);
334334
co.rsk.bitcoinj.core.Sha256Hash sigHash = pegoutBtcTx.hashForSignature(
335335
inputIndex,
336336
redeemScript,
@@ -348,12 +348,12 @@ protected void validateConfirmedPegoutCanBeSigned(BtcTransaction pegoutBtcTx) th
348348
}
349349

350350
// Check if any of the observed federations can sign the tx
351-
logger.trace("[validateConfirmedPegoutCanBeSigned] Checking if any of the observed federations can sign the pegout btc tx input {}", inputIndex);
351+
logger.trace("[validatePegoutBtcTxCanBeSigned] Checking if any of the observed federations can sign the pegout btc tx input {}", inputIndex);
352352
observedFederations.stream()
353-
.forEach(f -> logger.trace("[validateConfirmedPegoutCanBeSigned] federation p2sh redeem script {}", f.getRedeemScript()));
353+
.forEach(f -> logger.trace("[validatePegoutBtcTxCanBeSigned] federation p2sh redeem script {}", f.getRedeemScript()));
354354
List<Federation> spendingFedFilter = observedFederations.stream()
355355
.filter(f -> (extractDefaultRedeemScript(f)).equals(standardRedeemScript)).collect(Collectors.toList());
356-
logger.debug("[validateConfirmedPegoutCanBeSigned] spendingFedFilter size {}", spendingFedFilter.size());
356+
logger.debug("[validatePegoutBtcTxCanBeSigned] spendingFedFilter size {}", spendingFedFilter.size());
357357
if (spendingFedFilter.isEmpty()) {
358358
String message = String.format(
359359
"PegoutBtcTxHash %s can't be signed by any of the observed federations",
@@ -363,7 +363,7 @@ protected void validateConfirmedPegoutCanBeSigned(BtcTransaction pegoutBtcTx) th
363363
}
364364
}
365365
} catch (SignerException e) {
366-
String message = String.format("[validateConfirmedPegoutCanBeSigned] Error validating pegoutBtcTxHash %s, " +
366+
String message = String.format("[validatePegoutBtcTxCanBeSigned] Error validating pegoutBtcTxHash %s, " +
367367
"failed to get current federator public key", pegoutBtcTx.getHashAsString());
368368
logger.error(message, e);
369369
}
@@ -434,16 +434,16 @@ public void onBroadcastingSignedPegout(BtcTransaction signedBtcTx) {
434434
Received pegoutBtcTx inputs are replaced by base inputs without signatures that spend from the given federation.
435435
This way the pegoutBtcTx has the same hash as the one registered in release_requested event topics.
436436
*/
437-
protected void removeSignaturesFromPegoutBtxTx(BtcTransaction pegoutBtcTx, Federation spendingFed) {
437+
protected void removeSignaturesFromPegoutBtcTx(BtcTransaction pegoutBtcTx, Federation spendingFed) {
438438
for (int inputIndex = 0; inputIndex < pegoutBtcTx.getInputs().size(); inputIndex++) {
439439
//Get redeem script for current input
440440
TransactionInput txInput = pegoutBtcTx.getInput(inputIndex);
441441
Script inputRedeemScript = getRedeemScriptFromInput(txInput);
442-
logger.trace("[removeSignaturesFromPegoutBtxTx] input {} scriptSig {}", inputIndex, pegoutBtcTx.getInput(inputIndex).getScriptSig());
443-
logger.trace("[removeSignaturesFromPegoutBtxTx] input {} redeem script {}", inputIndex, inputRedeemScript);
442+
logger.trace("[removeSignaturesFromPegoutBtcTx] input {} scriptSig {}", inputIndex, pegoutBtcTx.getInput(inputIndex).getScriptSig());
443+
logger.trace("[removeSignaturesFromPegoutBtcTx] input {} redeem script {}", inputIndex, inputRedeemScript);
444444

445445
txInput.setScriptSig(createBaseInputScriptThatSpendsFromTheFederation(spendingFed, inputRedeemScript));
446-
logger.debug("[removeSignaturesFromPegoutBtxTx] Updated input {} scriptSig with base input script that " +
446+
logger.debug("[removeSignaturesFromPegoutBtcTx] Updated input {} scriptSig with base input script that " +
447447
"spends from the federation {}", inputIndex, spendingFed.getAddress());
448448
}
449449
}

src/main/java/co/rsk/federate/btcreleaseclient/BtcPegoutClientStorageSynchronizer.java

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,14 @@ private void sync() {
106106
return;
107107
}
108108

109-
Block fromBlock = findBlockToSearch(storageBestBlock);
109+
Block fromBlock;
110+
/* If there is no data in the file, set a limit to avoid looking up all the blockchain */
111+
if (storageBestBlock == null) {
112+
long lastBlockNumberToSearch = blockStore.getBestBlock().getNumber() - this.maxInitializationDepth;
113+
fromBlock = blockStore.getChainBlockByNumber(Math.max(lastBlockNumberToSearch, 0));
114+
} else {
115+
fromBlock = blockStore.getChainBlockByNumber(storageBestBlock.getNumber() + 1);
116+
}
110117

111118
logger.info(
112119
"[sync] going to sync from block {} ({})",
@@ -152,16 +159,6 @@ private boolean isStorageSync(Block storageBestBlock) {
152159
return false;
153160
}
154161

155-
private Block findBlockToSearch(Block storageBestBlock) {
156-
/* If there is no data in the file, set a limit to avoid looking up all the blockchain */
157-
if (storageBestBlock == null) {
158-
long lastBlockNumberToSearch = blockStore.getBestBlock().getNumber() - this.maxInitializationDepth;
159-
return blockStore.getChainBlockByNumber(Math.max(lastBlockNumberToSearch, 0));
160-
} else {
161-
return blockStore.getChainBlockByNumber(storageBestBlock.getNumber() + 1);
162-
}
163-
}
164-
165162
private Block getStorageBestBlock(Keccak256 storageBestBlockHash) {
166163
Block storageBestBlock = blockStore.getBlockByHash(storageBestBlockHash.getBytes());
167164
if (storageBestBlock == null) {

src/main/java/co/rsk/federate/io/btcreleaseclientstorage/BtcPegoutClientFileStorageImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ private BtcPegoutClientFileReadResult readFromRlp(byte[] fileData) {
9191
}
9292
}
9393
} catch (Exception e) {
94-
logger.error("[readFromRlp] error trying to file data.", e);
94+
logger.error("[readFromRlp] error trying to read file data.", e);
9595
return new BtcPegoutClientFileReadResult(Boolean.FALSE, null);
9696
}
9797

src/test/java/co/rsk/federate/btcreleaseclient/BtcPegoutClientTest.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,7 @@ void onBlock_return_when_pegout_is_disabled() {
558558
}
559559

560560
@Test
561-
void validateConfirmedPegoutCanBeSigned_ok() throws Exception {
561+
void validatePegoutBtcTxCanBeSigned_ok() throws Exception {
562562
// Arrange
563563
Federation federation = TestUtils.createFederation(params, 1);
564564

@@ -574,7 +574,7 @@ void validateConfirmedPegoutCanBeSigned_ok() throws Exception {
574574
}
575575

576576
@Test
577-
void validateConfirmedPegoutCanBeSigned_fast_bridge_ok() throws Exception {
577+
void validatePegoutBtcTxCanBeSigned_fast_bridge_ok() throws Exception {
578578
// Create a StandardMultisigFederation
579579
Federation federation = TestUtils.createFederation(params, 1);
580580

@@ -594,7 +594,7 @@ void validateConfirmedPegoutCanBeSigned_fast_bridge_ok() throws Exception {
594594
}
595595

596596
@Test
597-
void validateConfirmedPegoutCanBeSigned_erp_fed_ok() throws Exception {
597+
void validatePegoutBtcTxCanBeSigned_erp_fed_ok() throws Exception {
598598
Federation federation = TestUtils.createFederation(params, 3);
599599
FederationArgs federationArgs = federation.getArgs();
600600
ErpFederation nonStandardErpFederation =
@@ -610,7 +610,7 @@ void validateConfirmedPegoutCanBeSigned_erp_fed_ok() throws Exception {
610610
}
611611

612612
@Test
613-
void validateConfirmedPegoutCanBeSigned_federatorAlreadySigned() throws Exception {
613+
void validatePegoutBtcTxCanBeSigned_federatorAlreadySigned() throws Exception {
614614
// Arrange
615615
BtcECKey federator1PrivKey = new BtcECKey();
616616
BtcECKey federator2PrivKey = new BtcECKey();
@@ -664,11 +664,11 @@ void validateConfirmedPegoutCanBeSigned_federatorAlreadySigned() throws Exceptio
664664
client.start(federation);
665665

666666
// Act
667-
assertThrows(FederatorAlreadySignedException.class, () -> client.validateConfirmedPegoutCanBeSigned(pegoutBtcTx));
667+
assertThrows(FederatorAlreadySignedException.class, () -> client.validatePegoutBtcTxCanBeSigned(pegoutBtcTx));
668668
}
669669

670670
@Test
671-
void validateConfirmedPegoutCanBeSigned_federationCantSign() throws Exception {
671+
void validatePegoutBtcTxCanBeSigned_federationCantSign() throws Exception {
672672
// Arrange
673673
Federation federation = TestUtils.createFederation(params, 1);
674674

@@ -702,7 +702,7 @@ void validateConfirmedPegoutCanBeSigned_federationCantSign() throws Exception {
702702
);
703703

704704
// Act
705-
assertThrows(FederationCantSignException.class, () -> client.validateConfirmedPegoutCanBeSigned(pegoutBtcTx));
705+
assertThrows(FederationCantSignException.class, () -> client.validatePegoutBtcTxCanBeSigned(pegoutBtcTx));
706706
}
707707

708708
@Test
@@ -751,7 +751,7 @@ void removeSignaturesFromTransaction() {
751751
Sha256Hash signedTxHash = pegoutBtcTx.getHash();
752752

753753
// Act
754-
client.removeSignaturesFromPegoutBtxTx(pegoutBtcTx, federation);
754+
client.removeSignaturesFromPegoutBtcTx(pegoutBtcTx, federation);
755755
Sha256Hash removedSignaturesTxHash = pegoutBtcTx.getHash();
756756

757757
// Assert
@@ -838,7 +838,7 @@ private void test_validatePegoutBtcTxCanBeSigned(
838838
client.start(federation);
839839

840840
// Act
841-
client.validateConfirmedPegoutCanBeSigned(pegoutBtcTx);
841+
client.validatePegoutBtcTxCanBeSigned(pegoutBtcTx);
842842
}
843843

844844
private void test_extractStandardRedeemScript(

0 commit comments

Comments
 (0)