@@ -11,7 +11,6 @@ import (
1111 sdk "github.com/cosmos/cosmos-sdk/types"
1212
1313 types "pkg.akt.dev/go/node/bme/v1"
14- otypes "pkg.akt.dev/go/node/oracle/v2"
1514 "pkg.akt.dev/go/sdkutil"
1615)
1716
@@ -57,18 +56,50 @@ func (k *keeper) EndBlocker(ctx context.Context) error {
5756 return false , err
5857 }
5958
60- // Use CacheContext so that a partial failure (e.g. MintCoins succeeds
59+ // Use CacheContext so that a partial failure (e.g., MintCoins succeeds
6160 // but SendCoinsFromModuleToAccount fails) does not leave a corrupted
6261 // state. Only commit on success; on error the pending record stays
6362 // unmodified and will be retried next block.
6463 cacheCtx , writeCache := sctx .CacheContext ()
6564 err = k .executeBurnMint (cacheCtx , params , id , ownerAddr , dstAddr , value .CoinsToBurn , value .DenomToMint )
6665 if err == nil {
6766 writeCache ()
67+ processed ++
68+ return processed >= int64 (params .MaxEndblockerRecords ), nil
69+ }
70+
71+ // Error path: classify and handle
72+ if isFatalBurnMintError (err ) {
73+ // Fatal error: cancel immediately with specific reason
74+ cancelCtx , writeCancel := sctx .CacheContext ()
75+ reason := errorToCancelReason (err )
76+ if cancelErr := k .cancelBurnMint (cancelCtx , id , ownerAddr , dstAddr , value .CoinsToBurn , value .DenomToMint , reason ); cancelErr != nil {
77+ sctx .Logger ().Error ("failed to cancel burn/mint record" , "id" , id , "reason" , reason , "err" , cancelErr )
78+ return false , cancelErr
79+ }
80+ writeCancel ()
81+ } else {
82+ // Retriable error: increment attempts
83+ value .Attempts ++
84+ if value .Attempts >= params .MaxPendingAttempts {
85+ // Max attempts exceeded: cancel
86+ cancelCtx , writeCancel := sctx .CacheContext ()
87+ if cancelErr := k .cancelBurnMint (cancelCtx , id , ownerAddr , dstAddr , value .CoinsToBurn , value .DenomToMint , types .BMCancelReasonMaxAttempts ); cancelErr != nil {
88+ sctx .Logger ().Error ("failed to cancel burn/mint record after max attempts" , "id" , id , "attempts" , value .Attempts , "err" , cancelErr )
89+ return false , cancelErr
90+ }
91+ writeCancel ()
92+ } else {
93+ // Still has attempts: update pending record in-place
94+ if updErr := k .ledgerPending .Set (sctx , id , value ); updErr != nil {
95+ sctx .Logger ().Error ("failed to update pending record attempts" , "id" , id , "err" , updErr )
96+ return false , updErr
97+ }
98+ }
6899 }
69100
70101 processed ++
71- return processed >= int64 (params .MaxEndblockerRecords ), err
102+ return processed >= int64 (params .MaxEndblockerRecords ), nil
72103 }
73104
74105 iteratePending := func (p []byte , postCondition func () error ) error {
@@ -94,10 +125,7 @@ func (k *keeper) EndBlocker(ctx context.Context) error {
94125
95126 stop , err = executeMint (id , val )
96127 if err != nil {
97- sctx .Logger ().Error ("processing ledger pending records " , "id" , id , "err" , err )
98- if errors .Is (err , otypes .ErrPriceStalled ) {
99- return err
100- }
128+ sctx .Logger ().Error ("processing ledger pending records" , "id" , id , "err" , err )
101129 }
102130 }
103131
0 commit comments