-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
) (cherry picked from commit ee3d320) # Conflicts: # server/v2/appmanager/go.mod # server/v2/appmanager/go.sum # server/v2/stf/core_router_service.go # server/v2/stf/gas/defaults.go
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module cosmossdk.io/server/v2/appmanager | ||
|
||
go 1.23 | ||
|
||
require cosmossdk.io/core v1.0.0-alpha.4 | ||
|
||
require cosmossdk.io/schema v0.3.0 // indirect |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
cosmossdk.io/core v1.0.0-alpha.4 h1:9iuroT9ejDYETCsGkzkvs/wAY/5UFl7nCIINFRxyMJY= | ||
cosmossdk.io/core v1.0.0-alpha.4/go.mod h1:3u9cWq1FAVtiiCrDPpo4LhR+9V6k/ycSG4/Y/tREWCY= | ||
cosmossdk.io/schema v0.3.0 h1:01lcaM4trhzZ1HQTfTV8z6Ma1GziOZ/YmdzBN3F720c= | ||
cosmossdk.io/schema v0.3.0/go.mod h1:RDAhxIeNB4bYqAlF4NBJwRrgtnciMcyyg0DOKnhNZQQ= |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package stf | ||
|
||
import ( | ||
"context" | ||
|
||
"cosmossdk.io/core/router" | ||
"cosmossdk.io/core/transaction" | ||
) | ||
|
||
// NewMsgRouterService implements router.Service. | ||
func NewMsgRouterService(identity transaction.Identity) router.Service { | ||
return msgRouterService{identity: identity} | ||
} | ||
|
||
var _ router.Service = (*msgRouterService)(nil) | ||
|
||
type msgRouterService struct { | ||
// TODO(tip): the identity sits here for the purpose of disallowing modules to impersonate others (sudo). | ||
// right now this is not used, but it serves the reminder of something that we should be eventually | ||
// looking into. | ||
identity []byte | ||
} | ||
|
||
// CanInvoke returns an error if the given message cannot be invoked. | ||
func (m msgRouterService) CanInvoke(ctx context.Context, typeURL string) error { | ||
exCtx, err := getExecutionCtxFromContext(ctx) | ||
Check failure on line 26 in server/v2/stf/core_router_service.go GitHub Actions / dependency-review
Check failure on line 26 in server/v2/stf/core_router_service.go GitHub Actions / golangci-lint
|
||
if err != nil { | ||
return err | ||
} | ||
|
||
return exCtx.msgRouter.CanInvoke(ctx, typeURL) | ||
} | ||
|
||
// Invoke execute a message and returns a response. | ||
func (m msgRouterService) Invoke(ctx context.Context, msg transaction.Msg) (transaction.Msg, error) { | ||
exCtx, err := getExecutionCtxFromContext(ctx) | ||
Check failure on line 36 in server/v2/stf/core_router_service.go GitHub Actions / dependency-review
Check failure on line 36 in server/v2/stf/core_router_service.go GitHub Actions / golangci-lint
|
||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return exCtx.msgRouter.Invoke(ctx, msg) | ||
} | ||
|
||
// NewQueryRouterService implements router.Service. | ||
func NewQueryRouterService() router.Service { | ||
return queryRouterService{} | ||
} | ||
|
||
var _ router.Service = (*queryRouterService)(nil) | ||
|
||
type queryRouterService struct{} | ||
|
||
// CanInvoke returns an error if the given request cannot be invoked. | ||
func (m queryRouterService) CanInvoke(ctx context.Context, typeURL string) error { | ||
exCtx, err := getExecutionCtxFromContext(ctx) | ||
Check failure on line 55 in server/v2/stf/core_router_service.go GitHub Actions / dependency-review
Check failure on line 55 in server/v2/stf/core_router_service.go GitHub Actions / golangci-lint
|
||
if err != nil { | ||
return err | ||
} | ||
|
||
return exCtx.queryRouter.CanInvoke(ctx, typeURL) | ||
} | ||
|
||
// Invoke execute a message and returns a response. | ||
func (m queryRouterService) Invoke( | ||
ctx context.Context, | ||
req transaction.Msg, | ||
) (transaction.Msg, error) { | ||
exCtx, err := getExecutionCtxFromContext(ctx) | ||
Check failure on line 68 in server/v2/stf/core_router_service.go GitHub Actions / dependency-review
Check failure on line 68 in server/v2/stf/core_router_service.go GitHub Actions / golangci-lint
|
||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return exCtx.queryRouter.Invoke(ctx, req) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package gas | ||
|
||
import ( | ||
coregas "cosmossdk.io/core/gas" | ||
"cosmossdk.io/core/store" | ||
) | ||
|
||
// DefaultWrapWithGasMeter defines the default wrap with gas meter function in stf. In case | ||
// the meter sets as limit stf.NoGasLimit, then a fast path is taken and the store.WriterMap | ||
// is returned. | ||
func DefaultWrapWithGasMeter(meter coregas.Meter, state store.WriterMap) store.WriterMap { | ||
if meter.Limit() == coregas.NoGasLimit { | ||
return state | ||
} | ||
return NewMeteredWriterMap(DefaultConfig, meter, state) | ||
Check failure on line 15 in server/v2/stf/gas/defaults.go GitHub Actions / dependency-review
Check failure on line 15 in server/v2/stf/gas/defaults.go GitHub Actions / golangci-lint
|
||
} | ||
|
||
// DefaultGasMeter returns the default gas meter. In case it is coregas.NoGasLimit a NoOpMeter is returned. | ||
func DefaultGasMeter(gasLimit uint64) coregas.Meter { | ||
if gasLimit == coregas.NoGasLimit { | ||
return NoOpMeter{} | ||
} | ||
return NewMeter(gasLimit) | ||
Check failure on line 23 in server/v2/stf/gas/defaults.go GitHub Actions / dependency-review
Check failure on line 23 in server/v2/stf/gas/defaults.go GitHub Actions / golangci-lint
|
||
} | ||
|
||
// DefaultConfig returns the default gas config. | ||
// Unless overridden, the default gas costs are: | ||
var DefaultConfig = coregas.GasConfig{ | ||
HasCost: 1000, | ||
DeleteCost: 1000, | ||
ReadCostFlat: 1000, | ||
ReadCostPerByte: 3, | ||
WriteCostFlat: 2000, | ||
WriteCostPerByte: 30, | ||
IterNextCostFlat: 30, | ||
} | ||
|
||
type NoOpMeter struct{} | ||
|
||
func (n NoOpMeter) Consumed() coregas.Gas { return 0 } | ||
|
||
func (n NoOpMeter) Limit() coregas.Gas { return coregas.NoGasLimit } | ||
|
||
func (n NoOpMeter) Consume(_ coregas.Gas, _ string) error { return nil } | ||
|
||
func (n NoOpMeter) Refund(_ coregas.Gas, _ string) error { return nil } | ||
|
||
func (n NoOpMeter) Remaining() coregas.Gas { return coregas.NoGasLimit } |