File tree Expand file tree Collapse file tree 5 files changed +39
-16
lines changed Expand file tree Collapse file tree 5 files changed +39
-16
lines changed Original file line number Diff line number Diff line change @@ -25,6 +25,7 @@ public ActionContext(
25
25
int randomSeed ,
26
26
bool isPolicyAction ,
27
27
FungibleAssetValue ? maxGasPrice ,
28
+ long ? gasLimit = null ,
28
29
IReadOnlyList < ITransaction > ? txs = null ,
29
30
IReadOnlyList < EvidenceBase > ? evidence = null )
30
31
{
@@ -38,6 +39,7 @@ public ActionContext(
38
39
RandomSeed = randomSeed ;
39
40
IsPolicyAction = isPolicyAction ;
40
41
MaxGasPrice = maxGasPrice ;
42
+ GasLimit = gasLimit ;
41
43
_txs = txs ?? ImmutableList < Transaction > . Empty ;
42
44
Evidence = evidence ?? ImmutableList < EvidenceBase > . Empty ;
43
45
}
@@ -73,6 +75,10 @@ public ActionContext(
73
75
[ Pure ]
74
76
public FungibleAssetValue ? MaxGasPrice { get ; }
75
77
78
+ /// <inheritdoc cref="IActionContext.GasLimit"/>
79
+ [ Pure ]
80
+ public long ? GasLimit { get ; }
81
+
76
82
/// <inheritdoc cref="IActionContext.Txs"/>
77
83
public IReadOnlyList < ITransaction > Txs => IsPolicyAction
78
84
? _txs
Original file line number Diff line number Diff line change @@ -221,6 +221,7 @@ IActionContext CreateActionContext(
221
221
isPolicyAction : isPolicyAction ,
222
222
randomSeed : randomSeed ,
223
223
maxGasPrice : tx ? . MaxGasPrice ,
224
+ gasLimit : tx ? . GasLimit ,
224
225
evidence : block . Evidence ) ;
225
226
}
226
227
@@ -285,6 +286,7 @@ IActionContext CreateActionContext(IWorld newPrevState)
285
286
randomSeed : inputContext . RandomSeed ,
286
287
isPolicyAction : isPolicyAction ,
287
288
maxGasPrice : tx ? . MaxGasPrice ,
289
+ gasLimit : tx ? . GasLimit ,
288
290
txs : inputContext . Txs ,
289
291
evidence : inputContext . Evidence ) ;
290
292
}
@@ -470,8 +472,6 @@ internal IEnumerable<ActionEvaluation> EvaluateTx(
470
472
ITransaction tx ,
471
473
IWorld previousState )
472
474
{
473
- GasTracer . Initialize ( tx . GasLimit ?? long . MaxValue ) ;
474
- GasTracer . StartTrace ( ) ;
475
475
var evaluations = ImmutableList < ActionEvaluation > . Empty ;
476
476
if ( _policyActionsRegistry . BeginTxActions . Length > 0 )
477
477
{
@@ -500,8 +500,6 @@ internal IEnumerable<ActionEvaluation> EvaluateTx(
500
500
EvaluatePolicyEndTxActions ( block , tx , previousState ) ) ;
501
501
}
502
502
503
- GasTracer . EndTrace ( ) ;
504
-
505
503
return evaluations ;
506
504
}
507
505
Original file line number Diff line number Diff line change @@ -2,13 +2,18 @@ namespace Libplanet.Action
2
2
{
3
3
internal class GasMeter : IGasMeter
4
4
{
5
- public GasMeter ( long gasLimit , long gasUsed = 0 )
5
+ public GasMeter ( long gasLimit , long gasAvailable )
6
6
{
7
- SetGasLimit ( gasLimit ) ;
8
- GasUsed = gasUsed ;
7
+ if ( gasLimit < 0 )
8
+ {
9
+ throw new GasLimitNegativeException ( ) ;
10
+ }
11
+
12
+ GasLimit = gasLimit ;
13
+ GasAvailable = gasAvailable ;
9
14
}
10
15
11
- public long GasAvailable => GasLimit - GasUsed ;
16
+ public long GasAvailable { get ; private set ; }
12
17
13
18
public long GasLimit { get ; private set ; }
14
19
@@ -37,6 +42,12 @@ public void UseGas(long gas)
37
42
throw new GasLimitExceededException ( GasLimit , newGasUsed ) ;
38
43
}
39
44
45
+ if ( newGasUsed > GasAvailable )
46
+ {
47
+ GasUsed = GasAvailable ;
48
+ throw new GasLimitExceededException ( GasLimit , newGasUsed ) ;
49
+ }
50
+
40
51
GasUsed = newGasUsed ;
41
52
}
42
53
Original file line number Diff line number Diff line change @@ -44,20 +44,25 @@ public static void UseGas(long gas)
44
44
}
45
45
}
46
46
47
- internal static void Initialize ( long gasLimit )
48
- {
49
- GasMeter . Value = new GasMeter ( gasLimit ) ;
50
- IsTrace . Value = false ;
51
- }
52
-
53
- internal static void StartTrace ( )
47
+ public static void Initialize ( long gasLimit , long availableGasLimit )
54
48
{
49
+ GasMeter . Value = new GasMeter ( gasLimit , availableGasLimit ) ;
55
50
IsTrace . Value = true ;
56
51
}
57
52
58
- internal static void EndTrace ( )
53
+ public static void Release ( )
59
54
{
60
55
IsTrace . Value = false ;
61
56
}
57
+
58
+ // internal static void StartTrace()
59
+ // {
60
+ // IsTrace.Value = true;
61
+ // }
62
+
63
+ // internal static void EndTrace()
64
+ // {
65
+ // IsTrace.Value = false;
66
+ // }
62
67
}
63
68
}
Original file line number Diff line number Diff line change @@ -99,6 +99,9 @@ public interface IActionContext
99
99
[ Pure ]
100
100
FungibleAssetValue ? MaxGasPrice { get ; }
101
101
102
+ [ Pure ]
103
+ long ? GasLimit { get ; }
104
+
102
105
/// <summary>
103
106
/// A list of <see cref="ITransaction"/>s that are included in a <see cref="Block"/> as
104
107
/// the <see cref="IAction"/> to be evaluated. This information is provided only if
You can’t perform that action at this time.
0 commit comments