Skip to content

Commit

Permalink
- finished implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
iulianpascalau committed Sep 30, 2024
1 parent 3fc9ccb commit 8b9dc86
Show file tree
Hide file tree
Showing 7 changed files with 250 additions and 25 deletions.
4 changes: 2 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 @@ -23,5 +23,5 @@ PollingIntervalInMillis = 6000
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 = 120 # extra delay in seconds if the transaction execution errored
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
4 changes: 3 additions & 1 deletion executors/multiversx/module/scCallsModule.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type scCallsModule struct {
}

// NewScCallsModule creates a starts a new scCallsModule instance
func NewScCallsModule(cfg config.ScCallsModuleConfig, log logger.Logger) (*scCallsModule, error) {
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
29 changes: 22 additions & 7 deletions executors/multiversx/module/scCallsModule_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func TestNewScCallsModule(t *testing.T) {
cfg := createTestConfigs()
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
13 changes: 6 additions & 7 deletions executors/multiversx/scCallsExecutor.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"sync/atomic"
"time"

"github.com/ethereum/go-ethereum/log"
"github.com/multiversx/mx-bridge-eth-go/config"
"github.com/multiversx/mx-bridge-eth-go/errors"
"github.com/multiversx/mx-bridge-eth-go/parsers"
Expand Down Expand Up @@ -232,7 +231,7 @@ func (executor *scCallExecutor) executeOperations(ctx context.Context, pendingOp
for id, callData := range pendingOperations {
workingCtx, cancel := context.WithTimeout(ctx, executor.executionTimeout)

log.Debug("scCallExecutor.executeOperations", "executing ID", id, "call data", callData,
executor.log.Debug("scCallExecutor.executeOperations", "executing ID", id, "call data", callData,
"maximum timeout", executor.executionTimeout)
err = executor.executeOperation(workingCtx, id, callData, networkConfig)
cancel()
Expand Down Expand Up @@ -266,7 +265,7 @@ func (executor *scCallExecutor) executeOperation(

gasLimit, err := executor.codec.ExtractGasLimitFromRawCallData(callData.RawCallData)
if err != nil {
log.Warn("scCallExecutor.executeOperation found a non-parsable raw call data",
executor.log.Warn("scCallExecutor.executeOperation found a non-parsable raw call data",
"raw call data", callData.RawCallData, "error", err)
gasLimit = 0
}
Expand Down Expand Up @@ -378,7 +377,7 @@ func (executor *scCallExecutor) checkResults(ctx context.Context, hash string) (
}

func (executor *scCallExecutor) handleError(ctx context.Context, err error) {
if err != nil {
if err == nil {
return
}
if !executor.closeAppOnError {
Expand All @@ -398,17 +397,17 @@ func (executor *scCallExecutor) handleError(ctx context.Context, err error) {
func (executor *scCallExecutor) logFullTransaction(ctx context.Context, hash string) {
txData, err := executor.proxy.GetTransactionInfoWithResults(ctx, hash)
if err != nil {
log.Error("error getting the transaction for display", "error", err)
executor.log.Error("error getting the transaction for display", "error", err)
return
}

txDataString, err := json.MarshalIndent(txData.Data.Transaction, "", " ")
if err != nil {
log.Error("error preparing transaction for display", "error", err)
executor.log.Error("error preparing transaction for display", "error", err)
return
}

log.Error("transaction failed", "hash", hash, "full transaction details", string(txDataString))
executor.log.Error("transaction failed", "hash", hash, "full transaction details", string(txDataString))
}

func (executor *scCallExecutor) waitForExtraDelay(ctx context.Context, err error) {
Expand Down
Loading

0 comments on commit 8b9dc86

Please sign in to comment.