3
3
using System . Linq ;
4
4
using System . Threading ;
5
5
using System . Threading . Tasks ;
6
- using AElf . CSharp . Core . Extension ;
7
- using AElf . Kernel . Blockchain . Application ;
8
6
using AElf . Kernel . FeatureDisable . Core ;
9
7
using AElf . Kernel . SmartContract . Domain ;
10
8
using AElf . Kernel . SmartContract . Infrastructure ;
@@ -25,17 +23,14 @@ public class PlainTransactionExecutingService : IPlainTransactionExecutingServic
25
23
private readonly ISmartContractExecutiveService _smartContractExecutiveService ;
26
24
private readonly ITransactionContextFactory _transactionContextFactory ;
27
25
private readonly IFeatureDisableService _featureDisableService ;
28
- private readonly IBlockchainService _blockchainService ;
29
26
30
27
public PlainTransactionExecutingService ( ISmartContractExecutiveService smartContractExecutiveService ,
31
28
IEnumerable < IPostExecutionPlugin > postPlugins , IEnumerable < IPreExecutionPlugin > prePlugins ,
32
- ITransactionContextFactory transactionContextFactory , IFeatureDisableService featureDisableService ,
33
- IBlockchainService blockchainService )
29
+ ITransactionContextFactory transactionContextFactory , IFeatureDisableService featureDisableService )
34
30
{
35
31
_smartContractExecutiveService = smartContractExecutiveService ;
36
32
_transactionContextFactory = transactionContextFactory ;
37
33
_featureDisableService = featureDisableService ;
38
- _blockchainService = blockchainService ;
39
34
_prePlugins = GetUniquePlugins ( prePlugins ) ;
40
35
_postPlugins = GetUniquePlugins ( postPlugins ) ;
41
36
Logger = NullLogger < PlainTransactionExecutingService > . Instance ;
@@ -66,7 +61,6 @@ public async Task<List<ExecutionReturnSet>> ExecuteAsync(TransactionExecutingDto
66
61
var singleTxExecutingDto = new SingleTransactionExecutingDto
67
62
{
68
63
Depth = 0 ,
69
- InlineWithTransactionIdCounter = new InlineWithTransactionIdCounter ( ) ,
70
64
ChainContext = groupChainContext ,
71
65
Transaction = transaction ,
72
66
CurrentBlockTime = transactionExecutingDto . BlockHeader . Time ,
@@ -77,7 +71,7 @@ public async Task<List<ExecutionReturnSet>> ExecuteAsync(TransactionExecutingDto
77
71
var transactionExecutionTask = Task . Run ( ( ) => ExecuteOneAsync ( singleTxExecutingDto ,
78
72
cancellationToken ) , cancellationToken ) ;
79
73
80
- trace = await transactionExecutionTask ;
74
+ trace = await transactionExecutionTask . WithCancellation ( cancellationToken ) ;
81
75
}
82
76
catch ( OperationCanceledException )
83
77
{
@@ -96,7 +90,7 @@ public async Task<List<ExecutionReturnSet>> ExecuteAsync(TransactionExecutingDto
96
90
var result = GetTransactionResult ( trace , transactionExecutingDto . BlockHeader . Height ) ;
97
91
98
92
var returnSet = GetReturnSet ( trace , result ) ;
99
- returnSets . AddRange ( returnSet ) ;
93
+ returnSets . Add ( returnSet ) ;
100
94
}
101
95
102
96
return returnSets ;
@@ -181,22 +175,14 @@ protected virtual async Task<TransactionTrace> ExecuteOneAsync(
181
175
182
176
#endregion
183
177
184
- var methodName = txContext . Transaction . MethodName ;
185
- var originMethodName = MaybeRecoverInlineTransactionFunctionName ( methodName ) ;
186
- txContext . Transaction . MethodName = originMethodName ;
187
-
188
178
await executive . ApplyAsync ( txContext ) ;
189
179
190
180
if ( txContext . Trace . IsSuccessful ( ) )
191
- {
192
- // Maybe layered method name.
193
- txContext . Transaction . MethodName = methodName ;
194
181
await ExecuteInlineTransactions ( singleTxExecutingDto . Depth , singleTxExecutingDto . CurrentBlockTime ,
195
182
txContext , internalStateCache ,
196
183
internalChainContext ,
197
184
singleTxExecutingDto . OriginTransactionId ,
198
185
cancellationToken ) ;
199
- }
200
186
201
187
#region PostTransaction
202
188
@@ -235,40 +221,11 @@ private async Task ExecuteInlineTransactions(int depth, Timestamp currentBlockTi
235
221
{
236
222
var trace = txContext . Trace ;
237
223
internalStateCache . Update ( txContext . Trace . GetStateSets ( ) ) ;
238
-
239
- var methodNameCount = new Dictionary < string , int > ( ) ;
240
224
foreach ( var inlineTx in txContext . Trace . InlineTransactions )
241
225
{
242
- var needTxId = NeedTransactionId ( inlineTx . MethodName ) ;
243
- if ( needTxId )
244
- {
245
- txContext . InlineWithTransactionIdCounter . Increment ( ) ;
246
- if ( ! methodNameCount . TryAdd ( inlineTx . MethodName , 0 ) )
247
- {
248
- methodNameCount [ inlineTx . MethodName ] ++ ;
249
- inlineTx . MethodName =
250
- GenerateLayeredMethodNameForInlineTransaction (
251
- txContext . Transaction ,
252
- inlineTx . MethodName ,
253
- methodNameCount [ inlineTx . MethodName ]
254
- ) ;
255
- }
256
- else
257
- {
258
- inlineTx . MethodName = GenerateLayeredMethodNameForInlineTransaction (
259
- txContext . Transaction ,
260
- inlineTx . MethodName ,
261
- 0
262
- ) ;
263
- }
264
-
265
- await _blockchainService . AddTransactionsAsync ( [ inlineTx ] ) ;
266
- }
267
-
268
226
var singleTxExecutingDto = new SingleTransactionExecutingDto
269
227
{
270
228
Depth = depth + 1 ,
271
- InlineWithTransactionIdCounter = txContext . InlineWithTransactionIdCounter ,
272
229
ChainContext = internalChainContext ,
273
230
Transaction = inlineTx ,
274
231
CurrentBlockTime = currentBlockTime ,
@@ -289,25 +246,6 @@ private async Task ExecuteInlineTransactions(int depth, Timestamp currentBlockTi
289
246
}
290
247
}
291
248
292
- private static string GenerateLayeredMethodNameForInlineTransaction ( Transaction parentTx , string inlineFunctionName ,
293
- int index )
294
- {
295
- var parentTxMethodName = parentTx . MethodName ;
296
- inlineFunctionName = inlineFunctionName . StartsWith ( '.' ) ? inlineFunctionName [ 1 ..] : inlineFunctionName ;
297
- return $ "{ parentTx . GetHash ( ) . ToHex ( ) } .{ parentTxMethodName } .{ inlineFunctionName } .{ index } ";
298
- }
299
-
300
- private static string MaybeRecoverInlineTransactionFunctionName ( string methodName )
301
- {
302
- var parts = methodName . Split ( '.' ) ;
303
- return parts . Length > 1 ? parts [ ^ 2 ] : methodName ;
304
- }
305
-
306
- private static bool NeedTransactionId ( string methodName )
307
- {
308
- return methodName . Contains ( '.' ) ;
309
- }
310
-
311
249
private async Task < bool > ExecutePluginOnPreTransactionStageAsync ( IExecutive executive ,
312
250
ITransactionContext txContext ,
313
251
Timestamp currentBlockTime ,
@@ -455,7 +393,7 @@ private TransactionResult GetTransactionResult(TransactionTrace trace, long bloc
455
393
return txResult ;
456
394
}
457
395
458
- private IEnumerable < ExecutionReturnSet > GetReturnSet ( TransactionTrace trace , TransactionResult result )
396
+ private ExecutionReturnSet GetReturnSet ( TransactionTrace trace , TransactionResult result )
459
397
{
460
398
var returnSet = new ExecutionReturnSet
461
399
{
@@ -464,41 +402,12 @@ private IEnumerable<ExecutionReturnSet> GetReturnSet(TransactionTrace trace, Tra
464
402
Bloom = result . Bloom ,
465
403
TransactionResult = result
466
404
} ;
467
- var returnSets = new List < ExecutionReturnSet > { returnSet } ;
468
405
469
406
if ( trace . IsSuccessful ( ) )
470
407
{
471
408
var transactionExecutingStateSets = trace . GetStateSets ( ) ;
472
409
returnSet = GetReturnSet ( returnSet , transactionExecutingStateSets ) ;
473
410
returnSet . ReturnValue = trace . ReturnValue ;
474
-
475
- var inlineTxWithIdList = trace . GetAllInlineTransactions ( ) . Where ( tx => NeedTransactionId ( tx . MethodName ) ) ;
476
- foreach ( var inlineTx in inlineTxWithIdList )
477
- {
478
- var inlineTxId = inlineTx . GetHash ( ) ;
479
- var inlineReturnSet = new ExecutionReturnSet
480
- {
481
- TransactionId = inlineTxId ,
482
- Status = TransactionResultStatus . Mined ,
483
- TransactionResult = new TransactionResult
484
- {
485
- TransactionId = inlineTxId ,
486
- BlockNumber = result . BlockNumber ,
487
- Status = TransactionResultStatus . Mined
488
- }
489
- } ;
490
-
491
- // No need to execute GetReturnSet method, because changes are already set to `returnSet`.
492
-
493
- returnSets . Add ( inlineReturnSet ) ;
494
-
495
- Logger . LogWarning ( $ "Inline tx id: { inlineTx . GetHash ( ) . ToHex ( ) } \n { inlineTx } ") ;
496
- var log = new InlineTransactionCreated ( )
497
- {
498
- Transaction = inlineTx
499
- } ;
500
- returnSet . TransactionResult . Logs . Add ( log . ToLogEvent ( inlineTx . To ) ) ;
501
- }
502
411
}
503
412
else
504
413
{
@@ -517,7 +426,7 @@ private IEnumerable<ExecutionReturnSet> GetReturnSet(TransactionTrace trace, Tra
517
426
var reads = trace . GetFlattenedReads ( ) ;
518
427
foreach ( var read in reads ) returnSet . StateAccesses [ read . Key ] = read . Value ;
519
428
520
- return returnSets ;
429
+ return returnSet ;
521
430
}
522
431
523
432
private ExecutionReturnSet GetReturnSet ( ExecutionReturnSet returnSet ,
@@ -567,7 +476,6 @@ protected ITransactionContext CreateTransactionContext(SingleTransactionExecutin
567
476
singleTxExecutingDto . ChainContext , singleTxExecutingDto . OriginTransactionId , origin ,
568
477
singleTxExecutingDto . Depth , singleTxExecutingDto . CurrentBlockTime ) ;
569
478
570
- txContext . InlineWithTransactionIdCounter = singleTxExecutingDto . InlineWithTransactionIdCounter ;
571
479
return txContext ;
572
480
}
573
481
}
0 commit comments