Search in sources :

Example 11 with Trie

use of co.rsk.trie.Trie in project rskj by rsksmart.

the class TrieImplHashTest method sonWithSiblingAndOnlyOneGrandsonShouldBringSameHashBaseCase.

@Test
public void sonWithSiblingAndOnlyOneGrandsonShouldBringSameHashBaseCase() {
    Trie trie1 = new TrieImpl().put("roosevalt", "4243".getBytes()).put("rooseval_", "424344".getBytes()).put("roosevaltroosevalt", "42434445".getBytes()).delete("roosevalt");
    Trie trie2 = new TrieImpl().put("rooseval_", "424344".getBytes()).put("roosevaltroosevalt", "42434445".getBytes());
    Assert.assertTrue(Arrays.equals(trie1.get("rooseval_"), "424344".getBytes()));
    Assert.assertTrue(Arrays.equals(trie1.get("roosevaltroosevalt"), "42434445".getBytes()));
    Assert.assertNull(trie1.get("roosevalt"));
    Assert.assertEquals(trie1.getHash(), trie2.getHash());
}
Also used : TrieImpl(co.rsk.trie.TrieImpl) Trie(co.rsk.trie.Trie) Test(org.junit.Test)

Example 12 with Trie

use of co.rsk.trie.Trie in project rskj by rsksmart.

the class FreeBlock method getTxTrie.

public static Trie getTxTrie(List<Transaction> transactions) {
    if (transactions == null) {
        return new TrieImpl();
    }
    Trie txsState = new TrieImpl();
    for (int i = 0; i < transactions.size(); i++) {
        Transaction transaction = transactions.get(i);
        txsState = txsState.put(RLP.encodeInt(i), transaction.getEncoded());
    }
    return txsState;
}
Also used : TrieImpl(co.rsk.trie.TrieImpl) ImmutableTransaction(org.ethereum.core.ImmutableTransaction) Transaction(org.ethereum.core.Transaction) Trie(co.rsk.trie.Trie)

Example 13 with Trie

use of co.rsk.trie.Trie 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 14 with Trie

use of co.rsk.trie.Trie in project rskj by rsksmart.

the class Block method getTxTrie.

public static Trie getTxTrie(List<Transaction> transactions) {
    if (transactions == null) {
        return new TrieImpl();
    }
    Trie txsState = new TrieImpl();
    for (int i = 0; i < transactions.size(); i++) {
        Transaction transaction = transactions.get(i);
        txsState = txsState.put(RLP.encodeInt(i), transaction.getEncoded());
    }
    return txsState;
}
Also used : TrieImpl(co.rsk.trie.TrieImpl) RemascTransaction(co.rsk.remasc.RemascTransaction) Trie(co.rsk.trie.Trie)

Example 15 with Trie

use of co.rsk.trie.Trie in project rskj by rsksmart.

the class ContractDetailsCacheImpl method getStorageHash.

@Override
public byte[] getStorageHash() {
    // todo: unsupported
    Trie storageTrie = new TrieImpl(null, true);
    for (DataWord key : storage.keySet()) {
        DataWord value = storage.get(key);
        storageTrie = storageTrie.put(key.getData(), RLP.encodeElement(value.getNoLeadZeroesData()));
    }
    for (DataWord key : bytesStorage.keySet()) {
        byte[] value = bytesStorage.get(key);
        storageTrie = storageTrie.put(key.getData(), RLP.encodeElement(value));
    }
    return storageTrie.getHash().getBytes();
}
Also used : TrieImpl(co.rsk.trie.TrieImpl) DataWord(org.ethereum.vm.DataWord) Trie(co.rsk.trie.Trie)

Aggregations

Trie (co.rsk.trie.Trie)29 Test (org.junit.Test)24 TrieImpl (co.rsk.trie.TrieImpl)22 DataWord (org.ethereum.vm.DataWord)8 TestUtils.randomDataWord (org.ethereum.TestUtils.randomDataWord)7 TrieStore (co.rsk.trie.TrieStore)4 TrieStoreImpl (co.rsk.trie.TrieStoreImpl)4 HashMapDB (org.ethereum.datasource.HashMapDB)4 Coin (co.rsk.core.Coin)2 Keccak256 (co.rsk.crypto.Keccak256)2 BigInteger (java.math.BigInteger)2 Ignore (org.junit.Ignore)2 RskSystemProperties (co.rsk.config.RskSystemProperties)1 RskAddress (co.rsk.core.RskAddress)1 RemascTransaction (co.rsk.remasc.RemascTransaction)1 Set (java.util.Set)1 ImmutableTransaction (org.ethereum.core.ImmutableTransaction)1 Transaction (org.ethereum.core.Transaction)1 JSONObject (org.json.simple.JSONObject)1 JSONParser (org.json.simple.parser.JSONParser)1