use of org.hyperledger.besu.ethereum.eth.sync.snapsync.request.AccountRangeDataRequest in project besu by hyperledger.
the class PersistDataStepTest method assertDataPersisted.
private void assertDataPersisted(final List<Task<SnapDataRequest>> tasks) {
tasks.forEach(task -> {
if (task.getData() instanceof AccountRangeDataRequest) {
final AccountRangeDataRequest data = (AccountRangeDataRequest) task.getData();
StoredMerklePatriciaTrie<Bytes, Bytes> trie = new StoredMerklePatriciaTrie<>(worldStateStorage::getAccountStateTrieNode, data.getRootHash(), b -> b, b -> b);
data.getAccounts().forEach((key, value) -> assertThat(trie.get(key)).isPresent());
} else if (task.getData() instanceof StorageRangeDataRequest) {
final StorageRangeDataRequest data = (StorageRangeDataRequest) task.getData();
final StoredMerklePatriciaTrie<Bytes, Bytes> trie = new StoredMerklePatriciaTrie<>((location, hash) -> worldStateStorage.getAccountStorageTrieNode(Hash.wrap(data.getAccountHash()), location, hash), data.getStorageRoot(), b -> b, b -> b);
data.getSlots().forEach((key, value) -> assertThat(trie.get(key)).isPresent());
} else if (task.getData() instanceof BytecodeRequest) {
final BytecodeRequest data = (BytecodeRequest) task.getData();
assertThat(worldStateStorage.getCode(data.getCodeHash(), Hash.wrap(data.getAccountHash()))).isPresent();
} else {
fail("not expected message");
}
});
}
use of org.hyperledger.besu.ethereum.eth.sync.snapsync.request.AccountRangeDataRequest in project besu by hyperledger.
the class RequestDataStep method requestAccount.
public CompletableFuture<Task<SnapDataRequest>> requestAccount(final Task<SnapDataRequest> requestTask) {
final BlockHeader blockHeader = fastSyncState.getPivotBlockHeader().get();
final AccountRangeDataRequest accountDataRequest = (AccountRangeDataRequest) requestTask.getData();
final EthTask<AccountRangeMessage.AccountRangeData> getAccountTask = RetryingGetAccountRangeFromPeerTask.forAccountRange(ethContext, accountDataRequest.getStartKeyHash(), accountDataRequest.getEndKeyHash(), blockHeader, metricsSystem);
downloadState.addOutstandingTask(getAccountTask);
return getAccountTask.run().handle((response, error) -> {
if (response != null) {
downloadState.removeOutstandingTask(getAccountTask);
accountDataRequest.setRootHash(blockHeader.getStateRoot());
accountDataRequest.addResponse(worldStateProofProvider, response.accounts(), response.proofs());
}
return requestTask;
});
}
use of org.hyperledger.besu.ethereum.eth.sync.snapsync.request.AccountRangeDataRequest in project besu by hyperledger.
the class TaskGenerator method createAccountRequest.
public static List<Task<SnapDataRequest>> createAccountRequest(final boolean withData) {
final WorldStateStorage worldStateStorage = new InMemoryKeyValueStorageProvider().createWorldStateStorage(DataStorageFormat.FOREST);
final WorldStateProofProvider worldStateProofProvider = new WorldStateProofProvider(worldStateStorage);
final MerklePatriciaTrie<Bytes32, Bytes> trie = TrieGenerator.generateTrie(worldStateStorage, 1);
final RangeStorageEntriesCollector collector = RangeStorageEntriesCollector.createCollector(Bytes32.ZERO, RangeManager.MAX_RANGE, 1, Integer.MAX_VALUE);
final TrieIterator<Bytes> visitor = RangeStorageEntriesCollector.createVisitor(collector);
final TreeMap<Bytes32, Bytes> accounts = (TreeMap<Bytes32, Bytes>) trie.entriesFrom(root -> RangeStorageEntriesCollector.collectEntries(collector, visitor, root, Bytes32.ZERO));
final Hash rootHash = Hash.wrap(trie.getRootHash());
final AccountRangeDataRequest accountRangeDataRequest = SnapDataRequest.createAccountRangeDataRequest(rootHash, RangeManager.MIN_RANGE, RangeManager.MAX_RANGE);
if (withData) {
accountRangeDataRequest.addResponse(worldStateProofProvider, accounts, new ArrayDeque<>());
}
final StateTrieAccountValue stateTrieAccountValue = StateTrieAccountValue.readFrom(RLP.input(accounts.firstEntry().getValue()));
final Hash accountHash = Hash.wrap(accounts.firstKey());
final StorageRangeDataRequest storageRangeDataRequest = createStorageRangeDataRequest(worldStateProofProvider, worldStateStorage, rootHash, accountHash, stateTrieAccountValue.getStorageRoot(), withData);
final BytecodeRequest bytecodeRequest = createBytecodeDataRequest(worldStateStorage, rootHash, accountHash, stateTrieAccountValue.getCodeHash(), withData);
return List.of(new StubTask(accountRangeDataRequest), new StubTask(storageRangeDataRequest), new StubTask(bytecodeRequest));
}
Aggregations