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

Refactor addSignature as previous step to create addSvpSpendTxSignature method #2788

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
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
12 changes: 7 additions & 5 deletions rskj-core/src/main/java/co/rsk/peg/Bridge.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*/
package co.rsk.peg;

import static co.rsk.peg.BridgeSerializationUtils.deserializeRskTxHash;
import static org.ethereum.config.blockchain.upgrades.ConsensusRule.RSKIP417;

import co.rsk.bitcoinj.core.*;
Expand Down Expand Up @@ -617,14 +618,15 @@ public void addSignature(Object[] args) throws VMException {
}
signatures.add(signatureByteArray);
}
byte[] rskTxHash = (byte[]) args[2];
if (rskTxHash.length!=32) {
throw new BridgeIllegalArgumentException("Invalid rsk tx hash " + Bytes.of(rskTxHash));
byte[] rskTxHashSerialized = (byte[]) args[2];
Keccak256 rskTxHash;
try {
rskTxHash = deserializeRskTxHash(rskTxHashSerialized);
} catch (IllegalArgumentException e) {
throw new BridgeIllegalArgumentException("Invalid rsk tx hash " + Bytes.of(rskTxHashSerialized));
}
try {
bridgeSupport.addSignature(federatorPublicKey, signatures, rskTxHash);
} catch (BridgeIllegalArgumentException e) {
throw e;
} catch (Exception e) {
logger.warn("Exception in addSignature", e);
throw new VMException("Exception in addSignature", e);
Expand Down
16 changes: 10 additions & 6 deletions rskj-core/src/main/java/co/rsk/peg/BridgeSerializationUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package co.rsk.peg;

import static co.rsk.peg.federation.FederationFormatVersion.*;
import static java.util.Objects.isNull;

import co.rsk.bitcoinj.core.*;
import co.rsk.bitcoinj.script.Script;
Expand Down Expand Up @@ -65,8 +66,11 @@ private static byte[] serializeRskTxHash(Keccak256 rskTxHash) {
return RLP.encodeElement(rskTxHash.getBytes());
}

private static Keccak256 deserializeRskTxHashFromHashData(byte[] hashBytes) {
return new Keccak256(hashBytes);
public static Keccak256 deserializeRskTxHash(byte[] rskTxHashSerialized) {
if (isNull(rskTxHashSerialized)) {
throw new IllegalArgumentException("Serialized hash cannot be null.");
}
return new Keccak256(rskTxHashSerialized);
}

public static byte[] serializeBtcTransaction(BtcTransaction btcTransaction) {
Expand Down Expand Up @@ -186,7 +190,7 @@ private static Map.Entry<Keccak256, BtcTransaction> deserializeRskTxWaitingForSi

RLPElement rskTxHashRLPElement = rlpList.get(index * 2);
byte[] rskTxHashData = rskTxHashRLPElement.getRLPData();
Keccak256 rskTxHash = deserializeRskTxHashFromHashData(rskTxHashData);
Keccak256 rskTxHash = deserializeRskTxHash(rskTxHashData);

RLPElement btcTxRLPElement = rlpList.get(index * 2 + 1);
byte[] btcRawTx = btcTxRLPElement.getRLPData();
Expand Down Expand Up @@ -667,7 +671,7 @@ private static List<ReleaseRequestQueue.Entry> deserializeReleaseRequestQueueWit
Address address = new Address(networkParameters, addressBytes);
long amount = BigIntegers.fromUnsignedByteArray(rlpList.get(k * 3 + 1).getRLPData()).longValue();

Keccak256 txHash = deserializeRskTxHashFromHashData(rlpList.get(k * 3 + 2).getRLPData());
Keccak256 txHash = deserializeRskTxHash(rlpList.get(k * 3 + 2).getRLPData());

entries.add(new ReleaseRequestQueue.Entry(address, Coin.valueOf(amount), txHash));
}
Expand Down Expand Up @@ -760,7 +764,7 @@ private static PegoutsWaitingForConfirmations deserializePegoutWaitingForConfirm
BtcTransaction tx = new BtcTransaction(networkParameters, txPayload);

long height = BigIntegers.fromUnsignedByteArray(rlpList.get(k * 3 + 1).getRLPData()).longValue();
Keccak256 rskTxHash = deserializeRskTxHashFromHashData(rlpList.get(k * 3 + 2).getRLPData());
Keccak256 rskTxHash = deserializeRskTxHash(rlpList.get(k * 3 + 2).getRLPData());

entries.add(new PegoutsWaitingForConfirmations.Entry(tx, height, rskTxHash));
}
Expand Down Expand Up @@ -849,7 +853,7 @@ public static FlyoverFederationInformation deserializeFlyoverFederationInformati
if (rlpList.size() != 2) {
throw new RuntimeException(String.format("Invalid serialized Fast Bridge Federation: expected 2 value but got %d", rlpList.size()));
}
Keccak256 derivationHash = deserializeRskTxHashFromHashData(rlpList.get(0).getRLPData());
Keccak256 derivationHash = deserializeRskTxHash(rlpList.get(0).getRLPData());
byte[] federationP2SH = rlpList.get(1).getRLPData();

return new FlyoverFederationInformation(derivationHash, federationP2SH, flyoverScriptHash);
Expand Down
Loading