Skip to content

Commit

Permalink
Merge pull request #3626 from AElfProject/dev
Browse files Browse the repository at this point in the history
TransactionResult optimization
  • Loading branch information
JimAelf authored Dec 4, 2024
2 parents 39398fa + 9d567e4 commit 4926267
Show file tree
Hide file tree
Showing 30 changed files with 425 additions and 29 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/sonarqube.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
with:
dotnet-version: '8.0'
- name: Create temporary global.json
run: echo '{"sdk":{"version":"8.0.303"}}' > ./global.json
run: echo '{"sdk":{"version":"8.0.*"}}' > ./global.json
- name: Set up JDK 17
uses: actions/setup-java@v1
with:
Expand Down
10 changes: 5 additions & 5 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ jobs:
parts: 3
n: 2
codecoverage: true
- template: templates/build-template-macos.yml
parameters:
parts: 3
n: 3
codecoverage: true
# - template: templates/build-template-macos.yml
# parameters:
# parts: 3
# n: 3
# codecoverage: true

Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,12 @@ private void ProcessNextRound(NextRoundInput input)
{
var minersCount = GetMinersCount(nextRound);
if (minersCount != 0 && State.ElectionContract.Value != null)
{
State.ElectionContract.UpdateMinersCount.Send(new UpdateMinersCountInput
{
MinersCount = minersCount
});
}
}
}

Expand Down
29 changes: 29 additions & 0 deletions contract/AElf.Contracts.MultiToken/TokenContract_Actions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -691,6 +691,35 @@ public override Int32Value GetMaxBatchApproveCount(Empty input)
};
}

public override Empty ExtendSeedExpirationTime(ExtendSeedExpirationTimeInput input)
{
var tokenInfo = GetTokenInfo(input.Symbol);
if (tokenInfo == null)
{
throw new AssertionException("Seed NFT does not exist.");
}

Assert(tokenInfo.Owner == Context.Sender, "Sender is not Seed NFT owner.");
var oldExpireTimeLong = 0L;
if (tokenInfo.ExternalInfo.Value.TryGetValue(TokenContractConstants.SeedExpireTimeExternalInfoKey,
out var oldExpireTime))
{
long.TryParse(oldExpireTime, out oldExpireTimeLong);
}

tokenInfo.ExternalInfo.Value[TokenContractConstants.SeedExpireTimeExternalInfoKey] =
input.ExpirationTime.ToString();
State.TokenInfos[input.Symbol] = tokenInfo;
Context.Fire(new SeedExpirationTimeUpdated
{
ChainId = tokenInfo.IssueChainId,
Symbol = input.Symbol,
OldExpirationTime = oldExpireTimeLong,
NewExpirationTime = input.ExpirationTime
});
return new Empty();
}

private int GetMaxBatchApproveCount()
{
return State.MaxBatchApproveCount.Value == 0
Expand Down
8 changes: 7 additions & 1 deletion contract/AElf.Contracts.MultiToken/TokenContract_Helper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -215,10 +215,16 @@ private Address ExtractTokenContractAddress(ByteString bytes)
private void AssertCrossChainTransaction(Transaction originalTransaction, Address validAddress,
params string[] validMethodNames)
{
var validateResult = validMethodNames.Contains(originalTransaction.MethodName)
var validateResult = validMethodNames.Contains(MaybeRecoverInlineTransactionFunctionName(originalTransaction.MethodName))
&& originalTransaction.To == validAddress;
Assert(validateResult, "Invalid transaction.");
}

private static string MaybeRecoverInlineTransactionFunctionName(string methodName)
{
var parts = methodName.Split('.');
return parts.Length > 1 ? parts[^2] : methodName;
}

private void RegisterTokenInfo(TokenInfo tokenInfo)
{
Expand Down
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"sdk": {
"version": "8.0.x"
"version": "8.0.*"
}
}
15 changes: 15 additions & 0 deletions protobuf/inline_transaction.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
syntax = "proto3";

option csharp_namespace = "AElf.Types";


import "aelf/core.proto";
import "aelf/options.proto";

service InlineTransaction {
}

message InlineTransactionCreated {
option (aelf.is_event) = true;
aelf.Transaction transaction = 1 [(aelf.is_indexed) = true];
}
6 changes: 6 additions & 0 deletions protobuf/test_virtual_address_contract.proto
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ service VirtualAddressContract {
option (aelf.base) = "acs1.proto";

rpc VirtualAddressVote(VirtualAddressVoteInput) returns (google.protobuf.Empty);
rpc VirtualAddressVoteWithInline(VirtualAddressVoteWithCountInput) returns (google.protobuf.Empty);
rpc VirtualAddressWithdraw(aelf.Hash) returns (google.protobuf.Empty);
rpc VirtualAddressChangeVotingOption(VirtualAddressChangeVotingOptionInput) returns (google.protobuf.Empty);
rpc VirtualAddressClaimProfit(VirtualAddressClaimProfitInput) returns (google.protobuf.Empty);
Expand All @@ -32,6 +33,11 @@ message VirtualAddressVoteInput {
aelf.Hash token = 4;
}

message VirtualAddressVoteWithCountInput {
VirtualAddressVoteInput vote_input = 1; // Existing input type
int32 count = 2; // Additional count input
}

message VirtualAddressChangeVotingOptionInput {
bool is_reset = 1;
aelf.Hash vote_id = 2;
Expand Down
16 changes: 16 additions & 0 deletions protobuf/token_contract_impl.proto
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,9 @@ service TokenContractImpl {
rpc GetMaxBatchApproveCount (google.protobuf.Empty) returns (google.protobuf.Int32Value) {

}

rpc ExtendSeedExpirationTime (ExtendSeedExpirationTimeInput) returns (google.protobuf.Empty) {
}
}

message AdvanceResourceTokenInput {
Expand Down Expand Up @@ -444,4 +447,17 @@ message ModifyTokenIssuerAndOwnerInput {

message SetTokenIssuerAndOwnerModificationEnabledInput{
bool enabled = 1;
}

message ExtendSeedExpirationTimeInput {
string symbol = 1;
int64 expiration_time = 2;
}

message SeedExpirationTimeUpdated {
option (aelf.is_event) = true;
int32 chain_id = 1;
string symbol = 2;
int64 old_expiration_time = 3;
int64 new_expiration_time = 4;
}
2 changes: 1 addition & 1 deletion protobuf/virtual_transaction.proto
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ message VirtualTransactionCreated {
string method_name = 4 [(aelf.is_indexed) = true];
bytes params = 5;
aelf.Address signatory = 6 [(aelf.is_indexed) = true];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Threading;
using System.Threading.Tasks;
using AElf.Kernel;
using AElf.Kernel.Blockchain.Application;
using AElf.Kernel.FeatureDisable.Core;
using AElf.Kernel.SmartContract;
using AElf.Kernel.SmartContract.Application;
Expand All @@ -13,8 +14,8 @@ public class UnitTestPlainTransactionExecutingService : PlainTransactionExecutin
{
public UnitTestPlainTransactionExecutingService(ISmartContractExecutiveService smartContractExecutiveService,
IEnumerable<IPostExecutionPlugin> postPlugins, IEnumerable<IPreExecutionPlugin> prePlugins,
ITransactionContextFactory transactionContextFactory, IFeatureDisableService featureDisableService) : base(
smartContractExecutiveService, postPlugins, prePlugins, transactionContextFactory, featureDisableService)
ITransactionContextFactory transactionContextFactory, IFeatureDisableService featureDisableService,IBlockchainService blockchainService) : base(
smartContractExecutiveService, postPlugins, prePlugins, transactionContextFactory, featureDisableService,blockchainService)
{
}

Expand Down
13 changes: 13 additions & 0 deletions src/AElf.Kernel.Core/Extensions/TransactionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ public static int Size(this Transaction transaction)

public static bool VerifySignature(this Transaction transaction)
{
if (transaction.IsInlineWithTransactionId())
{
return true;
}
if (!transaction.VerifyFields())
return false;

Expand All @@ -27,7 +31,16 @@ public static bool VerifySignature(this Transaction transaction)

public static bool VerifyExpiration(this Transaction transaction, long chainBranchBlockHeight)
{
if (transaction.IsInlineWithTransactionId())
{
return true;
}
return transaction.RefBlockNumber <= chainBranchBlockHeight &&
transaction.GetExpiryBlockNumber() > chainBranchBlockHeight;
}

public static bool IsInlineWithTransactionId(this Transaction transaction)
{
return transaction.MethodName.Contains(".");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,8 @@
<ContractMessage Include="..\..\protobuf\virtual_transaction.proto">
<Link>Protobuf\Proto\virtual_transaction.proto</Link>
</ContractMessage>
<ContractMessage Include="..\..\protobuf\inline_transaction.proto">
<Link>Protobuf\Proto\inline_transaction.proto</Link>
</ContractMessage>
</ItemGroup>
</Project>
Loading

0 comments on commit 4926267

Please sign in to comment.