-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat(vm): optimize TVM delegate and undelegate execution #6920
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ouy95917
wants to merge
1
commit into
tronprotocol:develop
Choose a base branch
from
ouy95917:feat/optimize-delegate-undelegate-execution
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,7 @@ | |
| import static org.junit.Assert.assertEquals; | ||
| import static org.mockito.ArgumentMatchers.any; | ||
| import static org.tron.core.config.Parameter.ChainConstant.FROZEN_PERIOD; | ||
| import static org.tron.core.config.Parameter.ForkBlockVersionEnum.VERSION_4_8_2_2; | ||
|
|
||
| import java.util.List; | ||
| import java.util.Locale; | ||
|
|
@@ -16,6 +17,7 @@ | |
| import org.junit.BeforeClass; | ||
| import org.junit.Ignore; | ||
| import org.junit.Test; | ||
| import org.mockito.MockedStatic; | ||
| import org.mockito.Mockito; | ||
| import org.springframework.beans.factory.annotation.Autowired; | ||
| import org.springframework.util.StringUtils; | ||
|
|
@@ -24,6 +26,7 @@ | |
| import org.tron.common.parameter.CommonParameter; | ||
| import org.tron.common.runtime.InternalTransaction; | ||
| import org.tron.common.utils.DecodeUtil; | ||
| import org.tron.common.utils.ForkController; | ||
| import org.tron.core.Constant; | ||
| import org.tron.core.Wallet; | ||
| import org.tron.core.capsule.AccountCapsule; | ||
|
|
@@ -42,6 +45,7 @@ | |
| import org.tron.core.vm.config.ConfigLoader; | ||
| import org.tron.core.vm.config.VMConfig; | ||
| import org.tron.core.vm.program.Program; | ||
| import org.tron.core.vm.program.Program.OutOfTimeException; | ||
| import org.tron.core.vm.program.invoke.ProgramInvokeMockImpl; | ||
| import org.tron.core.vm.repository.Repository; | ||
| import org.tron.protos.Protocol; | ||
|
|
@@ -1182,6 +1186,7 @@ public void testSuicideAction() throws ContractValidateException { | |
|
|
||
| program.suicide(new DataWord( | ||
| dbManager.getAccountStore().getBlackhole().getAddress().toByteArray())); | ||
| Assert.assertTrue(program.getContractState().isSelfDestructed(program.getContextAddress())); | ||
|
|
||
| DecodeUtil.addressPreFixByte = prePrefixByte; | ||
| VMConfig.initAllowEnergyAdjustment(0); | ||
|
|
@@ -1240,6 +1245,7 @@ public void testSuicideAction2() throws ContractValidateException { | |
| OperationActions.suicideAction2(program); | ||
|
|
||
| Assert.assertEquals(1, program.getResult().getDeleteAccounts().size()); | ||
| Assert.assertTrue(program.getContractState().isSelfDestructed(contractAddr)); | ||
|
|
||
|
|
||
| invoke = new ProgramInvokeMockImpl(StoreFactory.getInstance(), new byte[0], contractAddr); | ||
|
|
@@ -1256,6 +1262,7 @@ public void testSuicideAction2() throws ContractValidateException { | |
| dbManager.getAccountStore().getBlackhole().getAddress().toByteArray())); | ||
|
|
||
| Assert.assertEquals(0, spyProgram.getResult().getDeleteAccounts().size()); | ||
| Assert.assertTrue(spyProgram.getContractState().isSelfDestructed(contractAddr)); | ||
|
|
||
| DecodeUtil.addressPreFixByte = prePrefixByte; | ||
| VMConfig.initAllowEnergyAdjustment(0); | ||
|
|
@@ -1266,6 +1273,31 @@ public void testSuicideAction2() throws ContractValidateException { | |
| VMConfig.initAllowTvmVote(0); | ||
| } | ||
|
|
||
| @Test | ||
| public void testSuicide2RejectsSelfDestructedBeneficiaryAfterFork() | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we also add a pre-fork case asserting that suicide2() succeeds when VERSION_4_8_2_2 is not activated? Since the beneficiary check is invoked unconditionally and gated inside MUtil, this would explicitly protect backward compatibility before the fork. |
||
| throws ContractValidateException { | ||
| byte[] contractAddr = Hex.decode("41471fd3ad3e9eeadeec4608b92d16ce6b500704cc"); | ||
| byte[] beneficiary = Hex.decode("411111111111111111111111111111111111111111"); | ||
| invoke = new ProgramInvokeMockImpl(StoreFactory.getInstance(), new byte[0], contractAddr); | ||
| program = new Program(null, null, invoke, | ||
| new InternalTransaction( | ||
| Protocol.Transaction.getDefaultInstance(), | ||
| InternalTransaction.TrxType.TRX_UNKNOWN_TYPE)); | ||
| program.getContractState().markSelfDestruct(beneficiary); | ||
|
|
||
| ForkController forkController = Mockito.mock(ForkController.class); | ||
| try (MockedStatic<ForkController> fork = Mockito.mockStatic(ForkController.class)) { | ||
| fork.when(ForkController::instance).thenReturn(forkController); | ||
| Mockito.when(forkController.pass(VERSION_4_8_2_2)).thenReturn(true); | ||
|
|
||
| OutOfTimeException exception = Assert.assertThrows(OutOfTimeException.class, | ||
| () -> program.suicide2(new DataWord(beneficiary))); | ||
| Assert.assertEquals( | ||
| "CPU timeout for SELFDESTRUCT with selfdestructed beneficiary", | ||
| exception.getMessage()); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| public void testVoteWitnessCost() throws ContractValidateException { | ||
| // Build stack environment, the stack from top to bottom is 0x00, 0x80, 0x00, 0x80 | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we also add a pre-fork case asserting that suicide2() succeeds when VERSION_4_8_2_2 is not activated? Since the beneficiary check is invoked unconditionally and gated inside MUtil, this would explicitly protect backward compatibility before the fork.