Skip to content

Commit

Permalink
Merge pull request #5728 from multiversx/remove-built-in-functions-co…
Browse files Browse the repository at this point in the history
…st-handler

Remove built in function cost handler
  • Loading branch information
miiu96 authored Feb 29, 2024
2 parents 6953030 + a7c032a commit cb193df
Show file tree
Hide file tree
Showing 25 changed files with 75 additions and 589 deletions.
7 changes: 3 additions & 4 deletions epochStart/metachain/systemSCs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1131,10 +1131,9 @@ func createEconomicsData() process.EconomicsDataHandler {
MaxGasPriceSetGuardian: "100000",
},
},
EpochNotifier: &epochNotifier.EpochNotifierStub{},
EnableEpochsHandler: &enableEpochsHandlerMock.EnableEpochsHandlerStub{},
BuiltInFunctionsCostHandler: &mock.BuiltInCostHandlerStub{},
TxVersionChecker: &testscommon.TxVersionCheckerStub{},
EpochNotifier: &epochNotifier.EpochNotifierStub{},
EnableEpochsHandler: &enableEpochsHandlerMock.EnableEpochsHandlerStub{},
TxVersionChecker: &testscommon.TxVersionCheckerStub{},
}
economicsData, _ := economicsHandler.NewEconomicsData(argsNewEconomicsData)
return economicsData
Expand Down
24 changes: 0 additions & 24 deletions epochStart/mock/builtInCostHandlerStub.go

This file was deleted.

29 changes: 4 additions & 25 deletions factory/core/coreComponents.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import (
"github.com/multiversx/mx-chain-go/process"
"github.com/multiversx/mx-chain-go/process/economics"
"github.com/multiversx/mx-chain-go/process/rating"
"github.com/multiversx/mx-chain-go/process/smartContract"
"github.com/multiversx/mx-chain-go/sharding"
"github.com/multiversx/mx-chain-go/sharding/nodesCoordinator"
"github.com/multiversx/mx-chain-go/statusHandler"
Expand Down Expand Up @@ -244,35 +243,15 @@ func (ccf *coreComponentsFactory) Create() (*coreComponents, error) {
}

wasmVMChangeLocker := &sync.RWMutex{}
gasScheduleConfigurationFolderName := ccf.configPathsHolder.GasScheduleDirectoryName
argsGasScheduleNotifier := forking.ArgsNewGasScheduleNotifier{
GasScheduleConfig: ccf.epochConfig.GasSchedule,
ConfigDir: gasScheduleConfigurationFolderName,
EpochNotifier: epochNotifier,
WasmVMChangeLocker: wasmVMChangeLocker,
}
gasScheduleNotifier, err := forking.NewGasScheduleNotifier(argsGasScheduleNotifier)
if err != nil {
return nil, err
}

builtInCostHandler, err := economics.NewBuiltInFunctionsCost(&economics.ArgsBuiltInFunctionCost{
ArgsParser: smartContract.NewArgumentParser(),
GasSchedule: gasScheduleNotifier,
})
if err != nil {
return nil, err
}

txVersionChecker := versioning.NewTxVersionChecker(ccf.config.GeneralSettings.MinTransactionVersion)

log.Trace("creating economics data components")
argsNewEconomicsData := economics.ArgsNewEconomicsData{
Economics: &ccf.economicsConfig,
EpochNotifier: epochNotifier,
EnableEpochsHandler: enableEpochsHandler,
BuiltInFunctionsCostHandler: builtInCostHandler,
TxVersionChecker: txVersionChecker,
Economics: &ccf.economicsConfig,
EpochNotifier: epochNotifier,
EnableEpochsHandler: enableEpochsHandler,
TxVersionChecker: txVersionChecker,
}
economicsData, err := economics.NewEconomicsData(argsNewEconomicsData)
if err != nil {
Expand Down
12 changes: 0 additions & 12 deletions factory/core/coreComponents_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,18 +248,6 @@ func TestCoreComponentsFactory_CreateCoreComponentsInvalidRoundConfigShouldErr(t
require.NotNil(t, err)
}

func TestCoreComponentsFactory_CreateCoreComponentsInvalidEpochConfigShouldErr(t *testing.T) {
t.Parallel()

args := componentsMock.GetCoreArgs()
args.EpochConfig = config.EpochConfig{}
ccf, _ := coreComp.NewCoreComponentsFactory(args)

cc, err := ccf.Create()
require.Nil(t, cc)
require.NotNil(t, err)
}

func TestCoreComponentsFactory_CreateCoreComponentsInvalidGenesisMaxNumberOfShardsShouldErr(t *testing.T) {
t.Parallel()

Expand Down
24 changes: 0 additions & 24 deletions integrationTests/mock/builtInCostHandlerStub.go

This file was deleted.

9 changes: 4 additions & 5 deletions integrationTests/testProcessorNode.go
Original file line number Diff line number Diff line change
Expand Up @@ -1081,11 +1081,10 @@ func (tpn *TestProcessorNode) initChainHandler() {
func (tpn *TestProcessorNode) initEconomicsData(economicsConfig *config.EconomicsConfig) {
tpn.EnableEpochs.PenalizedTooMuchGasEnableEpoch = 0
argsNewEconomicsData := economics.ArgsNewEconomicsData{
Economics: economicsConfig,
EpochNotifier: tpn.EpochNotifier,
EnableEpochsHandler: tpn.EnableEpochsHandler,
BuiltInFunctionsCostHandler: &mock.BuiltInCostHandlerStub{},
TxVersionChecker: &testscommon.TxVersionCheckerStub{},
Economics: economicsConfig,
EpochNotifier: tpn.EpochNotifier,
EnableEpochsHandler: tpn.EnableEpochsHandler,
TxVersionChecker: &testscommon.TxVersionCheckerStub{},
}
economicsData, _ := economics.NewEconomicsData(argsNewEconomicsData)
tpn.EconomicsData = economics.NewTestEconomicsData(economicsData)
Expand Down
12 changes: 3 additions & 9 deletions integrationTests/vm/testInitializer.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,11 +322,6 @@ func createEconomicsData(enableEpochsConfig config.EnableEpochs) (process.Econom
minGasLimit := strconv.FormatUint(1, 10)
testProtocolSustainabilityAddress := "erd1932eft30w753xyvme8d49qejgkjc09n5e49w4mwdjtm0neld797su0dlxp"

builtInCost, _ := economics.NewBuiltInFunctionsCost(&economics.ArgsBuiltInFunctionCost{
ArgsParser: smartContract.NewArgumentParser(),
GasSchedule: mock.NewGasScheduleNotifierMock(defaults.FillGasMapInternal(map[string]map[string]uint64{}, 1)),
})

realEpochNotifier := forking.NewGenericEpochNotifier()
enableEpochsHandler, _ := enablers.NewEnableEpochsHandler(enableEpochsConfig, realEpochNotifier)

Expand Down Expand Up @@ -371,10 +366,9 @@ func createEconomicsData(enableEpochsConfig config.EnableEpochs) (process.Econom
MaxGasPriceSetGuardian: "2000000000",
},
},
EpochNotifier: realEpochNotifier,
EnableEpochsHandler: enableEpochsHandler,
BuiltInFunctionsCostHandler: builtInCost,
TxVersionChecker: versioning.NewTxVersionChecker(minTransactionVersion),
EpochNotifier: realEpochNotifier,
EnableEpochsHandler: enableEpochsHandler,
TxVersionChecker: versioning.NewTxVersionChecker(minTransactionVersion),
}

return economics.NewEconomicsData(argsNewEconomicsData)
Expand Down
7 changes: 3 additions & 4 deletions integrationTests/vm/wasm/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,10 +250,9 @@ func (context *TestContext) initFeeHandlers() {
MaxGasPriceSetGuardian: "2000000000",
},
},
EpochNotifier: context.EpochNotifier,
EnableEpochsHandler: context.EnableEpochsHandler,
BuiltInFunctionsCostHandler: &mock.BuiltInCostHandlerStub{},
TxVersionChecker: &testscommon.TxVersionCheckerStub{},
EpochNotifier: context.EpochNotifier,
EnableEpochsHandler: context.EnableEpochsHandler,
TxVersionChecker: &testscommon.TxVersionCheckerStub{},
}
economicsData, _ := economics.NewEconomicsData(argsNewEconomicsData)

Expand Down
32 changes: 4 additions & 28 deletions node/chainSimulator/components/coreComponents.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import (
"github.com/multiversx/mx-chain-go/ntp"
"github.com/multiversx/mx-chain-go/process"
"github.com/multiversx/mx-chain-go/process/economics"
"github.com/multiversx/mx-chain-go/process/smartContract"
"github.com/multiversx/mx-chain-go/sharding"
"github.com/multiversx/mx-chain-go/sharding/nodesCoordinator"
"github.com/multiversx/mx-chain-go/statusHandler"
Expand Down Expand Up @@ -159,38 +158,15 @@ func CreateCoreComponents(args ArgsCoreComponentsHolder) (*coreComponentsHolder,
return nil, err

Check warning on line 158 in node/chainSimulator/components/coreComponents.go

View check run for this annotation

Codecov / codecov/patch

node/chainSimulator/components/coreComponents.go#L158

Added line #L158 was not covered by tests
}

argsGasSchedule := forking.ArgsNewGasScheduleNotifier{
GasScheduleConfig: config.GasScheduleConfig{
GasScheduleByEpochs: []config.GasScheduleByEpochs{
{
StartEpoch: 0,
FileName: args.GasScheduleFilename,
},
},
},
ConfigDir: "",
EpochNotifier: instance.epochNotifier,
WasmVMChangeLocker: instance.wasmVMChangeLocker,
}
gasScheduleNotifier, err := forking.NewGasScheduleNotifier(argsGasSchedule)
if err != nil {
return nil, err
}

builtInCostHandler, err := economics.NewBuiltInFunctionsCost(&economics.ArgsBuiltInFunctionCost{
ArgsParser: smartContract.NewArgumentParser(),
GasSchedule: gasScheduleNotifier,
})
if err != nil {
return nil, err

Check warning on line 162 in node/chainSimulator/components/coreComponents.go

View check run for this annotation

Codecov / codecov/patch

node/chainSimulator/components/coreComponents.go#L162

Added line #L162 was not covered by tests
}

argsEconomicsHandler := economics.ArgsNewEconomicsData{
TxVersionChecker: instance.txVersionChecker,
BuiltInFunctionsCostHandler: builtInCostHandler,
Economics: &args.EconomicsConfig,
EpochNotifier: instance.epochNotifier,
EnableEpochsHandler: instance.enableEpochsHandler,
TxVersionChecker: instance.txVersionChecker,
Economics: &args.EconomicsConfig,
EpochNotifier: instance.epochNotifier,
EnableEpochsHandler: instance.enableEpochsHandler,
}

instance.economicsData, err = economics.NewEconomicsData(argsEconomicsHandler)
Expand Down
16 changes: 7 additions & 9 deletions node/chainSimulator/components/testOnlyProcessingNode.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"github.com/multiversx/mx-chain-go/node/chainSimulator/dtos"
"github.com/multiversx/mx-chain-go/process"
"github.com/multiversx/mx-chain-go/process/block/postprocess"
"github.com/multiversx/mx-chain-go/process/economics"
"github.com/multiversx/mx-chain-go/process/smartContract"
"github.com/multiversx/mx-chain-go/sharding"
"github.com/multiversx/mx-chain-go/sharding/nodesCoordinator"
Expand Down Expand Up @@ -60,14 +59,13 @@ type testOnlyProcessingNode struct {
ProcessComponentsHolder factory.ProcessComponentsHandler
DataComponentsHolder factory.DataComponentsHandler

NodesCoordinator nodesCoordinator.NodesCoordinator
ChainHandler chainData.ChainHandler
ArgumentsParser process.ArgumentsParser
TransactionFeeHandler process.TransactionFeeHandler
StoreService dataRetriever.StorageService
BuiltinFunctionsCostHandler economics.BuiltInFunctionsCostHandler
DataPool dataRetriever.PoolsHolder
broadcastMessenger consensus.BroadcastMessenger
NodesCoordinator nodesCoordinator.NodesCoordinator
ChainHandler chainData.ChainHandler
ArgumentsParser process.ArgumentsParser
TransactionFeeHandler process.TransactionFeeHandler
StoreService dataRetriever.StorageService
DataPool dataRetriever.PoolsHolder
broadcastMessenger consensus.BroadcastMessenger

httpServer shared.UpgradeableHttpServerHandler
facadeHandler shared.FacadeHandler
Expand Down
3 changes: 1 addition & 2 deletions node/external/timemachine/fee/feeComputer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ import (
func createEconomicsData() process.EconomicsDataHandler {
economicsConfig := testscommon.GetEconomicsConfig()
economicsData, _ := economics.NewEconomicsData(economics.ArgsNewEconomicsData{
BuiltInFunctionsCostHandler: &testscommon.BuiltInCostHandlerStub{},
Economics: &economicsConfig,
Economics: &economicsConfig,
EnableEpochsHandler: &enableEpochsHandlerMock.EnableEpochsHandlerStub{
IsFlagEnabledInEpochCalled: func(flag core.EnableEpochFlag, epoch uint32) bool {
if flag == common.PenalizedTooMuchGasFlag {
Expand Down
3 changes: 1 addition & 2 deletions node/external/timemachine/fee/memoryFootprint/memory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ func TestFeeComputer_MemoryFootprint(t *testing.T) {

economicsConfig := testscommon.GetEconomicsConfig()
economicsData, _ := economics.NewEconomicsData(economics.ArgsNewEconomicsData{
BuiltInFunctionsCostHandler: &testscommon.BuiltInCostHandlerStub{},
Economics: &economicsConfig,
Economics: &economicsConfig,
EnableEpochsHandler: &enableEpochsHandlerMock.EnableEpochsHandlerStub{
IsFlagEnabledInEpochCalled: func(flag core.EnableEpochFlag, epoch uint32) bool {
if flag == common.PenalizedTooMuchGasFlag {
Expand Down
9 changes: 4 additions & 5 deletions node/external/transactionAPI/gasUsedAndFeeProcessor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,10 @@ import (
func createEconomicsData(enableEpochsHandler common.EnableEpochsHandler) process.EconomicsDataHandler {
economicsConfig := testscommon.GetEconomicsConfig()
economicsData, _ := economics.NewEconomicsData(economics.ArgsNewEconomicsData{
BuiltInFunctionsCostHandler: &testscommon.BuiltInCostHandlerStub{},
Economics: &economicsConfig,
EnableEpochsHandler: enableEpochsHandler,
TxVersionChecker: &testscommon.TxVersionCheckerStub{},
EpochNotifier: &epochNotifier.EpochNotifierStub{},
Economics: &economicsConfig,
EnableEpochsHandler: enableEpochsHandler,
TxVersionChecker: &testscommon.TxVersionCheckerStub{},
EpochNotifier: &epochNotifier.EpochNotifierStub{},
})

return economicsData
Expand Down
Loading

0 comments on commit cb193df

Please sign in to comment.