Skip to content

Commit

Permalink
Merge branch 'rc/v1.6.0' into overridable-configs-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
BeniaminDrasovean authored Nov 16, 2023
2 parents f8760e4 + cd89ae9 commit b6b59e2
Show file tree
Hide file tree
Showing 14 changed files with 91 additions and 9 deletions.
4 changes: 4 additions & 0 deletions cmd/node/config/fullArchiveP2P.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
[Node.Transports.TCP]
ListenAddress = "/ip4/0.0.0.0/tcp/%d" # TCP listen address
PreventPortReuse = false
[Node.ResourceLimiter]
Type = "default autoscale" #available options "default autoscale", "infinite", "default with manual scale".
ManualSystemMemoryInMB = 0 # not taken into account if the type is not "default with manual scale"
ManualMaximumFD = 0 # not taken into account if the type is not "default with manual scale"

# P2P peer discovery section

Expand Down
4 changes: 4 additions & 0 deletions cmd/node/config/p2p.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
[Node.Transports.TCP]
ListenAddress = "/ip4/0.0.0.0/tcp/%d" # TCP listen address
PreventPortReuse = false
[Node.ResourceLimiter]
Type = "default autoscale" #available options "default autoscale", "infinite", "default with manual scale".
ManualSystemMemoryInMB = 0 # not taken into account if the type is not "default with manual scale"
ManualMaximumFD = 0 # not taken into account if the type is not "default with manual scale"

# P2P peer discovery section

Expand Down
4 changes: 4 additions & 0 deletions cmd/seednode/config/p2p.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
[Node.Transports.TCP]
ListenAddress = "/ip4/0.0.0.0/tcp/%d" # TCP listen address
PreventPortReuse = true # seeder nodes will need to enable this option
[Node.ResourceLimiter]
Type = "default with manual scale"
ManualSystemMemoryInMB = 65536 # pretend that the host running the seeder has more RAM so it can handle more connections
ManualMaximumFD = 1048576

# P2P peer discovery section

Expand Down
9 changes: 9 additions & 0 deletions config/tomlConfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,10 @@ func TestP2pConfig(t *testing.T) {
[Node.Transports.TCP]
ListenAddress = "/ip4/0.0.0.0/tcp/%d"
PreventPortReuse = true
[Node.ResourceLimiter]
Type = "default autoscale" #available options "default autoscale", "infinite", "default with manual scale".
ManualSystemMemoryInMB = 1 # not taken into account if the type is not "default with manual scale"
ManualMaximumFD = 2 # not taken into account if the type is not "default with manual scale"
[KadDhtPeerDiscovery]
Enabled = false
Expand Down Expand Up @@ -529,6 +533,11 @@ func TestP2pConfig(t *testing.T) {
WebSocketAddress: "/ip4/0.0.0.0/tcp/%d/ws",
WebTransportAddress: "/ip4/0.0.0.0/udp/%d/quic-v1/webtransport",
},
ResourceLimiter: p2pConfig.P2PResourceLimiterConfig{
Type: "default autoscale",
ManualSystemMemoryInMB: 1,
ManualMaximumFD: 2,
},
},
KadDhtPeerDiscovery: p2pConfig.KadDhtPeerDiscoveryConfig{
ProtocolID: protocolID,
Expand Down
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ require (
github.com/google/gops v0.3.18
github.com/gorilla/websocket v1.5.0
github.com/mitchellh/mapstructure v1.5.0
github.com/multiversx/mx-chain-communication-go v1.0.8
github.com/multiversx/mx-chain-communication-go v1.0.9
github.com/multiversx/mx-chain-core-go v1.2.18
github.com/multiversx/mx-chain-crypto-go v1.2.9
github.com/multiversx/mx-chain-es-indexer-go v1.4.13
Expand All @@ -25,12 +25,14 @@ require (
github.com/multiversx/mx-chain-vm-v1_2-go v1.2.61
github.com/multiversx/mx-chain-vm-v1_3-go v1.3.62
github.com/multiversx/mx-chain-vm-v1_4-go v1.4.90
github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58
github.com/pelletier/go-toml v1.9.3
github.com/pkg/errors v0.9.1
github.com/shirou/gopsutil v3.21.11+incompatible
github.com/stretchr/testify v1.8.4
github.com/urfave/cli v1.22.10
golang.org/x/crypto v0.10.0
golang.org/x/sys v0.10.0
gopkg.in/go-playground/validator.v8 v8.18.2
)

Expand Down Expand Up @@ -136,7 +138,6 @@ require (
github.com/onsi/ginkgo/v2 v2.9.7 // indirect
github.com/opencontainers/runtime-spec v1.0.2 // indirect
github.com/opentracing/opentracing-go v1.2.0 // indirect
github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58 // indirect
github.com/pelletier/go-toml/v2 v2.0.8 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/polydawn/refmt v0.89.0 // indirect
Expand Down Expand Up @@ -178,7 +179,6 @@ require (
golang.org/x/mod v0.10.0 // indirect
golang.org/x/net v0.11.0 // indirect
golang.org/x/sync v0.2.0 // indirect
golang.org/x/sys v0.10.0 // indirect
golang.org/x/text v0.10.0 // indirect
golang.org/x/tools v0.9.1 // indirect
gonum.org/v1/gonum v0.11.0 // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -384,8 +384,8 @@ github.com/multiformats/go-varint v0.0.7 h1:sWSGR+f/eu5ABZA2ZpYKBILXTTs9JWpdEM/n
github.com/multiformats/go-varint v0.0.7/go.mod h1:r8PUYw/fD/SjBCiKOoDlGF6QawOELpZAu9eioSos/OU=
github.com/multiversx/concurrent-map v0.1.4 h1:hdnbM8VE4b0KYJaGY5yJS2aNIW9TFFsUYwbO0993uPI=
github.com/multiversx/concurrent-map v0.1.4/go.mod h1:8cWFRJDOrWHOTNSqgYCUvwT7c7eFQ4U2vKMOp4A/9+o=
github.com/multiversx/mx-chain-communication-go v1.0.8 h1:sTx4Vmx+QCpngUFq/LF/Ka8bevlK2vMxfclE284twfc=
github.com/multiversx/mx-chain-communication-go v1.0.8/go.mod h1:+oaUowpq+SqrEmAsMPGwhz44g7L81loWb6AiNQU9Ms4=
github.com/multiversx/mx-chain-communication-go v1.0.9 h1:unntj9uANJVzANQ4qaE+yth3Y2Tuih6c9ukKAaHOECs=
github.com/multiversx/mx-chain-communication-go v1.0.9/go.mod h1:+oaUowpq+SqrEmAsMPGwhz44g7L81loWb6AiNQU9Ms4=
github.com/multiversx/mx-chain-core-go v1.2.18 h1:fnub2eFL7XYOLrKKVZAPPsaM1TWEnaK5qqY3FLUv168=
github.com/multiversx/mx-chain-core-go v1.2.18/go.mod h1:BILOGHUOIG5dNNX8cgkzCNfDaVtoYrJRYcPnpxRMH84=
github.com/multiversx/mx-chain-crypto-go v1.2.9 h1:OEfF2kOQrtzUl273Z3DEcshjlTVUfPpJMd0R0SvTrlU=
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ func createDefaultConfig() p2pConfig.P2PConfig {
ListenAddress: p2p.LocalHostListenAddrWithIp4AndTcp,
},
},
ResourceLimiter: p2pConfig.P2PResourceLimiterConfig{
Type: p2p.DefaultWithScaleResourceLimiter,
},
},
KadDhtPeerDiscovery: p2pConfig.KadDhtPeerDiscoveryConfig{
Enabled: true,
Expand Down
9 changes: 9 additions & 0 deletions integrationTests/testInitializer.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,9 @@ func createP2PConfig(initialPeerList []string) p2pConfig.P2PConfig {
ListenAddress: p2p.LocalHostListenAddrWithIp4AndTcp,
},
},
ResourceLimiter: p2pConfig.P2PResourceLimiterConfig{
Type: p2p.DefaultWithScaleResourceLimiter,
},
},
KadDhtPeerDiscovery: p2pConfig.KadDhtPeerDiscoveryConfig{
Enabled: true,
Expand Down Expand Up @@ -237,6 +240,9 @@ func CreateP2PConfigWithNoDiscovery() p2pConfig.P2PConfig {
ListenAddress: p2p.LocalHostListenAddrWithIp4AndTcp,
},
},
ResourceLimiter: p2pConfig.P2PResourceLimiterConfig{
Type: p2p.DefaultWithScaleResourceLimiter,
},
},
KadDhtPeerDiscovery: p2pConfig.KadDhtPeerDiscoveryConfig{
Enabled: false,
Expand Down Expand Up @@ -264,6 +270,9 @@ func CreateMessengerWithNoDiscoveryAndPeersRatingHandler(peersRatingHanlder p2p.
ListenAddress: p2p.LocalHostListenAddrWithIp4AndTcp,
},
},
ResourceLimiter: p2pConfig.P2PResourceLimiterConfig{
Type: p2p.DefaultWithScaleResourceLimiter,
},
},
KadDhtPeerDiscovery: p2pConfig.KadDhtPeerDiscoveryConfig{
Enabled: false,
Expand Down
3 changes: 3 additions & 0 deletions p2p/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ type P2PTransportConfig = config.TransportConfig
// P2PTCPTransport will hold the P2P TCP transport config
type P2PTCPTransport = config.TCPProtocolConfig

// P2PResourceLimiterConfig will hold the P2P resource limiter configs
type P2PResourceLimiterConfig = config.ResourceLimiterConfig

// NodeConfig will hold basic p2p settings
type NodeConfig = config.NodeConfig

Expand Down
3 changes: 3 additions & 0 deletions p2p/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,8 @@ const ConnectionWatcherTypePrint = p2p.ConnectionWatcherTypePrint
// LocalHostListenAddrWithIp4AndTcp defines the local host listening ip v.4 address and TCP
const LocalHostListenAddrWithIp4AndTcp = p2p.LocalHostListenAddrWithIp4AndTcp

// DefaultWithScaleResourceLimiter defines the default & autoscale resource limiter
const DefaultWithScaleResourceLimiter = p2p.DefaultWithScaleResourceLimiter

// BroadcastMethod defines the broadcast method of the message
type BroadcastMethod = p2p.BroadcastMethod
3 changes: 3 additions & 0 deletions process/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -1223,3 +1223,6 @@ var ErrNilManagedPeersHolder = errors.New("nil managed peers holder")

// ErrNilStorageService signals that a nil storage service has been provided
var ErrNilStorageService = errors.New("nil storage service")

// ErrInvalidAsyncArguments signals that invalid arguments were given for async/callBack processing
var ErrInvalidAsyncArguments = errors.New("invalid arguments to process async/callback function")
30 changes: 30 additions & 0 deletions process/smartContract/processorV2/process_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1867,6 +1867,36 @@ func TestScProcessor_CreateVMDeployBadCode(t *testing.T) {
require.Equal(t, badCodeError, err)
}

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

vm := &mock.VMContainerMock{}
argParser := &mock.ArgumentParserMock{}
arguments := createMockSmartContractProcessorArguments()
arguments.VmContainer = vm
arguments.ArgsParser = argParser
sc, err := NewSmartContractProcessorV2(arguments)
require.NotNil(t, sc)
require.Nil(t, err)

tx := &smartContractResult.SmartContractResult{}
tx.Nonce = 0
tx.SndAddr = []byte("SRC")
tx.RcvAddr = []byte("DST")
tx.Data = []byte("data")
tx.Value = big.NewInt(45)
tx.CallType = vmData.AsynchronousCall

input, err := sc.createVMCallInput(tx, []byte{}, false)
require.Nil(t, input)
require.Equal(t, err, process.ErrInvalidAsyncArguments)

tx.CallType = vmData.AsynchronousCallBack
input, err = sc.createVMCallInput(tx, []byte{}, false)
require.Nil(t, input)
require.Equal(t, err, process.ErrInvalidAsyncArguments)
}

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

Expand Down
15 changes: 11 additions & 4 deletions process/smartContract/processorV2/vmInputV2.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,10 @@ func (sc *scProcessor) createVMCallInput(

finalArguments, gasLocked := getAsyncCallGasLockFromTxData(callType, arguments)

asyncArguments, callArguments := separateAsyncArguments(callType, finalArguments)
asyncArguments, callArguments, err := separateAsyncArguments(callType, finalArguments)
if err != nil {
return nil, err
}

vmCallInput := &vmcommon.ContractCallInput{}
vmCallInput.VMInput = vmcommon.VMInput{}
Expand Down Expand Up @@ -150,9 +153,9 @@ func getAsyncCallGasLockFromTxData(callType vm.CallType, arguments [][]byte) ([]
return argsWithoutGasLocked, gasLocked
}

func separateAsyncArguments(callType vm.CallType, arguments [][]byte) ([][]byte, [][]byte) {
func separateAsyncArguments(callType vm.CallType, arguments [][]byte) ([][]byte, [][]byte, error) {
if callType == vm.DirectCall || callType == vm.ESDTTransferAndExecute {
return nil, arguments
return nil, arguments, nil
}

var noOfAsyncArguments int
Expand All @@ -162,14 +165,18 @@ func separateAsyncArguments(callType vm.CallType, arguments [][]byte) ([][]byte,
noOfAsyncArguments = 4
}

if len(arguments) < noOfAsyncArguments {
return nil, nil, process.ErrInvalidAsyncArguments
}

noOfCallArguments := len(arguments) - noOfAsyncArguments
asyncArguments := make([][]byte, noOfAsyncArguments)
callArguments := make([][]byte, noOfCallArguments)

copy(callArguments, arguments[:noOfCallArguments])
copy(asyncArguments, arguments[noOfCallArguments:])

return asyncArguments, callArguments
return asyncArguments, callArguments, nil
}

func buildAsyncArgumentsObject(callType vm.CallType, asyncArguments [][]byte) *vmcommon.AsyncArguments {
Expand Down
3 changes: 3 additions & 0 deletions testscommon/components/components.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,9 @@ func GetNetworkFactoryArgs() networkComp.NetworkComponentsFactoryArgs {
ListenAddress: p2p.LocalHostListenAddrWithIp4AndTcp,
},
},
ResourceLimiter: p2pConfig.P2PResourceLimiterConfig{
Type: p2p.DefaultWithScaleResourceLimiter,
},
},
KadDhtPeerDiscovery: p2pConfig.KadDhtPeerDiscoveryConfig{
Enabled: false,
Expand Down

0 comments on commit b6b59e2

Please sign in to comment.