Skip to content

Commit

Permalink
Merge branch 'development' into merge-dev-into-liquid-staking
Browse files Browse the repository at this point in the history
# Conflicts:
#	process/factory/metachain/vmContainerFactory.go
  • Loading branch information
mariusmihaic committed Feb 28, 2022
2 parents 97398b8 + b87901a commit afda380
Show file tree
Hide file tree
Showing 93 changed files with 3,441 additions and 2,661 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ In order to join the network as an observer or as a validator, the required step
Alternatively, in order to use the Docker Image, jump to [Using the Docker Image](#using-the-docker-image).

### Step 1: install & configure go:
The installation of go should proceed as shown in official golang installation guide https://golang.org/doc/install . In order to run the node, minimum golang version should be 1.12.4.
The installation of go should proceed as shown in official golang installation guide https://golang.org/doc/install . In order to run the node, minimum golang version should be 1.17.6.

### Step 2: clone the repository and build the binaries:
The main branch that will be used is the master branch. Alternatively, an older release tag can be used.
Expand Down
7 changes: 5 additions & 2 deletions epochStart/metachain/systemSCs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -938,8 +938,11 @@ func createFullArgumentsForSystemSCProcessing(stakingV2EnableEpoch uint32, trieS
signVerifer, _ := disabled.NewMessageSignVerifier(&cryptoMocks.KeyGenStub{})

nodesSetup := &mock.NodesSetupStub{}

blockChainHookImpl, _ := hooks.NewBlockChainHookImpl(argsHook)
argsNewVMContainerFactory := metaProcess.ArgsNewVMContainerFactory{
ArgBlockChainHook: argsHook,
BlockChainHook: blockChainHookImpl,
PubkeyConv: argsHook.PubkeyConv,
Economics: createEconomicsData(),
MessageSignVerifier: signVerifer,
GasSchedule: gasScheduleNotifier,
Expand Down Expand Up @@ -1332,7 +1335,7 @@ func TestSystemSCProcessor_ESDTInitShouldWork(t *testing.T) {
require.Nil(t, err)
require.Equal(t, 4, len(updatedContractConfig))
require.Equal(t, args.ESDTOwnerAddressBytes, updatedContractConfig[0])
//the other config values should be unchanged
// the other config values should be unchanged
for i := 1; i < len(initialContractConfig); i++ {
assert.Equal(t, initialContractConfig[i], updatedContractConfig[i])
}
Expand Down
11 changes: 4 additions & 7 deletions facade/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,6 @@ type NodeHandler interface {
// SendBulkTransactions will send a bulk of transactions on the 'send transactions pipe' channel
SendBulkTransactions(txs []*transaction.Transaction) (uint64, error)

// GetTransaction will return a transaction based on the hash
GetTransaction(hash string, withResults bool) (*transaction.ApiTransactionResult, error)

// GetAccount returns an accountResponse containing information
// about the account correlated with provided address
GetAccount(address string) (api.AccountResponse, error)
Expand All @@ -90,10 +87,6 @@ type NodeHandler interface {
GetQueryHandler(name string) (debug.QueryHandler, error)
GetPeerInfo(pid string) ([]core.QueryP2PPeerInfo, error)

GetBlockByHash(hash string, withTxs bool) (*api.Block, error)
GetBlockByNonce(nonce uint64, withTxs bool) (*api.Block, error)
GetBlockByRound(round uint64, withTxs bool) (*api.Block, error)

GetProof(rootHash string, key string) (*common.GetProofResponse, error)
GetProofDataTrie(rootHash string, address string, key string) (*common.GetProofResponse, *common.GetProofResponse, error)
VerifyProof(rootHash string, address string, proof [][]byte) (bool, error)
Expand All @@ -113,6 +106,10 @@ type ApiResolver interface {
GetTotalStakedValue() (*api.StakeValues, error)
GetDirectStakedList() ([]*api.DirectStakedValue, error)
GetDelegatorsList() ([]*api.Delegator, error)
GetTransaction(hash string, withResults bool) (*transaction.ApiTransactionResult, error)
GetBlockByHash(hash string, withTxs bool) (*api.Block, error)
GetBlockByNonce(nonce uint64, withTxs bool) (*api.Block, error)
GetBlockByRound(round uint64, withTxs bool) (*api.Block, error)
Close() error
IsInterfaceNil() bool
}
Expand Down
64 changes: 60 additions & 4 deletions facade/mock/apiResolverStub.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,82 @@ type ApiResolverStub struct {
GetTotalStakedValueHandler func() (*api.StakeValues, error)
GetDirectStakedListHandler func() ([]*api.DirectStakedValue, error)
GetDelegatorsListHandler func() ([]*api.Delegator, error)
GetBlockByHashCalled func(hash string, withTxs bool) (*api.Block, error)
GetBlockByNonceCalled func(nonce uint64, withTxs bool) (*api.Block, error)
GetBlockByRoundCalled func(round uint64, withTxs bool) (*api.Block, error)
GetTransactionHandler func(hash string, withEvents bool) (*transaction.ApiTransactionResult, error)
}

// GetTransaction -
func (ars *ApiResolverStub) GetTransaction(hash string, withEvents bool) (*transaction.ApiTransactionResult, error) {
if ars.GetTransactionHandler != nil {
return ars.GetTransactionHandler(hash, withEvents)
}

return nil, nil
}

// GetBlockByHash -
func (ars *ApiResolverStub) GetBlockByHash(hash string, withTxs bool) (*api.Block, error) {
if ars.GetBlockByHashCalled != nil {
return ars.GetBlockByHashCalled(hash, withTxs)
}

return nil, nil
}

// GetBlockByNonce -
func (ars *ApiResolverStub) GetBlockByNonce(nonce uint64, withTxs bool) (*api.Block, error) {
if ars.GetBlockByNonceCalled != nil {
return ars.GetBlockByNonceCalled(nonce, withTxs)
}

return nil, nil
}

// GetBlockByRound -
func (ars *ApiResolverStub) GetBlockByRound(round uint64, withTxs bool) (*api.Block, error) {
if ars.GetBlockByRoundCalled != nil {
return ars.GetBlockByRoundCalled(round, withTxs)
}

return nil, nil
}

// ExecuteSCQuery -
func (ars *ApiResolverStub) ExecuteSCQuery(query *process.SCQuery) (*vmcommon.VMOutput, error) {
return ars.ExecuteSCQueryHandler(query)
if ars.ExecuteSCQueryHandler != nil {
return ars.ExecuteSCQueryHandler(query)
}

return nil, nil
}

// StatusMetrics -
func (ars *ApiResolverStub) StatusMetrics() external.StatusMetricsHandler {
return ars.StatusMetricsHandler()
if ars.StatusMetricsHandler != nil {
return ars.StatusMetricsHandler()
}

return nil
}

// ComputeTransactionGasLimit -
func (ars *ApiResolverStub) ComputeTransactionGasLimit(tx *transaction.Transaction) (*transaction.CostResponse, error) {
return ars.ComputeTransactionGasLimitHandler(tx)
if ars.ComputeTransactionGasLimitHandler != nil {
return ars.ComputeTransactionGasLimitHandler(tx)
}

return nil, nil
}

// GetTotalStakedValue -
func (ars *ApiResolverStub) GetTotalStakedValue() (*api.StakeValues, error) {
return ars.GetTotalStakedValueHandler()
if ars.GetTotalStakedValueHandler != nil {
return ars.GetTotalStakedValueHandler()
}

return nil, nil
}

// GetDirectStakedList -
Expand Down
27 changes: 0 additions & 27 deletions facade/mock/nodeStub.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ type NodeStub struct {
gasLimit uint64, data []byte, signatureHex string, chainID string, version, options uint32) (*transaction.Transaction, []byte, error)
ValidateTransactionHandler func(tx *transaction.Transaction) error
ValidateTransactionForSimulationCalled func(tx *transaction.Transaction, bypassSignature bool) error
GetTransactionHandler func(hash string, withEvents bool) (*transaction.ApiTransactionResult, error)
SendBulkTransactionsHandler func(txs []*transaction.Transaction) (uint64, error)
GetAccountHandler func(address string) (api.AccountResponse, error)
GetCodeCalled func(codeHash []byte) []byte
Expand All @@ -38,9 +37,6 @@ type NodeStub struct {
GetQueryHandlerCalled func(name string) (debug.QueryHandler, error)
GetValueForKeyCalled func(address string, key string) (string, error)
GetPeerInfoCalled func(pid string) ([]core.QueryP2PPeerInfo, error)
GetBlockByHashCalled func(hash string, withTxs bool) (*api.Block, error)
GetBlockByNonceCalled func(nonce uint64, withTxs bool) (*api.Block, error)
GetBlockByRoundCalled func(round uint64, withTxs bool) (*api.Block, error)
GetUsernameCalled func(address string) (string, error)
GetESDTDataCalled func(address string, key string, nonce uint64) (*esdt.ESDigitalToken, error)
GetAllESDTTokensCalled func(address string) (map[string]*esdt.ESDigitalToken, error)
Expand Down Expand Up @@ -113,24 +109,6 @@ func (ns *NodeStub) EncodeAddressPubkey(pk []byte) (string, error) {
return hex.EncodeToString(pk), nil
}

// GetBlockByHash -
func (ns *NodeStub) GetBlockByHash(hash string, withTxs bool) (*api.Block, error) {
return ns.GetBlockByHashCalled(hash, withTxs)
}

// GetBlockByNonce -
func (ns *NodeStub) GetBlockByNonce(nonce uint64, withTxs bool) (*api.Block, error) {
return ns.GetBlockByNonceCalled(nonce, withTxs)
}

// GetBlockByRound -
func (ns *NodeStub) GetBlockByRound(round uint64, withTxs bool) (*api.Block, error) {
if ns.GetBlockByRoundCalled != nil {
return ns.GetBlockByRoundCalled(round, withTxs)
}
return nil, nil
}

// DecodeAddressPubkey -
func (ns *NodeStub) DecodeAddressPubkey(pk string) ([]byte, error) {
return hex.DecodeString(pk)
Expand Down Expand Up @@ -158,11 +136,6 @@ func (ns *NodeStub) ValidateTransactionForSimulation(tx *transaction.Transaction
return ns.ValidateTransactionForSimulationCalled(tx, bypassSignature)
}

// GetTransaction -
func (ns *NodeStub) GetTransaction(hash string, withEvents bool) (*transaction.ApiTransactionResult, error) {
return ns.GetTransactionHandler(hash, withEvents)
}

// SendBulkTransactions -
func (ns *NodeStub) SendBulkTransactions(txs []*transaction.Transaction) (uint64, error) {
return ns.SendBulkTransactionsHandler(txs)
Expand Down
8 changes: 4 additions & 4 deletions facade/nodeFacade.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ func (nf *nodeFacade) SimulateTransactionExecution(tx *transaction.Transaction)

// GetTransaction gets the transaction with a specified hash
func (nf *nodeFacade) GetTransaction(hash string, withResults bool) (*transaction.ApiTransactionResult, error) {
return nf.node.GetTransaction(hash, withResults)
return nf.apiResolver.GetTransaction(hash, withResults)
}

// ComputeTransactionGasLimit will estimate how many gas a transaction will consume
Expand Down Expand Up @@ -369,17 +369,17 @@ func (nf *nodeFacade) GetThrottlerForEndpoint(endpoint string) (core.Throttler,

// GetBlockByHash return the block for a given hash
func (nf *nodeFacade) GetBlockByHash(hash string, withTxs bool) (*apiData.Block, error) {
return nf.node.GetBlockByHash(hash, withTxs)
return nf.apiResolver.GetBlockByHash(hash, withTxs)
}

// GetBlockByNonce returns the block for a given nonce
func (nf *nodeFacade) GetBlockByNonce(nonce uint64, withTxs bool) (*apiData.Block, error) {
return nf.node.GetBlockByNonce(nonce, withTxs)
return nf.apiResolver.GetBlockByNonce(nonce, withTxs)
}

// GetBlockByRound returns the block for a given round
func (nf *nodeFacade) GetBlockByRound(round uint64, withTxs bool) (*apiData.Block, error) {
return nf.node.GetBlockByRound(round, withTxs)
return nf.apiResolver.GetBlockByRound(round, withTxs)
}

// Close will cleanup started go routines
Expand Down
15 changes: 7 additions & 8 deletions facade/nodeFacade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,16 +225,17 @@ func TestNodeFacade_GetTransactionWithValidInputsShouldNotReturnError(t *testing

testHash := "testHash"
testTx := &transaction.ApiTransactionResult{}
node := &mock.NodeStub{
node := &mock.NodeStub{}

arg := createMockArguments()
arg.ApiResolver = &mock.ApiResolverStub{
GetTransactionHandler: func(hash string, withEvents bool) (*transaction.ApiTransactionResult, error) {
if hash == testHash {
return testTx, nil
}
return nil, nil
},
}

arg := createMockArguments()
arg.Node = node
nf, _ := NewNodeFacade(arg)

Expand All @@ -248,17 +249,15 @@ func TestNodeFacade_GetTransactionWithUnknowHashShouldReturnNilAndNoError(t *tes

testHash := "testHash"
testTx := &transaction.ApiTransactionResult{}
node := &mock.NodeStub{
arg := createMockArguments()
arg.ApiResolver = &mock.ApiResolverStub{
GetTransactionHandler: func(hash string, withEvents bool) (*transaction.ApiTransactionResult, error) {
if hash == testHash {
return testTx, nil
}
return nil, nil
},
}

arg := createMockArguments()
arg.Node = node
nf, _ := NewNodeFacade(arg)

tx, err := nf.GetTransaction("unknownHash", false)
Expand Down Expand Up @@ -1027,7 +1026,7 @@ func TestNodeFacade_GetBlockByRoundShouldWork(t *testing.T) {
Nonce: 2,
}

arg.Node = &mock.NodeStub{
arg.ApiResolver = &mock.ApiResolverStub{
GetBlockByRoundCalled: func(_ uint64, _ bool) (*api.Block, error) {
return blk, nil
},
Expand Down

0 comments on commit afda380

Please sign in to comment.