Search in sources :

Example 66 with RLPInput

use of org.hyperledger.besu.ethereum.rlp.RLPInput in project besu by hyperledger.

the class NewBlockHashesMessageTest method blockHeadersRoundTrip.

@Test
public void blockHeadersRoundTrip() throws IOException {
    final List<NewBlockHashesMessage.NewBlockHash> hashes = new ArrayList<>();
    final ByteBuffer buffer = ByteBuffer.wrap(Resources.toByteArray(this.getClass().getResource("/50.blocks")));
    for (int i = 0; i < 50; ++i) {
        final int blockSize = RLP.calculateSize(Bytes.wrapByteBuffer(buffer));
        final byte[] block = new byte[blockSize];
        buffer.get(block);
        buffer.compact().position(0);
        final RLPInput oneBlock = new BytesValueRLPInput(Bytes.wrap(block), false);
        oneBlock.enterList();
        final BlockHeader header = BlockHeader.readFrom(oneBlock, new MainnetBlockHeaderFunctions());
        hashes.add(new NewBlockHashesMessage.NewBlockHash(header.getHash(), header.getNumber()));
        // We don't care about the bodies, just the header hashes
        oneBlock.skipNext();
        oneBlock.skipNext();
    }
    final MessageData initialMessage = NewBlockHashesMessage.create(hashes);
    final MessageData raw = new RawMessage(EthPV62.NEW_BLOCK_HASHES, initialMessage.getData());
    final NewBlockHashesMessage message = NewBlockHashesMessage.readFrom(raw);
    final Iterator<NewBlockHashesMessage.NewBlockHash> readHeaders = message.getNewHashes();
    for (int i = 0; i < 50; ++i) {
        Assertions.assertThat(readHeaders.next()).isEqualTo(hashes.get(i));
    }
}
Also used : BytesValueRLPInput(org.hyperledger.besu.ethereum.rlp.BytesValueRLPInput) RLPInput(org.hyperledger.besu.ethereum.rlp.RLPInput) MessageData(org.hyperledger.besu.ethereum.p2p.rlpx.wire.MessageData) ArrayList(java.util.ArrayList) ByteBuffer(java.nio.ByteBuffer) BlockHeader(org.hyperledger.besu.ethereum.core.BlockHeader) RawMessage(org.hyperledger.besu.ethereum.p2p.rlpx.wire.RawMessage) BytesValueRLPInput(org.hyperledger.besu.ethereum.rlp.BytesValueRLPInput) MainnetBlockHeaderFunctions(org.hyperledger.besu.ethereum.mainnet.MainnetBlockHeaderFunctions) Test(org.junit.Test)

Example 67 with RLPInput

use of org.hyperledger.besu.ethereum.rlp.RLPInput in project besu by hyperledger.

the class GetTrieNodes method paths.

public TrieNodesPaths paths(final boolean withRequestId) {
    final RLPInput input = new BytesValueRLPInput(data, false);
    input.enterList();
    if (withRequestId)
        input.skipNext();
    final ImmutableTrieNodesPaths.Builder paths = ImmutableTrieNodesPaths.builder().worldStateRootHash(Hash.wrap(Bytes32.wrap(input.readBytes32()))).paths(input.readList(rlpInput -> rlpInput.readList(RLPInput::readBytes))).responseBytes(input.readBigIntegerScalar());
    input.leaveList();
    return paths.build();
}
Also used : RLPInput(org.hyperledger.besu.ethereum.rlp.RLPInput) BytesValueRLPInput(org.hyperledger.besu.ethereum.rlp.BytesValueRLPInput) BytesValueRLPInput(org.hyperledger.besu.ethereum.rlp.BytesValueRLPInput)

Example 68 with RLPInput

use of org.hyperledger.besu.ethereum.rlp.RLPInput in project besu by hyperledger.

the class TrieNodes method nodes.

public ArrayDeque<Bytes> nodes(final boolean withRequestId) {
    final ArrayDeque<Bytes> trieNodes = new ArrayDeque<>();
    final RLPInput input = new BytesValueRLPInput(data, false);
    input.enterList();
    if (withRequestId)
        input.skipNext();
    input.enterList();
    while (!input.isEndOfCurrentList()) {
        trieNodes.add(input.readBytes());
    }
    input.leaveList();
    input.leaveList();
    return trieNodes;
}
Also used : Bytes(org.apache.tuweni.bytes.Bytes) RLPInput(org.hyperledger.besu.ethereum.rlp.RLPInput) BytesValueRLPInput(org.hyperledger.besu.ethereum.rlp.BytesValueRLPInput) BytesValueRLPInput(org.hyperledger.besu.ethereum.rlp.BytesValueRLPInput) ArrayDeque(kotlin.collections.ArrayDeque)

Aggregations

RLPInput (org.hyperledger.besu.ethereum.rlp.RLPInput)68 BytesValueRLPInput (org.hyperledger.besu.ethereum.rlp.BytesValueRLPInput)34 Bytes (org.apache.tuweni.bytes.Bytes)24 Test (org.junit.Test)21 BytesValueRLPOutput (org.hyperledger.besu.ethereum.rlp.BytesValueRLPOutput)15 Hash (org.hyperledger.besu.datatypes.Hash)12 ArrayList (java.util.ArrayList)11 SECPSignature (org.hyperledger.besu.crypto.SECPSignature)11 Block (org.hyperledger.besu.ethereum.core.Block)9 BigInteger (java.math.BigInteger)8 Address (org.hyperledger.besu.datatypes.Address)8 BlockHeader (org.hyperledger.besu.ethereum.core.BlockHeader)7 Transaction (org.hyperledger.besu.ethereum.core.Transaction)7 ArrayDeque (kotlin.collections.ArrayDeque)6 Bytes32 (org.apache.tuweni.bytes.Bytes32)6 ByteBuffer (java.nio.ByteBuffer)5 Optional (java.util.Optional)5 Wei (org.hyperledger.besu.datatypes.Wei)5 MainnetBlockHeaderFunctions (org.hyperledger.besu.ethereum.mainnet.MainnetBlockHeaderFunctions)5 MessageData (org.hyperledger.besu.ethereum.p2p.rlpx.wire.MessageData)5