Skip to content

Commit

Permalink
Merge pull request #402 from multiversx/sc-executor-refactor-part2
Browse files Browse the repository at this point in the history
Implemented part2 of the SC executor refactor
  • Loading branch information
iulianpascalau authored Dec 23, 2024
2 parents e40c4c5 + 6a3bbb7 commit 688aab5
Show file tree
Hide file tree
Showing 12 changed files with 371 additions and 962 deletions.
35 changes: 21 additions & 14 deletions cmd/scCallsExecutor/config/config.toml
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
ScProxyBech32Addresses = [
"erd1qqqqqqqqqqqqqpgqnef5f5aq32d63kljld8w5vnvz4gk5sy9hrrq2ld08s",
]
ExtraGasToExecute = 60000000 # this value allow the SC calls without provided gas limit to be refunded
MaxGasLimitToUse = 249999999 # this is a safe max gas limit to use both intra-shard & cross-shard
GasLimitForOutOfGasTransactions = 30000000 # this value will be used when a transaction specified a gas limit > 249999999
NetworkAddress = "http://127.0.0.1:8085"
ProxyMaxNoncesDelta = 7
ProxyFinalityCheck = true
ProxyCacherExpirationSeconds = 600
ProxyRestAPIEntityType = "proxy"
IntervalToResendTxsInSeconds = 60
PrivateKeyFile = "keys/multiversx.pem"
PollingIntervalInMillis = 6000
[General]
ScProxyBech32Addresses = [
"erd1qqqqqqqqqqqqqpgqnef5f5aq32d63kljld8w5vnvz4gk5sy9hrrq2ld08s",
]
NetworkAddress = "http://127.0.0.1:8085"
ProxyMaxNoncesDelta = 7
ProxyFinalityCheck = true
ProxyCacherExpirationSeconds = 600
ProxyRestAPIEntityType = "proxy"
IntervalToResendTxsInSeconds = 60
PrivateKeyFile = "keys/multiversx.pem"

[ScCallsExecutor]
ExtraGasToExecute = 60000000 # this value allow the SC calls without provided gas limit to be refunded
MaxGasLimitToUse = 249999999 # this is a safe max gas limit to use both intra-shard & cross-shard
GasLimitForOutOfGasTransactions = 30000000 # this value will be used when a transaction specified a gas limit > 249999999
PollingIntervalInMillis = 6000

[RefundExecutor]
GasToExecute = 20000000
PollingIntervalInMillis = 6000

[Filter]
AllowedEthAddresses = ["*"] # execute SC calls from all ETH addresses
Expand Down
30 changes: 6 additions & 24 deletions cmd/scCallsExecutor/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,38 +94,20 @@ func startExecutor(ctx *cli.Context, version string) error {
}

if ctx.IsSet(networkAddress.Name) {
cfg.NetworkAddress = ctx.GlobalString(networkAddress.Name)
log.Info("using flag-defined network address", "address", cfg.NetworkAddress)
cfg.General.NetworkAddress = ctx.GlobalString(networkAddress.Name)
log.Info("using flag-defined network address", "address", cfg.General.NetworkAddress)
}
if ctx.IsSet(privateKeyFile.Name) {
cfg.PrivateKeyFile = ctx.GlobalString(privateKeyFile.Name)
log.Info("using flag-defined private key file", "filename", cfg.PrivateKeyFile)
cfg.General.PrivateKeyFile = ctx.GlobalString(privateKeyFile.Name)
log.Info("using flag-defined private key file", "filename", cfg.General.PrivateKeyFile)
}

if len(cfg.NetworkAddress) == 0 {
if len(cfg.General.NetworkAddress) == 0 {
return fmt.Errorf("empty NetworkAddress in config file")
}

args := config.ScCallsModuleConfig{
ScProxyBech32Addresses: cfg.ScProxyBech32Addresses,
ExtraGasToExecute: cfg.ExtraGasToExecute,
MaxGasLimitToUse: cfg.MaxGasLimitToUse,
GasLimitForOutOfGasTransactions: cfg.GasLimitForOutOfGasTransactions,
NetworkAddress: cfg.NetworkAddress,
ProxyMaxNoncesDelta: cfg.ProxyMaxNoncesDelta,
ProxyFinalityCheck: cfg.ProxyFinalityCheck,
ProxyCacherExpirationSeconds: cfg.ProxyCacherExpirationSeconds,
ProxyRestAPIEntityType: cfg.ProxyRestAPIEntityType,
IntervalToResendTxsInSeconds: cfg.IntervalToResendTxsInSeconds,
PrivateKeyFile: cfg.PrivateKeyFile,
PollingIntervalInMillis: cfg.PollingIntervalInMillis,
Filter: cfg.Filter,
Logs: cfg.Logs,
TransactionChecks: cfg.TransactionChecks,
}

chCloseApp := make(chan struct{}, 1)
scCallsExecutor, err := module.NewScCallsModule(args, log, chCloseApp)
scCallsExecutor, err := module.NewScCallsModule(cfg, log, chCloseApp)
if err != nil {
return err
}
Expand Down
39 changes: 28 additions & 11 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,21 +192,38 @@ type PendingOperationsFilterConfig struct {

// ScCallsModuleConfig will hold the settings for the SC calls module
type ScCallsModuleConfig struct {
ScProxyBech32Addresses []string
General GeneralScCallsModuleConfig
ScCallsExecutor ScCallsExecutorConfig
RefundExecutor RefundExecutorConfig
Filter PendingOperationsFilterConfig
Logs LogsConfig
TransactionChecks TransactionChecksConfig
}

// GeneralScCallsModuleConfig will hold the general settings for the SC calls module
type GeneralScCallsModuleConfig struct {
ScProxyBech32Addresses []string
NetworkAddress string
ProxyMaxNoncesDelta int
ProxyFinalityCheck bool
ProxyCacherExpirationSeconds uint64
ProxyRestAPIEntityType string
IntervalToResendTxsInSeconds uint64
PrivateKeyFile string
}

// ScCallsExecutorConfig will hold the settings for the SC calls executor
type ScCallsExecutorConfig struct {
ExtraGasToExecute uint64
MaxGasLimitToUse uint64
GasLimitForOutOfGasTransactions uint64
NetworkAddress string
ProxyMaxNoncesDelta int
ProxyFinalityCheck bool
ProxyCacherExpirationSeconds uint64
ProxyRestAPIEntityType string
IntervalToResendTxsInSeconds uint64
PrivateKeyFile string
PollingIntervalInMillis uint64
Filter PendingOperationsFilterConfig
Logs LogsConfig
TransactionChecks TransactionChecksConfig
}

// RefundExecutorConfig will hold the settings for the refund executor
type RefundExecutorConfig struct {
GasToExecute uint64
PollingIntervalInMillis uint64
}

// TransactionChecksConfig will hold the setting for how to handle the transaction execution
Expand Down
73 changes: 44 additions & 29 deletions config/tomlConfigs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -405,21 +405,29 @@ func TestScCallsExecutorConfigs(t *testing.T) {
t.Parallel()

expectedConfig := ScCallsModuleConfig{
ScProxyBech32Addresses: []string{
"erd1qqqqqqqqqqqqqpgqnef5f5aq32d63kljld8w5vnvz4gk5sy9hrrq2ld08s",
"erd1qqqqqqqqqqqqqpgqzyuaqg3dl7rqlkudrsnm5ek0j3a97qevd8sszj0glf",
General: GeneralScCallsModuleConfig{
ScProxyBech32Addresses: []string{
"erd1qqqqqqqqqqqqqpgqnef5f5aq32d63kljld8w5vnvz4gk5sy9hrrq2ld08s",
"erd1qqqqqqqqqqqqqpgqzyuaqg3dl7rqlkudrsnm5ek0j3a97qevd8sszj0glf",
},
NetworkAddress: "127.0.0.1:8085",
ProxyMaxNoncesDelta: 7,
ProxyFinalityCheck: true,
ProxyCacherExpirationSeconds: 600,
ProxyRestAPIEntityType: "observer",
IntervalToResendTxsInSeconds: 60,
PrivateKeyFile: "keys/multiversx.pem",
},
ScCallsExecutor: ScCallsExecutorConfig{
ExtraGasToExecute: 50000000,
MaxGasLimitToUse: 249999999,
GasLimitForOutOfGasTransactions: 30000000,
PollingIntervalInMillis: 6000,
},
RefundExecutor: RefundExecutorConfig{
GasToExecute: 20000000,
PollingIntervalInMillis: 6000,
},
ExtraGasToExecute: 50000000,
MaxGasLimitToUse: 249999999,
GasLimitForOutOfGasTransactions: 30000000,
NetworkAddress: "127.0.0.1:8085",
ProxyMaxNoncesDelta: 7,
ProxyFinalityCheck: true,
ProxyCacherExpirationSeconds: 600,
ProxyRestAPIEntityType: "observer",
IntervalToResendTxsInSeconds: 60,
PrivateKeyFile: "keys/multiversx.pem",
PollingIntervalInMillis: 6000,
Filter: PendingOperationsFilterConfig{
AllowedEthAddresses: []string{"*"},
AllowedMvxAddresses: []string{"*"},
Expand All @@ -439,21 +447,28 @@ func TestScCallsExecutorConfigs(t *testing.T) {
}

testString := `
ScProxyBech32Addresses = [
"erd1qqqqqqqqqqqqqpgqnef5f5aq32d63kljld8w5vnvz4gk5sy9hrrq2ld08s",
"erd1qqqqqqqqqqqqqpgqzyuaqg3dl7rqlkudrsnm5ek0j3a97qevd8sszj0glf",
]
ExtraGasToExecute = 50000000
MaxGasLimitToUse = 249999999 # this is a safe max gas limit to use both intra-shard & cross-shard
GasLimitForOutOfGasTransactions = 30000000 # this value will be used when a transaction specified a gas limit > 249999999
NetworkAddress = "127.0.0.1:8085"
ProxyMaxNoncesDelta = 7
ProxyFinalityCheck = true
ProxyCacherExpirationSeconds = 600
ProxyRestAPIEntityType = "observer"
IntervalToResendTxsInSeconds = 60
PrivateKeyFile = "keys/multiversx.pem"
PollingIntervalInMillis = 6000
[General]
ScProxyBech32Addresses = [
"erd1qqqqqqqqqqqqqpgqnef5f5aq32d63kljld8w5vnvz4gk5sy9hrrq2ld08s",
"erd1qqqqqqqqqqqqqpgqzyuaqg3dl7rqlkudrsnm5ek0j3a97qevd8sszj0glf",
]
NetworkAddress = "127.0.0.1:8085"
ProxyMaxNoncesDelta = 7
ProxyFinalityCheck = true
ProxyCacherExpirationSeconds = 600
ProxyRestAPIEntityType = "observer"
IntervalToResendTxsInSeconds = 60
PrivateKeyFile = "keys/multiversx.pem"
[ScCallsExecutor]
ExtraGasToExecute = 50000000
MaxGasLimitToUse = 249999999 # this is a safe max gas limit to use both intra-shard & cross-shard
GasLimitForOutOfGasTransactions = 30000000 # this value will be used when a transaction specified a gas limit > 249999999
PollingIntervalInMillis = 6000
[RefundExecutor]
GasToExecute = 20000000
PollingIntervalInMillis = 6000
[Filter]
AllowedEthAddresses = ["*"] # execute SC calls from all ETH addresses
Expand Down
1 change: 1 addition & 0 deletions executors/multiversx/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ var (
errTransactionFailed = errors.New("transaction failed")
errGasLimitIsLessThanAbsoluteMinimum = errors.New("provided gas limit is less than absolute minimum required")
errEmptyListOfBridgeSCProxy = errors.New("the bridge SC proxy addresses list is empty")
errNilTransactionExecutor = errors.New("nil transaction executor")
)
14 changes: 14 additions & 0 deletions executors/multiversx/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,17 @@ type Codec interface {
ExtractGasLimitFromRawCallData(buff []byte) (uint64, error)
IsInterfaceNil() bool
}

// TransactionExecutor defines the operations of an entity able to send executable transactions
type TransactionExecutor interface {
ExecuteTransaction(
ctx context.Context,
networkConfig *data.NetworkConfig,
receiver string,
transactionType string,
gasLimit uint64,
dataBytes []byte,
) error
GetNumSentTransaction() uint32
IsInterfaceNil() bool
}
54 changes: 32 additions & 22 deletions executors/multiversx/module/scCallsModule.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ func NewScCallsModule(cfg config.ScCallsModuleConfig, log logger.Logger, chClose
}

argsProxy := blockchain.ArgsProxy{
ProxyURL: cfg.NetworkAddress,
ProxyURL: cfg.General.NetworkAddress,
SameScState: false,
ShouldBeSynced: false,
FinalityCheck: cfg.ProxyFinalityCheck,
AllowedDeltaToFinal: cfg.ProxyMaxNoncesDelta,
CacheExpirationTime: time.Second * time.Duration(cfg.ProxyCacherExpirationSeconds),
EntityType: sdkCore.RestAPIEntityType(cfg.ProxyRestAPIEntityType),
FinalityCheck: cfg.General.ProxyFinalityCheck,
AllowedDeltaToFinal: cfg.General.ProxyMaxNoncesDelta,
CacheExpirationTime: time.Second * time.Duration(cfg.General.ProxyCacherExpirationSeconds),
EntityType: sdkCore.RestAPIEntityType(cfg.General.ProxyRestAPIEntityType),
}

proxy, err := blockchain.NewProxy(argsProxy)
Expand All @@ -54,15 +54,15 @@ func NewScCallsModule(cfg config.ScCallsModuleConfig, log logger.Logger, chClose

argNonceHandler := nonceHandlerV2.ArgsNonceTransactionsHandlerV2{
Proxy: proxy,
IntervalToResend: time.Second * time.Duration(cfg.IntervalToResendTxsInSeconds),
IntervalToResend: time.Second * time.Duration(cfg.General.IntervalToResendTxsInSeconds),
}
module.nonceTxsHandler, err = nonceHandlerV2.NewNonceTransactionHandlerV2(argNonceHandler)
if err != nil {
return nil, err
}

wallet := interactors.NewWallet()
multiversXPrivateKeyBytes, err := wallet.LoadPrivateKeyFromPemFile(cfg.PrivateKeyFile)
multiversXPrivateKeyBytes, err := wallet.LoadPrivateKeyFromPemFile(cfg.General.PrivateKeyFile)
if err != nil {
return nil, err
}
Expand All @@ -72,20 +72,30 @@ func NewScCallsModule(cfg config.ScCallsModuleConfig, log logger.Logger, chClose
return nil, err
}

argsTxExecutor := multiversx.ArgsTransactionExecutor{
Proxy: proxy,
Log: log,
NonceTxHandler: module.nonceTxsHandler,
PrivateKey: privateKey,
SingleSigner: singleSigner,
TransactionChecks: cfg.TransactionChecks,
CloseAppChan: chCloseApp,
}

transactionExecutor, err := multiversx.NewTransactionExecutor(argsTxExecutor)
if err != nil {
return nil, err
}

argsExecutor := multiversx.ArgsScCallExecutor{
ScProxyBech32Addresses: cfg.ScProxyBech32Addresses,
Proxy: proxy,
Codec: &parsers.MultiversxCodec{},
Filter: filter,
Log: log,
ExtraGasToExecute: cfg.ExtraGasToExecute,
MaxGasLimitToUse: cfg.MaxGasLimitToUse,
GasLimitForOutOfGasTransactions: cfg.GasLimitForOutOfGasTransactions,
NonceTxHandler: module.nonceTxsHandler,
PrivateKey: privateKey,
SingleSigner: singleSigner,
CloseAppChan: chCloseApp,
TransactionChecks: cfg.TransactionChecks,
ScProxyBech32Addresses: cfg.General.ScProxyBech32Addresses,
TransactionExecutor: transactionExecutor,
Proxy: proxy,
Codec: &parsers.MultiversxCodec{},
Filter: filter,
Log: log,
ExecutorConfig: cfg.ScCallsExecutor,
TransactionChecks: cfg.TransactionChecks,
}
module.executorInstance, err = multiversx.NewScCallExecutor(argsExecutor)
if err != nil {
Expand All @@ -95,8 +105,8 @@ func NewScCallsModule(cfg config.ScCallsModuleConfig, log logger.Logger, chClose
argsPollingHandler := polling.ArgsPollingHandler{
Log: log,
Name: "MultiversX SC calls",
PollingInterval: time.Duration(cfg.PollingIntervalInMillis) * time.Millisecond,
PollingWhenError: time.Duration(cfg.PollingIntervalInMillis) * time.Millisecond,
PollingInterval: time.Duration(cfg.ScCallsExecutor.PollingIntervalInMillis) * time.Millisecond,
PollingWhenError: time.Duration(cfg.ScCallsExecutor.PollingIntervalInMillis) * time.Millisecond,
Executor: module.executorInstance,
}

Expand Down
Loading

0 comments on commit 688aab5

Please sign in to comment.