Skip to content

Commit

Permalink
Merge pull request #5412 from multiversx/merge_rc160_into_feat_multik…
Browse files Browse the repository at this point in the history
…ey_metrics_2023.07.07

Merge rc160 into feat multikey metrics 2023.07.07
  • Loading branch information
sstanculeanu committed Jul 7, 2023
2 parents c54fdb2 + 1ecc939 commit cb8a589
Show file tree
Hide file tree
Showing 160 changed files with 3,484 additions and 3,063 deletions.
4 changes: 2 additions & 2 deletions api/groups/transactionGroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"github.com/multiversx/mx-chain-go/api/shared/logging"
"github.com/multiversx/mx-chain-go/common"
"github.com/multiversx/mx-chain-go/node/external"
txSimData "github.com/multiversx/mx-chain-go/process/txsimulator/data"
txSimData "github.com/multiversx/mx-chain-go/process/transactionEvaluator/data"
)

const (
Expand Down Expand Up @@ -48,7 +48,7 @@ type transactionFacadeHandler interface {
ValidateTransaction(tx *transaction.Transaction) error
ValidateTransactionForSimulation(tx *transaction.Transaction, checkSignature bool) error
SendBulkTransactions([]*transaction.Transaction) (uint64, error)
SimulateTransactionExecution(tx *transaction.Transaction) (*txSimData.SimulationResults, error)
SimulateTransactionExecution(tx *transaction.Transaction) (*txSimData.SimulationResultsWithVMOutput, error)
GetTransaction(hash string, withResults bool) (*transaction.ApiTransactionResult, error)
GetTransactionsPool(fields string) (*common.TransactionsPoolAPIResponse, error)
GetTransactionsPoolForSender(sender, fields string) (*common.TransactionsPoolForSenderApiResponse, error)
Expand Down
22 changes: 12 additions & 10 deletions api/groups/transactionGroup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"github.com/multiversx/mx-chain-go/common"
"github.com/multiversx/mx-chain-go/config"
"github.com/multiversx/mx-chain-go/node/external"
txSimData "github.com/multiversx/mx-chain-go/process/txsimulator/data"
txSimData "github.com/multiversx/mx-chain-go/process/transactionEvaluator/data"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
Expand Down Expand Up @@ -601,7 +601,7 @@ func TestTransactionGroup_simulateTransaction(t *testing.T) {
ValidateTransactionForSimulationHandler: func(tx *dataTx.Transaction, bypassSignature bool) error {
return expectedErr
},
SimulateTransactionExecutionHandler: func(tx *dataTx.Transaction) (*txSimData.SimulationResults, error) {
SimulateTransactionExecutionHandler: func(tx *dataTx.Transaction) (*txSimData.SimulationResultsWithVMOutput, error) {
require.Fail(t, "should have not been called")
return nil, nil
},
Expand All @@ -626,7 +626,7 @@ func TestTransactionGroup_simulateTransaction(t *testing.T) {
ValidateTransactionForSimulationHandler: func(tx *dataTx.Transaction, bypassSignature bool) error {
return nil
},
SimulateTransactionExecutionHandler: func(tx *dataTx.Transaction) (*txSimData.SimulationResults, error) {
SimulateTransactionExecutionHandler: func(tx *dataTx.Transaction) (*txSimData.SimulationResultsWithVMOutput, error) {
return nil, expectedErr
},
}
Expand All @@ -646,14 +646,16 @@ func TestTransactionGroup_simulateTransaction(t *testing.T) {
processTxWasCalled := false

facade := &mock.FacadeStub{
SimulateTransactionExecutionHandler: func(tx *dataTx.Transaction) (*txSimData.SimulationResults, error) {
SimulateTransactionExecutionHandler: func(tx *dataTx.Transaction) (*txSimData.SimulationResultsWithVMOutput, error) {
processTxWasCalled = true
return &txSimData.SimulationResults{
Status: "ok",
FailReason: "no reason",
ScResults: nil,
Receipts: nil,
Hash: "hash",
return &txSimData.SimulationResultsWithVMOutput{
SimulationResults: dataTx.SimulationResults{
Status: "ok",
FailReason: "no reason",
ScResults: nil,
Receipts: nil,
Hash: "hash",
},
}, nil
},
CreateTransactionHandler: func(txArgs *external.ArgsCreateTransaction) (*dataTx.Transaction, []byte, error) {
Expand Down
4 changes: 2 additions & 2 deletions api/groups/validatorGroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ import (
"github.com/multiversx/mx-chain-core-go/core/check"
"github.com/multiversx/mx-chain-go/api/errors"
"github.com/multiversx/mx-chain-go/api/shared"
"github.com/multiversx/mx-chain-go/state"
"github.com/multiversx/mx-chain-go/state/accounts"
)

const statisticsPath = "/statistics"

// validatorFacadeHandler defines the methods to be implemented by a facade for validator requests
type validatorFacadeHandler interface {
ValidatorStatisticsApi() (map[string]*state.ValidatorApiResponse, error)
ValidatorStatisticsApi() (map[string]*accounts.ValidatorApiResponse, error)
IsInterfaceNil() bool
}

Expand Down
23 changes: 12 additions & 11 deletions api/groups/validatorGroup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/multiversx/mx-chain-go/api/mock"
"github.com/multiversx/mx-chain-go/api/shared"
"github.com/multiversx/mx-chain-go/config"
"github.com/multiversx/mx-chain-go/state"
"github.com/multiversx/mx-chain-go/state/accounts"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
Expand All @@ -33,9 +33,10 @@ func TestNewValidatorGroup(t *testing.T) {
})
}

// ValidatorStatisticsResponse is the response for the validator statistics endpoint.
type ValidatorStatisticsResponse struct {
Result map[string]*state.ValidatorApiResponse `json:"statistics"`
Error string `json:"error"`
Result map[string]*accounts.ValidatorApiResponse `json:"statistics"`
Error string `json:"error"`
}

func TestValidatorStatistics_ErrorWhenFacadeFails(t *testing.T) {
Expand All @@ -44,7 +45,7 @@ func TestValidatorStatistics_ErrorWhenFacadeFails(t *testing.T) {
errStr := "error in facade"

facade := mock.FacadeStub{
ValidatorStatisticsHandler: func() (map[string]*state.ValidatorApiResponse, error) {
ValidatorStatisticsHandler: func() (map[string]*accounts.ValidatorApiResponse, error) {
return nil, errors.New(errStr)
},
}
Expand All @@ -69,16 +70,16 @@ func TestValidatorStatistics_ErrorWhenFacadeFails(t *testing.T) {
func TestValidatorStatistics_ReturnsSuccessfully(t *testing.T) {
t.Parallel()

mapToReturn := make(map[string]*state.ValidatorApiResponse)
mapToReturn["test"] = &state.ValidatorApiResponse{
mapToReturn := make(map[string]*accounts.ValidatorApiResponse)
mapToReturn["test"] = &accounts.ValidatorApiResponse{
NumLeaderSuccess: 5,
NumLeaderFailure: 2,
NumValidatorSuccess: 7,
NumValidatorFailure: 3,
}

facade := mock.FacadeStub{
ValidatorStatisticsHandler: func() (map[string]*state.ValidatorApiResponse, error) {
ValidatorStatisticsHandler: func() (map[string]*accounts.ValidatorApiResponse, error) {
return mapToReturn, nil
},
}
Expand Down Expand Up @@ -130,15 +131,15 @@ func TestValidatorGroup_UpdateFacade(t *testing.T) {
t.Run("should work", func(t *testing.T) {
t.Parallel()

mapToReturn := make(map[string]*state.ValidatorApiResponse)
mapToReturn["test"] = &state.ValidatorApiResponse{
mapToReturn := make(map[string]*accounts.ValidatorApiResponse)
mapToReturn["test"] = &accounts.ValidatorApiResponse{
NumLeaderSuccess: 5,
NumLeaderFailure: 2,
NumValidatorSuccess: 7,
NumValidatorFailure: 3,
}
facade := mock.FacadeStub{
ValidatorStatisticsHandler: func() (map[string]*state.ValidatorApiResponse, error) {
ValidatorStatisticsHandler: func() (map[string]*accounts.ValidatorApiResponse, error) {
return mapToReturn, nil
},
}
Expand All @@ -162,7 +163,7 @@ func TestValidatorGroup_UpdateFacade(t *testing.T) {

expectedErr := errors.New("expected error")
newFacade := mock.FacadeStub{
ValidatorStatisticsHandler: func() (map[string]*state.ValidatorApiResponse, error) {
ValidatorStatisticsHandler: func() (map[string]*accounts.ValidatorApiResponse, error) {
return nil, expectedErr
},
}
Expand Down
11 changes: 6 additions & 5 deletions api/mock/facadeStub.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ import (
"github.com/multiversx/mx-chain-go/heartbeat/data"
"github.com/multiversx/mx-chain-go/node/external"
"github.com/multiversx/mx-chain-go/process"
txSimData "github.com/multiversx/mx-chain-go/process/txsimulator/data"
txSimData "github.com/multiversx/mx-chain-go/process/transactionEvaluator/data"
"github.com/multiversx/mx-chain-go/state"
"github.com/multiversx/mx-chain-go/state/accounts"
)

// FacadeStub is the mock implementation of a node router handler
Expand All @@ -35,7 +36,7 @@ type FacadeStub struct {
SendBulkTransactionsHandler func(txs []*transaction.Transaction) (uint64, error)
ExecuteSCQueryHandler func(query *process.SCQuery) (*vm.VMOutputApi, error)
StatusMetricsHandler func() external.StatusMetricsHandler
ValidatorStatisticsHandler func() (map[string]*state.ValidatorApiResponse, error)
ValidatorStatisticsHandler func() (map[string]*accounts.ValidatorApiResponse, error)
ComputeTransactionGasLimitHandler func(tx *transaction.Transaction) (*transaction.CostResponse, error)
NodeConfigCalled func() map[string]interface{}
GetQueryHandlerCalled func(name string) (debug.QueryHandler, error)
Expand All @@ -48,7 +49,7 @@ type FacadeStub struct {
GetUsernameCalled func(address string, options api.AccountQueryOptions) (string, api.BlockInfo, error)
GetCodeHashCalled func(address string, options api.AccountQueryOptions) ([]byte, api.BlockInfo, error)
GetKeyValuePairsCalled func(address string, options api.AccountQueryOptions) (map[string]string, api.BlockInfo, error)
SimulateTransactionExecutionHandler func(tx *transaction.Transaction) (*txSimData.SimulationResults, error)
SimulateTransactionExecutionHandler func(tx *transaction.Transaction) (*txSimData.SimulationResultsWithVMOutput, error)
GetESDTDataCalled func(address string, key string, nonce uint64, options api.AccountQueryOptions) (*esdt.ESDigitalToken, api.BlockInfo, error)
GetAllESDTTokensCalled func(address string, options api.AccountQueryOptions) (map[string]*esdt.ESDigitalToken, api.BlockInfo, error)
GetESDTsWithRoleCalled func(address string, role string, options api.AccountQueryOptions) ([]string, api.BlockInfo, error)
Expand Down Expand Up @@ -305,7 +306,7 @@ func (f *FacadeStub) GetTransaction(hash string, withResults bool) (*transaction
}

// SimulateTransactionExecution is the mock implementation of a handler's SimulateTransactionExecution method
func (f *FacadeStub) SimulateTransactionExecution(tx *transaction.Transaction) (*txSimData.SimulationResults, error) {
func (f *FacadeStub) SimulateTransactionExecution(tx *transaction.Transaction) (*txSimData.SimulationResultsWithVMOutput, error) {
return f.SimulateTransactionExecutionHandler(tx)
}

Expand All @@ -325,7 +326,7 @@ func (f *FacadeStub) ValidateTransactionForSimulation(tx *transaction.Transactio
}

// ValidatorStatisticsApi is the mock implementation of a handler's ValidatorStatisticsApi method
func (f *FacadeStub) ValidatorStatisticsApi() (map[string]*state.ValidatorApiResponse, error) {
func (f *FacadeStub) ValidatorStatisticsApi() (map[string]*accounts.ValidatorApiResponse, error) {
return f.ValidatorStatisticsHandler()
}

Expand Down
7 changes: 4 additions & 3 deletions api/shared/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ import (
"github.com/multiversx/mx-chain-go/heartbeat/data"
"github.com/multiversx/mx-chain-go/node/external"
"github.com/multiversx/mx-chain-go/process"
txSimData "github.com/multiversx/mx-chain-go/process/txsimulator/data"
txSimData "github.com/multiversx/mx-chain-go/process/transactionEvaluator/data"
"github.com/multiversx/mx-chain-go/state"
"github.com/multiversx/mx-chain-go/state/accounts"
)

// HttpServerCloser defines the basic actions of starting and closing that a web server should be able to do
Expand Down Expand Up @@ -109,11 +110,11 @@ type FacadeHandler interface {
ValidateTransaction(tx *transaction.Transaction) error
ValidateTransactionForSimulation(tx *transaction.Transaction, checkSignature bool) error
SendBulkTransactions([]*transaction.Transaction) (uint64, error)
SimulateTransactionExecution(tx *transaction.Transaction) (*txSimData.SimulationResults, error)
SimulateTransactionExecution(tx *transaction.Transaction) (*txSimData.SimulationResultsWithVMOutput, error)
GetTransaction(hash string, withResults bool) (*transaction.ApiTransactionResult, error)
ComputeTransactionGasLimit(tx *transaction.Transaction) (*transaction.CostResponse, error)
EncodeAddressPubkey(pk []byte) (string, error)
ValidatorStatisticsApi() (map[string]*state.ValidatorApiResponse, error)
ValidatorStatisticsApi() (map[string]*accounts.ValidatorApiResponse, error)
ExecuteSCQuery(*process.SCQuery) (*vm.VMOutputApi, error)
DecodeAddressPubkey(pk string) ([]byte, error)
RestApiInterface() string
Expand Down
2 changes: 1 addition & 1 deletion cmd/node/config/external.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
# marshalled structures in block events data
MarshallerType = "json"

[HostDriverConfig]
[[HostDriversConfig]]
# This flag shall only be used for observer nodes
Enabled = false
# This flag will start the WebSocket connector as server or client (can be "client" or "server")
Expand Down
6 changes: 3 additions & 3 deletions config/externalConfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ package config
type ExternalConfig struct {
ElasticSearchConnector ElasticSearchConfig
EventNotifierConnector EventNotifierConfig
HostDriverConfig HostDriverConfig
HostDriversConfig []HostDriversConfig
}

// ElasticSearchConfig will hold the configuration for the elastic search
Expand Down Expand Up @@ -38,8 +38,8 @@ type CovalentConfig struct {
RouteAcknowledgeData string
}

// HostDriverConfig will hold the configuration for WebSocket driver
type HostDriverConfig struct {
// HostDriversConfig will hold the configuration for WebSocket driver
type HostDriversConfig struct {
Enabled bool
WithAcknowledge bool
BlockingAckOnError bool
Expand Down
68 changes: 41 additions & 27 deletions epochStart/metachain/baseRewards_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,14 @@ import (
"github.com/multiversx/mx-chain-go/epochStart/mock"
"github.com/multiversx/mx-chain-go/process"
"github.com/multiversx/mx-chain-go/sharding"
"github.com/multiversx/mx-chain-go/state"
"github.com/multiversx/mx-chain-go/state/factory"
"github.com/multiversx/mx-chain-go/testscommon"
dataRetrieverMock "github.com/multiversx/mx-chain-go/testscommon/dataRetriever"
"github.com/multiversx/mx-chain-go/testscommon/enableEpochsHandlerMock"
"github.com/multiversx/mx-chain-go/testscommon/hashingMocks"
"github.com/multiversx/mx-chain-go/testscommon/marshallerMock"
"github.com/multiversx/mx-chain-go/testscommon/shardingMocks"
stateMock "github.com/multiversx/mx-chain-go/testscommon/state"
"github.com/multiversx/mx-chain-go/testscommon/storage"
trieMock "github.com/multiversx/mx-chain-go/testscommon/trie"
"github.com/multiversx/mx-chain-go/trie"
vmcommon "github.com/multiversx/mx-chain-vm-common-go"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -818,41 +815,58 @@ func TestBaseRewardsCreator_RemoveBlockDataFromPools(t *testing.T) {
func TestBaseRewardsCreator_isSystemDelegationSC(t *testing.T) {
t.Parallel()

nonExistentAccountAddress := []byte("address")
peerAccountAddress := []byte("addressPeer")
userAccountAddress := []byte("addressUser")

args := getBaseRewardsArguments()
args.UserAccountsDB = &stateMock.AccountsStub{
GetExistingAccountCalled: func(addressContainer []byte) (vmcommon.AccountHandler, error) {
if bytes.Equal(addressContainer, nonExistentAccountAddress) {
return nil, fmt.Errorf("account does not exist")
}

if bytes.Equal(addressContainer, peerAccountAddress) {
peerAccount := &stateMock.PeerAccountHandlerMock{
AddressBytesCalled: func() []byte {
return peerAccountAddress
},
}

return peerAccount, nil
}

if bytes.Equal(addressContainer, userAccountAddress) {
userAccount := &stateMock.UserAccountStub{
RetrieveValueCalled: func(key []byte) ([]byte, uint32, error) {
if bytes.Equal(key, []byte(core.DelegationSystemSCKey)) {
return []byte("delegation"), 0, nil
}
return nil, 0, fmt.Errorf("not found")
},
}

return userAccount, nil
}

return &stateMock.UserAccountStub{}, nil
},
}
rwd, err := NewBaseRewardsCreator(args)
require.Nil(t, err)
require.NotNil(t, rwd)

// not existing account
isDelegationSCAddress := rwd.isSystemDelegationSC([]byte("address"))
isDelegationSCAddress := rwd.isSystemDelegationSC(nonExistentAccountAddress)
require.False(t, isDelegationSCAddress)

// peer account
peerAccount, err := state.NewPeerAccount([]byte("addressPeer"))
require.Nil(t, err)
err = rwd.userAccountsDB.SaveAccount(peerAccount)
require.Nil(t, err)
isDelegationSCAddress = rwd.isSystemDelegationSC(peerAccount.AddressBytes())
isDelegationSCAddress = rwd.isSystemDelegationSC(peerAccountAddress)
require.False(t, isDelegationSCAddress)

argsAccCreation := state.ArgsAccountCreation{
Hasher: &hashingMocks.HasherMock{},
Marshaller: &marshallerMock.MarshalizerMock{},
EnableEpochsHandler: &enableEpochsHandlerMock.EnableEpochsHandlerStub{},
}
// existing user account
userAccount, err := state.NewUserAccount([]byte("userAddress"), argsAccCreation)
require.Nil(t, err)

userAccount.SetDataTrie(&trieMock.TrieStub{
GetCalled: func(key []byte) ([]byte, uint32, error) {
if bytes.Equal(key, []byte(core.DelegationSystemSCKey)) {
return []byte("delegation"), 0, nil
}
return nil, 0, fmt.Errorf("not found")
},
})

isDelegationSCAddress = rwd.isSystemDelegationSC(userAccountAddress)
require.True(t, isDelegationSCAddress)
}

func TestBaseRewardsCreator_isSystemDelegationSCTrue(t *testing.T) {
Expand Down Expand Up @@ -1148,7 +1162,7 @@ func getBaseRewardsArguments() BaseRewardsCreatorArgs {
storageManagerArgs.Hasher = hasher

trieFactoryManager, _ := trie.CreateTrieStorageManager(storageManagerArgs, storage.GetStorageManagerOptions())
argsAccCreator := state.ArgsAccountCreation{
argsAccCreator := factory.ArgsAccountCreator{
Hasher: hasher,
Marshaller: marshalizer,
EnableEpochsHandler: &enableEpochsHandlerMock.EnableEpochsHandlerStub{},
Expand Down

0 comments on commit cb8a589

Please sign in to comment.