Skip to content

Commit

Permalink
Add a constant for the prefix of logs in registerBtcCoinbaseTransacti…
Browse files Browse the repository at this point in the history
…on method
  • Loading branch information
marcos-iov committed Jan 27, 2025
1 parent 25d1675 commit 9b7347f
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions rskj-core/src/main/java/co/rsk/peg/BridgeSupport.java
Original file line number Diff line number Diff line change
Expand Up @@ -2465,34 +2465,35 @@ public void registerBtcCoinbaseTransaction(
Sha256Hash witnessMerkleRoot,
byte[] witnessReservedValue
) throws VMException {
final String LOG_PREFIX = "[registerBtcCoinbaseTransaction]";
Context.propagate(btcContext);
try{
this.ensureBtcBlockStore();
}catch (BlockStoreException | IOException e) {
String message = String.format("Exception in registerBtcCoinbaseTransaction. %s", e.getMessage());
logger.warn("[registerBtcCoinbaseTransaction] {}", message);
logger.warn("{} {}", LOG_PREFIX, message);
throw new VMException(message, e);
}

Sha256Hash btcTxHash = BtcTransactionFormatUtils.calculateBtcTxHash(btcTxSerialized);
logger.debug("[registerBtcCoinbaseTransaction] Going to register coinbase information for btcTx: {}", btcTxHash);
logger.debug("{} Going to register coinbase information for btcTx: {}", LOG_PREFIX, btcTxHash);

if (witnessReservedValue.length != 32) {
String message = String.format(
"Witness reserved value length can't be different than 32 bytes. Value received: %s",
Bytes.of(witnessReservedValue)
);
logger.warn("[registerBtcCoinbaseTransaction] {}", message);
logger.warn("{} {}", LOG_PREFIX, message);
throw new BridgeIllegalArgumentException(message);
}
logger.trace("[registerBtcCoinbaseTransaction] Witness reserved value: {}", Bytes.of(witnessReservedValue));
logger.trace("{} Witness reserved value: {}", LOG_PREFIX, Bytes.of(witnessReservedValue));

if (!PartialMerkleTreeFormatUtils.hasExpectedSize(pmtSerialized)) {
String message = String.format(
"PartialMerkleTree doesn't have expected size. Value received: %s",
Bytes.of(pmtSerialized)
);
logger.warn("[registerBtcCoinbaseTransaction] {}", message);
logger.warn("{} {}", LOG_PREFIX, message);
throw new BridgeIllegalArgumentException(message);
}

Expand All @@ -2503,18 +2504,19 @@ public void registerBtcCoinbaseTransaction(
merkleRoot = pmt.getTxnHashAndMerkleRoot(hashesInPmt);
if (!hashesInPmt.contains(btcTxHash)) {
logger.warn(
"[registerBtcCoinbaseTransaction] Supplied btc tx {} is not in the supplied partial merkle tree {}",
"{} Supplied btc tx {} is not in the supplied partial merkle tree {}",
LOG_PREFIX,
btcTxHash,
pmt
);
return;
}
} catch (VerificationException e) {
String message = String.format("Partial merkle tree could not be parsed. %s", Bytes.of(pmtSerialized));
logger.warn("[registerBtcCoinbaseTransaction] {}", message);
logger.warn("{} {}", LOG_PREFIX, message);
throw new BridgeIllegalArgumentException(message, e);
}
logger.trace("[registerBtcCoinbaseTransaction] Merkle root: {}", merkleRoot);
logger.trace("{} Merkle root: {}", LOG_PREFIX, merkleRoot);

// Check merkle root equals btc block merkle root at the specified height in the btc best chain
// Btc blockstore is available since we've already queried the best chain height
Expand All @@ -2523,19 +2525,21 @@ public void registerBtcCoinbaseTransaction(
storedBlock = btcBlockStore.get(blockHash);
} catch (BlockStoreException e) {
logger.error(
"[registerBtcCoinbaseTransaction] Error gettin block {} from block store. {}",
"{} Error gettin block {} from block store. {}",
LOG_PREFIX,
blockHash,
e.getMessage()
);
}

if (storedBlock == null) {
String message = String.format("Block %s not yet registered", blockHash);
logger.warn("[registerBtcCoinbaseTransaction] {}", message);
logger.warn("{} {}", LOG_PREFIX, message);
throw new BridgeIllegalArgumentException(message);
}
logger.trace(
"[registerBtcCoinbaseTransaction] Found block with hash {} at height {}",
"{} Found block with hash {} at height {}",
LOG_PREFIX,
blockHash,
storedBlock.getHeight()
);
Expand All @@ -2548,7 +2552,7 @@ public void registerBtcCoinbaseTransaction(
merkleRoot,
blockHeader.getMerkleRoot()
);
logger.warn("[registerBtcCoinbaseTransaction] {}", panicMessage);
logger.warn("{} {}", LOG_PREFIX, panicMessage);
panicProcessor.panic("btclock", panicMessage);
return;
}
Expand All @@ -2561,7 +2565,7 @@ public void registerBtcCoinbaseTransaction(
CoinbaseInformation coinbaseInformation = new CoinbaseInformation(witnessMerkleRoot);
provider.setCoinbaseInformation(blockHeader.getHash(), coinbaseInformation);

logger.debug("[registerBtcCoinbaseTransaction] Registered coinbase information for btc tx {}", btcTxHash);
logger.debug("{} Registered coinbase information for btc tx {}", LOG_PREFIX, btcTxHash);
}

private void validateWitnessInformation(
Expand Down

0 comments on commit 9b7347f

Please sign in to comment.