@agoric/cosmos 0.34.1 → 0.34.2-calypso-dev-84eb287.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 +67 -41
- package/agoric/config.go +35 -0
- package/ante/ante.go +65 -0
- package/ante/expected_keepers.go +26 -0
- package/ante/inbound.go +137 -0
- package/ante/inbound_test.go +228 -0
- package/ante/vm_admission.go +65 -0
- package/app/app.go +396 -211
- package/app/export.go +13 -9
- package/app/sim_test.go +4 -4
- package/app/upgrade.go +215 -0
- package/binding.gyp.in +29 -4
- package/buf.work.yaml +4 -0
- package/cmd/agd/agvm.go +42 -0
- package/cmd/agd/find_binary.go +22 -7
- package/cmd/agd/main.go +133 -10
- package/cmd/libdaemon/main.go +67 -53
- package/cmd/libdaemon/main_test.go +37 -0
- package/daemon/cmd/genaccounts.go +22 -18
- package/daemon/cmd/root.go +253 -52
- package/daemon/cmd/root_test.go +190 -2
- package/daemon/cmd/testnet.go +17 -6
- package/daemon/main.go +6 -3
- package/e2e_test/Makefile +29 -0
- package/e2e_test/README.md +100 -0
- package/e2e_test/go.mod +217 -0
- package/e2e_test/go.sum +1323 -0
- package/e2e_test/ibc_conformance_test.go +56 -0
- package/e2e_test/pfm_test.go +613 -0
- package/e2e_test/util.go +271 -0
- package/git-revision.txt +1 -0
- package/go.mod +207 -0
- package/go.sum +1877 -0
- package/package.json +13 -21
- package/proto/agoric/swingset/genesis.proto +14 -0
- package/proto/agoric/swingset/swingset.proto +6 -3
- package/proto/agoric/vlocalchain/.clang-format +7 -0
- package/proto/agoric/vlocalchain/vlocalchain.proto +31 -0
- package/proto/agoric/vstorage/query.proto +53 -1
- package/proto/agoric/vtransfer/genesis.proto +18 -0
- package/scripts/protocgen.sh +16 -6
- package/third_party/proto/buf.yaml +1 -0
- package/third_party/proto/cosmos/base/query/v1beta1/pagination.proto +4 -1
- package/third_party/proto/cosmos/base/v1beta1/coin.proto +7 -4
- package/third_party/proto/cosmos/upgrade/v1beta1/upgrade.proto +16 -6
- package/third_party/proto/cosmos_proto/cosmos.proto +97 -0
- package/third_party/proto/google/api/annotations.proto +1 -1
- package/third_party/proto/google/api/http.proto +181 -120
- package/third_party/proto/google/api/httpbody.proto +9 -6
- package/third_party/proto/google/protobuf/any.proto +1 -7
- package/third_party/proto/ibc/core/channel/v1/channel.proto +15 -1
- package/third_party/proto/ibc/core/client/v1/client.proto +9 -6
- package/tools/tools.go +11 -0
- package/types/events.go +41 -0
- package/types/kv_entry.go +114 -0
- package/types/kv_entry_helpers.go +276 -0
- package/types/kv_entry_helpers_test.go +237 -0
- package/types/kv_entry_test.go +143 -0
- package/upgradegaia.sh +75 -0
- package/vm/action.go +134 -0
- package/vm/action_test.go +149 -0
- package/vm/client.go +113 -0
- package/vm/client_test.go +182 -0
- package/vm/controller.go +49 -0
- package/vm/core_proposals.go +51 -0
- package/vm/jsonrpcconn/jsonrpcconn.go +160 -0
- package/vm/jsonrpcconn/jsonrpcconn_test.go +126 -0
- package/vm/proto_json.go +38 -0
- package/vm/proto_json_test.go +103 -0
- package/vm/server.go +124 -0
- package/x/swingset/abci.go +26 -37
- package/x/swingset/alias.go +9 -6
- package/x/swingset/client/cli/query.go +2 -2
- package/x/swingset/client/cli/tx.go +52 -33
- package/x/swingset/client/proposal_handler.go +2 -17
- package/x/swingset/genesis.go +163 -37
- package/x/swingset/handler.go +2 -1
- package/x/swingset/keeper/extension_snapshotter.go +309 -0
- package/x/swingset/keeper/extension_snapshotter_test.go +104 -0
- package/x/swingset/keeper/keeper.go +95 -48
- package/x/swingset/keeper/keeper_test.go +77 -0
- package/x/swingset/keeper/migrations.go +7 -2
- package/x/swingset/keeper/msg_server.go +71 -56
- package/x/swingset/keeper/proposal.go +15 -9
- package/x/swingset/keeper/querier.go +24 -15
- package/x/swingset/keeper/swing_store_exports_handler.go +872 -0
- package/x/swingset/keeper/swing_store_exports_handler_test.go +247 -0
- package/x/swingset/keeper/test_utils.go +16 -0
- package/x/swingset/module.go +33 -11
- package/x/swingset/proposal_handler.go +5 -4
- package/x/swingset/swingset.go +73 -0
- package/x/swingset/testing/queue.go +17 -0
- package/x/swingset/types/codec.go +2 -2
- package/x/swingset/types/default-params.go +23 -17
- package/x/swingset/types/expected_keepers.go +14 -2
- package/x/swingset/types/genesis.pb.go +361 -18
- package/x/swingset/types/msgs.go +87 -26
- package/x/swingset/types/msgs.pb.go +16 -16
- package/x/swingset/types/params.go +76 -1
- package/x/swingset/types/params_test.go +116 -0
- package/x/swingset/types/proposal.go +10 -9
- package/x/swingset/types/swingset.pb.go +83 -81
- package/x/swingset/types/types.go +30 -28
- package/x/vbank/genesis.go +0 -2
- package/x/vbank/handler.go +2 -1
- package/x/vbank/keeper/keeper.go +3 -2
- package/x/vbank/keeper/querier.go +9 -4
- package/x/vbank/keeper/rewards.go +1 -1
- package/x/vbank/module.go +0 -5
- package/x/vbank/types/msgs.go +0 -12
- package/x/vbank/vbank.go +34 -32
- package/x/vbank/vbank_test.go +20 -20
- package/x/vibc/alias.go +3 -0
- package/x/vibc/handler.go +17 -15
- package/x/vibc/keeper/keeper.go +113 -89
- package/x/vibc/keeper/triggers.go +101 -0
- package/x/vibc/module.go +5 -8
- package/x/vibc/types/expected_keepers.go +28 -6
- package/x/vibc/types/ibc_module.go +336 -0
- package/x/vibc/types/msgs.go +1 -1
- package/x/vibc/types/msgs.pb.go +1 -1
- package/x/vibc/types/receiver.go +170 -0
- package/x/vlocalchain/alias.go +19 -0
- package/x/vlocalchain/handler.go +21 -0
- package/x/vlocalchain/keeper/keeper.go +279 -0
- package/x/vlocalchain/keeper/keeper_test.go +97 -0
- package/x/vlocalchain/types/codec.go +34 -0
- package/x/vlocalchain/types/key.go +27 -0
- package/x/vlocalchain/types/msgs.go +16 -0
- package/x/vlocalchain/types/vlocalchain.pb.go +1072 -0
- package/x/vlocalchain/vlocalchain.go +114 -0
- package/x/vlocalchain/vlocalchain_test.go +434 -0
- package/x/vstorage/README.md +138 -0
- package/x/vstorage/capdata/capdata.go +298 -0
- package/x/vstorage/capdata/capdata_test.go +352 -0
- package/x/vstorage/client/cli/query.go +51 -4
- package/x/vstorage/genesis.go +0 -3
- package/x/vstorage/handler.go +2 -1
- package/x/vstorage/keeper/grpc_query.go +220 -0
- package/x/vstorage/keeper/keeper.go +75 -57
- package/x/vstorage/keeper/keeper_grpc_test.go +300 -0
- package/x/vstorage/keeper/keeper_test.go +40 -62
- package/x/vstorage/keeper/querier.go +39 -14
- package/x/vstorage/keeper/querier_test.go +113 -0
- package/x/vstorage/module.go +0 -5
- package/x/vstorage/testing/queue.go +27 -0
- package/x/vstorage/types/path_keys.go +22 -10
- package/x/vstorage/types/path_keys_test.go +84 -18
- package/x/vstorage/types/query.pb.go +646 -36
- package/x/vstorage/types/query.pb.gw.go +119 -0
- package/x/vstorage/types/types.go +0 -66
- package/x/vstorage/vstorage.go +33 -35
- package/x/vstorage/vstorage_test.go +19 -19
- package/x/vtransfer/alias.go +13 -0
- package/x/vtransfer/genesis.go +39 -0
- package/x/vtransfer/genesis_test.go +12 -0
- package/x/vtransfer/handler.go +20 -0
- package/x/vtransfer/ibc_middleware.go +186 -0
- package/x/vtransfer/ibc_middleware_test.go +448 -0
- package/x/vtransfer/keeper/keeper.go +281 -0
- package/x/vtransfer/module.go +124 -0
- package/x/vtransfer/types/expected_keepers.go +38 -0
- package/x/vtransfer/types/genesis.pb.go +327 -0
- package/x/vtransfer/types/key.go +9 -0
- package/x/vtransfer/types/msgs.go +9 -0
- package/app/const.go +0 -6
- package/cmd/helper/main.go +0 -21
- package/proto/agoric/lien/genesis.proto +0 -25
- package/proto/agoric/lien/lien.proto +0 -25
- package/x/lien/alias.go +0 -17
- package/x/lien/genesis.go +0 -58
- package/x/lien/genesis_test.go +0 -101
- package/x/lien/keeper/account.go +0 -285
- package/x/lien/keeper/keeper.go +0 -254
- package/x/lien/keeper/keeper_test.go +0 -623
- package/x/lien/lien.go +0 -203
- package/x/lien/lien_test.go +0 -529
- package/x/lien/module.go +0 -115
- package/x/lien/spec/01_concepts.md +0 -146
- package/x/lien/spec/02_messages.md +0 -96
- package/x/lien/types/accountkeeper.go +0 -81
- package/x/lien/types/accountstate.go +0 -27
- package/x/lien/types/expected_keepers.go +0 -18
- package/x/lien/types/genesis.pb.go +0 -567
- package/x/lien/types/key.go +0 -25
- package/x/lien/types/lien.pb.go +0 -403
- package/x/swingset/keeper/snapshotter.go +0 -491
- package/x/swingset/keeper/snapshotter_test.go +0 -185
- package/x/swingset/legacy/v32/params.go +0 -37
- package/x/swingset/legacy/v32/params_test.go +0 -133
- package/x/vibc/ibc.go +0 -442
- /package/{src/index.cjs → index.cjs} +0 -0
package/MAINTAINERS.md
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
When updating the protos here, be mindful that `@agoric/cosmic-proto` will need refreshing to get them.
|
|
2
|
+
|
|
3
|
+
https://github.com/Agoric/agoric-sdk/issues/8131 will help automate updating protos, but not the publishing to NPM of the codegen-ed JS utilities for working with the APIs they define.
|
package/Makefile
CHANGED
|
@@ -32,21 +32,23 @@ ldflags = -X github.com/cosmos/cosmos-sdk/version.Name=$(VersionName) \
|
|
|
32
32
|
-X "github.com/cosmos/cosmos-sdk/version.BuildTags=$(build_tags_comma_sep)"
|
|
33
33
|
|
|
34
34
|
gcflags =
|
|
35
|
+
shared_ldflags = $(ldflags)
|
|
35
36
|
|
|
36
37
|
ifneq ($(GO_DEBUG),)
|
|
37
38
|
ldflags += -compressdwarf=false
|
|
38
39
|
gcflags += -N -l
|
|
40
|
+
else ifeq ($(shell uname -s 2>/dev/null),Darwin)
|
|
41
|
+
# Darwin's latest ld crashes with https://github.com/Agoric/agoric-sdk/issues/8367
|
|
42
|
+
shared_ldflags += -w
|
|
39
43
|
endif
|
|
40
44
|
|
|
41
|
-
ldflags_helper = $(ldflags) \
|
|
42
|
-
-X github.com/cosmos/cosmos-sdk/version.AppName=ag-cosmos-helper
|
|
43
45
|
BUILD_FLAGS := -tags "$(build_tags)" -gcflags '$(gcflags)' -ldflags '$(ldflags)'
|
|
44
|
-
|
|
46
|
+
SHARED_BUILD_FLAGS := -tags "$(build_tags)" -gcflags '$(gcflags)' -ldflags '$(shared_ldflags)'
|
|
45
47
|
|
|
46
48
|
all: compile-chain
|
|
47
49
|
|
|
48
|
-
compile-chain: compile-agd compile-
|
|
49
|
-
compile-go: compile-agd compile-
|
|
50
|
+
compile-chain: compile-agd compile-daemon
|
|
51
|
+
compile-go: compile-agd compile-libdaemon
|
|
50
52
|
compile-node: node-compile-gyp
|
|
51
53
|
|
|
52
54
|
compile-daemon: compile-libdaemon node-compile-gyp
|
|
@@ -60,10 +62,10 @@ node-compile-gyp:
|
|
|
60
62
|
fi
|
|
61
63
|
|
|
62
64
|
compile-agd: go-mod-cache
|
|
63
|
-
go build -v $(MOD_READONLY) $(
|
|
65
|
+
go build -v $(MOD_READONLY) $(BUILD_FLAGS) -buildmode=exe -o build/agd ./cmd/agd
|
|
64
66
|
|
|
65
67
|
install-agd: go-mod-cache
|
|
66
|
-
go install -v $(MOD_READONLY) $(
|
|
68
|
+
go install -v $(MOD_READONLY) $(BUILD_FLAGS) -buildmode=exe ./cmd/agd
|
|
67
69
|
|
|
68
70
|
# Only run from the package.json build:gyp script.
|
|
69
71
|
compile-gyp:
|
|
@@ -71,18 +73,15 @@ compile-gyp:
|
|
|
71
73
|
node-gyp configure build $(GYP_DEBUG) || { status=$$?; rm -f binding.gyp; exit $$status; }
|
|
72
74
|
rm -f binding.gyp
|
|
73
75
|
|
|
74
|
-
compile-helper: go-mod-cache
|
|
75
|
-
go build -v $(MOD_READONLY) $(BUILD_FLAGS_HELPER) -o build/ag-cosmos-helper ./cmd/helper
|
|
76
|
-
|
|
77
76
|
compile-libdaemon: go-mod-cache
|
|
78
|
-
go build -v $(MOD_READONLY) $(
|
|
79
|
-
|
|
77
|
+
go build -v $(MOD_READONLY) $(SHARED_BUILD_FLAGS) -buildmode=c-shared \
|
|
78
|
+
-o build/libagcosmosdaemon.so ./cmd/libdaemon/main.go
|
|
80
79
|
|
|
81
|
-
go-mod-cache:
|
|
80
|
+
go-mod-cache: go.sum
|
|
82
81
|
@echo "--> Download go modules to local cache"
|
|
83
82
|
@go mod download
|
|
84
83
|
|
|
85
|
-
|
|
84
|
+
go.sum: go.mod
|
|
86
85
|
@echo "--> Ensure dependencies have not been modified"
|
|
87
86
|
GO111MODULE=on go mod verify
|
|
88
87
|
|
|
@@ -99,48 +98,68 @@ proto-lint: proto-tools
|
|
|
99
98
|
proto-check-breaking: proto-tools
|
|
100
99
|
${BIN}/buf breaking --against $(PR_TARGET_REPO)#branch=$(PR_TARGET_BRANCH),subdir=golang/cosmos
|
|
101
100
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
TM_URL := file://$(shell go list -m -f '{{ .Dir }}' github.com/tendermint/tendermint)/proto/tendermint
|
|
109
|
-
GOGO_PROTO_URL := file://$(shell go list -m -f '{{ .Dir }}' github.com/gogo/protobuf)
|
|
110
|
-
IBC_PROTO_URL := file://$(shell go list -m -f '{{ .Dir }}' github.com/cosmos/ibc-go/v3)/proto/ibc/core
|
|
111
|
-
COSMOS_SDK_PROTO_URL := file://$(shell go list -m -f '{{ .Dir }}' github.com/cosmos/cosmos-sdk)/proto/cosmos
|
|
101
|
+
GOGO_PROTO_URL = file://$(shell go list -m -f '{{ .Dir }}' github.com/gogo/protobuf)
|
|
102
|
+
# GOOGLE_API_URL = file://$(shell go list -m -f '{{ .Dir }}' github.com/googleapis/googleapis)/google/api
|
|
103
|
+
IBC_PROTO_URL = file://$(shell go list -m -f '{{ .Dir }}' github.com/cosmos/ibc-go/v6)/proto/ibc/core
|
|
104
|
+
COSMOS_PROTO_PROTO_URL = file://$(shell go list -m -f '{{ .Dir }}' github.com/cosmos/cosmos-proto)/proto/cosmos_proto
|
|
105
|
+
COSMOS_SDK_PROTO_URL = file://$(shell go list -m -f '{{ .Dir }}' github.com/cosmos/cosmos-sdk)/proto/cosmos
|
|
112
106
|
|
|
107
|
+
COSMOS_PROTO_TYPES = third_party/proto/cosmos_proto
|
|
113
108
|
GOGO_PROTO_TYPES = third_party/proto/gogoproto
|
|
109
|
+
GOOGLE_API_TYPES = third_party/proto/google/api
|
|
110
|
+
GOOGLE_PROTO_TYPES = third_party/proto/google/protobuf
|
|
114
111
|
IBC_CHANNEL_TYPES = third_party/proto/ibc/core/channel/v1
|
|
115
112
|
IBC_CLIENT_TYPES = third_party/proto/ibc/core/client/v1
|
|
116
|
-
|
|
113
|
+
SDK_BASE_TYPES = third_party/proto/cosmos/base/v1beta1
|
|
114
|
+
SDK_QUERY_TYPES = third_party/proto/cosmos/base/query/v1beta1
|
|
117
115
|
SDK_UPGRADE_TYPES = third_party/proto/cosmos/upgrade/v1beta1
|
|
118
116
|
|
|
119
117
|
proto-update-deps:
|
|
120
|
-
mkdir -p $(
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
mkdir -p $(IBC_CHANNEL_TYPES)
|
|
124
|
-
curl -sSL $(IBC_PROTO_URL)/channel/v1/channel.proto > $(IBC_CHANNEL_TYPES)/channel.proto
|
|
125
|
-
|
|
126
|
-
mkdir -p $(IBC_CLIENT_TYPES)
|
|
127
|
-
curl -sSL $(IBC_PROTO_URL)/client/v1/client.proto > $(IBC_CLIENT_TYPES)/client.proto
|
|
128
|
-
|
|
129
|
-
mkdir -p $(SDK_QUERY_TYPES)
|
|
130
|
-
curl -sSL $(COSMOS_SDK_PROTO_URL)/base/query/v1beta1/pagination.proto > $(SDK_QUERY_TYPES)/pagination.proto
|
|
131
|
-
|
|
132
|
-
mkdir -p $(SDK_UPGRADE_TYPES)
|
|
133
|
-
curl -sSL $(COSMOS_SDK_PROTO_URL)/upgrade/v1beta1/upgrade.proto > $(SDK_UPGRADE_TYPES)/upgrade.proto
|
|
118
|
+
mkdir -p $(COSMOS_PROTO_TYPES)
|
|
119
|
+
url="$(COSMOS_PROTO_PROTO_URL)"; \
|
|
120
|
+
curl -sSL $$url/cosmos.proto > $(COSMOS_PROTO_TYPES)/cosmos.proto
|
|
134
121
|
|
|
122
|
+
mkdir -p $(GOGO_PROTO_TYPES)
|
|
123
|
+
url="$(GOGO_PROTO_URL)"; \
|
|
124
|
+
curl -sSL $$url/gogoproto/gogo.proto > $(GOGO_PROTO_TYPES)/gogo.proto
|
|
125
|
+
|
|
126
|
+
# Downloading from a not-a-go-module is problematic. These files are artifacts for now.
|
|
127
|
+
# mkdir -p $(GOOGLE_API_TYPES)
|
|
128
|
+
# url="$(GOOGLE_API_URL)"; \
|
|
129
|
+
# curl -sSL $$url/annotations.proto > $(GOOGLE_API_TYPES)/annotations.proto && \
|
|
130
|
+
# curl -sSL $$url/http.proto > $(GOOGLE_API_TYPES)/http.proto && \
|
|
131
|
+
# curl -sSL $$url/httpbody.proto > $(GOOGLE_API_TYPES)/httpbody.proto &&
|
|
132
|
+
|
|
133
|
+
mkdir -p $(GOOGLE_PROTO_TYPES)
|
|
134
|
+
url="$(GOGO_PROTO_URL)"; \
|
|
135
|
+
curl -sSL $$url/protobuf/google/protobuf/any.proto > $(GOOGLE_PROTO_TYPES)/any.proto
|
|
136
|
+
|
|
137
|
+
url="$(IBC_PROTO_URL)"; \
|
|
138
|
+
mkdir -p $(IBC_CHANNEL_TYPES) && \
|
|
139
|
+
curl -sSL $$url/channel/v1/channel.proto > $(IBC_CHANNEL_TYPES)/channel.proto && \
|
|
140
|
+
mkdir -p $(IBC_CLIENT_TYPES) && \
|
|
141
|
+
curl -sSL $$url/client/v1/client.proto > $(IBC_CLIENT_TYPES)/client.proto
|
|
142
|
+
|
|
143
|
+
url="$(COSMOS_SDK_PROTO_URL)"; \
|
|
144
|
+
mkdir -p $(SDK_BASE_TYPES) && \
|
|
145
|
+
curl -sSL $$url/base/v1beta1/coin.proto > $(SDK_BASE_TYPES)/coin.proto && \
|
|
146
|
+
mkdir -p $(SDK_QUERY_TYPES) && \
|
|
147
|
+
curl -sSL $$url/base/query/v1beta1/pagination.proto > $(SDK_QUERY_TYPES)/pagination.proto && \
|
|
148
|
+
mkdir -p $(SDK_UPGRADE_TYPES) && \
|
|
149
|
+
curl -sSL $$url/upgrade/v1beta1/upgrade.proto > $(SDK_UPGRADE_TYPES)/upgrade.proto
|
|
135
150
|
|
|
136
151
|
UNAME_S ?= $(shell uname -s)
|
|
137
152
|
UNAME_M ?= $(shell uname -m)
|
|
138
153
|
|
|
139
|
-
BUF_VERSION ?= 0.
|
|
154
|
+
BUF_VERSION ?= 1.0.0
|
|
140
155
|
|
|
141
156
|
PROTOC_VERSION ?= 3.11.2
|
|
142
157
|
ifeq ($(UNAME_S),Linux)
|
|
143
|
-
|
|
158
|
+
ifeq ($(UNAME_M),aarch64)
|
|
159
|
+
PROTOC_ZIP ?= protoc-${PROTOC_VERSION}-linux-aarch_64.zip
|
|
160
|
+
else
|
|
161
|
+
PROTOC_ZIP ?= protoc-${PROTOC_VERSION}-linux-x86_64.zip
|
|
162
|
+
endif
|
|
144
163
|
endif
|
|
145
164
|
ifeq ($(UNAME_S),Darwin)
|
|
146
165
|
PROTOC_ZIP ?= protoc-${PROTOC_VERSION}-osx-x86_64.zip
|
|
@@ -186,3 +205,10 @@ grpc-gateway-stamp:
|
|
|
186
205
|
|
|
187
206
|
tools-clean:
|
|
188
207
|
rm -f proto-tools-stamp buf-stamp grpc-gateway-stamp
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
lint:
|
|
211
|
+
golangci-lint run
|
|
212
|
+
|
|
213
|
+
test:
|
|
214
|
+
go test -coverprofile=coverage.txt -covermode=atomic ./...
|
package/agoric/config.go
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
package agoric
|
|
2
|
+
|
|
3
|
+
import (
|
|
4
|
+
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
5
|
+
)
|
|
6
|
+
|
|
7
|
+
const (
|
|
8
|
+
// Bech32MainPrefix defines the Bech32 prefix used by all types
|
|
9
|
+
Bech32MainPrefix = "agoric"
|
|
10
|
+
|
|
11
|
+
// CoinType is used in the slip44 HD key derivation path.
|
|
12
|
+
// https://github.com/satoshilabs/slips/blob/master/slip-0044.md
|
|
13
|
+
CoinType = 564
|
|
14
|
+
|
|
15
|
+
// Bech32PrefixAccAddr defines the Bech32 prefix of an account's address
|
|
16
|
+
Bech32PrefixAccAddr = Bech32MainPrefix
|
|
17
|
+
// Bech32PrefixAccPub defines the Bech32 prefix of an account's public key
|
|
18
|
+
Bech32PrefixAccPub = Bech32MainPrefix + sdk.PrefixPublic
|
|
19
|
+
// Bech32PrefixValAddr defines the Bech32 prefix of a validator's operator address
|
|
20
|
+
Bech32PrefixValAddr = Bech32MainPrefix + sdk.PrefixValidator + sdk.PrefixOperator
|
|
21
|
+
// Bech32PrefixValPub defines the Bech32 prefix of a validator's operator public key
|
|
22
|
+
Bech32PrefixValPub = Bech32MainPrefix + sdk.PrefixValidator + sdk.PrefixOperator + sdk.PrefixPublic
|
|
23
|
+
// Bech32PrefixConsAddr defines the Bech32 prefix of a consensus node address
|
|
24
|
+
Bech32PrefixConsAddr = Bech32MainPrefix + sdk.PrefixValidator + sdk.PrefixConsensus
|
|
25
|
+
// Bech32PrefixConsPub defines the Bech32 prefix of a consensus node public key
|
|
26
|
+
Bech32PrefixConsPub = Bech32MainPrefix + sdk.PrefixValidator + sdk.PrefixConsensus + sdk.PrefixPublic
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
// SetAgoricConfig sets the appropriate parameters for the Agoric chain.
|
|
30
|
+
func SetAgoricConfig(config *sdk.Config) {
|
|
31
|
+
config.SetCoinType(CoinType)
|
|
32
|
+
config.SetBech32PrefixForAccount(Bech32PrefixAccAddr, Bech32PrefixAccPub)
|
|
33
|
+
config.SetBech32PrefixForValidator(Bech32PrefixValAddr, Bech32PrefixValPub)
|
|
34
|
+
config.SetBech32PrefixForConsensusNode(Bech32PrefixConsAddr, Bech32PrefixConsPub)
|
|
35
|
+
}
|
package/ante/ante.go
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
package ante
|
|
2
|
+
|
|
3
|
+
import (
|
|
4
|
+
sdkioerrors "cosmossdk.io/errors"
|
|
5
|
+
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
6
|
+
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
|
7
|
+
"github.com/cosmos/cosmos-sdk/x/auth/ante"
|
|
8
|
+
ibcante "github.com/cosmos/ibc-go/v6/modules/core/ante"
|
|
9
|
+
ibckeeper "github.com/cosmos/ibc-go/v6/modules/core/keeper"
|
|
10
|
+
)
|
|
11
|
+
|
|
12
|
+
// HandlerOptions extend the SDK's AnteHandler options by requiring the IBC
|
|
13
|
+
// channel keeper.
|
|
14
|
+
type HandlerOptions struct {
|
|
15
|
+
ante.HandlerOptions
|
|
16
|
+
|
|
17
|
+
IBCKeeper *ibckeeper.Keeper
|
|
18
|
+
FeeCollectorName string
|
|
19
|
+
AdmissionData interface{}
|
|
20
|
+
SwingsetKeeper SwingsetKeeper
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
func NewAnteHandler(opts HandlerOptions) (sdk.AnteHandler, error) {
|
|
24
|
+
if opts.AccountKeeper == nil {
|
|
25
|
+
return nil, sdkioerrors.Wrap(sdkerrors.ErrLogic, "account keeper is required for AnteHandler")
|
|
26
|
+
}
|
|
27
|
+
if opts.BankKeeper == nil {
|
|
28
|
+
return nil, sdkioerrors.Wrap(sdkerrors.ErrLogic, "bank keeper is required for AnteHandler")
|
|
29
|
+
}
|
|
30
|
+
if opts.SignModeHandler == nil {
|
|
31
|
+
return nil, sdkioerrors.Wrap(sdkerrors.ErrLogic, "sign mode handler is required for ante builder")
|
|
32
|
+
}
|
|
33
|
+
if opts.AdmissionData == nil {
|
|
34
|
+
return nil, sdkioerrors.Wrap(sdkerrors.ErrLogic, "admission data is required for AnteHandler")
|
|
35
|
+
}
|
|
36
|
+
if opts.SwingsetKeeper == nil {
|
|
37
|
+
return nil, sdkioerrors.Wrap(sdkerrors.ErrLogic, "swingset keeper is required for AnteHandler")
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
var sigGasConsumer = opts.SigGasConsumer
|
|
41
|
+
if sigGasConsumer == nil {
|
|
42
|
+
sigGasConsumer = ante.DefaultSigVerificationGasConsumer
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
anteDecorators := []sdk.AnteDecorator{
|
|
46
|
+
ante.NewSetUpContextDecorator(),
|
|
47
|
+
ante.NewExtensionOptionsDecorator(nil), // reject all extensions
|
|
48
|
+
ante.NewValidateBasicDecorator(),
|
|
49
|
+
ante.NewTxTimeoutHeightDecorator(),
|
|
50
|
+
ante.NewValidateMemoDecorator(opts.AccountKeeper),
|
|
51
|
+
ante.NewConsumeGasForTxSizeDecorator(opts.AccountKeeper),
|
|
52
|
+
NewInboundDecorator(opts.SwingsetKeeper),
|
|
53
|
+
ante.NewDeductFeeDecoratorWithName(opts.AccountKeeper, opts.BankKeeper, opts.FeegrantKeeper, nil, opts.FeeCollectorName),
|
|
54
|
+
// SetPubKeyDecorator must be called before all signature verification decorators
|
|
55
|
+
ante.NewSetPubKeyDecorator(opts.AccountKeeper),
|
|
56
|
+
ante.NewValidateSigCountDecorator(opts.AccountKeeper),
|
|
57
|
+
ante.NewSigGasConsumeDecorator(opts.AccountKeeper, sigGasConsumer),
|
|
58
|
+
ante.NewSigVerificationDecorator(opts.AccountKeeper, opts.SignModeHandler),
|
|
59
|
+
NewAdmissionDecorator(opts.AdmissionData),
|
|
60
|
+
ante.NewIncrementSequenceDecorator(opts.AccountKeeper),
|
|
61
|
+
ibcante.NewRedundantRelayDecorator(opts.IBCKeeper),
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return sdk.ChainAnteDecorators(anteDecorators...), nil
|
|
65
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
package ante
|
|
2
|
+
|
|
3
|
+
import (
|
|
4
|
+
swingtypes "github.com/Agoric/agoric-sdk/golang/cosmos/x/swingset/types"
|
|
5
|
+
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
6
|
+
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
|
|
7
|
+
)
|
|
8
|
+
|
|
9
|
+
// AccountKeeper defines the contract needed for AccountKeeper related APIs.
|
|
10
|
+
// Interface provides support to use non-sdk AccountKeeper for AnteHandler's decorators.
|
|
11
|
+
type AccountKeeper interface {
|
|
12
|
+
GetParams(ctx sdk.Context) (params authtypes.Params)
|
|
13
|
+
GetAccount(ctx sdk.Context, addr sdk.AccAddress) authtypes.AccountI
|
|
14
|
+
SetAccount(ctx sdk.Context, acc authtypes.AccountI)
|
|
15
|
+
GetModuleAddress(moduleName string) sdk.AccAddress
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// FeegrantKeeper defines the expected feegrant keeper.
|
|
19
|
+
type FeegrantKeeper interface {
|
|
20
|
+
UseGrantedFees(ctx sdk.Context, granter, grantee sdk.AccAddress, fee sdk.Coins, msgs []sdk.Msg) error
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
type SwingsetKeeper interface {
|
|
24
|
+
InboundQueueLength(ctx sdk.Context) (int32, error)
|
|
25
|
+
GetState(ctx sdk.Context) swingtypes.State
|
|
26
|
+
}
|
package/ante/inbound.go
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
package ante
|
|
2
|
+
|
|
3
|
+
import (
|
|
4
|
+
"github.com/armon/go-metrics"
|
|
5
|
+
|
|
6
|
+
"github.com/cosmos/cosmos-sdk/telemetry"
|
|
7
|
+
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
8
|
+
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
|
9
|
+
|
|
10
|
+
"github.com/Agoric/agoric-sdk/golang/cosmos/vm"
|
|
11
|
+
swingtypes "github.com/Agoric/agoric-sdk/golang/cosmos/x/swingset/types"
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
/*
|
|
15
|
+
This AnteDecorator enforces a limit on the size of the Swingset inbound queue
|
|
16
|
+
by scanning for Cosmos-messages which end up on Swingset's message queues. Note
|
|
17
|
+
that when running DeliverTx, inbound messages are placed in either the
|
|
18
|
+
actionQueue or the highPriorityQueue (forming the Swingset inbound queue),
|
|
19
|
+
and kept there until processed by SwingSet. Previous Txs in the block will have
|
|
20
|
+
already been added to the inbound queue, so we must reject Txs which would grow
|
|
21
|
+
the actionQueue beyond the allowed inbound size. Additions to the
|
|
22
|
+
highPriorityQueue are exempt of inbound queue size checks but count towards the
|
|
23
|
+
overall inbound queue size, which means the inbound queue can "overflow" its
|
|
24
|
+
limits when adding high priority actions.
|
|
25
|
+
|
|
26
|
+
We would like to reject messages during mempool admission (CheckTx)
|
|
27
|
+
rather than during block execution (DeliverTx), but at CheckTx time
|
|
28
|
+
we don't know how many messages will be allowed at DeliverTx time,
|
|
29
|
+
nor the size of the inbound queue from preceding Txs in the block.
|
|
30
|
+
To mitigate this, x/swingset implements an hysteresis by computing
|
|
31
|
+
the number of messages allowed for mempool admission as if its max
|
|
32
|
+
queue length was lower (e.g. 50%). This is the QueueInboundMempool
|
|
33
|
+
entry in the Swingset state QueueAllowed field. At DeliverTx time
|
|
34
|
+
the QueueInbound entry gives the number of allowed messages.
|
|
35
|
+
*/
|
|
36
|
+
|
|
37
|
+
const (
|
|
38
|
+
maxInboundPerTx = 1
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
// TODO: We don't have a more appropriate error type for this.
|
|
42
|
+
var ErrInboundQueueFull = sdkerrors.ErrMempoolIsFull
|
|
43
|
+
|
|
44
|
+
// inboundAnte is an sdk.AnteDecorator which enforces the allowed size of the inbound queue.
|
|
45
|
+
type inboundAnte struct {
|
|
46
|
+
sk SwingsetKeeper
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// NewInboundDecorator returns an AnteDecorator which honors the allowed size of the inbound queue.
|
|
50
|
+
func NewInboundDecorator(sk SwingsetKeeper) sdk.AnteDecorator {
|
|
51
|
+
return inboundAnte{sk: sk}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// AnteHandle implements sdk.AnteDecorator.
|
|
55
|
+
// Lazily consults the Swingset state to avoid overhead when dealing
|
|
56
|
+
// with pure Cosmos-level Txs.
|
|
57
|
+
func (ia inboundAnte) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (sdk.Context, error) {
|
|
58
|
+
msgs := tx.GetMsgs()
|
|
59
|
+
inboundsAllowed := int32(-1)
|
|
60
|
+
for _, msg := range msgs {
|
|
61
|
+
inbounds := inboundMessages(msg)
|
|
62
|
+
if inbounds == 0 {
|
|
63
|
+
continue
|
|
64
|
+
}
|
|
65
|
+
if inboundsAllowed == -1 {
|
|
66
|
+
var err error
|
|
67
|
+
inboundsAllowed, err = ia.allowedInbound(ctx)
|
|
68
|
+
if err != nil {
|
|
69
|
+
return ctx, err
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
isHighPriority, err := ia.isPriorityMessage(ctx, msg)
|
|
73
|
+
if err != nil {
|
|
74
|
+
return ctx, err
|
|
75
|
+
}
|
|
76
|
+
if inboundsAllowed >= inbounds {
|
|
77
|
+
inboundsAllowed -= inbounds
|
|
78
|
+
} else if isHighPriority {
|
|
79
|
+
inboundsAllowed = 0
|
|
80
|
+
} else {
|
|
81
|
+
defer func() {
|
|
82
|
+
telemetry.IncrCounterWithLabels(
|
|
83
|
+
[]string{"tx", "ante", "inbound_not_allowed"},
|
|
84
|
+
1,
|
|
85
|
+
[]metrics.Label{
|
|
86
|
+
telemetry.NewLabel("msg", sdk.MsgTypeURL(msg)),
|
|
87
|
+
},
|
|
88
|
+
)
|
|
89
|
+
}()
|
|
90
|
+
return ctx, ErrInboundQueueFull
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return next(ctx, tx, simulate)
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
func (ia inboundAnte) isPriorityMessage(ctx sdk.Context, msg sdk.Msg) (bool, error) {
|
|
97
|
+
if c, ok := msg.(vm.ControllerAdmissionMsg); ok {
|
|
98
|
+
return c.IsHighPriority(ctx, ia.sk)
|
|
99
|
+
}
|
|
100
|
+
return false, nil
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// allowedInbound returns the allowed number of inbound queue messages or an error.
|
|
104
|
+
// Look up the limit from the swingset state queue sizes: from QueueInboundMempool
|
|
105
|
+
// if we're running CheckTx (for the hysteresis described above), otherwise QueueAllowed.
|
|
106
|
+
func (ia inboundAnte) allowedInbound(ctx sdk.Context) (int32, error) {
|
|
107
|
+
state := ia.sk.GetState(ctx)
|
|
108
|
+
entry := swingtypes.QueueInbound
|
|
109
|
+
if ctx.IsCheckTx() {
|
|
110
|
+
entry = swingtypes.QueueInboundMempool
|
|
111
|
+
}
|
|
112
|
+
allowed, found := swingtypes.QueueSizeEntry(state.QueueAllowed, entry)
|
|
113
|
+
if !found {
|
|
114
|
+
// if number of allowed entries not given, fail closed
|
|
115
|
+
return 0, nil
|
|
116
|
+
}
|
|
117
|
+
actions, err := ia.sk.InboundQueueLength(ctx)
|
|
118
|
+
if err != nil {
|
|
119
|
+
return 0, err
|
|
120
|
+
}
|
|
121
|
+
if actions >= allowed {
|
|
122
|
+
return 0, nil
|
|
123
|
+
}
|
|
124
|
+
allowed -= actions
|
|
125
|
+
if allowed > maxInboundPerTx {
|
|
126
|
+
return maxInboundPerTx, nil
|
|
127
|
+
}
|
|
128
|
+
return allowed, nil
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// inboundMessages returns the nunber of inbound queue messages in msg.
|
|
132
|
+
func inboundMessages(msg sdk.Msg) int32 {
|
|
133
|
+
if c, ok := msg.(vm.ControllerAdmissionMsg); ok {
|
|
134
|
+
return c.GetInboundMsgCount()
|
|
135
|
+
}
|
|
136
|
+
return 0
|
|
137
|
+
}
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
package ante
|
|
2
|
+
|
|
3
|
+
import (
|
|
4
|
+
"context"
|
|
5
|
+
"fmt"
|
|
6
|
+
"reflect"
|
|
7
|
+
"testing"
|
|
8
|
+
|
|
9
|
+
sdkmath "cosmossdk.io/math"
|
|
10
|
+
swingtypes "github.com/Agoric/agoric-sdk/golang/cosmos/x/swingset/types"
|
|
11
|
+
"github.com/cosmos/cosmos-sdk/codec/types"
|
|
12
|
+
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
13
|
+
"github.com/cosmos/cosmos-sdk/types/tx"
|
|
14
|
+
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
|
|
15
|
+
"github.com/gogo/protobuf/proto"
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
func TestInboundAnteHandle(t *testing.T) {
|
|
19
|
+
for _, tt := range []struct {
|
|
20
|
+
name string
|
|
21
|
+
checkTx bool
|
|
22
|
+
tx sdk.Tx
|
|
23
|
+
simulate bool
|
|
24
|
+
inboundQueueLength int32
|
|
25
|
+
inboundQueueLengthErr error
|
|
26
|
+
inboundLimit int32
|
|
27
|
+
mempoolLimit int32
|
|
28
|
+
errMsg string
|
|
29
|
+
isHighPriorityOwner bool
|
|
30
|
+
}{
|
|
31
|
+
{
|
|
32
|
+
name: "empty-empty",
|
|
33
|
+
tx: makeTestTx(),
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
name: "reject-on-zero-allowed",
|
|
37
|
+
tx: makeTestTx(&swingtypes.MsgDeliverInbound{}),
|
|
38
|
+
errMsg: ErrInboundQueueFull.Error(),
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
name: "has-room",
|
|
42
|
+
tx: makeTestTx(&swingtypes.MsgInstallBundle{}),
|
|
43
|
+
inboundLimit: 10,
|
|
44
|
+
inboundQueueLength: 8,
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
name: "at-limit",
|
|
48
|
+
tx: makeTestTx(&swingtypes.MsgInstallBundle{}),
|
|
49
|
+
inboundLimit: 10,
|
|
50
|
+
inboundQueueLength: 9,
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
name: "no-room",
|
|
54
|
+
tx: makeTestTx(&swingtypes.MsgProvision{}),
|
|
55
|
+
inboundLimit: 10,
|
|
56
|
+
inboundQueueLength: 10,
|
|
57
|
+
errMsg: ErrInboundQueueFull.Error(),
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
name: "state-lookup-error",
|
|
61
|
+
tx: makeTestTx(&swingtypes.MsgWalletAction{}, &swingtypes.MsgWalletSpendAction{}),
|
|
62
|
+
inboundLimit: 10,
|
|
63
|
+
inboundQueueLengthErr: fmt.Errorf("sunspots"),
|
|
64
|
+
errMsg: "sunspots",
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
name: "allow-non-swingset-msgs",
|
|
68
|
+
tx: makeTestTx(&banktypes.MsgSend{}, &banktypes.MsgSend{}),
|
|
69
|
+
inboundLimit: 1,
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
name: "lazy-queue-length-lookup",
|
|
73
|
+
tx: makeTestTx(&banktypes.MsgSend{}, &banktypes.MsgSend{}),
|
|
74
|
+
inboundLimit: 1,
|
|
75
|
+
inboundQueueLengthErr: fmt.Errorf("sunspots"),
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
name: "checktx",
|
|
79
|
+
checkTx: true,
|
|
80
|
+
tx: makeTestTx(&swingtypes.MsgDeliverInbound{}),
|
|
81
|
+
inboundLimit: 10,
|
|
82
|
+
mempoolLimit: 5,
|
|
83
|
+
inboundQueueLength: 7,
|
|
84
|
+
errMsg: ErrInboundQueueFull.Error(),
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
name: "empty-queue-allowed",
|
|
88
|
+
tx: makeTestTx(&swingtypes.MsgInstallBundle{}),
|
|
89
|
+
inboundLimit: -1,
|
|
90
|
+
errMsg: ErrInboundQueueFull.Error(),
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
name: "already-full",
|
|
94
|
+
tx: makeTestTx(&swingtypes.MsgProvision{}),
|
|
95
|
+
inboundLimit: 10,
|
|
96
|
+
inboundQueueLength: 10,
|
|
97
|
+
errMsg: ErrInboundQueueFull.Error(),
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
name: "max-per-tx",
|
|
101
|
+
tx: makeTestTx(&swingtypes.MsgWalletAction{}, &swingtypes.MsgWalletSpendAction{}),
|
|
102
|
+
inboundLimit: 10,
|
|
103
|
+
inboundQueueLength: 5,
|
|
104
|
+
errMsg: ErrInboundQueueFull.Error(),
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
name: "priority-limit-bypass",
|
|
108
|
+
tx: makeTestTx(&swingtypes.MsgWalletSpendAction{}),
|
|
109
|
+
isHighPriorityOwner: true,
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
name: "priority-multi-bypass",
|
|
113
|
+
tx: makeTestTx(&swingtypes.MsgWalletSpendAction{}, &swingtypes.MsgWalletSpendAction{}),
|
|
114
|
+
isHighPriorityOwner: true,
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
name: "mixed-priority-limit-first-fail",
|
|
118
|
+
tx: makeTestTx(&swingtypes.MsgWalletSpendAction{}, &swingtypes.MsgProvision{}),
|
|
119
|
+
isHighPriorityOwner: true,
|
|
120
|
+
inboundLimit: 1,
|
|
121
|
+
errMsg: ErrInboundQueueFull.Error(),
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
name: "mixed-priority-limit-last-succeed",
|
|
125
|
+
tx: makeTestTx(&swingtypes.MsgProvision{}, &swingtypes.MsgWalletSpendAction{}),
|
|
126
|
+
isHighPriorityOwner: true,
|
|
127
|
+
inboundLimit: 1,
|
|
128
|
+
},
|
|
129
|
+
} {
|
|
130
|
+
t.Run(tt.name, func(t *testing.T) {
|
|
131
|
+
ctx := sdk.Context{}.WithContext(context.Background()).WithIsCheckTx(tt.checkTx)
|
|
132
|
+
emptyQueueAllowed := false
|
|
133
|
+
if tt.inboundLimit == -1 {
|
|
134
|
+
emptyQueueAllowed = true
|
|
135
|
+
}
|
|
136
|
+
mock := mockSwingsetKeeper{
|
|
137
|
+
inboundQueueLength: tt.inboundQueueLength,
|
|
138
|
+
inboundQueueLengthErr: tt.inboundQueueLengthErr,
|
|
139
|
+
inboundLimit: tt.inboundLimit,
|
|
140
|
+
mempoolLimit: tt.mempoolLimit,
|
|
141
|
+
emptyQueueAllowed: emptyQueueAllowed,
|
|
142
|
+
isHighPriorityOwner: tt.isHighPriorityOwner,
|
|
143
|
+
}
|
|
144
|
+
decorator := NewInboundDecorator(mock)
|
|
145
|
+
newCtx, err := decorator.AnteHandle(ctx, tt.tx, tt.simulate, nilAnteHandler)
|
|
146
|
+
if !reflect.DeepEqual(newCtx, ctx) {
|
|
147
|
+
t.Errorf("want ctx %v, got %v", ctx, newCtx)
|
|
148
|
+
}
|
|
149
|
+
if err != nil {
|
|
150
|
+
if tt.errMsg == "" {
|
|
151
|
+
t.Errorf("want no error, got %s", err.Error())
|
|
152
|
+
} else if err.Error() != tt.errMsg {
|
|
153
|
+
t.Errorf("want error %s, got %s", tt.errMsg, err.Error())
|
|
154
|
+
}
|
|
155
|
+
} else if tt.errMsg != "" {
|
|
156
|
+
t.Errorf("want error %s, got none", tt.errMsg)
|
|
157
|
+
}
|
|
158
|
+
})
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
func makeTestTx(msgs ...proto.Message) sdk.Tx {
|
|
163
|
+
wrappedMsgs := make([]*types.Any, len(msgs))
|
|
164
|
+
for i, m := range msgs {
|
|
165
|
+
any, err := types.NewAnyWithValue(m)
|
|
166
|
+
if err != nil {
|
|
167
|
+
panic(err)
|
|
168
|
+
}
|
|
169
|
+
wrappedMsgs[i] = any
|
|
170
|
+
}
|
|
171
|
+
return &tx.Tx{
|
|
172
|
+
Body: &tx.TxBody{
|
|
173
|
+
Messages: wrappedMsgs,
|
|
174
|
+
},
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
func nilAnteHandler(ctx sdk.Context, tx sdk.Tx, simulate bool) (newCtx sdk.Context, err error) {
|
|
179
|
+
return ctx, nil
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
type mockSwingsetKeeper struct {
|
|
183
|
+
inboundQueueLength int32
|
|
184
|
+
inboundQueueLengthErr error
|
|
185
|
+
inboundLimit int32
|
|
186
|
+
mempoolLimit int32
|
|
187
|
+
emptyQueueAllowed bool
|
|
188
|
+
isHighPriorityOwner bool
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
var _ SwingsetKeeper = mockSwingsetKeeper{}
|
|
192
|
+
var _ swingtypes.SwingSetKeeper = mockSwingsetKeeper{}
|
|
193
|
+
|
|
194
|
+
func (msk mockSwingsetKeeper) InboundQueueLength(ctx sdk.Context) (int32, error) {
|
|
195
|
+
return msk.inboundQueueLength, msk.inboundQueueLengthErr
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
func (msk mockSwingsetKeeper) GetState(ctx sdk.Context) swingtypes.State {
|
|
199
|
+
if msk.emptyQueueAllowed {
|
|
200
|
+
return swingtypes.State{}
|
|
201
|
+
}
|
|
202
|
+
return swingtypes.State{
|
|
203
|
+
QueueAllowed: []swingtypes.QueueSize{
|
|
204
|
+
swingtypes.NewQueueSize(swingtypes.QueueInbound, msk.inboundLimit),
|
|
205
|
+
swingtypes.NewQueueSize(swingtypes.QueueInboundMempool, msk.mempoolLimit),
|
|
206
|
+
},
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
func (msk mockSwingsetKeeper) IsHighPriorityAddress(ctx sdk.Context, addr sdk.AccAddress) (bool, error) {
|
|
211
|
+
return msk.isHighPriorityOwner, nil
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
func (msk mockSwingsetKeeper) GetBeansPerUnit(ctx sdk.Context) map[string]sdkmath.Uint {
|
|
215
|
+
return nil
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
func (msk mockSwingsetKeeper) ChargeBeans(ctx sdk.Context, addr sdk.AccAddress, beans sdkmath.Uint) error {
|
|
219
|
+
return fmt.Errorf("not implemented")
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
func (msk mockSwingsetKeeper) GetSmartWalletState(ctx sdk.Context, addr sdk.AccAddress) swingtypes.SmartWalletState {
|
|
223
|
+
panic(fmt.Errorf("not implemented"))
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
func (msk mockSwingsetKeeper) ChargeForSmartWallet(ctx sdk.Context, addr sdk.AccAddress) error {
|
|
227
|
+
return fmt.Errorf("not implemented")
|
|
228
|
+
}
|