Search in sources :

Example 46 with Keccak256

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++;
    }
}
Also used : Keccak256(co.rsk.crypto.Keccak256) Trie(co.rsk.trie.Trie)

Example 47 with Keccak256

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;
}
Also used : ArrayList(java.util.ArrayList) Block(org.ethereum.core.Block) Keccak256(co.rsk.crypto.Keccak256) BlockHeader(org.ethereum.core.BlockHeader)

Example 48 with Keccak256

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;
}
Also used : ArrayList(java.util.ArrayList) Block(org.ethereum.core.Block) Keccak256(co.rsk.crypto.Keccak256)

Example 49 with Keccak256

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);
    }
}
Also used : Keccak256(co.rsk.crypto.Keccak256)

Example 50 with Keccak256

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;
}
Also used : BigInteger(java.math.BigInteger) Keccak256(co.rsk.crypto.Keccak256)

Aggregations

Keccak256 (co.rsk.crypto.Keccak256)102 Test (org.junit.Test)53 Block (org.ethereum.core.Block)40 BlockGenerator (co.rsk.blockchain.utils.BlockGenerator)15 BigInteger (java.math.BigInteger)14 RskSystemProperties (co.rsk.config.RskSystemProperties)8 SimpleMessageChannel (co.rsk.net.simples.SimpleMessageChannel)8 SyncConfiguration (co.rsk.net.sync.SyncConfiguration)8 HashMapDB (org.ethereum.datasource.HashMapDB)8 RepositoryImpl (co.rsk.db.RepositoryImpl)7 ArrayList (java.util.ArrayList)7 Blockchain (org.ethereum.core.Blockchain)7 BlockStore (org.ethereum.db.BlockStore)7 IndexedBlockStore (org.ethereum.db.IndexedBlockStore)7 RLPList (org.ethereum.util.RLPList)6 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)6 Script (co.rsk.bitcoinj.script.Script)5 Coin (co.rsk.core.Coin)5 IOException (java.io.IOException)5 BlockHeader (org.ethereum.core.BlockHeader)5