Search in sources :

Example 96 with Keccak256

use of co.rsk.crypto.Keccak256 in project rskj by rsksmart.

the class FamilyUtils method getAncestors.

public static Set<Keccak256> getAncestors(BlockStore blockStore, long blockNumber, byte[] parentHash, int limitNum) {
    Set<Keccak256> ret = new HashSet<>();
    if (blockStore == null) {
        return ret;
    }
    int limit = (int) max(0, blockNumber - limitNum);
    Block it = blockStore.getBlockByHash(parentHash);
    while (it != null && it.getNumber() >= limit) {
        ret.add(it.getHash());
        it = blockStore.getBlockByHash(it.getParentHash().getBytes());
    }
    return ret;
}
Also used : Block(org.ethereum.core.Block) Keccak256(co.rsk.crypto.Keccak256) HashSet(java.util.HashSet)

Example 97 with Keccak256

use of co.rsk.crypto.Keccak256 in project rskj by rsksmart.

the class FamilyUtils method getUsedUncles.

public static Set<Keccak256> getUsedUncles(BlockStore blockStore, long blockNumber, byte[] parentHash, int limitNum) {
    Set<Keccak256> ret = new HashSet<>();
    if (blockStore == null) {
        return ret;
    }
    long minNumber = max(0, blockNumber - limitNum);
    Block it = blockStore.getBlockByHash(parentHash);
    while (it != null && it.getNumber() >= minNumber) {
        for (BlockHeader uncle : it.getUncleList()) {
            ret.add(uncle.getHash());
        }
        it = blockStore.getBlockByHash(it.getParentHash().getBytes());
    }
    return ret;
}
Also used : Block(org.ethereum.core.Block) Keccak256(co.rsk.crypto.Keccak256) BlockHeader(org.ethereum.core.BlockHeader) HashSet(java.util.HashSet)

Example 98 with Keccak256

use of co.rsk.crypto.Keccak256 in project rskj by rsksmart.

the class TransactionPoolImpl method removeTransactions.

@Override
public synchronized void removeTransactions(List<Transaction> txs) {
    for (Transaction tx : txs) {
        Keccak256 khash = tx.getHash();
        pendingTransactions.removeTransactionByHash(khash);
        queuedTransactions.removeTransactionByHash(khash);
        logger.trace("Clear transaction, hash: [{}]", khash);
    }
}
Also used : Keccak256(co.rsk.crypto.Keccak256)

Example 99 with Keccak256

use of co.rsk.crypto.Keccak256 in project rskj by rsksmart.

the class TransactionPoolImpl method addTransaction.

@Override
public synchronized boolean addTransaction(final Transaction tx) {
    if (!shouldAcceptTx(tx)) {
        return false;
    }
    Keccak256 hash = tx.getHash();
    logger.trace("add transaction {} {}", toBI(tx.getNonce()), tx.getHash());
    Long bnumber = Long.valueOf(getCurrentBestBlockNumber());
    if (pendingTransactions.hasTransaction(tx)) {
        return false;
    }
    if (queuedTransactions.hasTransaction(tx)) {
        return false;
    }
    transactionBlocks.put(hash, bnumber);
    final long timestampSeconds = this.getCurrentTimeInSeconds();
    transactionTimes.put(hash, timestampSeconds);
    BigInteger txnonce = tx.getNonceAsInteger();
    if (!txnonce.equals(this.getNextNonceByAccount(tx.getSender()))) {
        this.addQueuedTransaction(tx);
        return false;
    }
    pendingTransactions.addTransaction(tx);
    executeTransaction(tx);
    if (listener != null) {
        EventDispatchThread.invokeLater(() -> {
            listener.onPendingTransactionsReceived(Collections.singletonList(tx));
            listener.onTransactionPoolChanged(TransactionPoolImpl.this);
        });
    }
    return true;
}
Also used : BigInteger(java.math.BigInteger) Keccak256(co.rsk.crypto.Keccak256)

Example 100 with Keccak256

use of co.rsk.crypto.Keccak256 in project rskj by rsksmart.

the class ContractDetailsImpl method decode.

@Override
public final void decode(byte[] rlpBytes) {
    ArrayList<RLPElement> rlpData = RLP.decode2(rlpBytes);
    RLPList rlpList = (RLPList) rlpData.get(0);
    RLPItem rlpAddress = (RLPItem) rlpList.get(0);
    RLPItem rlpIsExternalStorage = (RLPItem) rlpList.get(1);
    RLPItem rlpStorage = (RLPItem) rlpList.get(2);
    RLPElement rlpCode = rlpList.get(3);
    RLPList rlpKeys = (RLPList) rlpList.get(4);
    this.address = rlpAddress.getRLPData();
    this.externalStorage = rlpIsExternalStorage.getRLPData() != null;
    this.originalExternalStorage = this.externalStorage;
    if (this.externalStorage) {
        Keccak256 snapshotHash = new Keccak256(rlpStorage.getRLPData());
        this.trie = new TrieImpl(new TrieStoreImpl(levelDbByName(config, getDataSourceName())), true).getSnapshotTo(snapshotHash);
    } else {
        this.trie = TrieImpl.deserialize(rlpStorage.getRLPData());
    }
    this.code = (rlpCode.getRLPData() == null) ? EMPTY_BYTE_ARRAY : rlpCode.getRLPData();
    for (RLPElement key : rlpKeys) {
        addKey(key.getRLPData());
    }
    logger.trace("decoding contract details from bytes, hash {}, address {}, storage size {}, has external storage {}", this.getStorageHashAsString(), this.getAddressAsString(), this.getStorageSize(), this.hasExternalStorage());
}
Also used : RLPItem(org.ethereum.util.RLPItem) RLPElement(org.ethereum.util.RLPElement) Keccak256(co.rsk.crypto.Keccak256) RLPList(org.ethereum.util.RLPList)

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