@agoric/cosmos 0.34.2-orchestration-dev-096c4e8.0 → 0.34.2-upgrade-16-dev-8879538.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/MAINTAINERS.md +3 -0
- package/Makefile +29 -26
- package/ante/ante.go +1 -4
- package/app/app.go +69 -39
- package/cmd/agd/main.go +6 -7
- package/cmd/libdaemon/main.go +8 -8
- package/daemon/cmd/root.go +16 -10
- package/daemon/cmd/root_test.go +189 -1
- package/git-revision.txt +1 -1
- package/go.mod +8 -8
- package/go.sum +15 -14
- package/package.json +4 -3
- package/proto/agoric/swingset/swingset.proto +1 -1
- package/scripts/protocgen.sh +7 -8
- package/upgradegaia.sh +8 -8
- package/vm/client_test.go +29 -29
- package/vm/controller.go +0 -38
- package/vm/server.go +106 -5
- package/x/swingset/genesis.go +2 -3
- package/x/swingset/keeper/extension_snapshotter.go +2 -2
- package/x/swingset/module.go +0 -5
- package/x/swingset/types/swingset.pb.go +1 -1
- package/x/vbank/module.go +0 -5
- package/x/vibc/module.go +2 -7
- package/x/vibc/types/ibc_module.go +3 -2
- package/x/vlocalchain/vlocalchain.go +1 -1
- package/x/vlocalchain/vlocalchain_test.go +1 -1
- package/x/vstorage/keeper/grpc_query.go +0 -1
- package/x/vstorage/keeper/keeper.go +4 -12
- package/x/vstorage/module.go +0 -5
- package/ante/fee.go +0 -97
package/vm/server.go
CHANGED
|
@@ -1,23 +1,124 @@
|
|
|
1
1
|
package vm
|
|
2
2
|
|
|
3
3
|
import (
|
|
4
|
+
"context"
|
|
4
5
|
"fmt"
|
|
6
|
+
"sync"
|
|
7
|
+
|
|
8
|
+
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
5
9
|
)
|
|
6
10
|
|
|
7
|
-
|
|
11
|
+
// AgdServer manages communication from the VM to the ABCI app. The structure
|
|
12
|
+
// is mutable and the mutex must be held to read or write any field.
|
|
13
|
+
type AgdServer struct {
|
|
14
|
+
currentCtx context.Context
|
|
15
|
+
mtx sync.Mutex
|
|
16
|
+
// zero is an out-of-bounds port number
|
|
17
|
+
lastPort int
|
|
18
|
+
// portToHandler[i] is nonzero iff portToName[i] is nonempty
|
|
19
|
+
portToHandler map[int]PortHandler
|
|
20
|
+
// portToName[nameToPort[s]] == s && nameToPort[portToName[i]] == i for all i, s
|
|
21
|
+
portToName map[int]string
|
|
22
|
+
nameToPort map[string]int
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
var wrappedEmptySDKContext = sdk.WrapSDKContext(
|
|
26
|
+
sdk.Context{}.WithContext(context.Background()),
|
|
27
|
+
)
|
|
8
28
|
|
|
29
|
+
// NewAgdServer returns a pointer to a new AgdServer with empty context and port
|
|
30
|
+
// mappings.
|
|
9
31
|
func NewAgdServer() *AgdServer {
|
|
10
|
-
return &AgdServer{
|
|
32
|
+
return &AgdServer{
|
|
33
|
+
currentCtx: wrappedEmptySDKContext,
|
|
34
|
+
mtx: sync.Mutex{},
|
|
35
|
+
portToHandler: make(map[int]PortHandler),
|
|
36
|
+
portToName: make(map[int]string),
|
|
37
|
+
nameToPort: make(map[string]int),
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// SetControllerContext sets the context to the given argument and returns a function
|
|
42
|
+
// which will reset the context to an empty context (not the old context).
|
|
43
|
+
func (s *AgdServer) SetControllerContext(ctx sdk.Context) func() {
|
|
44
|
+
// We are only called by the controller, so we assume that it is billing its
|
|
45
|
+
// own meter usage.
|
|
46
|
+
s.mtx.Lock()
|
|
47
|
+
defer s.mtx.Unlock()
|
|
48
|
+
s.currentCtx = sdk.WrapSDKContext(ctx.WithGasMeter(sdk.NewInfiniteGasMeter()))
|
|
49
|
+
return func() {
|
|
50
|
+
s.mtx.Lock()
|
|
51
|
+
defer s.mtx.Unlock()
|
|
52
|
+
s.currentCtx = wrappedEmptySDKContext
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// getContextAndHandler returns the current context and the handler for the
|
|
57
|
+
// given port number.
|
|
58
|
+
func (s *AgdServer) getContextAndHandler(port int) (context.Context, PortHandler) {
|
|
59
|
+
s.mtx.Lock()
|
|
60
|
+
defer s.mtx.Unlock()
|
|
61
|
+
ctx := s.currentCtx
|
|
62
|
+
handler := s.portToHandler[port]
|
|
63
|
+
return ctx, handler
|
|
11
64
|
}
|
|
12
65
|
|
|
13
66
|
// ReceiveMessage is the method the VM calls in order to have agd receive a
|
|
14
67
|
// Message.
|
|
15
|
-
func (s AgdServer) ReceiveMessage(msg *Message, reply *string) error {
|
|
16
|
-
handler :=
|
|
68
|
+
func (s *AgdServer) ReceiveMessage(msg *Message, reply *string) error {
|
|
69
|
+
ctx, handler := s.getContextAndHandler(msg.Port)
|
|
17
70
|
if handler == nil {
|
|
18
71
|
return fmt.Errorf("unregistered port %d", msg.Port)
|
|
19
72
|
}
|
|
20
|
-
resp, err := handler.Receive(
|
|
73
|
+
resp, err := handler.Receive(ctx, msg.Data)
|
|
21
74
|
*reply = resp
|
|
22
75
|
return err
|
|
23
76
|
}
|
|
77
|
+
|
|
78
|
+
// GetPort returns the port number for the given port name, or 0 if the name is
|
|
79
|
+
// not registered.
|
|
80
|
+
func (s *AgdServer) GetPort(name string) int {
|
|
81
|
+
s.mtx.Lock()
|
|
82
|
+
defer s.mtx.Unlock()
|
|
83
|
+
return s.nameToPort[name]
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// MustRegisterPortHandler attempts to RegisterPortHandler, panicing on error.
|
|
87
|
+
func (s *AgdServer) MustRegisterPortHandler(name string, portHandler PortHandler) int {
|
|
88
|
+
port, err := s.RegisterPortHandler(name, portHandler)
|
|
89
|
+
if err != nil {
|
|
90
|
+
panic(err)
|
|
91
|
+
}
|
|
92
|
+
return port
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// RegisterPortHandler registers the handler to a new port number, then maps the name to it,
|
|
96
|
+
// returning the port number. If the name was previously in use, an error is returned.
|
|
97
|
+
func (s *AgdServer) RegisterPortHandler(name string, portHandler PortHandler) (int, error) {
|
|
98
|
+
s.mtx.Lock()
|
|
99
|
+
defer s.mtx.Unlock()
|
|
100
|
+
if _, ok := s.nameToPort[name]; ok {
|
|
101
|
+
return 0, fmt.Errorf("name %s already in use", name)
|
|
102
|
+
}
|
|
103
|
+
s.lastPort++
|
|
104
|
+
s.portToHandler[s.lastPort] = NewProtectedPortHandler(portHandler)
|
|
105
|
+
s.portToName[s.lastPort] = name
|
|
106
|
+
s.nameToPort[name] = s.lastPort
|
|
107
|
+
return s.lastPort, nil
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// UnregisterPortHandler unregisters the handler and name mappings for this port
|
|
111
|
+
// number, and the reverse mapping for its name, if any of these exist. If
|
|
112
|
+
// portNum is not registered, return an error.
|
|
113
|
+
func (s *AgdServer) UnregisterPortHandler(portNum int) error {
|
|
114
|
+
s.mtx.Lock()
|
|
115
|
+
defer s.mtx.Unlock()
|
|
116
|
+
if s.portToHandler[portNum] == nil {
|
|
117
|
+
return fmt.Errorf("port %d not registered", portNum)
|
|
118
|
+
}
|
|
119
|
+
delete(s.portToHandler, portNum)
|
|
120
|
+
name := s.portToName[portNum]
|
|
121
|
+
delete(s.portToName, portNum)
|
|
122
|
+
delete(s.nameToPort, name)
|
|
123
|
+
return nil
|
|
124
|
+
}
|
package/x/swingset/genesis.go
CHANGED
|
@@ -64,7 +64,7 @@ func InitGenesis(ctx sdk.Context, k Keeper, swingStoreExportsHandler *SwingStore
|
|
|
64
64
|
ReadNextArtifact: artifactProvider.ReadNextArtifact,
|
|
65
65
|
},
|
|
66
66
|
keeper.SwingStoreRestoreOptions{
|
|
67
|
-
ArtifactMode: keeper.
|
|
67
|
+
ArtifactMode: keeper.SwingStoreArtifactModeOperational,
|
|
68
68
|
ExportDataMode: keeper.SwingStoreExportDataModeAll,
|
|
69
69
|
},
|
|
70
70
|
)
|
|
@@ -98,9 +98,8 @@ func ExportGenesis(ctx sdk.Context, k Keeper, swingStoreExportsHandler *SwingSto
|
|
|
98
98
|
// The export will fail if the export of a historical height was requested
|
|
99
99
|
snapshotHeight,
|
|
100
100
|
swingStoreGenesisEventHandler{exportDir: swingStoreExportDir, snapshotHeight: snapshotHeight},
|
|
101
|
-
// The export will fail if the swing-store does not contain all replay artifacts
|
|
102
101
|
keeper.SwingStoreExportOptions{
|
|
103
|
-
ArtifactMode: keeper.
|
|
102
|
+
ArtifactMode: keeper.SwingStoreArtifactModeOperational,
|
|
104
103
|
ExportDataMode: keeper.SwingStoreExportDataModeSkip,
|
|
105
104
|
},
|
|
106
105
|
)
|
|
@@ -125,7 +125,7 @@ func (snapshotter *ExtensionSnapshotter) InitiateSnapshot(height int64) error {
|
|
|
125
125
|
blockHeight := uint64(height)
|
|
126
126
|
|
|
127
127
|
return snapshotter.swingStoreExportsHandler.InitiateExport(blockHeight, snapshotter, SwingStoreExportOptions{
|
|
128
|
-
ArtifactMode:
|
|
128
|
+
ArtifactMode: SwingStoreArtifactModeOperational,
|
|
129
129
|
ExportDataMode: SwingStoreExportDataModeSkip,
|
|
130
130
|
})
|
|
131
131
|
}
|
|
@@ -304,6 +304,6 @@ func (snapshotter *ExtensionSnapshotter) RestoreExtension(blockHeight uint64, fo
|
|
|
304
304
|
|
|
305
305
|
return snapshotter.swingStoreExportsHandler.RestoreExport(
|
|
306
306
|
SwingStoreExportProvider{BlockHeight: blockHeight, GetExportDataReader: getExportDataReader, ReadNextArtifact: readNextArtifact},
|
|
307
|
-
SwingStoreRestoreOptions{ArtifactMode:
|
|
307
|
+
SwingStoreRestoreOptions{ArtifactMode: SwingStoreArtifactModeOperational, ExportDataMode: SwingStoreExportDataModeAll},
|
|
308
308
|
)
|
|
309
309
|
}
|
package/x/swingset/module.go
CHANGED
|
@@ -5,7 +5,6 @@ import (
|
|
|
5
5
|
"encoding/json"
|
|
6
6
|
"fmt"
|
|
7
7
|
|
|
8
|
-
"github.com/gorilla/mux"
|
|
9
8
|
"github.com/grpc-ecosystem/grpc-gateway/runtime"
|
|
10
9
|
"github.com/spf13/cobra"
|
|
11
10
|
|
|
@@ -60,10 +59,6 @@ func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, config client.TxEncod
|
|
|
60
59
|
return ValidateGenesis(&data)
|
|
61
60
|
}
|
|
62
61
|
|
|
63
|
-
// Register rest routes
|
|
64
|
-
func (AppModuleBasic) RegisterRESTRoutes(ctx client.Context, rtr *mux.Router) {
|
|
65
|
-
}
|
|
66
|
-
|
|
67
62
|
func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) {
|
|
68
63
|
_ = types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx))
|
|
69
64
|
}
|
|
@@ -27,7 +27,7 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package
|
|
|
27
27
|
|
|
28
28
|
// CoreEvalProposal is a gov Content type for evaluating code in the SwingSet
|
|
29
29
|
// core.
|
|
30
|
-
// See `agoric-sdk
|
|
30
|
+
// See `bridgeCoreEval` in agoric-sdk packages/vats/src/core/chain-behaviors.js.
|
|
31
31
|
type CoreEvalProposal struct {
|
|
32
32
|
Title string `protobuf:"bytes,1,opt,name=title,proto3" json:"title,omitempty"`
|
|
33
33
|
Description string `protobuf:"bytes,2,opt,name=description,proto3" json:"description,omitempty"`
|
package/x/vbank/module.go
CHANGED
|
@@ -5,7 +5,6 @@ import (
|
|
|
5
5
|
"encoding/json"
|
|
6
6
|
stdlog "log"
|
|
7
7
|
|
|
8
|
-
"github.com/gorilla/mux"
|
|
9
8
|
"github.com/grpc-ecosystem/grpc-gateway/runtime"
|
|
10
9
|
"github.com/spf13/cobra"
|
|
11
10
|
|
|
@@ -60,10 +59,6 @@ func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, config client.TxEncod
|
|
|
60
59
|
return ValidateGenesis(&data)
|
|
61
60
|
}
|
|
62
61
|
|
|
63
|
-
// Register rest routes
|
|
64
|
-
func (AppModuleBasic) RegisterRESTRoutes(clientCtx client.Context, rtr *mux.Router) {
|
|
65
|
-
}
|
|
66
|
-
|
|
67
62
|
func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) {
|
|
68
63
|
_ = types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx))
|
|
69
64
|
}
|
package/x/vibc/module.go
CHANGED
|
@@ -3,7 +3,6 @@ package vibc
|
|
|
3
3
|
import (
|
|
4
4
|
"encoding/json"
|
|
5
5
|
|
|
6
|
-
"github.com/gorilla/mux"
|
|
7
6
|
"github.com/grpc-ecosystem/grpc-gateway/runtime"
|
|
8
7
|
"github.com/spf13/cobra"
|
|
9
8
|
|
|
@@ -51,10 +50,6 @@ func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, config client.TxEncod
|
|
|
51
50
|
return nil
|
|
52
51
|
}
|
|
53
52
|
|
|
54
|
-
// Register rest routes
|
|
55
|
-
func (AppModuleBasic) RegisterRESTRoutes(ctx client.Context, rtr *mux.Router) {
|
|
56
|
-
}
|
|
57
|
-
|
|
58
53
|
func (AppModuleBasic) RegisterGRPCGatewayRoutes(_ client.Context, _ *runtime.ServeMux) {
|
|
59
54
|
}
|
|
60
55
|
|
|
@@ -70,7 +65,7 @@ func (AppModuleBasic) GetQueryCmd() *cobra.Command {
|
|
|
70
65
|
|
|
71
66
|
type AppModule struct {
|
|
72
67
|
AppModuleBasic
|
|
73
|
-
keeper
|
|
68
|
+
keeper Keeper
|
|
74
69
|
bankKeeper types.BankKeeper
|
|
75
70
|
}
|
|
76
71
|
|
|
@@ -79,7 +74,7 @@ func NewAppModule(k Keeper, bankKeeper types.BankKeeper) AppModule {
|
|
|
79
74
|
am := AppModule{
|
|
80
75
|
AppModuleBasic: AppModuleBasic{},
|
|
81
76
|
keeper: k,
|
|
82
|
-
bankKeeper:
|
|
77
|
+
bankKeeper: bankKeeper,
|
|
83
78
|
}
|
|
84
79
|
return am
|
|
85
80
|
}
|
|
@@ -7,7 +7,6 @@ import (
|
|
|
7
7
|
channeltypes "github.com/cosmos/ibc-go/v6/modules/core/04-channel/types"
|
|
8
8
|
porttypes "github.com/cosmos/ibc-go/v6/modules/core/05-port/types"
|
|
9
9
|
host "github.com/cosmos/ibc-go/v6/modules/core/24-host"
|
|
10
|
-
ibckeeper "github.com/cosmos/ibc-go/v6/modules/core/keeper"
|
|
11
10
|
|
|
12
11
|
"github.com/cosmos/ibc-go/v6/modules/core/exported"
|
|
13
12
|
|
|
@@ -19,7 +18,9 @@ const (
|
|
|
19
18
|
// asynchronous versions. If it does, then the VM must supply an empty
|
|
20
19
|
// version string to indicate that the VM explicitly (possibly async)
|
|
21
20
|
// performs the Write* method.
|
|
22
|
-
|
|
21
|
+
// This flag is created in anticipation of ibc-go implementing async versions,
|
|
22
|
+
// see https://github.com/Agoric/agoric-sdk/issues/9358 for more details.
|
|
23
|
+
AsyncVersions = false
|
|
23
24
|
)
|
|
24
25
|
|
|
25
26
|
var (
|
|
@@ -45,7 +45,7 @@ func (h portHandler) Receive(cctx context.Context, str string) (ret string, err
|
|
|
45
45
|
}
|
|
46
46
|
ret = string(bz)
|
|
47
47
|
|
|
48
|
-
case "
|
|
48
|
+
case "VLOCALCHAIN_QUERY_MANY":
|
|
49
49
|
// Copy the JSON messages string into a CosmosTx object so we can
|
|
50
50
|
// deserialize it with just proto3 JSON.
|
|
51
51
|
cosmosTxBz := []byte(`{"messages":` + string(msg.Messages) + `}`)
|
|
@@ -180,7 +180,7 @@ func TestQuery(t *testing.T) {
|
|
|
180
180
|
tc := tc
|
|
181
181
|
ctx := sdk.UnwrapSDKContext(cctx)
|
|
182
182
|
t.Run(tc.name, func(t *testing.T) {
|
|
183
|
-
msgGetBalances := `{"type":"
|
|
183
|
+
msgGetBalances := `{"type":"VLOCALCHAIN_QUERY_MANY","messages":[{"@type":"/cosmos.bank.v1beta1.QueryAllBalancesRequest","address":"` + tc.addr + `"}]}`
|
|
184
184
|
t.Logf("query request: %v", msgGetBalances)
|
|
185
185
|
ret, err := handler.Receive(cctx, msgGetBalances)
|
|
186
186
|
t.Logf("query response: %v", ret)
|
|
@@ -94,7 +94,6 @@ var capDataRemotableValueFormats = map[string]string{
|
|
|
94
94
|
// }
|
|
95
95
|
//
|
|
96
96
|
// ```
|
|
97
|
-
// cf. https://github.com/Agoric/agoric-sdk/blob/6e5b422b80e47c4dac151404f43faea5ab41e9b0/scripts/get-flattened-publication.sh
|
|
98
97
|
func flatten(input interface{}, output map[string]interface{}, key string, top bool) error {
|
|
99
98
|
// Act on the raw representation of a Remotable.
|
|
100
99
|
if remotable, ok := input.(*capdata.CapdataRemotable); ok {
|
|
@@ -22,8 +22,8 @@ import (
|
|
|
22
22
|
// StreamCell is an envelope representing a sequence of values written at a path in a single block.
|
|
23
23
|
// It is persisted to storage as a { "blockHeight": "<digits>", "values": ["...", ...] } JSON text
|
|
24
24
|
// that off-chain consumers rely upon.
|
|
25
|
-
// Many of those consumers *also* rely upon the strings of "values" being valid JSON text
|
|
26
|
-
//
|
|
25
|
+
// Many of those consumers *also* rely upon the strings of "values" being valid JSON text,
|
|
26
|
+
// but we do not enforce that in this package.
|
|
27
27
|
type StreamCell struct {
|
|
28
28
|
BlockHeight string `json:"blockHeight"`
|
|
29
29
|
Values []string `json:"values"`
|
|
@@ -52,14 +52,6 @@ var _ ChangeManager = (*BatchingChangeManager)(nil)
|
|
|
52
52
|
// 2 ** 256 - 1
|
|
53
53
|
var MaxSDKInt = sdk.NewIntFromBigInt(new(big.Int).Sub(new(big.Int).Exp(big.NewInt(2), big.NewInt(256), nil), big.NewInt(1)))
|
|
54
54
|
|
|
55
|
-
// TODO: Use bytes.CutPrefix once we can rely upon go >= 1.20.
|
|
56
|
-
func cutPrefix(s, prefix []byte) (after []byte, found bool) {
|
|
57
|
-
if !bytes.HasPrefix(s, prefix) {
|
|
58
|
-
return s, false
|
|
59
|
-
}
|
|
60
|
-
return s[len(prefix):], true
|
|
61
|
-
}
|
|
62
|
-
|
|
63
55
|
// Keeper maintains the link to data storage and exposes getter/setter methods
|
|
64
56
|
// for the various parts of the state machine
|
|
65
57
|
type Keeper struct {
|
|
@@ -164,7 +156,7 @@ func (k Keeper) ExportStorageFromPrefix(ctx sdk.Context, pathPrefix string) []*t
|
|
|
164
156
|
if !strings.HasPrefix(path, pathPrefix) {
|
|
165
157
|
continue
|
|
166
158
|
}
|
|
167
|
-
value, hasPrefix :=
|
|
159
|
+
value, hasPrefix := bytes.CutPrefix(rawValue, types.EncodedDataPrefix)
|
|
168
160
|
if !hasPrefix {
|
|
169
161
|
panic(fmt.Errorf("value at path %q starts with unexpected prefix", path))
|
|
170
162
|
}
|
|
@@ -266,7 +258,7 @@ func (k Keeper) GetEntry(ctx sdk.Context, path string) agoric.KVEntry {
|
|
|
266
258
|
if bytes.Equal(rawValue, types.EncodedNoDataValue) {
|
|
267
259
|
return agoric.NewKVEntryWithNoValue(path)
|
|
268
260
|
}
|
|
269
|
-
value, hasPrefix :=
|
|
261
|
+
value, hasPrefix := bytes.CutPrefix(rawValue, types.EncodedDataPrefix)
|
|
270
262
|
if !hasPrefix {
|
|
271
263
|
panic(fmt.Errorf("value at path %q starts with unexpected prefix", path))
|
|
272
264
|
}
|
package/x/vstorage/module.go
CHANGED
|
@@ -4,7 +4,6 @@ import (
|
|
|
4
4
|
"context"
|
|
5
5
|
"encoding/json"
|
|
6
6
|
|
|
7
|
-
"github.com/gorilla/mux"
|
|
8
7
|
"github.com/grpc-ecosystem/grpc-gateway/runtime"
|
|
9
8
|
"github.com/spf13/cobra"
|
|
10
9
|
|
|
@@ -57,10 +56,6 @@ func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, config client.TxEncod
|
|
|
57
56
|
return ValidateGenesis(&data)
|
|
58
57
|
}
|
|
59
58
|
|
|
60
|
-
// Register rest routes
|
|
61
|
-
func (AppModuleBasic) RegisterRESTRoutes(ctx client.Context, rtr *mux.Router) {
|
|
62
|
-
}
|
|
63
|
-
|
|
64
59
|
func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) {
|
|
65
60
|
_ = types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx))
|
|
66
61
|
}
|
package/ante/fee.go
DELETED
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
package ante
|
|
2
|
-
|
|
3
|
-
import (
|
|
4
|
-
"fmt"
|
|
5
|
-
|
|
6
|
-
sdkioerrors "cosmossdk.io/errors"
|
|
7
|
-
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
8
|
-
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
|
9
|
-
"github.com/cosmos/cosmos-sdk/x/auth/types"
|
|
10
|
-
)
|
|
11
|
-
|
|
12
|
-
// DeductFeeDecorator deducts fees from the first signer of the tx
|
|
13
|
-
// If the first signer does not have the funds to pay for the fees, return with InsufficientFunds error
|
|
14
|
-
// Call next AnteHandler if fees successfully deducted
|
|
15
|
-
// CONTRACT: Tx must implement FeeTx interface to use DeductFeeDecorator
|
|
16
|
-
type DeductFeeDecorator struct {
|
|
17
|
-
ak AccountKeeper
|
|
18
|
-
bankKeeper types.BankKeeper
|
|
19
|
-
feegrantKeeper FeegrantKeeper
|
|
20
|
-
feeCollectorName string
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
func NewDeductFeeDecorator(ak AccountKeeper, bk types.BankKeeper, fk FeegrantKeeper, feeCollectorName string) DeductFeeDecorator {
|
|
24
|
-
return DeductFeeDecorator{
|
|
25
|
-
ak: ak,
|
|
26
|
-
bankKeeper: bk,
|
|
27
|
-
feegrantKeeper: fk,
|
|
28
|
-
feeCollectorName: feeCollectorName,
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
func (dfd DeductFeeDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) {
|
|
33
|
-
feeTx, ok := tx.(sdk.FeeTx)
|
|
34
|
-
if !ok {
|
|
35
|
-
return ctx, sdkioerrors.Wrap(sdkerrors.ErrTxDecode, "Tx must be a FeeTx")
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
if addr := dfd.ak.GetModuleAddress(dfd.feeCollectorName); addr == nil {
|
|
39
|
-
return ctx, fmt.Errorf("fee collector module account (%s) has not been set", dfd.feeCollectorName)
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
fee := feeTx.GetFee()
|
|
43
|
-
feePayer := feeTx.FeePayer()
|
|
44
|
-
feeGranter := feeTx.FeeGranter()
|
|
45
|
-
|
|
46
|
-
deductFeesFrom := feePayer
|
|
47
|
-
|
|
48
|
-
// if feegranter set deduct fee from feegranter account.
|
|
49
|
-
// this works with only when feegrant enabled.
|
|
50
|
-
if feeGranter != nil {
|
|
51
|
-
if dfd.feegrantKeeper == nil {
|
|
52
|
-
return ctx, sdkioerrors.Wrap(sdkerrors.ErrInvalidRequest, "fee grants are not enabled")
|
|
53
|
-
} else if !feeGranter.Equals(feePayer) {
|
|
54
|
-
err := dfd.feegrantKeeper.UseGrantedFees(ctx, feeGranter, feePayer, fee, tx.GetMsgs())
|
|
55
|
-
|
|
56
|
-
if err != nil {
|
|
57
|
-
return ctx, sdkioerrors.Wrapf(err, "%s not allowed to pay fees from %s", feeGranter, feePayer)
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
deductFeesFrom = feeGranter
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
deductFeesFromAcc := dfd.ak.GetAccount(ctx, deductFeesFrom)
|
|
65
|
-
if deductFeesFromAcc == nil {
|
|
66
|
-
return ctx, sdkioerrors.Wrapf(sdkerrors.ErrUnknownAddress, "fee payer address: %s does not exist", deductFeesFrom)
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
// deduct the fees
|
|
70
|
-
if !feeTx.GetFee().IsZero() {
|
|
71
|
-
err = DeductFees(dfd.bankKeeper, ctx, deductFeesFromAcc, feeTx.GetFee(), dfd.feeCollectorName)
|
|
72
|
-
if err != nil {
|
|
73
|
-
return ctx, err
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
events := sdk.Events{sdk.NewEvent(sdk.EventTypeTx,
|
|
78
|
-
sdk.NewAttribute(sdk.AttributeKeyFee, feeTx.GetFee().String()),
|
|
79
|
-
)}
|
|
80
|
-
ctx.EventManager().EmitEvents(events)
|
|
81
|
-
|
|
82
|
-
return next(ctx, tx, simulate)
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
// DeductFees deducts fees from the given account.
|
|
86
|
-
func DeductFees(bankKeeper types.BankKeeper, ctx sdk.Context, acc types.AccountI, fees sdk.Coins, feeCollectorName string) error {
|
|
87
|
-
if !fees.IsValid() {
|
|
88
|
-
return sdkioerrors.Wrapf(sdkerrors.ErrInsufficientFee, "invalid fee amount: %s", fees)
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
err := bankKeeper.SendCoinsFromAccountToModule(ctx, acc.GetAddress(), feeCollectorName, fees)
|
|
92
|
-
if err != nil {
|
|
93
|
-
return sdkioerrors.Wrapf(sdkerrors.ErrInsufficientFunds, err.Error())
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
return nil
|
|
97
|
-
}
|