use of org.hyperledger.besu.util.io.RollingFileWriter in project besu by hyperledger.
the class StateBackupService method backupChainData.
private void backupChainData() throws IOException {
try (final RollingFileWriter headerWriter = new RollingFileWriter(this::headerFileName, backupStatus.compressed);
final RollingFileWriter bodyWriter = new RollingFileWriter(this::bodyFileName, backupStatus.compressed);
final RollingFileWriter receiptsWriter = new RollingFileWriter(this::receiptFileName, backupStatus.compressed)) {
for (long blockNumber = 0; blockNumber <= backupStatus.targetBlock; blockNumber++) {
final Optional<Block> block = blockchain.getBlockByNumber(blockNumber);
checkState(block.isPresent(), "Block data for %s was not found in the archive", blockNumber);
final Optional<List<TransactionReceipt>> receipts = blockchain.getTxReceipts(block.get().getHash());
checkState(receipts.isPresent(), "Receipts for %s was not found in the archive", blockNumber);
final BytesValueRLPOutput headerOutput = new BytesValueRLPOutput();
block.get().getHeader().writeTo(headerOutput);
headerWriter.writeBytes(headerOutput.encoded().toArrayUnsafe());
final BytesValueRLPOutput bodyOutput = new BytesValueRLPOutput();
block.get().getBody().writeTo(bodyOutput);
bodyWriter.writeBytes(bodyOutput.encoded().toArrayUnsafe());
final BytesValueRLPOutput receiptsOutput = new BytesValueRLPOutput();
receiptsOutput.writeList(receipts.get(), TransactionReceipt::writeToWithRevertReason);
receiptsWriter.writeBytes(receiptsOutput.encoded().toArrayUnsafe());
backupStatus.storedBlock = blockNumber;
}
}
}
use of org.hyperledger.besu.util.io.RollingFileWriter in project besu by hyperledger.
the class StateBackupService method backupLeaves.
private void backupLeaves() throws IOException {
final Optional<BlockHeader> header = blockchain.getBlockHeader(backupStatus.targetBlock);
if (header.isEmpty()) {
backupStatus.currentAccount = null;
return;
}
final Optional<Bytes> worldStateRoot = worldStateStorage.getAccountStateTrieNode(Bytes.EMPTY, header.get().getStateRoot());
if (worldStateRoot.isEmpty()) {
backupStatus.currentAccount = null;
return;
}
try (final RollingFileWriter accountFileWriter = new RollingFileWriter(this::accountFileName, backupStatus.compressed)) {
this.accountFileWriter = accountFileWriter;
final StoredMerklePatriciaTrie<Bytes32, Bytes> accountTrie = new StoredMerklePatriciaTrie<>(worldStateStorage::getAccountStateTrieNode, header.get().getStateRoot(), Function.identity(), Function.identity());
accountTrie.visitLeafs(this::visitAccount);
backupStatus.currentAccount = null;
}
}
Aggregations