Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Eth63 started. Response answers handling only. Receipts fully handled…
…, NodeData only for stateRoots.
- Loading branch information
Showing
14 changed files
with
671 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
116 changes: 116 additions & 0 deletions
116
ethereumj-core/src/main/java/org/ethereum/net/eth/handler/Eth63.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
package org.ethereum.net.eth.handler; | ||
|
||
import io.netty.channel.ChannelHandlerContext; | ||
import org.ethereum.config.SystemProperties; | ||
import org.ethereum.core.Block; | ||
import org.ethereum.core.Blockchain; | ||
import org.ethereum.core.Transaction; | ||
import org.ethereum.core.TransactionInfo; | ||
import org.ethereum.core.TransactionReceipt; | ||
import org.ethereum.db.RepositoryImpl; | ||
import org.ethereum.listener.CompositeEthereumListener; | ||
import org.ethereum.net.eth.EthVersion; | ||
import org.ethereum.net.eth.message.EthMessage; | ||
import org.ethereum.net.eth.message.GetNodeDataMessage; | ||
import org.ethereum.net.eth.message.GetReceiptsMessage; | ||
import org.ethereum.net.eth.message.NodeDataMessage; | ||
import org.ethereum.net.eth.message.ReceiptsMessage; | ||
|
||
import org.ethereum.util.Value; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.context.annotation.Scope; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import static org.ethereum.crypto.HashUtil.sha3; | ||
import static org.ethereum.net.eth.EthVersion.V63; | ||
|
||
/** | ||
* Fast synchronization (PV63) Handler | ||
*/ | ||
@Component | ||
@Scope("prototype") | ||
public class Eth63 extends Eth62 { | ||
|
||
@Autowired | ||
private RepositoryImpl repository; | ||
|
||
private static final EthVersion version = V63; | ||
|
||
public Eth63() { | ||
super(version); | ||
} | ||
|
||
@Autowired | ||
public Eth63(final SystemProperties config, final Blockchain blockchain, | ||
final CompositeEthereumListener ethereumListener) { | ||
super(version, config, blockchain, ethereumListener); | ||
} | ||
|
||
@Override | ||
public void channelRead0(final ChannelHandlerContext ctx, EthMessage msg) throws InterruptedException { | ||
|
||
super.channelRead0(ctx, msg); | ||
|
||
// Only commands that were added in V63, V62 are handled in child | ||
switch (msg.getCommand()) { | ||
case GET_NODE_DATA: | ||
processGetNodeData((GetNodeDataMessage) msg); | ||
break; | ||
case NODE_DATA: | ||
// TODO: Implement | ||
break; | ||
case GET_RECEIPTS: | ||
processGetReceipts((GetReceiptsMessage) msg); | ||
break; | ||
case RECEIPTS: | ||
// TODO: Implement | ||
break; | ||
default: | ||
break; | ||
} | ||
} | ||
|
||
protected synchronized void processGetNodeData(GetNodeDataMessage msg) { | ||
|
||
if (logger.isTraceEnabled()) logger.trace( | ||
"Peer {}: processing GetNodeData, size [{}]", | ||
channel.getPeerIdShort(), | ||
msg.getStateRoots().size() | ||
); | ||
|
||
List<Value> states = new ArrayList<>(); | ||
for (byte[] stateRoot : msg.getStateRoots()) { | ||
Value value = repository.getState(stateRoot); | ||
if (value != null) states.add(value); | ||
} | ||
|
||
sendMessage(new NodeDataMessage(states)); | ||
} | ||
|
||
protected synchronized void processGetReceipts(GetReceiptsMessage msg) { | ||
|
||
if (logger.isTraceEnabled()) logger.trace( | ||
"Peer {}: processing GetReceipts, size [{}]", | ||
channel.getPeerIdShort(), | ||
msg.getBlockHashes().size() | ||
); | ||
|
||
List<List<TransactionReceipt>> receipts = new ArrayList<>(); | ||
for (byte[] blockHash : msg.getBlockHashes()) { | ||
Block block = blockchain.getBlockByHash(blockHash); | ||
if (block == null) continue; | ||
|
||
List<TransactionReceipt> blockReceipts = new ArrayList<>(); | ||
for (Transaction transaction : block.getTransactionsList()) { | ||
TransactionInfo transactionInfo = blockchain.getTransactionInfo(transaction.getHash()); | ||
blockReceipts.add(transactionInfo.getReceipt()); | ||
} | ||
receipts.add(blockReceipts); | ||
}; | ||
|
||
sendMessage(new ReceiptsMessage(receipts)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
ethereumj-core/src/main/java/org/ethereum/net/eth/message/Eth63MessageFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package org.ethereum.net.eth.message; | ||
|
||
import org.ethereum.net.message.Message; | ||
import org.ethereum.net.message.MessageFactory; | ||
|
||
import static org.ethereum.net.eth.EthVersion.V63; | ||
|
||
/** | ||
* Fast synchronization (PV63) message factory | ||
*/ | ||
public class Eth63MessageFactory implements MessageFactory { | ||
|
||
@Override | ||
public Message create(byte code, byte[] encoded) { | ||
|
||
EthMessageCodes receivedCommand = EthMessageCodes.fromByte(code, V63); | ||
switch (receivedCommand) { | ||
case STATUS: | ||
return new StatusMessage(encoded); | ||
case NEW_BLOCK_HASHES: | ||
return new NewBlockHashesMessage(encoded); | ||
case TRANSACTIONS: | ||
return new TransactionsMessage(encoded); | ||
case GET_BLOCK_HEADERS: | ||
return new GetBlockHeadersMessage(encoded); | ||
case BLOCK_HEADERS: | ||
return new BlockHeadersMessage(encoded); | ||
case GET_BLOCK_BODIES: | ||
return new GetBlockBodiesMessage(encoded); | ||
case BLOCK_BODIES: | ||
return new BlockBodiesMessage(encoded); | ||
case NEW_BLOCK: | ||
return new NewBlockMessage(encoded); | ||
case GET_NODE_DATA: | ||
return new GetNodeDataMessage(encoded); | ||
case NODE_DATA: | ||
return new NodeDataMessage(encoded); | ||
case GET_RECEIPTS: | ||
return new GetReceiptsMessage(encoded); | ||
case RECEIPTS: | ||
return new ReceiptsMessage(encoded); | ||
default: | ||
throw new IllegalArgumentException("No such message"); | ||
} | ||
} | ||
} |
Oops, something went wrong.