Search in sources :

Example 16 with Metric

use of co.rsk.metrics.profilers.Metric in project rskj by rsksmart.

the class Transaction method getKey.

/*
     * Crypto
     */
public ECKey getKey() {
    Metric metric = profiler.start(Profiler.PROFILING_TYPE.KEY_RECOV_FROM_SIG);
    byte[] raw = getRawHash().getBytes();
    // We clear the 4th bit, the compress bit, in case a signature is using compress in true
    ECKey key = Secp256k1.getInstance().recoverFromSignature((signature.getV() - 27) & ~4, signature, raw, true);
    profiler.stop(metric);
    return key;
}
Also used : Metric(co.rsk.metrics.profilers.Metric) ECKey(org.ethereum.crypto.ECKey)

Example 17 with Metric

use of co.rsk.metrics.profilers.Metric in project rskj by rsksmart.

the class Transaction method getSender.

public synchronized RskAddress getSender() {
    if (sender != null) {
        return sender;
    }
    Metric metric = profiler.start(Profiler.PROFILING_TYPE.KEY_RECOV_FROM_SIG);
    try {
        ECKey key = Secp256k1.getInstance().signatureToKey(getRawHash().getBytes(), getSignature());
        sender = new RskAddress(key.getAddress());
    } catch (SignatureException e) {
        logger.error(e.getMessage(), e);
        panicProcessor.panic("transaction", e.getMessage());
        sender = RskAddress.nullAddress();
    } finally {
        profiler.stop(metric);
    }
    return sender;
}
Also used : RskAddress(co.rsk.core.RskAddress) Metric(co.rsk.metrics.profilers.Metric) ECKey(org.ethereum.crypto.ECKey) SignatureException(java.security.SignatureException)

Example 18 with Metric

use of co.rsk.metrics.profilers.Metric in project rskj by rsksmart.

the class BlockExecutor method executeInternal.

private BlockResult executeInternal(@Nullable ProgramTraceProcessor programTraceProcessor, int vmTraceOptions, Block block, BlockHeader parent, boolean discardInvalidTxs, boolean acceptInvalidTransactions) {
    boolean vmTrace = programTraceProcessor != null;
    logger.trace("Start executeInternal.");
    logger.trace("applyBlock: block: [{}] tx.list: [{}]", block.getNumber(), block.getTransactionsList().size());
    // Forks the repo, does not change "repository". It will have a completely different
    // image of the repo, where the middle caches are immediately ignored.
    // In fact, while cloning everything, it asserts that no cache elements remains.
    // (see assertNoCache())
    // Which means that you must commit changes and save them to be able to recover
    // in the next block processed.
    // Note that creating a snapshot is important when the block is executed twice
    // (e.g. once while building the block in tests/mining, and the other when trying
    // to conect the block). This is because the first execution will change the state
    // of the repository to the state post execution, so it's necessary to get it to
    // the state prior execution again.
    Metric metric = profiler.start(Profiler.PROFILING_TYPE.BLOCK_EXECUTE);
    Repository track = repositoryLocator.startTrackingAt(parent);
    maintainPrecompiledContractStorageRoots(track, activationConfig.forBlock(block.getNumber()));
    int i = 1;
    long totalGasUsed = 0;
    Coin totalPaidFees = Coin.ZERO;
    List<TransactionReceipt> receipts = new ArrayList<>();
    List<Transaction> executedTransactions = new ArrayList<>();
    Set<DataWord> deletedAccounts = new HashSet<>();
    int txindex = 0;
    for (Transaction tx : block.getTransactionsList()) {
        logger.trace("apply block: [{}] tx: [{}] ", block.getNumber(), i);
        TransactionExecutor txExecutor = transactionExecutorFactory.newInstance(tx, txindex++, block.getCoinbase(), track, block, totalGasUsed, vmTrace, vmTraceOptions, deletedAccounts);
        boolean transactionExecuted = txExecutor.executeTransaction();
        if (!acceptInvalidTransactions && !transactionExecuted) {
            if (discardInvalidTxs) {
                logger.warn("block: [{}] discarded tx: [{}]", block.getNumber(), tx.getHash());
                continue;
            } else {
                logger.warn("block: [{}] execution interrupted because of invalid tx: [{}]", block.getNumber(), tx.getHash());
                profiler.stop(metric);
                return BlockResult.INTERRUPTED_EXECUTION_BLOCK_RESULT;
            }
        }
        executedTransactions.add(tx);
        if (this.registerProgramResults) {
            this.transactionResults.put(tx.getHash(), txExecutor.getResult());
        }
        if (vmTrace) {
            txExecutor.extractTrace(programTraceProcessor);
        }
        logger.trace("tx executed");
        // No need to commit the changes here. track.commit();
        logger.trace("track commit");
        long gasUsed = txExecutor.getGasUsed();
        totalGasUsed += gasUsed;
        Coin paidFees = txExecutor.getPaidFees();
        if (paidFees != null) {
            totalPaidFees = totalPaidFees.add(paidFees);
        }
        deletedAccounts.addAll(txExecutor.getResult().getDeleteAccounts());
        TransactionReceipt receipt = new TransactionReceipt();
        receipt.setGasUsed(gasUsed);
        receipt.setCumulativeGas(totalGasUsed);
        receipt.setTxStatus(txExecutor.getReceipt().isSuccessful());
        receipt.setTransaction(tx);
        receipt.setLogInfoList(txExecutor.getVMLogs());
        receipt.setStatus(txExecutor.getReceipt().getStatus());
        logger.trace("block: [{}] executed tx: [{}]", block.getNumber(), tx.getHash());
        logger.trace("tx[{}].receipt", i);
        i++;
        receipts.add(receipt);
        logger.trace("tx done");
    }
    logger.trace("End txs executions.");
    if (!vmTrace) {
        logger.trace("Saving track.");
        track.save();
        logger.trace("End saving track.");
    }
    logger.trace("Building execution results.");
    BlockResult result = new BlockResult(block, executedTransactions, receipts, totalGasUsed, totalPaidFees, vmTrace ? null : track.getTrie());
    profiler.stop(metric);
    logger.trace("End executeInternal.");
    return result;
}
Also used : DataWord(org.ethereum.vm.DataWord) Coin(co.rsk.core.Coin) Metric(co.rsk.metrics.profilers.Metric)

Example 19 with Metric

use of co.rsk.metrics.profilers.Metric in project rskj by rsksmart.

the class Trie method get.

/**
 * get returns the value associated with a key
 *
 * @param key the key associated with the value, a byte array (variable length)
 *
 * @return  the associated value, a byte array, or null if there is no associated value to the key
 */
@Nullable
public byte[] get(byte[] key) {
    Metric metric = profiler.start(Profiler.PROFILING_TYPE.TRIE_GET_VALUE_FROM_KEY);
    Trie node = find(key);
    if (node == null) {
        profiler.stop(metric);
        return null;
    }
    byte[] result = node.getValue();
    profiler.stop(metric);
    return result;
}
Also used : Metric(co.rsk.metrics.profilers.Metric) Nullable(javax.annotation.Nullable)

Example 20 with Metric

use of co.rsk.metrics.profilers.Metric in project rskj by rsksmart.

the class Trie method fromMessage.

/**
 * Deserialize a Trie, either using the original format or RSKIP 107 format, based on version flags.
 * The original trie wasted the first byte by encoding the arity, which was always 2. We use this marker to
 * recognize the old serialization format.
 */
public static Trie fromMessage(byte[] message, TrieStore store) {
    Trie trie;
    Metric metric = profiler.start(Profiler.PROFILING_TYPE.BUILD_TRIE_FROM_MSG);
    if (message[0] == ARITY) {
        trie = fromMessageOrchid(message, store);
    } else {
        trie = fromMessageRskip107(ByteBuffer.wrap(message), store);
    }
    profiler.stop(metric);
    return trie;
}
Also used : Metric(co.rsk.metrics.profilers.Metric)

Aggregations

Metric (co.rsk.metrics.profilers.Metric)20 Coin (co.rsk.core.Coin)3 IOException (java.io.IOException)3 RskAddress (co.rsk.core.RskAddress)2 ECKey (org.ethereum.crypto.ECKey)2 ByteArrayWrapper (org.ethereum.db.ByteArrayWrapper)2 VMException (org.ethereum.vm.exception.VMException)2 BlockDifficulty (co.rsk.core.BlockDifficulty)1 Path (java.nio.file.Path)1 SignatureException (java.security.SignatureException)1 Nullable (javax.annotation.Nullable)1 DataWord (org.ethereum.vm.DataWord)1 Program (org.ethereum.vm.program.Program)1 ProgramInvoke (org.ethereum.vm.program.invoke.ProgramInvoke)1