Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
181 commits
Select commit Hold shift + click to select a range
b76bbe6
feat(chainbase): add archive state collector
bladehan1 Jul 17, 2026
49a580e
feat(chainbase): persist archive block history
bladehan1 Jul 17, 2026
f384ab3
feat(chainbase): add scalable state archive
bladehan1 Aug 18, 2026
49511d4
feat(block): add offline block file tools
bladehan1 Aug 14, 2026
4d1da0b
feat(block): add offline block replay
bladehan1 Aug 14, 2026
0c882f4
fix(block): flush replay snapshot tail
bladehan1 Aug 14, 2026
c36a61e
feat(block): add resumable HTTP export
bladehan1 Aug 18, 2026
2cc0339
fix(block): parse large HTTP block ranges
bladehan1 Aug 18, 2026
a27785c
feat(block): replay consecutive block chunks
bladehan1 Aug 19, 2026
6f01b4a
feat(chainbase): persist archive recovery state
bladehan1 Aug 19, 2026
6f84a29
feat(chainbase): pin archive engine generations
bladehan1 Aug 19, 2026
a43bcef
feat(chainbase): publish archive recovery state
bladehan1 Aug 19, 2026
7a74bfb
feat(chainbase): coordinate archive recovery
bladehan1 Aug 20, 2026
b8b4073
feat(chainbase): capture archive mutations
bladehan1 Aug 20, 2026
de81c62
test(chainbase): cover archive capture recovery
bladehan1 Aug 20, 2026
dc4ae14
test(chainbase): cover consecutive archive targets
bladehan1 Aug 20, 2026
5ec30bc
feat(chainbase): own archive block projections
bladehan1 Aug 20, 2026
e38cc60
refactor(chainbase): exclude abi from archive state
bladehan1 Aug 20, 2026
5df3f56
test(chainbase): cover archive projection ownership
bladehan1 Aug 20, 2026
e4e9278
feat(chainbase): seal archive flush receipts
bladehan1 Aug 20, 2026
bb35b01
test(chainbase): cover durable flush sealing
bladehan1 Aug 20, 2026
4c0e21f
test(chainbase): assert legacy asset freeze
bladehan1 Aug 20, 2026
e3447dd
feat(chainbase): bind archive exact-26 scope
bladehan1 Aug 20, 2026
8927c88
test(chainbase): reject stale archive scopes
bladehan1 Aug 20, 2026
1341cdd
refactor(chainbase): centralize archive scope identity
bladehan1 Aug 20, 2026
d4463c8
feat(chainbase): bind archive progress scope
bladehan1 Aug 20, 2026
ac33451
feat(chainbase): bind serving generation scope
bladehan1 Aug 20, 2026
34f1d7e
feat(chainbase): add P66 asset archive codec
bladehan1 Aug 20, 2026
ecd7f4f
refactor(chainbase): unify P66 asset projection codec
bladehan1 Aug 20, 2026
eba63e8
feat(chainbase): bind p66 phase to mutation plans
bladehan1 Aug 20, 2026
19264c6
feat(chainbase): integrate archive startup recovery
bladehan1 Aug 21, 2026
399f249
feat(chainbase): integrate archive normal flush
bladehan1 Aug 21, 2026
f4eec19
feat(chainbase): bootstrap archive base
bladehan1 Aug 21, 2026
262db1f
fix(chainbase): align archive source set
bladehan1 Aug 21, 2026
ecf7c2b
fix(chainbase): bind archive flush topology
bladehan1 Aug 21, 2026
c63463b
feat(chainbase): support multi-target archive flush
bladehan1 Aug 21, 2026
2523bdf
fix(chainbase): bind batched flush topology
bladehan1 Aug 21, 2026
ce205a2
feat(chainbase): add path state commitment codec
bladehan1 Aug 21, 2026
88a6842
feat(chainbase): add path-addressed trie core
bladehan1 Aug 21, 2026
230797a
feat(chainbase): aggregate path state roots
bladehan1 Aug 21, 2026
effa052
feat(chainbase): validate path state mutations
bladehan1 Aug 21, 2026
24b4456
test(chainbase): verify path state engines
bladehan1 Aug 21, 2026
910be8f
feat(chainbase): define path state participants
bladehan1 Aug 21, 2026
1bac88c
feat(chainbase): canonicalize path state values
bladehan1 Aug 21, 2026
e6373b7
feat(chainbase): bind path state transitions
bladehan1 Aug 21, 2026
15fc1c8
feat(chainbase): define path state persistence
bladehan1 Aug 21, 2026
6f4a93a
feat(chainbase): persist path state authority
bladehan1 Aug 21, 2026
fbcb0e1
feat(chainbase): add native path node stores
bladehan1 Aug 21, 2026
d79de7b
feat(chainbase): batch path state progress
bladehan1 Aug 21, 2026
378e6fd
feat(chainbase): recover path state base
bladehan1 Aug 21, 2026
e508278
feat(chainbase): restore durable path leaves
bladehan1 Aug 21, 2026
c83c0ee
feat(chainbase): inherit path state layers
bladehan1 Aug 21, 2026
e01ea26
feat(chainbase): recover path state layers
bladehan1 Aug 21, 2026
bec75d8
feat(chainbase): bound path state layers
bladehan1 Aug 21, 2026
9e3c450
feat(chainbase): switch path state ancestry
bladehan1 Aug 21, 2026
da50681
feat(chainbase): retire path state forks
bladehan1 Aug 22, 2026
9ecbc8a
test(chainbase): guard current-only path state
bladehan1 Aug 22, 2026
37d9070
feat(chainbase): integrate native archive lifecycle
bladehan1 Aug 25, 2026
2927f86
test(chainbase): remove legacy archive coverage
bladehan1 Aug 25, 2026
07fa6b4
test(chainbase): cover native archive lifecycle
bladehan1 Aug 25, 2026
56e16c3
fix(common): handle short market price keys
bladehan1 Aug 25, 2026
d545505
fix(chainbase): guard archive readable state
bladehan1 Aug 25, 2026
5bd235a
feat(chainbase): add bounded archive range index
bladehan1 Aug 25, 2026
7c6e49c
feat(framework): add archive startup diagnostics
bladehan1 Aug 25, 2026
7526080
feat(chainbase): add exact archive serving index
bladehan1 Aug 26, 2026
a8baa2a
feat(chainbase): add path state rebuild coordinator
bladehan1 Aug 27, 2026
21e95f1
feat(chainbase): add path state native snapshot source
bladehan1 Aug 27, 2026
b05fdff
feat(chainbase): validate path state p66 layout
bladehan1 Aug 27, 2026
513118d
feat(chainbase): resume path state rebuild
bladehan1 Aug 27, 2026
1dd276a
feat(chainbase): add path state catch-up queue
bladehan1 Aug 27, 2026
939f394
perf(trie): update path state nodes locally
bladehan1 Aug 27, 2026
e34d0fe
feat(db): partition state archive history
bladehan1 Aug 27, 2026
e225dbd
perf(trie): store layer node deltas
bladehan1 Aug 27, 2026
e54be0e
perf(trie): store layer leaf deltas
bladehan1 Aug 27, 2026
2456cd9
perf(trie): reuse immutable parent state
bladehan1 Aug 27, 2026
c682a44
feat(trie): own committed snapshot head
bladehan1 Aug 27, 2026
796798f
feat(trie): prepare state transition in memory
bladehan1 Aug 27, 2026
2351a5e
test(trie): verify rebuild with oracle
bladehan1 Aug 27, 2026
63b75b7
feat(config): admit path state root startup
bladehan1 Aug 27, 2026
5abeee4
feat(db): attach path state root startup
bladehan1 Aug 27, 2026
869309b
feat(db): rebuild path state root on startup
bladehan1 Aug 27, 2026
f586b88
feat(db): attach path state block transitions
bladehan1 Aug 27, 2026
e0211d7
feat(db): rewind path state during reorg
bladehan1 Aug 27, 2026
9f0985e
feat(db): compact durable path state base
bladehan1 Aug 27, 2026
10c7083
feat(db): migrate path state on P66 activation
bladehan1 Aug 27, 2026
20813b2
feat(db): expose path state runtime status
bladehan1 Aug 27, 2026
f8723fa
test(db): verify path state shadow equivalence
bladehan1 Aug 27, 2026
bf0aaa0
feat(db): publish non-consensus path state root
bladehan1 Aug 27, 2026
63cfb73
chore(db): merge archive history partitioning
bladehan1 Aug 27, 2026
457401b
fix(db): admit empty path state index keys
bladehan1 Aug 27, 2026
03f7997
fix(db): project lazy account assets during rebuild
bladehan1 Aug 27, 2026
ea21a82
perf(db): reduce path state rebuild memory
bladehan1 Aug 29, 2026
c177dee
perf(chainbase): avoid path state cross-store reads
bladehan1 Aug 29, 2026
74900a9
perf(chainbase): parallelize state root rebuild stores
bladehan1 Aug 29, 2026
67e5ba7
perf(chainbase): bound large state root rebuilds
bladehan1 Aug 30, 2026
92fe63c
perf(chainbase): report state root rebuild progress
bladehan1 Aug 30, 2026
351650e
fix(chainbase): bound path-state rebuild memory
bladehan1 Aug 30, 2026
ca2a863
fix(chainbase): migrate rebuild checkpoints lazily
bladehan1 Aug 30, 2026
b0a9423
fix(chainbase): skip absent asset projections
bladehan1 Aug 30, 2026
5638069
feat(chainbase): report trie build progress
bladehan1 Aug 30, 2026
2f7735e
fix(chainbase): retire rebuild spools
bladehan1 Aug 30, 2026
f8cc4bd
fix(chainbase): recover failed store rebuilds
bladehan1 Aug 31, 2026
1b0276e
feat(chainbase): add physical path state runtime
bladehan1 Aug 31, 2026
1cf4434
perf(trie): batch physical state bootstrap writes
bladehan1 Sep 1, 2026
09db7f8
perf(trie): optimize physical state updates
bladehan1 Sep 1, 2026
a9639b0
perf(trie): cache transition node reads
bladehan1 Sep 2, 2026
e2f5cd0
perf(trie): parallelize path state updates
bladehan1 Sep 2, 2026
c77a1ed
feat(jsonrpc): support historical eth_call
bladehan1 Sep 2, 2026
97c9805
feat(trie): add physical state root oracle
bladehan1 Sep 2, 2026
a204e0a
feat(chainbase): add checkpointed state archive
bladehan1 Sep 4, 2026
27c0554
perf(trie): reduce path state block overhead
bladehan1 Sep 4, 2026
aa16135
fix(chainbase): honor archive index engine
bladehan1 Sep 5, 2026
5e860b2
fix(chainbase): wire common checkpoint runtime
bladehan1 Sep 5, 2026
f12126e
fix(chainbase): flush common checkpoint on close
bladehan1 Sep 5, 2026
b854173
fix(chainbase): isolate common checkpoint recovery
bladehan1 Sep 5, 2026
48ca42f
fix(chainbase): honor archive engine configuration
bladehan1 Sep 5, 2026
cfe764a
feat(db): configure archive database profiles
bladehan1 Sep 5, 2026
011bd12
fix(db): preserve path state format compatibility
bladehan1 Sep 5, 2026
8652a55
perf(db): reuse archive checkpoint index handle
bladehan1 Sep 5, 2026
d70de81
fix(chainbase): bound path state snapshot retention
bladehan1 Sep 5, 2026
a6224b3
feat(chainbase): add checkpoint phase timings
bladehan1 Sep 6, 2026
9b0a5e3
perf(chainbase): reuse archive checkpoint writer
bladehan1 Sep 6, 2026
8c110bd
fix(chainbase): bound common checkpoint markers
bladehan1 Sep 7, 2026
5eb3f4c
fix(chainbase): redo checkpoint before path open
bladehan1 Sep 7, 2026
e38d5a5
feat(chainbase): add state archive hot store
bladehan1 Sep 7, 2026
c3f4b61
feat(db): add rocksdb hot store column families
bladehan1 Sep 8, 2026
eb69be9
fix(chainbase): integrate checkpoint recovery
bladehan1 Sep 8, 2026
abc0d5c
refactor(db): remove mutation view digest
bladehan1 Sep 8, 2026
735570f
fix(chainbase): bound path-state snapshot retention
bladehan1 Sep 8, 2026
98214e1
perf(chainbase): retain archive serving writer
bladehan1 Sep 9, 2026
abaeca5
style(chainbase): clarify path-state prefixes
bladehan1 Sep 9, 2026
60237df
fix(chainbase): prevent path-state worker stalls
bladehan1 Sep 9, 2026
cf49f5c
feat(chainbase): add append-file state archive
bladehan1 Sep 10, 2026
4e246cf
feat(chainbase): add archive catalog serving
bladehan1 Sep 10, 2026
885b4ed
fix(chainbase): seal previously marked segments
bladehan1 Sep 10, 2026
af5cb41
perf(chainbase): bound archive recovery reads
bladehan1 Sep 10, 2026
77dc131
feat(chainbase): materialize p66 snapshot
bladehan1 Sep 10, 2026
e0057ac
feat(chainbase): merge p66 snapshot pipeline
bladehan1 Sep 10, 2026
ed791f6
fix(chainbase): preserve p66 recovery format
bladehan1 Sep 10, 2026
01ba1db
perf(chainbase): reduce archive bookkeeping
bladehan1 Sep 10, 2026
74661c3
feat(chainbase): isolate archive index worker
bladehan1 Sep 10, 2026
0cd959a
build(chainbase): support high rocksdb x86 candidate
bladehan1 Sep 10, 2026
c52aa8c
build(chainbase): allow explicit amd jdk17 candidate
bladehan1 Sep 10, 2026
fd8d5cb
feat(platform): allow opt-in x86 java17 candidate
bladehan1 Sep 10, 2026
222cb8c
fix(chainbase): recover finalized archive appends safely
bladehan1 Sep 11, 2026
d030c04
perf(chainbase): reuse and time serving index
bladehan1 Sep 11, 2026
1fcc9c2
perf(chainbase): reuse checkpoint suffix nodes
bladehan1 Sep 11, 2026
26ef142
fix(chainbase): retain large serving filters
bladehan1 Sep 11, 2026
435512a
perf(db): retain large account trie filters
bladehan1 Sep 12, 2026
3d411ec
feat(db): add fine-grained pathstate attribution
bladehan1 Sep 12, 2026
c6f017e
feat(db): extend pathstate read attribution
bladehan1 Sep 12, 2026
99d596c
feat(db): observe pathstate rocksdb cache events
bladehan1 Sep 12, 2026
adccf61
fix(common): satisfy math and config checks
bladehan1 Sep 12, 2026
7277f6e
perf(db): add bounded read cache candidate
bladehan1 Sep 12, 2026
c211daa
perf(db): add account cache capacity candidate
bladehan1 Sep 12, 2026
817a40e
feat(metrics): add chainbase execution attribution
bladehan1 Sep 12, 2026
a9952fc
feat(metrics): attribute business cache reads
bladehan1 Sep 12, 2026
6686276
style(metrics): align cache attribution formatting
bladehan1 Sep 12, 2026
59fb272
feat(db): add account cache capacity probe
bladehan1 Sep 13, 2026
c2cd699
feat(metrics): sample native get internals
bladehan1 Sep 13, 2026
46c99a0
feat(metrics): attribute business read waits
bladehan1 Sep 13, 2026
9e1261e
refactor(db): remove unadopted cache probes
bladehan1 Sep 14, 2026
9dabc02
test(db): add process-kill recovery tests for archive rotation and wal
bladehan1 Sep 14, 2026
ab02048
feat(db): reopen archive from the persisted proof boundary
bladehan1 Sep 14, 2026
74b235c
fix(archive): bound catalog generation retention to three
bladehan1 Sep 15, 2026
521557c
feat(archive): wire historical query rpc and vm context
bladehan1 Sep 15, 2026
9512c29
feat(db): reopen archive from the persisted proof boundary
bladehan1 Sep 15, 2026
65b3c2a
fix(archive): use fast reopen for published proof
bladehan1 Sep 15, 2026
a9686c4
fix(db): restore conservative archive recovery
bladehan1 Sep 15, 2026
97b7ca1
fix(chainbase): align archive recovery with checkpoint
bladehan1 Sep 15, 2026
34a5ea9
chore(chainbase): merge archive recovery history
bladehan1 Sep 15, 2026
a7a7bd8
fix(chainbase): align lagging archive catalog
bladehan1 Sep 15, 2026
9f26f2d
fix(chainbase): resume archive catalog retention
bladehan1 Sep 15, 2026
84e3b65
feat(chainbase): add catalogless archive v4
bladehan1 Sep 17, 2026
a9d6eb1
feat(chainbase): add geth-style archive index
bladehan1 Sep 17, 2026
9c483be
fix(chainbase): read committed archive prefixes
bladehan1 Sep 17, 2026
65f9d63
feat(config): add test archive handoff
bladehan1 Sep 18, 2026
3f01766
perf(chainbase): bound serving archive validation
bladehan1 Sep 18, 2026
396c766
perf(chainbase): batch background serving updates
bladehan1 Sep 18, 2026
42d8847
fix(chainbase): always materialize p66 snapshots
bladehan1 Sep 18, 2026
8d36759
perf(chainbase): pin path-state l0 index and isolate compaction io
bladehan1 Sep 18, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
49 changes: 39 additions & 10 deletions actuator/src/main/java/org/tron/core/actuator/VMActuator.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.function.LongSupplier;
import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
Expand Down Expand Up @@ -54,8 +55,10 @@
import org.tron.core.vm.program.ProgramPrecompile;
import org.tron.core.vm.program.invoke.ProgramInvoke;
import org.tron.core.vm.program.invoke.ProgramInvokeFactory;
import org.tron.core.vm.repository.CurrentRepositoryProvider;
import org.tron.core.vm.repository.Repository;
import org.tron.core.vm.repository.RepositoryImpl;
import org.tron.core.vm.repository.RepositoryProvider;
import org.tron.core.vm.utils.MUtil;
import org.tron.protos.Protocol;
import org.tron.protos.Protocol.Block;
Expand Down Expand Up @@ -97,8 +100,15 @@ public class VMActuator implements Actuator2 {

private LogInfoTriggerParser logInfoTriggerParser;

private final RepositoryProvider repositoryProvider;

public VMActuator(boolean isConstantCall) {
this(isConstantCall, CurrentRepositoryProvider.INSTANCE);
}

public VMActuator(boolean isConstantCall, RepositoryProvider repositoryProvider) {
this.isConstantCall = isConstantCall;
this.repositoryProvider = Objects.requireNonNull(repositoryProvider, "repositoryProvider");
this.maxEnergyLimit = CommonParameter.getInstance().maxEnergyLimitForConstant;
}

Expand All @@ -111,6 +121,11 @@ private static long getEnergyFee(long callerEnergyUsage, long callerEnergyFrozen
.divide(BigInteger.valueOf(callerEnergyTotal)).longValueExact();
}

private long dynamicLong(String key, LongSupplier currentValue) {
return rootRepository.isHistorical()
? ConfigLoader.property(rootRepository, key) : currentValue.getAsLong();
}

@Override
public void validate(Object object) throws ContractValidateException {

Expand All @@ -119,16 +134,24 @@ public void validate(Object object) throws ContractValidateException {
throw new RuntimeException("TransactionContext is null");
}

// Load Config
ConfigLoader.load(context.getStoreFactory(), isConstantCall);
rootRepository = Objects.requireNonNull(repositoryProvider.createRoot(context),
"repositoryProvider returned null");
if (rootRepository.isHistorical()) {
if (!isConstantCall) {
throw new ContractValidateException("Historical execution must be a constant call");
}
ConfigLoader.load(rootRepository);
} else {
ConfigLoader.load(context.getStoreFactory(), isConstantCall);
}
// Warm up registry class
OperationRegistry.init();
trx = context.getTrxCap().getInstance();
// If tx`s fee limit is set, use it to calc max energy limit for constant call
if (isConstantCall && trx.getRawData().getFeeLimit() > 0) {
maxEnergyLimit = min(maxEnergyLimit, trx.getRawData().getFeeLimit()
/ context.getStoreFactory().getChainBaseManager()
.getDynamicPropertiesStore().getEnergyFee(), VMConfig.disableJavaLangMath());
/ dynamicLong("ENERGY_FEE", () -> context.getStoreFactory().getChainBaseManager()
.getDynamicPropertiesStore().getEnergyFee()), VMConfig.disableJavaLangMath());
}
blockCap = context.getBlockCap();
if ((VMConfig.allowTvmFreeze() || VMConfig.allowTvmFreezeV2())
Expand All @@ -137,8 +160,10 @@ public void validate(Object object) throws ContractValidateException {
}
//Route Type
ContractType contractType = this.trx.getRawData().getContract(0).getType();
//Prepare Repository
rootRepository = RepositoryImpl.createRoot(context.getStoreFactory());
if (rootRepository.isHistorical() && contractType != ContractType.TriggerSmartContract) {
throw new ContractValidateException(
"Historical execution only supports TriggerSmartContract");
}

enableEventListener = context.isEventPluginLoaded();

Expand Down Expand Up @@ -462,7 +487,8 @@ private void create()
private void call()
throws ContractValidateException {

if (!rootRepository.getDynamicPropertiesStore().supportVM()) {
if (dynamicLong("ALLOW_CREATION_OF_CONTRACTS",
() -> rootRepository.getDynamicPropertiesStore().getAllowCreationOfContracts()) != 1L) {
logger.info("vm work is off, need to be opened by the committee");
throw new ContractValidateException("VM work is off, need to be opened by the committee");
}
Expand Down Expand Up @@ -507,10 +533,12 @@ private void call()
byte[] code = rootRepository.getCode(contractAddress);
if (isNotEmpty(code)) {
long feeLimit = trx.getRawData().getFeeLimit();
if (feeLimit < 0 || feeLimit > rootRepository.getDynamicPropertiesStore().getMaxFeeLimit()) {
long maxFeeLimit = dynamicLong("MAX_FEE_LIMIT",
() -> rootRepository.getDynamicPropertiesStore().getMaxFeeLimit());
if (feeLimit < 0 || feeLimit > maxFeeLimit) {
logger.info("invalid feeLimit {}", feeLimit);
throw new ContractValidateException("feeLimit must be >= 0 and <= "
+ rootRepository.getDynamicPropertiesStore().getMaxFeeLimit());
+ maxFeeLimit);
}
AccountCapsule caller = rootRepository.getAccount(callerAddress);
long energyLimit;
Expand All @@ -523,7 +551,8 @@ private void call()
}

long thisTxCPULimitInUs = calculateCpuLimitInUs(isConstantCall,
rootRepository.getDynamicPropertiesStore().getMaxCpuTimeOfOneTx(),
dynamicLong("MAX_CPU_TIME_OF_ONE_TX",
() -> rootRepository.getDynamicPropertiesStore().getMaxCpuTimeOfOneTx()),
getCpuLimitInUsRatio(), CommonParameter.getInstance().getConstantCallTimeoutMs());
long vmStartInUs = System.nanoTime() / VMConstant.ONE_THOUSAND;
long vmShouldEndInUs = vmStartInUs + thisTxCPULimitInUs;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.tron.core.vm;

/** Fail-closed rejection for a state capability unavailable to historical execution. */
public class HistoricalCapabilityException extends RuntimeException {

public HistoricalCapabilityException(String message) {
super(message);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package org.tron.core.vm;

/** Runtime allowlist for capabilities reachable only after bytecode dispatch. */
public final class HistoricalExecutionGuard {

private HistoricalExecutionGuard() {
}

public static void requirePrecompileAllowed(
PrecompiledContracts.PrecompiledContract contract) {
if (contract instanceof PrecompiledContracts.Identity
|| contract instanceof PrecompiledContracts.Sha256
|| contract instanceof PrecompiledContracts.Ripempd160
|| contract instanceof PrecompiledContracts.ECRecover
|| contract instanceof PrecompiledContracts.ModExp
|| contract instanceof PrecompiledContracts.BN128Addition
|| contract instanceof PrecompiledContracts.BN128Multiplication
|| contract instanceof PrecompiledContracts.BN128Pairing
|| contract instanceof PrecompiledContracts.EthRipemd160
|| contract instanceof PrecompiledContracts.Blake2F
|| contract instanceof PrecompiledContracts.P256Verify) {
return;
}
throw new HistoricalCapabilityException(
"Precompile is not allowed by historical execution: "
+ contract.getClass().getSimpleName());
}
}
8 changes: 8 additions & 0 deletions actuator/src/main/java/org/tron/core/vm/OperationActions.java
Original file line number Diff line number Diff line change
Expand Up @@ -1070,6 +1070,10 @@ public static void revertAction(Program program) {
}

public static void suicideAction(Program program) {
if (program.getContractState().isHistorical()) {
throw new HistoricalCapabilityException(
"SELFDESTRUCT is not supported by historical execution");
}
if (program.isStaticCall()) {
throw new Program.StaticCallModificationException();
}
Expand All @@ -1085,6 +1089,10 @@ public static void suicideAction(Program program) {
}

public static void suicideAction2(Program program) {
if (program.getContractState().isHistorical()) {
throw new HistoricalCapabilityException(
"SELFDESTRUCT is not supported by historical execution");
}
if (program.isStaticCall()) {
throw new Program.StaticCallModificationException();
}
Expand Down
7 changes: 7 additions & 0 deletions actuator/src/main/java/org/tron/core/vm/VM.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,17 @@ public static void play(Program program, JumpTable jumpTable) {
long factor = DYNAMIC_ENERGY_FACTOR_DECIMAL;
long energyUsage = 0L;
// hoist once per execution: avoids a per-opcode VMConfig.current() thread-local lookup
final boolean historical = program.getContractState().isHistorical();
final boolean allowDynamicEnergy = VMConfig.allowDynamicEnergy();

if (allowDynamicEnergy) {
factor = program.updateContextContractFactor();
}

while (!program.isStopped()) {
if (historical) {
program.getContractState().checkHistoricalQueryActive();
}
if (VMConfig.vmTrace()) {
program.saveOpTrace();
}
Expand Down Expand Up @@ -88,6 +92,9 @@ public static void play(Program program, JumpTable jumpTable) {

/* exec op action */
op.execute(program);
if (historical) {
program.getContractState().checkHistoricalQueryActive();
}

program.setPreviouslyExecutedOp((byte) op.getOpcode());
} catch (RuntimeException e) {
Expand Down
60 changes: 57 additions & 3 deletions actuator/src/main/java/org/tron/core/vm/config/ConfigLoader.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package org.tron.core.vm.config;

import static org.tron.core.capsule.ReceiptCapsule.checkForEnergyLimit;

import lombok.extern.slf4j.Slf4j;
import org.tron.common.parameter.CommonParameter;
import org.tron.core.store.DynamicPropertiesStore;
import org.tron.core.store.StoreFactory;
import org.tron.core.vm.HistoricalCapabilityException;
import org.tron.core.vm.repository.Repository;

@Slf4j(topic = "VMConfigLoader")
public class ConfigLoader {
Expand All @@ -21,8 +21,9 @@ public static void load(StoreFactory storeFactory, boolean isolate) {
DynamicPropertiesStore ds = storeFactory.getChainBaseManager().getDynamicPropertiesStore();
VMConfig.setVmTrace(CommonParameter.getInstance().isVmTrace());
if (ds != null) {
VMConfig.initVmHardFork(checkForEnergyLimit(ds));
VMConfig.Snapshot snapshot = new VMConfig.Snapshot();
snapshot.energyLimitHardFork = ds.getLatestBlockHeaderNumber()
>= CommonParameter.getInstance().getBlockNumForEnergyLimit();
snapshot.allowMultiSign = ds.getAllowMultiSign() == 1;
snapshot.allowTvmTransferTrc10 = ds.getAllowTvmTransferTrc10() == 1;
snapshot.allowTvmConstantinople = ds.getAllowTvmConstantinople() == 1;
Expand Down Expand Up @@ -53,9 +54,62 @@ public static void load(StoreFactory storeFactory, boolean isolate) {
if (isolate) {
VMConfig.setLocalSnapshot(snapshot);
} else {
VMConfig.initVmHardFork(snapshot.energyLimitHardFork);
VMConfig.setGlobalSnapshot(snapshot);
}
}
}
}

/** Loads an isolated VM view exclusively from a Repository's request-owned state source. */
public static void load(Repository repository) {
if (disable) {
throw new HistoricalCapabilityException(
"Historical VM config loading cannot be disabled");
}
VMConfig.setVmTrace(CommonParameter.getInstance().isVmTrace());
VMConfig.Snapshot snapshot = new VMConfig.Snapshot();
snapshot.energyLimitHardFork = property(repository, "latest_block_header_number")
>= CommonParameter.getInstance().getBlockNumForEnergyLimit();
snapshot.allowMultiSign = enabled(repository, "ALLOW_MULTI_SIGN");
snapshot.allowTvmTransferTrc10 = enabled(repository, "ALLOW_TVM_TRANSFER_TRC10");
snapshot.allowTvmConstantinople = enabled(repository, "ALLOW_TVM_CONSTANTINOPLE");
snapshot.allowTvmSolidity059 = enabled(repository, "ALLOW_TVM_SOLIDITY_059");
snapshot.allowShieldedTRC20Transaction =
enabled(repository, "ALLOW_SHIELDED_TRC20_TRANSACTION");
snapshot.allowTvmIstanbul = enabled(repository, "ALLOW_TVM_ISTANBUL");
snapshot.allowTvmFreeze = enabled(repository, "ALLOW_TVM_FREEZE");
snapshot.allowTvmVote = enabled(repository, "ALLOW_TVM_VOTE");
snapshot.allowTvmLondon = enabled(repository, "ALLOW_TVM_LONDON");
snapshot.allowTvmCompatibleEvm = enabled(repository, "ALLOW_TVM_COMPATIBLE_EVM");
snapshot.allowHigherLimitForMaxCpuTimeOfOneTx =
enabled(repository, "ALLOW_HIGHER_LIMIT_FOR_MAX_CPU_TIME_OF_ONE_TX");
snapshot.allowTvmFreezeV2 = property(repository, "UNFREEZE_DELAY_DAYS") > 0;
snapshot.allowOptimizedReturnValueOfChainId =
enabled(repository, "ALLOW_OPTIMIZED_RETURN_VALUE_OF_CHAIN_ID");
snapshot.allowDynamicEnergy = enabled(repository, "ALLOW_DYNAMIC_ENERGY");
snapshot.dynamicEnergyThreshold = property(repository, "DYNAMIC_ENERGY_THRESHOLD");
snapshot.dynamicEnergyIncreaseFactor = property(repository, "DYNAMIC_ENERGY_INCREASE_FACTOR");
snapshot.dynamicEnergyMaxFactor = property(repository, "DYNAMIC_ENERGY_MAX_FACTOR");
snapshot.allowTvmShanghai = enabled(repository, "ALLOW_TVM_SHANGHAI");
snapshot.allowEnergyAdjustment = enabled(repository, "ALLOW_ENERGY_ADJUSTMENT");
snapshot.allowStrictMath = enabled(repository, "ALLOW_STRICT_MATH");
snapshot.allowTvmCancun = enabled(repository, "ALLOW_TVM_CANCUN");
snapshot.disableJavaLangMath = enabled(repository, "CONSENSUS_LOGIC_OPTIMIZATION");
snapshot.allowTvmBlob = enabled(repository, "ALLOW_TVM_BLOB");
snapshot.allowTvmSelfdestructRestriction =
enabled(repository, "ALLOW_TVM_SELFDESTRUCT_RESTRICTION");
snapshot.allowTvmOsaka = enabled(repository, "ALLOW_TVM_OSAKA");
snapshot.allowHardenResourceCalculation =
enabled(repository, "ALLOW_HARDEN_RESOURCE_CALCULATION");
VMConfig.setLocalSnapshot(snapshot);
}

public static long property(Repository repository, String key) {
return repository.getDynamicPropertyLong(key);
}

private static boolean enabled(Repository repository, String key) {
return property(repository, key) == 1L;
}
}
10 changes: 10 additions & 0 deletions actuator/src/main/java/org/tron/core/vm/program/ContractState.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@ public void setProgramListener(ProgramListener listener) {
this.programListener = listener;
}

@Override
public void checkHistoricalQueryActive() {
repository.checkHistoricalQueryActive();
}

@Override
public boolean isHistorical() {
return repository.isHistorical();
}

@Override
public AssetIssueCapsule getAssetIssue(byte[] tokenId) {
return repository.getAssetIssue(tokenId);
Expand Down
14 changes: 12 additions & 2 deletions actuator/src/main/java/org/tron/core/vm/program/Program.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@
import org.tron.core.exception.TronException;
import org.tron.core.utils.TransactionUtil;
import org.tron.core.vm.EnergyCost;
import org.tron.core.vm.HistoricalCapabilityException;
import org.tron.core.vm.HistoricalExecutionGuard;
import org.tron.core.vm.MessageCall;
import org.tron.core.vm.Op;
import org.tron.core.vm.OperationRegistry;
Expand Down Expand Up @@ -811,6 +813,10 @@ public void createContract(DataWord value, DataWord memStart, DataWord memSize)

private void createContractImpl(DataWord value, byte[] programCode, byte[] newAddress,
boolean isCreate2) {
if (getContractState().isHistorical()) {
throw new HistoricalCapabilityException(
"CREATE and CREATE2 are not supported by historical execution");
}
byte[] senderAddress = getContextAddress();

if (logger.isDebugEnabled()) {
Expand Down Expand Up @@ -1660,6 +1666,10 @@ public void callToPrecompiledAddress(MessageCall msg,
PrecompiledContracts.PrecompiledContract contract) {
returnDataBuffer = null; // reset return buffer right before the call

if (getContractState().isHistorical()) {
HistoricalExecutionGuard.requirePrecompileAllowed(contract);
}

if (getCallDeep() == MAX_DEPTH) {
stackPushZero();
this.refundEnergy(msg.getEnergy().longValue(), " call deep limit reach");
Expand Down Expand Up @@ -2363,11 +2373,11 @@ public long updateContextContractFactor() {

if (contractStateCapsule == null) {
contractStateCapsule = new ContractStateCapsule(
contractState.getDynamicPropertiesStore().getCurrentCycleNumber());
contractState.getDynamicPropertyLong("CURRENT_CYCLE_NUMBER"));
contractState.updateContractState(getContextAddress(), contractStateCapsule);
} else {
if (contractStateCapsule.catchUpToCycle(
contractState.getDynamicPropertiesStore().getCurrentCycleNumber(),
contractState.getDynamicPropertyLong("CURRENT_CYCLE_NUMBER"),
VMConfig.getDynamicEnergyThreshold(),
VMConfig.getDynamicEnergyIncreaseFactor(),
VMConfig.getDynamicEnergyMaxFactor(),
Expand Down
Loading
Loading