use of co.rsk.crypto.Keccak256 in project rskj by rsksmart.
the class DoPrune method processBlocks.
public void processBlocks(long from, TrieImpl sourceTrie, RskAddress contractAddress, TrieStore targetStore) {
long n = from;
if (n <= 0) {
n = 1;
}
while (true) {
List<Block> blocks = this.blockchain.getBlocksByNumber(n);
if (blocks.isEmpty()) {
break;
}
for (Block b : blocks) {
byte[] stateRoot = b.getStateRoot();
logger.info("Block height {} State root {}", b.getNumber(), Hex.toHexString(stateRoot));
Repository repo = this.blockchain.getRepository();
repo.syncToRoot(stateRoot);
logger.info("Repo root {}", Hex.toHexString(repo.getRoot()));
AccountState accountState = repo.getAccountState(contractAddress);
Keccak256 trieRoot = new Keccak256(accountState.getStateRoot());
logger.info("Trie root {}", trieRoot);
Trie contractStorage = sourceTrie.getSnapshotTo(trieRoot);
contractStorage.copyTo(targetStore);
logger.info("Trie root {}", contractStorage.getHash());
}
n++;
}
}
use of co.rsk.crypto.Keccak256 in project rskj by rsksmart.
the class FamilyUtils method getUnclesHeaders.
public static List<BlockHeader> getUnclesHeaders(@Nonnull BlockStore store, long blockNumber, byte[] parentHash, int levels) {
List<BlockHeader> uncles = new ArrayList<>();
Set<Keccak256> unclesHeaders = getUncles(store, blockNumber, parentHash, levels);
for (Keccak256 uncleHash : unclesHeaders) {
Block uncle = store.getBlockByHash(uncleHash.getBytes());
if (uncle != null) {
uncles.add(uncle.getHeader());
}
}
return uncles;
}
use of co.rsk.crypto.Keccak256 in project rskj by rsksmart.
the class FamilyUtils method getFamily.
public static Set<Keccak256> getFamily(BlockStore store, long blockNumber, byte[] parentHash, int levels) {
long minNumber = max(0, blockNumber - levels);
List<Block> ancestors = new ArrayList<>();
Block parent = store.getBlockByHash(parentHash);
while (parent != null && parent.getNumber() >= minNumber) {
ancestors.add(0, parent);
parent = store.getBlockByHash(parent.getParentHash().getBytes());
}
Set<Keccak256> family = ancestors.stream().map(Block::getHash).collect(Collectors.toSet());
for (int k = 1; k < ancestors.size(); k++) {
Block ancestorParent = ancestors.get(k - 1);
Block ancestor = ancestors.get(k);
List<Block> uncles = store.getChainBlocksByNumber(ancestor.getNumber());
for (Block uncle : uncles) {
// TODO quick fix, the block storage should be reviewed
if (uncle == null) {
continue;
}
if (!ancestorParent.getHash().equals(uncle.getParentHash())) {
continue;
}
if (ancestor.getHash().equals(uncle.getHash())) {
continue;
}
family.add(uncle.getHash());
}
}
return family;
}
use of co.rsk.crypto.Keccak256 in project rskj by rsksmart.
the class TransactionPoolImpl method removeTransactionList.
private void removeTransactionList(List<Keccak256> toremove) {
for (Keccak256 key : toremove) {
pendingTransactions.removeTransactionByHash(key);
queuedTransactions.removeTransactionByHash(key);
transactionBlocks.remove(key);
transactionTimes.remove(key);
}
}
use of co.rsk.crypto.Keccak256 in project rskj by rsksmart.
the class HashRateCalculator method hashRate.
private BigInteger hashRate(BlockHeaderElement elem, Predicate<BlockHeaderElement> countCondition, Predicate<BlockHeaderElement> cutCondition) {
BigInteger hashRate = BigInteger.ZERO;
BlockHeaderElement element = elem;
while (element != null && cutCondition.test(element)) {
if (countCondition.test(element)) {
hashRate = hashRate.add(element.getDifficulty().asBigInteger());
}
Keccak256 parentHash = element.getBlockHeader().getParentHash();
element = getHeaderElement(parentHash);
}
return hashRate;
}
Aggregations