@agoric/cosmos 0.34.1-dev-13050c2.0 → 0.34.1
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/CHANGELOG.md +11 -0
- package/Makefile +3 -2
- package/binding.gyp.in +4 -29
- package/cmd/agd/find_binary.go +7 -22
- package/cmd/agd/main.go +3 -2
- package/package.json +18 -6
- package/agoric/config.go +0 -35
- package/ante/ante.go +0 -65
- package/ante/expected_keepers.go +0 -26
- package/ante/fee.go +0 -96
- package/ante/inbound.go +0 -137
- package/ante/inbound_test.go +0 -219
- package/ante/vm_admission.go +0 -64
- package/buf.work.yaml +0 -4
- package/git-revision.txt +0 -1
- package/go.mod +0 -155
- package/go.sum +0 -1225
- package/tools/tools.go +0 -11
- package/types/events.go +0 -41
- package/upgradegaia.sh +0 -66
- package/vm/controller.go +0 -80
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,17 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
### [0.34.1](https://github.com/Agoric/agoric-sdk/compare/@agoric/cosmos@0.34.0...@agoric/cosmos@0.34.1) (2023-06-09)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @agoric/cosmos
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
### Updated go.mod and go.sum to include the barberry fix
|
|
15
|
+
|
|
16
|
+
|
|
6
17
|
## [0.34.0](https://github.com/Agoric/agoric-sdk/compare/@agoric/cosmos@0.32.2...@agoric/cosmos@0.34.0) (2023-05-19)
|
|
7
18
|
|
|
8
19
|
|
package/Makefile
CHANGED
|
@@ -76,12 +76,13 @@ compile-helper: go-mod-cache
|
|
|
76
76
|
|
|
77
77
|
compile-libdaemon: go-mod-cache
|
|
78
78
|
go build -v $(MOD_READONLY) $(BUILD_FLAGS) -buildmode=c-shared -o build/libagcosmosdaemon.so ./cmd/libdaemon/main.go
|
|
79
|
+
test "`uname -s 2>/dev/null`" != Darwin || install_name_tool -id $$PWD/build/libagcosmosdaemon.so build/libagcosmosdaemon.so
|
|
79
80
|
|
|
80
|
-
go-mod-cache: go.sum
|
|
81
|
+
go-mod-cache: ../../go.sum
|
|
81
82
|
@echo "--> Download go modules to local cache"
|
|
82
83
|
@go mod download
|
|
83
84
|
|
|
84
|
-
go.sum: go.mod
|
|
85
|
+
../../go.sum: ../../go.mod
|
|
85
86
|
@echo "--> Ensure dependencies have not been modified"
|
|
86
87
|
GO111MODULE=on go mod verify
|
|
87
88
|
|
package/binding.gyp.in
CHANGED
|
@@ -2,9 +2,6 @@
|
|
|
2
2
|
"targets": [
|
|
3
3
|
{
|
|
4
4
|
"target_name": "agcosmosdaemon",
|
|
5
|
-
'variables': {
|
|
6
|
-
"target_lib": "lib<(_target_name).so",
|
|
7
|
-
},
|
|
8
5
|
"cflags!": [ "-fno-exceptions" ],
|
|
9
6
|
"cflags_cc!": [ "-fno-exceptions" ],
|
|
10
7
|
"xcode_settings": {
|
|
@@ -21,39 +18,17 @@
|
|
|
21
18
|
"<!@(node -p \"require('napi-thread-safe-callback').include\")"
|
|
22
19
|
],
|
|
23
20
|
"dependencies": ["<!(node -p \"require('node-addon-api').gyp\")"],
|
|
24
|
-
"libraries": [
|
|
25
|
-
"<(target_lib)"
|
|
26
|
-
],
|
|
21
|
+
"libraries": [ "-Wl,-rpath,<!(pwd)/build", "<!(pwd)/build/libagcosmosdaemon.so" ],
|
|
27
22
|
"conditions": [
|
|
28
23
|
['OS=="mac"', {
|
|
29
24
|
'cflags+': ['-fvisibility=hidden'],
|
|
30
25
|
'xcode_settings': {
|
|
31
26
|
'GCC_SYMBOLS_PRIVATE_EXTERN': 'YES', # -fvisibility=hidden
|
|
32
|
-
}
|
|
33
|
-
'libraries+': [
|
|
34
|
-
"-Wl,-rpath,@loader_path/..",
|
|
35
|
-
],
|
|
36
|
-
'postbuilds': [
|
|
37
|
-
{
|
|
38
|
-
'postbuild_name': 'Add prefix @rpath/<(target_lib)',
|
|
39
|
-
'action': [
|
|
40
|
-
'install_name_tool',
|
|
41
|
-
'-change',
|
|
42
|
-
'<(target_lib)',
|
|
43
|
-
'@rpath/<(target_lib)',
|
|
44
|
-
'<(PRODUCT_DIR)/<(_target_name).node',
|
|
45
|
-
],
|
|
46
|
-
},
|
|
47
|
-
],
|
|
27
|
+
}
|
|
48
28
|
}],
|
|
49
29
|
['OS=="win"', {
|
|
50
|
-
'defines': [ '_HAS_EXCEPTIONS=1' ]
|
|
51
|
-
}]
|
|
52
|
-
['OS=="linux"', {
|
|
53
|
-
'libraries+': [
|
|
54
|
-
"-Wl,-rpath,'$$ORIGIN/..'",
|
|
55
|
-
],
|
|
56
|
-
}],
|
|
30
|
+
'defines': [ '_HAS_EXCEPTIONS=1' ]
|
|
31
|
+
}]
|
|
57
32
|
]
|
|
58
33
|
},
|
|
59
34
|
],
|
package/cmd/agd/find_binary.go
CHANGED
|
@@ -8,19 +8,14 @@ import (
|
|
|
8
8
|
|
|
9
9
|
// FindBinaryNextToMe looks for binName next to the current executable.
|
|
10
10
|
// It returns an absolute filename for binName, or an error.
|
|
11
|
-
func FindBinaryNextToMe(
|
|
11
|
+
func FindBinaryNextToMe(binName string) (string, error) {
|
|
12
12
|
ex, err := os.Executable()
|
|
13
13
|
if err != nil {
|
|
14
14
|
return "", err
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
// Calculate the binary's filename.
|
|
18
|
-
|
|
19
|
-
for i := 0; i <= walkUp; i++ {
|
|
20
|
-
dir = filepath.Dir(dir)
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
bin := filepath.Join(append([]string{dir}, path...)...)
|
|
18
|
+
bin := filepath.Join(filepath.Dir(ex), binName)
|
|
24
19
|
|
|
25
20
|
// Take the absolute path.
|
|
26
21
|
bin, err = filepath.Abs(bin)
|
|
@@ -29,30 +24,20 @@ func FindBinaryNextToMe(walkUp int, path... string) (string, error) {
|
|
|
29
24
|
}
|
|
30
25
|
|
|
31
26
|
// Check that the binary exists.
|
|
32
|
-
if _, err
|
|
27
|
+
if _, err := os.Stat(bin); err != nil {
|
|
33
28
|
return "", err
|
|
34
29
|
}
|
|
35
|
-
|
|
36
30
|
return bin, nil
|
|
37
31
|
}
|
|
38
32
|
|
|
39
|
-
//
|
|
33
|
+
// FindBinary looks for binName in the following locations:
|
|
40
34
|
// 1. The executable's directory
|
|
41
|
-
// 2.
|
|
42
|
-
// 3. Walking up to ../../../packages/cosmic-swingset/src/entrypoint.js
|
|
43
|
-
// 4. The system PATH
|
|
35
|
+
// 2. The system PATH
|
|
44
36
|
//
|
|
45
37
|
// It returns the absolute filename for binName if it is found, otherwise an
|
|
46
38
|
// error.
|
|
47
|
-
func
|
|
48
|
-
|
|
49
|
-
if binary, err := FindBinaryNextToMe(0, binName); err == nil {
|
|
50
|
-
return binary, nil
|
|
51
|
-
}
|
|
52
|
-
if binary, err := FindBinaryNextToMe(2, "cosmic-swingset", "src", "entrypoint.js"); err == nil {
|
|
53
|
-
return binary, nil
|
|
54
|
-
}
|
|
55
|
-
if binary, err := FindBinaryNextToMe(3, "packages", "cosmic-swingset", "src", "entrypoint.js"); err == nil {
|
|
39
|
+
func FindBinary(binName string) (string, error) {
|
|
40
|
+
if binary, err := FindBinaryNextToMe(binName); err == nil {
|
|
56
41
|
return binary, nil
|
|
57
42
|
}
|
|
58
43
|
|
package/cmd/agd/main.go
CHANGED
|
@@ -17,12 +17,13 @@ func main() {
|
|
|
17
17
|
args := []string{"ag-chain-cosmos", "--home", gaia.DefaultNodeHome}
|
|
18
18
|
args = append(args, os.Args[1:]...)
|
|
19
19
|
|
|
20
|
-
|
|
20
|
+
logger.Info("Start chain delegating to JS executable", "args", args)
|
|
21
|
+
|
|
22
|
+
binary, lookErr := FindBinary(args[0])
|
|
21
23
|
if lookErr != nil {
|
|
22
24
|
panic(lookErr)
|
|
23
25
|
}
|
|
24
26
|
|
|
25
|
-
logger.Info("Start chain delegating to JS executable", "binary", binary, "args", args)
|
|
26
27
|
execErr := syscall.Exec(binary, args, os.Environ())
|
|
27
28
|
if execErr != nil {
|
|
28
29
|
panic(execErr)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agoric/cosmos",
|
|
3
|
-
"version": "0.34.1
|
|
3
|
+
"version": "0.34.1",
|
|
4
4
|
"description": "Connect JS to the Cosmos blockchain SDK",
|
|
5
5
|
"parsers": {
|
|
6
6
|
"js": "mjs"
|
|
@@ -11,18 +11,18 @@
|
|
|
11
11
|
},
|
|
12
12
|
"scripts": {
|
|
13
13
|
"test": "exit 0",
|
|
14
|
-
"build:all": "make",
|
|
15
14
|
"build:gyp": "make compile-gyp",
|
|
16
15
|
"build:gyp-debug": "make compile-gyp GYP_DEBUG=--debug",
|
|
17
16
|
"test:xs": "exit 0",
|
|
18
|
-
"prepack": "git rev-parse --short HEAD > git-revision.txt && rm -rf build",
|
|
19
|
-
"postpack": "git clean -f git-revision.txt",
|
|
20
17
|
"build": "exit 0",
|
|
21
18
|
"lint-fix": "yarn lint:eslint --fix",
|
|
22
19
|
"lint": "eslint '**/*.{cjs,js}'"
|
|
23
20
|
},
|
|
24
21
|
"dependencies": {
|
|
25
|
-
"bindings": "^1.2.1"
|
|
22
|
+
"bindings": "^1.2.1"
|
|
23
|
+
},
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"esm": "agoric-labs/esm#Agoric-built",
|
|
26
26
|
"napi-thread-safe-callback": "0.0.6",
|
|
27
27
|
"node-addon-api": "^1.7.1"
|
|
28
28
|
},
|
|
@@ -32,8 +32,20 @@
|
|
|
32
32
|
"url": "https://github.com/Agoric/agoric-sdk/issues"
|
|
33
33
|
},
|
|
34
34
|
"homepage": "https://github.com/Agoric/agoric-sdk/tree/HEAD/golang/cosmos",
|
|
35
|
+
"files": [
|
|
36
|
+
"Makefile*",
|
|
37
|
+
"app",
|
|
38
|
+
"binding.gyp.in",
|
|
39
|
+
"cmd",
|
|
40
|
+
"daemon",
|
|
41
|
+
"proto",
|
|
42
|
+
"scripts",
|
|
43
|
+
"src",
|
|
44
|
+
"third_party",
|
|
45
|
+
"x"
|
|
46
|
+
],
|
|
35
47
|
"publishConfig": {
|
|
36
48
|
"access": "public"
|
|
37
49
|
},
|
|
38
|
-
"gitHead": "
|
|
50
|
+
"gitHead": "ba3b776444425bbcb275ce918794d9259f8e15da"
|
|
39
51
|
}
|
package/agoric/config.go
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
package ante
|
|
2
|
-
|
|
3
|
-
import (
|
|
4
|
-
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
5
|
-
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
|
6
|
-
"github.com/cosmos/cosmos-sdk/x/auth/ante"
|
|
7
|
-
ibcante "github.com/cosmos/ibc-go/v3/modules/core/ante"
|
|
8
|
-
ibckeeper "github.com/cosmos/ibc-go/v3/modules/core/keeper"
|
|
9
|
-
)
|
|
10
|
-
|
|
11
|
-
// HandlerOptions extend the SDK's AnteHandler options by requiring the IBC
|
|
12
|
-
// channel keeper.
|
|
13
|
-
type HandlerOptions struct {
|
|
14
|
-
ante.HandlerOptions
|
|
15
|
-
|
|
16
|
-
IBCKeeper *ibckeeper.Keeper
|
|
17
|
-
FeeCollectorName string
|
|
18
|
-
AdmissionData interface{}
|
|
19
|
-
SwingsetKeeper SwingsetKeeper
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
func NewAnteHandler(opts HandlerOptions) (sdk.AnteHandler, error) {
|
|
23
|
-
if opts.AccountKeeper == nil {
|
|
24
|
-
return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "account keeper is required for AnteHandler")
|
|
25
|
-
}
|
|
26
|
-
if opts.BankKeeper == nil {
|
|
27
|
-
return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "bank keeper is required for AnteHandler")
|
|
28
|
-
}
|
|
29
|
-
if opts.SignModeHandler == nil {
|
|
30
|
-
return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "sign mode handler is required for ante builder")
|
|
31
|
-
}
|
|
32
|
-
if opts.AdmissionData == nil {
|
|
33
|
-
return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "admission data is required for AnteHandler")
|
|
34
|
-
}
|
|
35
|
-
if opts.SwingsetKeeper == nil {
|
|
36
|
-
return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "swingset keeper is required for AnteHandler")
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
var sigGasConsumer = opts.SigGasConsumer
|
|
40
|
-
if sigGasConsumer == nil {
|
|
41
|
-
sigGasConsumer = ante.DefaultSigVerificationGasConsumer
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
anteDecorators := []sdk.AnteDecorator{
|
|
45
|
-
ante.NewSetUpContextDecorator(),
|
|
46
|
-
ante.NewRejectExtensionOptionsDecorator(),
|
|
47
|
-
ante.NewMempoolFeeDecorator(),
|
|
48
|
-
ante.NewValidateBasicDecorator(),
|
|
49
|
-
ante.NewTxTimeoutHeightDecorator(),
|
|
50
|
-
ante.NewValidateMemoDecorator(opts.AccountKeeper),
|
|
51
|
-
ante.NewConsumeGasForTxSizeDecorator(opts.AccountKeeper),
|
|
52
|
-
NewInboundDecorator(opts.SwingsetKeeper),
|
|
53
|
-
NewDeductFeeDecorator(opts.AccountKeeper, opts.BankKeeper, opts.FeegrantKeeper, 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.NewAnteDecorator(opts.IBCKeeper),
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
return sdk.ChainAnteDecorators(anteDecorators...), nil
|
|
65
|
-
}
|
package/ante/expected_keepers.go
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
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/fee.go
DELETED
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
package ante
|
|
2
|
-
|
|
3
|
-
import (
|
|
4
|
-
"fmt"
|
|
5
|
-
|
|
6
|
-
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
7
|
-
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
|
8
|
-
"github.com/cosmos/cosmos-sdk/x/auth/types"
|
|
9
|
-
)
|
|
10
|
-
|
|
11
|
-
// DeductFeeDecorator deducts fees from the first signer of the tx
|
|
12
|
-
// If the first signer does not have the funds to pay for the fees, return with InsufficientFunds error
|
|
13
|
-
// Call next AnteHandler if fees successfully deducted
|
|
14
|
-
// CONTRACT: Tx must implement FeeTx interface to use DeductFeeDecorator
|
|
15
|
-
type DeductFeeDecorator struct {
|
|
16
|
-
ak AccountKeeper
|
|
17
|
-
bankKeeper types.BankKeeper
|
|
18
|
-
feegrantKeeper FeegrantKeeper
|
|
19
|
-
feeCollectorName string
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
func NewDeductFeeDecorator(ak AccountKeeper, bk types.BankKeeper, fk FeegrantKeeper, feeCollectorName string) DeductFeeDecorator {
|
|
23
|
-
return DeductFeeDecorator{
|
|
24
|
-
ak: ak,
|
|
25
|
-
bankKeeper: bk,
|
|
26
|
-
feegrantKeeper: fk,
|
|
27
|
-
feeCollectorName: feeCollectorName,
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
func (dfd DeductFeeDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) {
|
|
32
|
-
feeTx, ok := tx.(sdk.FeeTx)
|
|
33
|
-
if !ok {
|
|
34
|
-
return ctx, sdkerrors.Wrap(sdkerrors.ErrTxDecode, "Tx must be a FeeTx")
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
if addr := dfd.ak.GetModuleAddress(dfd.feeCollectorName); addr == nil {
|
|
38
|
-
return ctx, fmt.Errorf("Fee collector module account (%s) has not been set", dfd.feeCollectorName)
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
fee := feeTx.GetFee()
|
|
42
|
-
feePayer := feeTx.FeePayer()
|
|
43
|
-
feeGranter := feeTx.FeeGranter()
|
|
44
|
-
|
|
45
|
-
deductFeesFrom := feePayer
|
|
46
|
-
|
|
47
|
-
// if feegranter set deduct fee from feegranter account.
|
|
48
|
-
// this works with only when feegrant enabled.
|
|
49
|
-
if feeGranter != nil {
|
|
50
|
-
if dfd.feegrantKeeper == nil {
|
|
51
|
-
return ctx, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "fee grants are not enabled")
|
|
52
|
-
} else if !feeGranter.Equals(feePayer) {
|
|
53
|
-
err := dfd.feegrantKeeper.UseGrantedFees(ctx, feeGranter, feePayer, fee, tx.GetMsgs())
|
|
54
|
-
|
|
55
|
-
if err != nil {
|
|
56
|
-
return ctx, sdkerrors.Wrapf(err, "%s not allowed to pay fees from %s", feeGranter, feePayer)
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
deductFeesFrom = feeGranter
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
deductFeesFromAcc := dfd.ak.GetAccount(ctx, deductFeesFrom)
|
|
64
|
-
if deductFeesFromAcc == nil {
|
|
65
|
-
return ctx, sdkerrors.Wrapf(sdkerrors.ErrUnknownAddress, "fee payer address: %s does not exist", deductFeesFrom)
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
// deduct the fees
|
|
69
|
-
if !feeTx.GetFee().IsZero() {
|
|
70
|
-
err = DeductFees(dfd.bankKeeper, ctx, deductFeesFromAcc, feeTx.GetFee(), dfd.feeCollectorName)
|
|
71
|
-
if err != nil {
|
|
72
|
-
return ctx, err
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
events := sdk.Events{sdk.NewEvent(sdk.EventTypeTx,
|
|
77
|
-
sdk.NewAttribute(sdk.AttributeKeyFee, feeTx.GetFee().String()),
|
|
78
|
-
)}
|
|
79
|
-
ctx.EventManager().EmitEvents(events)
|
|
80
|
-
|
|
81
|
-
return next(ctx, tx, simulate)
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
// DeductFees deducts fees from the given account.
|
|
85
|
-
func DeductFees(bankKeeper types.BankKeeper, ctx sdk.Context, acc types.AccountI, fees sdk.Coins, feeCollectorName string) error {
|
|
86
|
-
if !fees.IsValid() {
|
|
87
|
-
return sdkerrors.Wrapf(sdkerrors.ErrInsufficientFee, "invalid fee amount: %s", fees)
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
err := bankKeeper.SendCoinsFromAccountToModule(ctx, acc.GetAddress(), feeCollectorName, fees)
|
|
91
|
-
if err != nil {
|
|
92
|
-
return sdkerrors.Wrapf(sdkerrors.ErrInsufficientFunds, err.Error())
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
return nil
|
|
96
|
-
}
|
package/ante/inbound.go
DELETED
|
@@ -1,137 +0,0 @@
|
|
|
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
|
-
}
|