Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update p2p separate repo rc v1.4.0 #4508

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -514,3 +514,6 @@ var ErrInvalidPID = errors.New("invalid PID")

// ErrInvalidSignature signals that the given signature is invalid
var ErrInvalidSignature = errors.New("invalid signature")

// ErrInvalidHeartbeatV2Config signals that an invalid heartbeat v2 configuration has been provided
var ErrInvalidHeartbeatV2Config = errors.New("invalid heartbeat v2 configuration")
8 changes: 6 additions & 2 deletions factory/heartbeat/heartbeatV2Components.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package heartbeat

import (
"fmt"
"time"

"github.com/ElrondNetwork/elrond-go-core/core"
Expand Down Expand Up @@ -113,6 +114,11 @@ func (hcf *heartbeatV2ComponentsFactory) Create() (*heartbeatV2Components, error
}
}

cfg := hcf.config.HeartbeatV2
if cfg.HeartbeatExpiryTimespanInSec <= cfg.PeerAuthenticationTimeBetweenSendsInSec {
return nil, fmt.Errorf("%w, HeartbeatExpiryTimespanInSec must be greater than PeerAuthenticationTimeBetweenSendsInSec", errors.ErrInvalidHeartbeatV2Config)
}

peerSubType := core.RegularPeer
if hcf.prefs.Preferences.FullArchive {
peerSubType = core.FullHistoryObserver
Expand All @@ -121,8 +127,6 @@ func (hcf *heartbeatV2ComponentsFactory) Create() (*heartbeatV2Components, error
shardC := hcf.boostrapComponents.ShardCoordinator()
heartbeatTopic := common.HeartbeatV2Topic + shardC.CommunicationIdentifier(shardC.SelfId())

cfg := hcf.config.HeartbeatV2

argPeerTypeProvider := peer.ArgPeerTypeProvider{
NodesCoordinator: hcf.processComponents.NodesCoordinator(),
StartEpoch: hcf.processComponents.EpochStartTrigger().MetaEpoch(),
Expand Down
51 changes: 35 additions & 16 deletions factory/heartbeat/heartbeatV2Components_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package heartbeat_test

import (
"errors"
"testing"

"github.com/ElrondNetwork/elrond-go-core/core/check"
"github.com/ElrondNetwork/elrond-go/config"
errErd "github.com/ElrondNetwork/elrond-go/errors"
bootstrapComp "github.com/ElrondNetwork/elrond-go/factory/bootstrap"
heartbeatComp "github.com/ElrondNetwork/elrond-go/factory/heartbeat"
"github.com/ElrondNetwork/elrond-go/factory/mock"
Expand Down Expand Up @@ -72,25 +74,42 @@ func createMockHeartbeatV2ComponentsFactoryArgs() heartbeatComp.ArgHeartbeatV2Co
}
}

func Test_heartbeatV2Components_Create_ShouldWork(t *testing.T) {
func Test_heartbeatV2Components_Create(t *testing.T) {
t.Parallel()

defer func() {
r := recover()
if r != nil {
assert.Fail(t, "should not panic")
}
}()
t.Run("invalid config should error", func(t *testing.T) {
t.Parallel()

args := createMockHeartbeatV2ComponentsFactoryArgs()
hcf, err := heartbeatComp.NewHeartbeatV2ComponentsFactory(args)
assert.False(t, check.IfNil(hcf))
assert.Nil(t, err)
args := createMockHeartbeatV2ComponentsFactoryArgs()
args.Config.HeartbeatV2.HeartbeatExpiryTimespanInSec = args.Config.HeartbeatV2.PeerAuthenticationTimeBetweenSendsInSec
hcf, err := heartbeatComp.NewHeartbeatV2ComponentsFactory(args)
assert.False(t, check.IfNil(hcf))
assert.Nil(t, err)

hc, err := hcf.Create()
assert.NotNil(t, hc)
assert.Nil(t, err)
hc, err := hcf.Create()
assert.Nil(t, hc)
assert.True(t, errors.Is(err, errErd.ErrInvalidHeartbeatV2Config))
})
t.Run("should work", func(t *testing.T) {
t.Parallel()

err = hc.Close()
assert.Nil(t, err)
defer func() {
r := recover()
if r != nil {
assert.Fail(t, "should not panic")
}
}()

args := createMockHeartbeatV2ComponentsFactoryArgs()
hcf, err := heartbeatComp.NewHeartbeatV2ComponentsFactory(args)
assert.False(t, check.IfNil(hcf))
assert.Nil(t, err)

hc, err := hcf.Create()
assert.NotNil(t, hc)
assert.Nil(t, err)

err = hc.Close()
assert.Nil(t, err)
})
}
2 changes: 0 additions & 2 deletions heartbeat/processor/peerAuthenticationRequestsProcessor.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ type peerAuthenticationRequestsProcessor struct {
epoch uint32
minPeersThreshold float32
delayBetweenRequests time.Duration
maxTimeout time.Duration
maxMissingKeysInRequest uint32
randomizer dataRetriever.IntRandomizer
cancel func()
Expand All @@ -69,7 +68,6 @@ func NewPeerAuthenticationRequestsProcessor(args ArgPeerAuthenticationRequestsPr
epoch: args.Epoch,
minPeersThreshold: args.MinPeersThreshold,
delayBetweenRequests: args.DelayBetweenRequests,
maxTimeout: args.MaxTimeout,
maxMissingKeysInRequest: args.MaxMissingKeysInRequest,
randomizer: args.Randomizer,
}
Expand Down