Skip to content

Commit

Permalink
Remove cross-aa code
Browse files Browse the repository at this point in the history
  • Loading branch information
chopin-fan committed Dec 23, 2024
1 parent b8fb0d8 commit 586a98a
Show file tree
Hide file tree
Showing 20 changed files with 21 additions and 332 deletions.
8 changes: 1 addition & 7 deletions contract/AElf.Contracts.MultiToken/TokenContract_Helper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -215,16 +215,10 @@ private Address ExtractTokenContractAddress(ByteString bytes)
private void AssertCrossChainTransaction(Transaction originalTransaction, Address validAddress,
params string[] validMethodNames)
{
var validateResult = validMethodNames.Contains(MaybeRecoverInlineTransactionFunctionName(originalTransaction.MethodName))
var validateResult = validMethodNames.Contains(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
6 changes: 0 additions & 6 deletions protobuf/test_virtual_address_contract.proto
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ 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 @@ -33,11 +32,6 @@ 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
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
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 @@ -14,8 +13,8 @@ public class UnitTestPlainTransactionExecutingService : PlainTransactionExecutin
{
public UnitTestPlainTransactionExecutingService(ISmartContractExecutiveService smartContractExecutiveService,
IEnumerable<IPostExecutionPlugin> postPlugins, IEnumerable<IPreExecutionPlugin> prePlugins,
ITransactionContextFactory transactionContextFactory, IFeatureDisableService featureDisableService,IBlockchainService blockchainService) : base(
smartContractExecutiveService, postPlugins, prePlugins, transactionContextFactory, featureDisableService,blockchainService)
ITransactionContextFactory transactionContextFactory, IFeatureDisableService featureDisableService) : base(
smartContractExecutiveService, postPlugins, prePlugins, transactionContextFactory, featureDisableService)
{
}

Expand Down
13 changes: 0 additions & 13 deletions src/AElf.Kernel.Core/Extensions/TransactionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@ 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 @@ -31,16 +27,7 @@ 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,8 +22,5 @@
<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>
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using AElf.CSharp.Core.Extension;
using AElf.Kernel.Blockchain.Application;
using AElf.Kernel.FeatureDisable.Core;
using AElf.Kernel.SmartContract.Domain;
using AElf.Kernel.SmartContract.Infrastructure;
Expand All @@ -25,17 +23,14 @@ public class PlainTransactionExecutingService : IPlainTransactionExecutingServic
private readonly ISmartContractExecutiveService _smartContractExecutiveService;
private readonly ITransactionContextFactory _transactionContextFactory;
private readonly IFeatureDisableService _featureDisableService;
private readonly IBlockchainService _blockchainService;

public PlainTransactionExecutingService(ISmartContractExecutiveService smartContractExecutiveService,
IEnumerable<IPostExecutionPlugin> postPlugins, IEnumerable<IPreExecutionPlugin> prePlugins,
ITransactionContextFactory transactionContextFactory, IFeatureDisableService featureDisableService,
IBlockchainService blockchainService)
ITransactionContextFactory transactionContextFactory, IFeatureDisableService featureDisableService)
{
_smartContractExecutiveService = smartContractExecutiveService;
_transactionContextFactory = transactionContextFactory;
_featureDisableService = featureDisableService;
_blockchainService = blockchainService;
_prePlugins = GetUniquePlugins(prePlugins);
_postPlugins = GetUniquePlugins(postPlugins);
Logger = NullLogger<PlainTransactionExecutingService>.Instance;
Expand Down Expand Up @@ -66,7 +61,6 @@ public async Task<List<ExecutionReturnSet>> ExecuteAsync(TransactionExecutingDto
var singleTxExecutingDto = new SingleTransactionExecutingDto
{
Depth = 0,
InlineWithTransactionIdCounter = new InlineWithTransactionIdCounter(),
ChainContext = groupChainContext,
Transaction = transaction,
CurrentBlockTime = transactionExecutingDto.BlockHeader.Time,
Expand All @@ -77,7 +71,7 @@ public async Task<List<ExecutionReturnSet>> ExecuteAsync(TransactionExecutingDto
var transactionExecutionTask = Task.Run(() => ExecuteOneAsync(singleTxExecutingDto,
cancellationToken), cancellationToken);

trace = await transactionExecutionTask;
trace = await transactionExecutionTask.WithCancellation(cancellationToken);
}
catch (OperationCanceledException)
{
Expand All @@ -96,7 +90,7 @@ public async Task<List<ExecutionReturnSet>> ExecuteAsync(TransactionExecutingDto
var result = GetTransactionResult(trace, transactionExecutingDto.BlockHeader.Height);

var returnSet = GetReturnSet(trace, result);
returnSets.AddRange(returnSet);
returnSets.Add(returnSet);
}

return returnSets;
Expand Down Expand Up @@ -181,22 +175,14 @@ protected virtual async Task<TransactionTrace> ExecuteOneAsync(

#endregion

var methodName = txContext.Transaction.MethodName;
var originMethodName = MaybeRecoverInlineTransactionFunctionName(methodName);
txContext.Transaction.MethodName = originMethodName;

await executive.ApplyAsync(txContext);

if (txContext.Trace.IsSuccessful())
{
// Maybe layered method name.
txContext.Transaction.MethodName = methodName;
await ExecuteInlineTransactions(singleTxExecutingDto.Depth, singleTxExecutingDto.CurrentBlockTime,
txContext, internalStateCache,
internalChainContext,
singleTxExecutingDto.OriginTransactionId,
cancellationToken);
}

#region PostTransaction

Expand Down Expand Up @@ -235,40 +221,11 @@ private async Task ExecuteInlineTransactions(int depth, Timestamp currentBlockTi
{
var trace = txContext.Trace;
internalStateCache.Update(txContext.Trace.GetStateSets());

var methodNameCount = new Dictionary<string, int>();
foreach (var inlineTx in txContext.Trace.InlineTransactions)
{
var needTxId = NeedTransactionId(inlineTx.MethodName);
if (needTxId)
{
txContext.InlineWithTransactionIdCounter.Increment();
if (!methodNameCount.TryAdd(inlineTx.MethodName, 0))
{
methodNameCount[inlineTx.MethodName]++;
inlineTx.MethodName =
GenerateLayeredMethodNameForInlineTransaction(
txContext.Transaction,
inlineTx.MethodName,
methodNameCount[inlineTx.MethodName]
);
}
else
{
inlineTx.MethodName = GenerateLayeredMethodNameForInlineTransaction(
txContext.Transaction,
inlineTx.MethodName,
0
);
}

await _blockchainService.AddTransactionsAsync([inlineTx]);
}

var singleTxExecutingDto = new SingleTransactionExecutingDto
{
Depth = depth + 1,
InlineWithTransactionIdCounter = txContext.InlineWithTransactionIdCounter,
ChainContext = internalChainContext,
Transaction = inlineTx,
CurrentBlockTime = currentBlockTime,
Expand All @@ -289,25 +246,6 @@ private async Task ExecuteInlineTransactions(int depth, Timestamp currentBlockTi
}
}

private static string GenerateLayeredMethodNameForInlineTransaction(Transaction parentTx, string inlineFunctionName,
int index)
{
var parentTxMethodName = parentTx.MethodName;
inlineFunctionName = inlineFunctionName.StartsWith('.') ? inlineFunctionName[1..] : inlineFunctionName;
return $"{parentTx.GetHash().ToHex()}.{parentTxMethodName}.{inlineFunctionName}.{index}";
}

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

private static bool NeedTransactionId(string methodName)
{
return methodName.Contains('.');
}

private async Task<bool> ExecutePluginOnPreTransactionStageAsync(IExecutive executive,
ITransactionContext txContext,
Timestamp currentBlockTime,
Expand Down Expand Up @@ -455,7 +393,7 @@ private TransactionResult GetTransactionResult(TransactionTrace trace, long bloc
return txResult;
}

private IEnumerable<ExecutionReturnSet> GetReturnSet(TransactionTrace trace, TransactionResult result)
private ExecutionReturnSet GetReturnSet(TransactionTrace trace, TransactionResult result)
{
var returnSet = new ExecutionReturnSet
{
Expand All @@ -464,41 +402,12 @@ private IEnumerable<ExecutionReturnSet> GetReturnSet(TransactionTrace trace, Tra
Bloom = result.Bloom,
TransactionResult = result
};
var returnSets = new List<ExecutionReturnSet> { returnSet };

if (trace.IsSuccessful())
{
var transactionExecutingStateSets = trace.GetStateSets();
returnSet = GetReturnSet(returnSet, transactionExecutingStateSets);
returnSet.ReturnValue = trace.ReturnValue;

var inlineTxWithIdList = trace.GetAllInlineTransactions().Where(tx => NeedTransactionId(tx.MethodName));
foreach (var inlineTx in inlineTxWithIdList)
{
var inlineTxId = inlineTx.GetHash();
var inlineReturnSet = new ExecutionReturnSet
{
TransactionId = inlineTxId,
Status = TransactionResultStatus.Mined,
TransactionResult = new TransactionResult
{
TransactionId = inlineTxId,
BlockNumber = result.BlockNumber,
Status = TransactionResultStatus.Mined
}
};

// No need to execute GetReturnSet method, because changes are already set to `returnSet`.

returnSets.Add(inlineReturnSet);

Logger.LogWarning($"Inline tx id: {inlineTx.GetHash().ToHex()}\n{inlineTx}");
var log = new InlineTransactionCreated()
{
Transaction = inlineTx
};
returnSet.TransactionResult.Logs.Add(log.ToLogEvent(inlineTx.To));
}
}
else
{
Expand All @@ -517,7 +426,7 @@ private IEnumerable<ExecutionReturnSet> GetReturnSet(TransactionTrace trace, Tra
var reads = trace.GetFlattenedReads();
foreach (var read in reads) returnSet.StateAccesses[read.Key] = read.Value;

return returnSets;
return returnSet;
}

private ExecutionReturnSet GetReturnSet(ExecutionReturnSet returnSet,
Expand Down Expand Up @@ -567,7 +476,6 @@ protected ITransactionContext CreateTransactionContext(SingleTransactionExecutin
singleTxExecutingDto.ChainContext, singleTxExecutingDto.OriginTransactionId, origin,
singleTxExecutingDto.Depth, singleTxExecutingDto.CurrentBlockTime);

txContext.InlineWithTransactionIdCounter = singleTxExecutingDto.InlineWithTransactionIdCounter;
return txContext;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,4 @@ public class SingleTransactionExecutingDto
public bool IsCancellable { get; set; } = true;

public Hash OriginTransactionId { get; set; }
public InlineWithTransactionIdCounter InlineWithTransactionIdCounter { get; set; }
}
1 change: 0 additions & 1 deletion src/AElf.Kernel.SmartContract/ITransactionContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,4 @@ public interface ITransactionContext
Transaction Transaction { get; set; }
TransactionTrace Trace { get; set; }
IStateCache StateCache { get; set; }
InlineWithTransactionIdCounter InlineWithTransactionIdCounter { get; set; }
}
18 changes: 0 additions & 18 deletions src/AElf.Kernel.SmartContract/InlineWithTransactionIdCounter.cs

This file was deleted.

1 change: 0 additions & 1 deletion src/AElf.Kernel.SmartContract/TransactionContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,4 @@ public class TransactionContext : ITransactionContext
public Transaction Transaction { get; set; }
public TransactionTrace Trace { get; set; }
public IStateCache StateCache { get; set; }
public InlineWithTransactionIdCounter InlineWithTransactionIdCounter { get; set; }
}
Loading

0 comments on commit 586a98a

Please sign in to comment.