use of co.rsk.crypto.Keccak256 in project rskj by rsksmart.
the class NodeBlockProcessor method processGetBlock.
/**
* processGetBlock sends a requested block to a peer if the block is available.
*
* @param sender the sender of the GetBlock message.
* @param hash the requested block's hash.
*/
@Override
public void processGetBlock(@Nonnull final MessageChannel sender, @Nonnull final byte[] hash) {
logger.trace("Processing get block {} from {}", Hex.toHexString(hash).substring(0, 10), sender.getPeerNodeID().toString());
final Block block = blockSyncService.getBlockFromStoreOrBlockchain(hash);
if (block == null) {
return;
}
nodeInformation.addBlockToNode(new Keccak256(hash), sender.getPeerNodeID());
sender.sendMessage(new BlockMessage(block));
}
use of co.rsk.crypto.Keccak256 in project rskj by rsksmart.
the class NodeMessageHandler method relayTransactions.
private void relayTransactions(@Nonnull MessageChannel sender, List<Transaction> acceptedTxs) {
for (Transaction tx : acceptedTxs) {
Keccak256 txHash = tx.getHash();
transactionNodeInformation.addTransactionToNode(txHash, sender.getPeerNodeID());
final Set<NodeID> nodesToSkip = new HashSet<>(transactionNodeInformation.getNodesByTransaction(txHash));
final Set<NodeID> newNodes = channelManager.broadcastTransaction(tx, nodesToSkip);
newNodes.forEach(nodeID -> transactionNodeInformation.addTransactionToNode(txHash, nodeID));
}
}
use of co.rsk.crypto.Keccak256 in project rskj by rsksmart.
the class NodeMessageHandler method tryAddMessage.
private void tryAddMessage(MessageChannel sender, Message message) {
Keccak256 encodedMessage = new Keccak256(HashUtil.keccak256(message.getEncoded()));
if (!receivedMessages.contains(encodedMessage)) {
if (message.getMessageType() == MessageType.BLOCK_MESSAGE || message.getMessageType() == MessageType.TRANSACTIONS) {
if (this.receivedMessages.size() >= MAX_NUMBER_OF_MESSAGES_CACHED) {
this.receivedMessages.clear();
}
this.receivedMessages.add(encodedMessage);
}
if (!this.queue.offer(new MessageTask(sender, message))) {
logger.trace("Queue full, message not added to the queue");
}
} else {
recordEvent(sender, EventType.REPEATED_MESSAGE);
logger.trace("Received message already known, not added to the queue");
}
}
use of co.rsk.crypto.Keccak256 in project rskj by rsksmart.
the class BridgeSerializationUtils method deserializeMap.
public static SortedMap<Keccak256, BtcTransaction> deserializeMap(byte[] data, NetworkParameters networkParameters, boolean noInputsTxs) {
SortedMap<Keccak256, BtcTransaction> map = new TreeMap<>();
if (data == null || data.length == 0) {
return map;
}
RLPList rlpList = (RLPList) RLP.decode2(data).get(0);
int ntxs = rlpList.size() / 2;
for (int k = 0; k < ntxs; k++) {
Keccak256 hash = new Keccak256(rlpList.get(k * 2).getRLPData());
byte[] payload = rlpList.get(k * 2 + 1).getRLPData();
BtcTransaction tx;
if (!noInputsTxs) {
tx = new BtcTransaction(networkParameters, payload);
} else {
tx = new BtcTransaction(networkParameters);
tx.parseNoInputs(payload);
}
map.put(hash, tx);
}
return map;
}
use of co.rsk.crypto.Keccak256 in project rskj by rsksmart.
the class BridgeSupport method addSignature.
/**
* Adds a federator signature to a btc release tx.
* The hash for the signature must be calculated with Transaction.SigHash.ALL and anyoneCanPay=false. The signature must be canonical.
* If enough signatures were added, ask federators to broadcast the btc release tx.
*
* @param executionBlockNumber The block number of the block that is currently being procesed
* @param federatorPublicKey Federator who is signing
* @param signatures 1 signature per btc tx input
* @param rskTxHash The id of the rsk tx
*/
public void addSignature(long executionBlockNumber, BtcECKey federatorPublicKey, List<byte[]> signatures, byte[] rskTxHash) throws Exception {
Context.propagate(btcContext);
Federation retiringFederation = getRetiringFederation();
if (!getActiveFederation().getPublicKeys().contains(federatorPublicKey) && (retiringFederation == null || !retiringFederation.getPublicKeys().contains(federatorPublicKey))) {
logger.warn("Supplied federator public key {} does not belong to any of the federators.", federatorPublicKey);
return;
}
BtcTransaction btcTx = provider.getRskTxsWaitingForSignatures().get(new Keccak256(rskTxHash));
if (btcTx == null) {
logger.warn("No tx waiting for signature for hash {}. Probably fully signed already.", new Keccak256(rskTxHash));
return;
}
if (btcTx.getInputs().size() != signatures.size()) {
logger.warn("Expected {} signatures but received {}.", btcTx.getInputs().size(), signatures.size());
return;
}
eventLogger.logAddSignature(federatorPublicKey, btcTx, rskTxHash);
processSigning(executionBlockNumber, federatorPublicKey, signatures, rskTxHash, btcTx);
}
Aggregations