@@ -12,6 +12,7 @@ import (
12
12
"time"
13
13
14
14
"github.com/golang/protobuf/proto"
15
+ "github.com/iotexproject/iotex-proto/golang/iotextypes"
15
16
"github.com/pkg/errors"
16
17
17
18
"github.com/iotexproject/go-pkgs/hash"
@@ -211,7 +212,16 @@ func (p *Protocol) Handle(ctx context.Context, act action.Action, sm protocol.St
211
212
if err != nil {
212
213
return nil , err
213
214
}
214
- return p .handle (ctx , act , csm )
215
+
216
+ r , err := p .handle (ctx , act , csm )
217
+ if err != nil {
218
+ if status , ok := canEarlyResolve (err ); ok {
219
+ actionCtx := protocol .MustGetActionCtx (ctx )
220
+ gasFee := big .NewInt (0 ).Mul (actionCtx .GasPrice , big .NewInt (0 ).SetUint64 (actionCtx .IntrinsicGas ))
221
+ return p .settleAction (ctx , csm , status , gasFee )
222
+ }
223
+ }
224
+ return r , err
215
225
}
216
226
217
227
func (p * Protocol ) handle (ctx context.Context , act action.Action , csm CandidateStateManager ) (* action.Receipt , error ) {
@@ -342,3 +352,19 @@ func (p *Protocol) Name() string {
342
352
func (p * Protocol ) calculateVoteWeight (v * VoteBucket , selfStake bool ) * big.Int {
343
353
return calculateVoteWeight (p .config .VoteWeightCalConsts , v , selfStake )
344
354
}
355
+
356
+ func canEarlyResolve (err error ) (uint64 , bool ) {
357
+ cause := errors .Cause (err )
358
+ if cause == ErrInvalidCanName ||
359
+ cause == ErrInvalidOperator ||
360
+ cause == ErrInvalidSelfStkIndex {
361
+ return uint64 (iotextypes .ReceiptStatus_ErrCandidateConflict ), true
362
+ }
363
+
364
+ if cause == ErrInvalidAmount ||
365
+ cause == ErrInvalidOwner ||
366
+ cause == ErrInvalidReward {
367
+ return uint64 (iotextypes .ReceiptStatus_ErrCandidateNotExist ), true
368
+ }
369
+ return 0 , false
370
+ }
0 commit comments