MCPcopy Create free account
hub / github.com/akash-network/node / mintStatusUpdate

Method mintStatusUpdate

x/bme/keeper/keeper.go:882–946  ·  view source on GitHub ↗
(sctx sdk.Context)

Source from the content-addressed store, hash-verified

880}
881
882func (k *keeper) mintStatusUpdate(sctx sdk.Context) (bmetypes.Status, bool) {
883 params, err := k.GetParams(sctx)
884 if err != nil {
885 // if unable to load params, something went horribly wrong
886 panic(err)
887 }
888
889 cb, err := k.status.Get(sctx)
890 if err != nil {
891 // if unable to load circuit breaker state, something went horribly wrong
892 panic(err)
893 }
894 pCb := cb
895
896 cr, err := k.calculateCR(sctx)
897 if err != nil {
898 cb.Status = bmetypes.MintStatusHaltCR
899 if errors.Is(err, otypes.ErrPriceStalled) || errors.Is(err, bmetypes.ErrZeroPrice) {
900 cb.Status = bmetypes.MintStatusHaltOracle
901 }
902 } else {
903 // Clamp CR in BPS to math.MaxUint32 to prevent int64→uint32 overflow
904 // when CR is extremely large (e.g., zero outstanding ACT supply).
905 crInt := cr.Mul(sdkmath.LegacyNewDec(10000)).TruncateInt64()
906 if crInt > math.MaxUint32 {
907 crInt = math.MaxUint32
908 }
909
910 warnThreshold := int64(params.CircuitBreakerWarnThreshold)
911 haltThreshold := int64(params.CircuitBreakerHaltThreshold)
912
913 if crInt > warnThreshold {
914 cb.Status = bmetypes.MintStatusHealthy
915 cb.EpochHeightDiff = calculateBlocksDiff(params, crInt)
916 } else if crInt <= warnThreshold && crInt > haltThreshold {
917 cb.Status = bmetypes.MintStatusWarning
918 cb.EpochHeightDiff = calculateBlocksDiff(params, crInt)
919 } else {
920 // halt ACT mint
921 cb.Status = bmetypes.MintStatusHaltCR
922 }
923 }
924
925 changed := !cb.Equal(pCb)
926
927 if changed {
928 cb.PreviousStatus = pCb.Status
929
930 err = k.status.Set(sctx, cb)
931 if err != nil {
932 panic(err)
933 }
934
935 err = sctx.EventManager().EmitTypedEvent(&bmetypes.EventMintStatusChange{
936 PreviousStatus: cb.PreviousStatus,
937 NewStatus: cb.Status,
938 CollateralRatio: cr,
939 })

Callers 1

EndBlockerMethod · 0.95

Calls 6

GetParamsMethod · 0.95
calculateCRMethod · 0.95
calculateBlocksDiffFunction · 0.85
GetMethod · 0.65
ErrorMethod · 0.65
LoggerMethod · 0.45

Tested by

no test coverage detected