Coverage Summary for Class: TransactionExecutorFactory (co.rsk.core)
Class |
Class, %
|
Method, %
|
Line, %
|
TransactionExecutorFactory |
100%
(1/1)
|
100%
(3/3)
|
76.2%
(16/21)
|
1 /*
2 * This file is part of RskJ
3 * Copyright (C) 2019 RSK Labs Ltd.
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU Lesser General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 package co.rsk.core;
20
21 import co.rsk.config.RskSystemProperties;
22 import co.rsk.config.VmConfig;
23 import org.ethereum.core.*;
24 import org.ethereum.db.BlockStore;
25 import org.ethereum.db.ReceiptStore;
26 import org.ethereum.vm.DataWord;
27 import org.ethereum.vm.PrecompiledContracts;
28 import org.ethereum.vm.program.invoke.ProgramInvokeFactory;
29
30 import java.util.HashSet;
31 import java.util.Set;
32
33 public class TransactionExecutorFactory {
34
35 private final RskSystemProperties config;
36 private final BlockStore blockStore;
37 private final ReceiptStore receiptStore;
38 private final BlockFactory blockFactory;
39 private final ProgramInvokeFactory programInvokeFactory;
40 private final PrecompiledContracts precompiledContracts;
41 private BlockTxSignatureCache blockTxSignatureCache;
42
43 public TransactionExecutorFactory(
44 RskSystemProperties config,
45 BlockStore blockStore,
46 ReceiptStore receiptStore,
47 BlockFactory blockFactory,
48 ProgramInvokeFactory programInvokeFactory,
49 PrecompiledContracts precompiledContracts,
50 BlockTxSignatureCache blockTxSignatureCache) {
51 this.config = config;
52 this.blockStore = blockStore;
53 this.receiptStore = receiptStore;
54 this.blockFactory = blockFactory;
55 this.programInvokeFactory = programInvokeFactory;
56 this.precompiledContracts = precompiledContracts;
57 this.blockTxSignatureCache = blockTxSignatureCache;
58 }
59
60 public TransactionExecutor newInstance(
61 Transaction tx,
62 int txindex,
63 RskAddress coinbase,
64 Repository track,
65 Block block,
66 long totalGasUsed) {
67 return newInstance(tx, txindex, coinbase, track, block, totalGasUsed, false, 0, new HashSet<>());
68 }
69
70 public TransactionExecutor newInstance(
71 Transaction tx,
72 int txindex,
73 RskAddress coinbase,
74 Repository track,
75 Block block,
76 long totalGasUsed,
77 boolean vmTrace,
78 int vmTraceOptions,
79 Set<DataWord> deletedAccounts) {
80 // Tracing configuration is scattered across different files (VM, DetailedProgramTrace, etc.) and
81 // TransactionExecutor#extractTrace doesn't work when called independently.
82 // It would be great to decouple from VmConfig#vmTrace, but sadly that's a major refactor we can't do now.
83 VmConfig vmConfig = config.getVmConfig();
84 if (vmTrace) {
85 vmConfig = new VmConfig(
86 true,
87 vmTraceOptions,
88 vmConfig.vmTraceInitStorageLimit(),
89 vmConfig.dumpBlock(),
90 vmConfig.dumpStyle(),
91 vmConfig.getChainId()
92 );
93 }
94
95 return new TransactionExecutor(
96 config.getNetworkConstants(),
97 config.getActivationConfig(),
98 tx,
99 txindex,
100 coinbase,
101 track,
102 blockStore,
103 receiptStore,
104 blockFactory,
105 programInvokeFactory,
106 block,
107 totalGasUsed,
108 vmConfig,
109 config.isRemascEnabled(),
110 precompiledContracts,
111 deletedAccounts,
112 blockTxSignatureCache
113 );
114 }
115 }