Search in sources :

Example 1 with ArrayDeque

use of kotlin.collections.ArrayDeque in project besu by hyperledger.

the class AccountRangeMessage method accountData.

public AccountRangeData accountData(final boolean withRequestId) {
    final TreeMap<Bytes32, Bytes> accounts = new TreeMap<>();
    final ArrayDeque<Bytes> proofs = new ArrayDeque<>();
    final RLPInput input = new BytesValueRLPInput(data, false);
    input.enterList();
    if (withRequestId)
        input.skipNext();
    input.readList(rlpInput -> {
        rlpInput.enterList();
        Map.Entry<Bytes32, Bytes> entry = Maps.immutableEntry(rlpInput.readBytes32(), toFullAccount(rlpInput.readAsRlp()));
        rlpInput.leaveList();
        return entry;
    }).forEach(entry -> accounts.put(entry.getKey(), entry.getValue()));
    input.enterList();
    while (!input.isEndOfCurrentList()) {
        proofs.add(input.readBytes());
    }
    input.leaveList();
    input.leaveList();
    return ImmutableAccountRangeData.builder().accounts(accounts).proofs(proofs).build();
}
Also used : BytesValueRLPInput(org.hyperledger.besu.ethereum.rlp.BytesValueRLPInput) Bytes(org.apache.tuweni.bytes.Bytes) Maps(com.google.common.collect.Maps) ArrayDeque(kotlin.collections.ArrayDeque) BytesValueRLPOutput(org.hyperledger.besu.ethereum.rlp.BytesValueRLPOutput) List(java.util.List) MessageData(org.hyperledger.besu.ethereum.p2p.rlpx.wire.MessageData) StateTrieAccountValue(org.hyperledger.besu.ethereum.worldstate.StateTrieAccountValue) TreeMap(java.util.TreeMap) RLPInput(org.hyperledger.besu.ethereum.rlp.RLPInput) Value(org.immutables.value.Value) Map(java.util.Map) AbstractSnapMessageData(org.hyperledger.besu.ethereum.p2p.rlpx.wire.AbstractSnapMessageData) Optional(java.util.Optional) BigInteger(java.math.BigInteger) Bytes32(org.apache.tuweni.bytes.Bytes32) Bytes(org.apache.tuweni.bytes.Bytes) BytesValueRLPInput(org.hyperledger.besu.ethereum.rlp.BytesValueRLPInput) RLPInput(org.hyperledger.besu.ethereum.rlp.RLPInput) TreeMap(java.util.TreeMap) Bytes32(org.apache.tuweni.bytes.Bytes32) BytesValueRLPInput(org.hyperledger.besu.ethereum.rlp.BytesValueRLPInput) ArrayDeque(kotlin.collections.ArrayDeque)

Example 2 with ArrayDeque

use of kotlin.collections.ArrayDeque in project besu by hyperledger.

the class ByteCodesMessage method bytecodes.

public ByteCodes bytecodes(final boolean withRequestId) {
    final ArrayDeque<Bytes> codes = new ArrayDeque<>();
    final RLPInput input = new BytesValueRLPInput(data, false);
    input.enterList();
    if (withRequestId)
        input.skipNext();
    input.enterList();
    while (!input.isEndOfCurrentList()) {
        codes.add(input.readBytes());
    }
    input.leaveList();
    input.leaveList();
    return ImmutableByteCodes.builder().codes(codes).build();
}
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)

Example 3 with ArrayDeque

use of kotlin.collections.ArrayDeque in project besu by hyperledger.

the class StorageRangeMessage method slotsData.

public SlotRangeData slotsData(final boolean withRequestId) {
    final ArrayDeque<TreeMap<Bytes32, Bytes>> slots = new ArrayDeque<>();
    final ArrayDeque<Bytes> proofs = new ArrayDeque<>();
    final RLPInput input = new BytesValueRLPInput(data, false);
    input.enterList();
    if (withRequestId)
        input.skipNext();
    input.readList(accountRlpInput -> {
        slots.add(new TreeMap<>());
        return accountRlpInput.readList(slotRlpInput -> {
            slotRlpInput.enterList();
            slots.last().put(slotRlpInput.readBytes32(), slotRlpInput.readBytes());
            slotRlpInput.leaveList();
            // we don't need the response
            return Void.TYPE;
        });
    });
    input.enterList();
    while (!input.isEndOfCurrentList()) {
        proofs.add(input.readBytes());
    }
    input.leaveList();
    input.leaveList();
    return ImmutableSlotRangeData.builder().slots(slots).proofs(proofs).build();
}
Also used : Bytes(org.apache.tuweni.bytes.Bytes) BytesValueRLPInput(org.hyperledger.besu.ethereum.rlp.BytesValueRLPInput) RLPInput(org.hyperledger.besu.ethereum.rlp.RLPInput) TreeMap(java.util.TreeMap) BytesValueRLPInput(org.hyperledger.besu.ethereum.rlp.BytesValueRLPInput) ArrayDeque(kotlin.collections.ArrayDeque)

Example 4 with ArrayDeque

use of kotlin.collections.ArrayDeque in project besu by hyperledger.

the class TrieNodesMessage 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)

Example 5 with ArrayDeque

use of kotlin.collections.ArrayDeque in project besu by hyperledger.

the class RequestDataStep method requestStorage.

public CompletableFuture<List<Task<SnapDataRequest>>> requestStorage(final List<Task<SnapDataRequest>> requestTasks) {
    final List<Bytes32> accountHashes = requestTasks.stream().map(Task::getData).map(StorageRangeDataRequest.class::cast).map(StorageRangeDataRequest::getAccountHash).collect(Collectors.toList());
    final BlockHeader blockHeader = fastSyncState.getPivotBlockHeader().get();
    final Bytes32 minRange = requestTasks.size() == 1 ? ((StorageRangeDataRequest) requestTasks.get(0).getData()).getStartKeyHash() : RangeManager.MIN_RANGE;
    final Bytes32 maxRange = requestTasks.size() == 1 ? ((StorageRangeDataRequest) requestTasks.get(0).getData()).getEndKeyHash() : RangeManager.MAX_RANGE;
    final EthTask<StorageRangeMessage.SlotRangeData> getStorageRangeTask = RetryingGetStorageRangeFromPeerTask.forStorageRange(ethContext, accountHashes, minRange, maxRange, blockHeader, metricsSystem);
    downloadState.addOutstandingTask(getStorageRangeTask);
    return getStorageRangeTask.run().handle((response, error) -> {
        if (response != null) {
            downloadState.removeOutstandingTask(getStorageRangeTask);
            for (int i = 0; i < response.slots().size(); i++) {
                final StorageRangeDataRequest request = (StorageRangeDataRequest) requestTasks.get(i).getData();
                request.setRootHash(blockHeader.getStateRoot());
                request.addResponse(downloadState, worldStateProofProvider, response.slots().get(i), i < response.slots().size() - 1 ? new ArrayDeque<>() : response.proofs());
            }
        }
        return requestTasks;
    });
}
Also used : BlockHeader(org.hyperledger.besu.ethereum.core.BlockHeader) Bytes32(org.apache.tuweni.bytes.Bytes32) ArrayDeque(kotlin.collections.ArrayDeque) StorageRangeDataRequest(org.hyperledger.besu.ethereum.eth.sync.snapsync.request.StorageRangeDataRequest)

Aggregations

ArrayDeque (kotlin.collections.ArrayDeque)11 Bytes (org.apache.tuweni.bytes.Bytes)9 Bytes32 (org.apache.tuweni.bytes.Bytes32)7 BytesValueRLPInput (org.hyperledger.besu.ethereum.rlp.BytesValueRLPInput)7 RLPInput (org.hyperledger.besu.ethereum.rlp.RLPInput)7 TreeMap (java.util.TreeMap)6 List (java.util.List)4 Hash (org.hyperledger.besu.datatypes.Hash)3 StorageRangeDataRequest (org.hyperledger.besu.ethereum.eth.sync.snapsync.request.StorageRangeDataRequest)3 MessageData (org.hyperledger.besu.ethereum.p2p.rlpx.wire.MessageData)3 StateTrieAccountValue (org.hyperledger.besu.ethereum.worldstate.StateTrieAccountValue)3 BigInteger (java.math.BigInteger)2 Optional (java.util.Optional)2 InMemoryKeyValueStorageProvider (org.hyperledger.besu.ethereum.core.InMemoryKeyValueStorageProvider)2 TrieGenerator (org.hyperledger.besu.ethereum.core.TrieGenerator)2 AccountRangeDataRequest (org.hyperledger.besu.ethereum.eth.sync.snapsync.request.AccountRangeDataRequest)2 BytecodeRequest (org.hyperledger.besu.ethereum.eth.sync.snapsync.request.BytecodeRequest)2 SnapDataRequest (org.hyperledger.besu.ethereum.eth.sync.snapsync.request.SnapDataRequest)2 AbstractSnapMessageData (org.hyperledger.besu.ethereum.p2p.rlpx.wire.AbstractSnapMessageData)2 WorldStateProofProvider (org.hyperledger.besu.ethereum.proof.WorldStateProofProvider)2