Skip to content

Commit

Permalink
Merge pull request #345 from multiversx/mvx-executor-improvement
Browse files Browse the repository at this point in the history
Mvx executor improvements
  • Loading branch information
iulianpascalau authored Oct 2, 2024
2 parents ca973ab + be16359 commit 0a8e83d
Show file tree
Hide file tree
Showing 10 changed files with 561 additions and 52 deletions.
12 changes: 10 additions & 2 deletions cmd/scCallsExecutor/config/config.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
ScProxyBech32Address = "erd1qqqqqqqqqqqqqpgqnef5f5aq32d63kljld8w5vnvz4gk5sy9hrrq2ld08s"
ExtraGasToExecute = 60000000 #this value allow the SC calls without provided gas limit to be refunded
NetworkAddress = "127.0.0.1:8085"
NetworkAddress = "http://127.0.0.1:8085"
ProxyMaxNoncesDelta = 7
ProxyFinalityCheck = true
ProxyCacherExpirationSeconds = 600
Expand All @@ -9,11 +9,19 @@ IntervalToResendTxsInSeconds = 60
PrivateKeyFile = "keys/multiversx.pem"
PollingIntervalInMillis = 6000

[FilterConfig]
[Filter]
AllowedEthAddresses = ["*"] # execute SC calls from all ETH addresses
AllowedMvxAddresses = ["*"] # execute SC calls to all MvX contracts
AllowedTokens = ["*"] # execute SC calls for all tokens

[Logs]
LogFileLifeSpanInSec = 86400 # 24h
LogFileLifeSpanInMB = 1024 # 1GB

[TransactionChecks]
CheckTransactionResults = true # enable or disable the transaction execution checking
TimeInSecondsBetweenChecks = 6 # the number of seconds to recheck the status of the transaction
ExecutionTimeoutInSeconds = 120 # the number of seconds reserved for each execution to complete
CloseAppOnError = false # enable or disable if the executor should automatically close on a transaction execution error
ExtraDelayInSecondsOnError = 300 # extra delay in seconds if the transaction execution errored

15 changes: 10 additions & 5 deletions cmd/scCallsExecutor/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,21 +121,26 @@ func startRelay(ctx *cli.Context, version string) error {
IntervalToResendTxsInSeconds: cfg.IntervalToResendTxsInSeconds,
PrivateKeyFile: cfg.PrivateKeyFile,
PollingIntervalInMillis: cfg.PollingIntervalInMillis,
FilterConfig: cfg.FilterConfig,
Filter: cfg.Filter,
Logs: cfg.Logs,
TransactionChecks: cfg.TransactionChecks,
}

scCallsExecutor, err := module.NewScCallsModule(args, log)
chCloseApp := make(chan struct{}, 1)
scCallsExecutor, err := module.NewScCallsModule(args, log, chCloseApp)
if err != nil {
return err
}

sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)

<-sigs

log.Info("application closing, calling Close on all subcomponents...")
select {
case <-sigs:
log.Info("application closing by user error input, calling Close on all subcomponents...")
case <-chCloseApp:
log.Info("application closing, requested internally, calling Close on all subcomponents...")
}

return scCallsExecutor.Close()
}
Expand Down
12 changes: 11 additions & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,18 @@ type ScCallsModuleConfig struct {
IntervalToResendTxsInSeconds uint64
PrivateKeyFile string
PollingIntervalInMillis uint64
FilterConfig PendingOperationsFilterConfig
Filter PendingOperationsFilterConfig
Logs LogsConfig
TransactionChecks TransactionChecksConfig
}

// TransactionChecksConfig will hold the setting for how to handle the transaction execution
type TransactionChecksConfig struct {
CheckTransactionResults bool
TimeInSecondsBetweenChecks uint64
ExecutionTimeoutInSeconds uint64
CloseAppOnError bool
ExtraDelayInSecondsOnError uint64
}

// MigrationToolConfig is the migration tool config struct
Expand Down
18 changes: 16 additions & 2 deletions config/tomlConfigs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ func TestScCallsExecutorConfigs(t *testing.T) {
IntervalToResendTxsInSeconds: 60,
PrivateKeyFile: "keys/multiversx.pem",
PollingIntervalInMillis: 6000,
FilterConfig: PendingOperationsFilterConfig{
Filter: PendingOperationsFilterConfig{
AllowedEthAddresses: []string{"*"},
AllowedMvxAddresses: []string{"*"},
AllowedTokens: []string{"MEME-a43fa1"},
Expand All @@ -424,6 +424,13 @@ func TestScCallsExecutorConfigs(t *testing.T) {
LogFileLifeSpanInSec: 86400,
LogFileLifeSpanInMB: 1024,
},
TransactionChecks: TransactionChecksConfig{
CheckTransactionResults: true,
TimeInSecondsBetweenChecks: 6,
ExecutionTimeoutInSeconds: 120,
CloseAppOnError: false,
ExtraDelayInSecondsOnError: 120,
},
}

testString := `
Expand All @@ -438,14 +445,21 @@ IntervalToResendTxsInSeconds = 60
PrivateKeyFile = "keys/multiversx.pem"
PollingIntervalInMillis = 6000
[FilterConfig]
[Filter]
AllowedEthAddresses = ["*"] # execute SC calls from all ETH addresses
AllowedMvxAddresses = ["*"] # execute SC calls to all MvX contracts
AllowedTokens = ["MEME-a43fa1"] # execute SC calls for this token only
[Logs]
LogFileLifeSpanInSec = 86400 # 24h
LogFileLifeSpanInMB = 1024 # 1GB
[TransactionChecks]
CheckTransactionResults = true # enable or disable the transaction execution checking
TimeInSecondsBetweenChecks = 6 # the number of seconds to recheck the status of the transaction
ExecutionTimeoutInSeconds = 120 # the number of seconds after the transaction is considered failed if it was not seen by the blockchain
CloseAppOnError = false # enable or disable if the executor should automatically close on a transaction execution error
ExtraDelayInSecondsOnError = 120 # extra delay in seconds if the transaction execution errored
`

cfg := ScCallsModuleConfig{}
Expand Down
3 changes: 3 additions & 0 deletions executors/multiversx/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,7 @@ var (
errNilNonceTxHandler = errors.New("nil nonce transaction handler")
errNilPrivateKey = errors.New("nil private key")
errNilSingleSigner = errors.New("nil single signer")
errInvalidValue = errors.New("invalid value")
errNilCloseAppChannel = errors.New("nil close application channel")
errTransactionFailed = errors.New("transaction failed")
)
6 changes: 4 additions & 2 deletions executors/multiversx/module/scCallsModule.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ type scCallsModule struct {
}

// NewScCallsModule creates a starts a new scCallsModule instance
func NewScCallsModule(cfg config.ScCallsModuleConfig, log logger.Logger) (*scCallsModule, error) {
filter, err := filters.NewPendingOperationFilter(cfg.FilterConfig, log)
func NewScCallsModule(cfg config.ScCallsModuleConfig, log logger.Logger, chCloseApp chan struct{}) (*scCallsModule, error) {
filter, err := filters.NewPendingOperationFilter(cfg.Filter, log)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -82,6 +82,8 @@ func NewScCallsModule(cfg config.ScCallsModuleConfig, log logger.Logger) (*scCal
NonceTxHandler: module.nonceTxsHandler,
PrivateKey: privateKey,
SingleSigner: singleSigner,
CloseAppChan: chCloseApp,
TransactionChecks: cfg.TransactionChecks,
}
module.executorInstance, err = multiversx.NewScCallExecutor(argsExecutor)
if err != nil {
Expand Down
33 changes: 24 additions & 9 deletions executors/multiversx/module/scCallsModule_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func createTestConfigs() config.ScCallsModuleConfig {
IntervalToResendTxsInSeconds: 1,
PrivateKeyFile: "testdata/grace.pem",
PollingIntervalInMillis: 10000,
FilterConfig: config.PendingOperationsFilterConfig{
Filter: config.PendingOperationsFilterConfig{
DeniedEthAddresses: nil,
AllowedEthAddresses: []string{"*"},
DeniedMvxAddresses: nil,
Expand All @@ -39,9 +39,9 @@ func TestNewScCallsModule(t *testing.T) {
t.Parallel()

cfg := createTestConfigs()
cfg.FilterConfig.DeniedTokens = []string{"*"}
cfg.Filter.DeniedTokens = []string{"*"}

module, err := NewScCallsModule(cfg, &testsCommon.LoggerStub{})
module, err := NewScCallsModule(cfg, &testsCommon.LoggerStub{}, nil)
assert.NotNil(t, err)
assert.Contains(t, err.Error(), "unsupported marker * on item at index 0 in list DeniedTokens")
assert.Nil(t, module)
Expand All @@ -52,7 +52,7 @@ func TestNewScCallsModule(t *testing.T) {
cfg := createTestConfigs()
cfg.ProxyCacherExpirationSeconds = 0

module, err := NewScCallsModule(cfg, &testsCommon.LoggerStub{})
module, err := NewScCallsModule(cfg, &testsCommon.LoggerStub{}, nil)
assert.NotNil(t, err)
assert.Contains(t, err.Error(), "invalid caching duration, provided: 0s, minimum: 1s")
assert.Nil(t, module)
Expand All @@ -63,7 +63,7 @@ func TestNewScCallsModule(t *testing.T) {
cfg := createTestConfigs()
cfg.IntervalToResendTxsInSeconds = 0

module, err := NewScCallsModule(cfg, &testsCommon.LoggerStub{})
module, err := NewScCallsModule(cfg, &testsCommon.LoggerStub{}, nil)
assert.NotNil(t, err)
assert.Contains(t, err.Error(), "invalid value for intervalToResend in NewNonceTransactionHandlerV2")
assert.Nil(t, module)
Expand All @@ -74,7 +74,7 @@ func TestNewScCallsModule(t *testing.T) {
cfg := createTestConfigs()
cfg.PrivateKeyFile = ""

module, err := NewScCallsModule(cfg, &testsCommon.LoggerStub{})
module, err := NewScCallsModule(cfg, &testsCommon.LoggerStub{}, nil)
assert.NotNil(t, err)
assert.Nil(t, module)
})
Expand All @@ -84,16 +84,31 @@ func TestNewScCallsModule(t *testing.T) {
cfg := createTestConfigs()
cfg.PollingIntervalInMillis = 0

module, err := NewScCallsModule(cfg, &testsCommon.LoggerStub{})
module, err := NewScCallsModule(cfg, &testsCommon.LoggerStub{}, nil)
assert.NotNil(t, err)
assert.Contains(t, err.Error(), "invalid value for PollingInterval")
assert.Nil(t, module)
})
t.Run("should work", func(t *testing.T) {
t.Run("should work with nil close app chan", func(t *testing.T) {
t.Parallel()

cfg := createTestConfigs()
module, err := NewScCallsModule(cfg, &testsCommon.LoggerStub{})
module, err := NewScCallsModule(cfg, &testsCommon.LoggerStub{}, nil)
assert.Nil(t, err)
assert.NotNil(t, module)

err = module.Close()
assert.Nil(t, err)
})
t.Run("should work with nil close app chan", func(t *testing.T) {
t.Parallel()

cfg := createTestConfigs()
cfg.TransactionChecks.CheckTransactionResults = true
cfg.TransactionChecks.TimeInSecondsBetweenChecks = 1
cfg.TransactionChecks.ExecutionTimeoutInSeconds = 1
cfg.TransactionChecks.CloseAppOnError = true
module, err := NewScCallsModule(cfg, &testsCommon.LoggerStub{}, make(chan struct{}, 1))
assert.Nil(t, err)
assert.NotNil(t, module)

Expand Down
Loading

0 comments on commit 0a8e83d

Please sign in to comment.