Skip to content

Commit

Permalink
Make MaxGasInvoke configurable (#3208)
Browse files Browse the repository at this point in the history
Closes #3207.
  • Loading branch information
roman-khimov authored Mar 6, 2025
2 parents db3b58e + d277f8e commit e593f30
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Changelog for NeoFS Node

### Added
- IR `fschain.consensus.p2p_notary_request_payload_pool_size` config option (#3195)
- IR `fschain.consensus.rpc.max_gas_invoke` config option (#3208)

### Fixed
- Zero range denial by `neofs-cli object range|hash` commands (#3182)
Expand Down
2 changes: 2 additions & 0 deletions cmd/neofs-ir/internal/validate/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ type validConfig struct {
Listen []string `mapstructure:"listen"`
MaxWebSocketClients uint32 `mapstructure:"max_websocket_clients"`
SessionPoolSize uint32 `mapstructure:"session_pool_size"`
MaxGasInvoke uint32 `mapstructure:"max_gas_invoke"`
TLS struct {
Enabled bool `mapstructure:"enabled"`
Listen []string `mapstructure:"listen"`
Expand Down Expand Up @@ -108,6 +109,7 @@ type validConfig struct {
Listen []string `mapstructure:"listen"`
MaxWebSocketClients uint32 `mapstructure:"max_websocket_clients"`
SessionPoolSize uint32 `mapstructure:"session_pool_size"`
MaxGasInvoke uint32 `mapstructure:"max_gas_invoke"`
TLS struct {
Enabled bool `mapstructure:"enabled"`
Listen []string `mapstructure:"listen"`
Expand Down
2 changes: 2 additions & 0 deletions config/example/ir.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ fschain:
# Must be unsigned integer in range [1:2147483647].
session_pool_size: 100 # Optional maximum number of concurrent iterator sessions. Defaults to 20.
# Must be unsigned integer in range [1:2147483647].
max_gas_invoke: 200 # Optional maximum amount of GAS which can be spent during an RPC call,
# should be taken in GAS units. Defaults to 100. Must be unsigned integer in range [1:2147483647].
tls: # Additional addresses to listen to using TLS setup; must not overlap with `listen` section
enabled: false # Additional TLS serving switcher
listen: # Addresses to listen to; required to be at least 1-length if 'enabled' is 'true'
Expand Down
6 changes: 6 additions & 0 deletions pkg/innerring/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,12 @@ func parseBlockchainConfig(v *viper.Viper, _logger *zap.Logger) (c blockchain.Co
}
c.RPC.SessionPoolSize = uint(sessionPoolSize)

maxGasInvoke, err := parseConfigUint64Range(v, rpcSection+".max_gas_invoke", "maximum amount of GAS which can be spent during an RPC call", 1, math.MaxInt32)
if err != nil && !errors.Is(err, errMissingConfig) {
return c, err
}
c.RPC.MaxGasInvoke = uint(maxGasInvoke)

var rpcTLSSection = rpcSection + ".tls"
if v.GetBool(rpcTLSSection + ".enabled") {
c.RPC.TLSConfig.Enabled = true
Expand Down
4 changes: 4 additions & 0 deletions pkg/innerring/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ const validBlockchainConfigOptions = `
rpc:
max_websocket_clients: 100
session_pool_size: 100
max_gas_invoke: 200
listen:
- localhost:30000
- localhost:30001
Expand Down Expand Up @@ -179,6 +180,7 @@ func TestParseBlockchainConfig(t *testing.T) {
RPC: blockchain.RPCConfig{
MaxWebSocketClients: 100,
SessionPoolSize: 100,
MaxGasInvoke: 200,
Addresses: []string{
"localhost:30000",
"localhost:30001",
Expand Down Expand Up @@ -295,6 +297,8 @@ func TestParseBlockchainConfig(t *testing.T) {
{kvF("rpc.max_websocket_clients", math.MaxInt32+1)},
{kvF("rpc.session_pool_size", -1)},
{kvF("rpc.session_pool_size", math.MaxInt32+1)},
{kvF("rpc.max_gas_invoke", -1)},
{kvF("rpc.max_gas_invoke", math.MaxInt32+1)},
{kvF("rpc.tls.enabled", true), kvF("rpc.tls.cert_file", "")}, // enabled but no cert file is provided
{kvF("rpc.tls.enabled", true), kvF("rpc.tls.cert_file", " \t")}, // enabled but no but blank cert is provided
{kvF("rpc.tls.enabled", true), kvF("rpc.tls.cert_file", "/path/"), kvF("rpc.tls.key_file", "")}, // enabled but no key is provided
Expand Down
10 changes: 9 additions & 1 deletion pkg/innerring/internal/blockchain/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ type RPCConfig struct {
//
// Optional: defaults to 20. Must not be larger than math.MaxInt32.
SessionPoolSize uint

// The maximum amount of GAS which can be spent during an RPC call.
//
// Optional: defaults to 100. Must not be larger than math.MaxInt32.
MaxGasInvoke uint
}

// TLSConfig configures additional RPC serving over TLS.
Expand Down Expand Up @@ -375,6 +380,9 @@ func New(cfg Config) (res *Blockchain, err error) {
if cfg.P2PNotaryRequestPayloadPoolSize == 0 {
cfg.P2PNotaryRequestPayloadPoolSize = 1000
}
if cfg.RPC.MaxGasInvoke == 0 {
cfg.RPC.MaxGasInvoke = 100
}

standByCommittee := make([]string, len(cfg.Committee))
for i := range cfg.Committee {
Expand Down Expand Up @@ -420,7 +428,7 @@ func New(cfg Config) (res *Blockchain, err error) {
cfgBaseApp.P2PNotary.Enabled = true
cfgBaseApp.P2PNotary.UnlockWallet = cfg.Wallet
cfgBaseApp.RPC.StartWhenSynchronized = true
cfgBaseApp.RPC.MaxGasInvoke = fixedn.Fixed8FromInt64(100)
cfgBaseApp.RPC.MaxGasInvoke = fixedn.Fixed8FromInt64(int64(cfg.RPC.MaxGasInvoke))
cfgBaseApp.RPC.SessionEnabled = true
cfgBaseApp.P2P.Addresses = cfg.P2P.ListenAddresses
cfgBaseApp.P2P.DialTimeout = cfg.P2P.DialTimeout
Expand Down

0 comments on commit e593f30

Please sign in to comment.