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

Feat/consensus size changes #4843

Merged
merged 123 commits into from
Jan 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
123 commits
Select commit Hold shift + click to select a range
774dba5
EN-13432: [wip] first implementation
bogdan-rosianu Nov 24, 2022
0862e6a
EN-13432: [wip] fix some tests
bogdan-rosianu Nov 28, 2022
39d2048
EN-13432: [wip] fix tests
bogdan-rosianu Nov 28, 2022
d2e2a2e
EN-13432: [wip] fix update package
bogdan-rosianu Nov 28, 2022
15cc311
EN-13432: fixes
bogdan-rosianu Nov 29, 2022
82d6e99
EN-13432: move chain parameters to config.toml
bogdan-rosianu Nov 29, 2022
b2eba45
Merge branch 'feat/optimise-consensus-sigcheck' into EN-13432-increas…
bogdan-rosianu Nov 29, 2022
c1d0367
EN-13432: code cleanup
bogdan-rosianu Dec 5, 2022
572a83b
Merge branch 'feat/optimise-consensus-sigcheck' into EN-13432-increas…
bogdan-rosianu Dec 5, 2022
5befd90
renaming
bogdan-rosianu Dec 5, 2022
29bbdd8
Merge branch 'feat/optimise-consensus-sigcheck' into EN-13432-increas…
bogdan-rosianu Dec 7, 2022
61d2233
EN-13432: extract new component for holding chain parameters
bogdan-rosianu Dec 7, 2022
37b4aca
EN-13432: refactor ratingsdata to use chain parameters handler
bogdan-rosianu Dec 8, 2022
9b5dccd
EN-13432: refactor ratingsdata to use chain parameters handler
bogdan-rosianu Dec 8, 2022
48f2b4c
EN-13432: update test values
bogdan-rosianu Dec 8, 2022
381af5b
Merge remote-tracking branch 'origin/rc/v1.5.0' into EN-13432-increas…
bogdan-rosianu Dec 8, 2022
eceb8f9
EN-13432: update matching versions for rating data steps
bogdan-rosianu Dec 8, 2022
8df2bde
fixes after review
bogdan-rosianu Dec 12, 2022
6914d33
use args for tests + added todo
bogdan-rosianu Dec 12, 2022
8a62898
check error on test
bogdan-rosianu Dec 12, 2022
a32b139
further fixes after review
bogdan-rosianu Dec 12, 2022
1da049e
further fixes after review
bogdan-rosianu Dec 12, 2022
adda94f
Merge pull request #4742 from ElrondNetwork/EN-13432-increase-shard-c…
bogdan-rosianu Dec 12, 2022
19a13a7
EN-13432: fix todos + refactoring
bogdan-rosianu Dec 13, 2022
09a6c65
Merge branch 'feat/consensus-size-changes' into EN-13432-consensus-gr…
bogdan-rosianu Dec 13, 2022
156b5ae
EN-13432: shuffler refactoring
bogdan-rosianu Dec 13, 2022
6b1da86
EN-13432: fixes after self review
bogdan-rosianu Dec 13, 2022
6bb172e
fixes after first review
bogdan-rosianu Dec 13, 2022
38d96a4
Merge pull request #4797 from ElrondNetwork/EN-13432-consensus-group-…
bogdan-rosianu Dec 14, 2022
3bb1758
Merge branch 'feat/consensus-size-changes' into EN-13432-shuffler-ref…
bogdan-rosianu Dec 14, 2022
f6be0d3
EN-13432: update index hashed nodes coordinator
bogdan-rosianu Dec 14, 2022
8441d0e
EN-13432: fix mock
bogdan-rosianu Dec 14, 2022
1fad090
EN-13432: fixes after review:
bogdan-rosianu Dec 16, 2022
7715298
Merge branch 'EN-13432-shuffler-refactoring' into EN-13432-nodes-coor…
bogdan-rosianu Dec 16, 2022
05b984e
EN-13432: params for epoch fixes
bogdan-rosianu Dec 20, 2022
28f22fb
use epoch-1 for consensus group size where needed
bogdan-rosianu Dec 21, 2022
7efe443
EN-13432: stub and mock cleanup
bogdan-rosianu Dec 21, 2022
dc61e55
EN-13432: use constants for a test
bogdan-rosianu Dec 21, 2022
e559437
Merge pull request #4799 from ElrondNetwork/EN-13432-shuffler-refacto…
bogdan-rosianu Dec 21, 2022
b643b9f
Merge branch 'feat/consensus-size-changes' into EN-13432-nodes-coordi…
bogdan-rosianu Dec 21, 2022
62290eb
Merge pull request #4806 from ElrondNetwork/EN-13432-nodes-coordinato…
bogdan-rosianu Dec 21, 2022
9b66182
Merge branch 'feat/consensus-size-changes' into EN-13432-nodes-coordi…
bogdan-rosianu Dec 22, 2022
1af4234
fixes after review
bogdan-rosianu Dec 22, 2022
742d02f
fixes after review
bogdan-rosianu Jan 4, 2023
bc62b16
Merge pull request #4819 from multiversx/EN-13432-nodes-coordinator-c…
bogdan-rosianu Jan 5, 2023
8b6847d
Merge branch 'rc/v1.5.0' into feat/consensus-size-changes
bogdan-rosianu Jan 5, 2023
90112fd
Merge pull request #4844 from multiversx/merge-rc-1-5-into-feat-conse…
bogdan-rosianu Jan 5, 2023
429c124
Merge branch 'rc/v1.5.0' into merge-rc-v1-5-into-feat-consensus-jan27
bogdan-rosianu Jan 27, 2023
42487ef
fixes after merge
bogdan-rosianu Jan 27, 2023
aa5cf68
remove empty stub file
bogdan-rosianu Jan 27, 2023
60c0fd6
fix import
bogdan-rosianu Jan 27, 2023
5cd466b
Merge pull request #4917 from multiversx/merge-rc-v1-5-into-feat-cons…
bogdan-rosianu Jan 27, 2023
8238e5b
chain parameters notifier
bogdan-rosianu Jan 30, 2023
be4806f
fix linter + stubs
bogdan-rosianu Jan 30, 2023
e071567
fix stub
bogdan-rosianu Jan 30, 2023
6b6e478
added test for the notification of the new params
bogdan-rosianu Jan 31, 2023
053fe06
remove unused interface
bogdan-rosianu Jan 31, 2023
617da1e
fix subscriber instance
bogdan-rosianu Feb 1, 2023
abc1890
fixes after review
bogdan-rosianu Feb 2, 2023
84c3c53
Merge branch 'rc/v1.5.0' into feat/consensus-size-changes
bogdan-rosianu Feb 17, 2023
c1f351a
Merge pull request #4997 from multiversx/merge-rc-v1-5-feat-consensus…
bogdan-rosianu Feb 17, 2023
1b49b5a
Merge branch 'feat/consensus-size-changes' into chain-parameters-noti…
bogdan-rosianu Feb 17, 2023
a885724
test renaming
bogdan-rosianu Feb 17, 2023
b210638
fix compilation issue
bogdan-rosianu Feb 17, 2023
56bcfb7
add changes from the consensus-group-size-further-updates branch
bogdan-rosianu Feb 21, 2023
19b2db2
remove option
bogdan-rosianu Feb 21, 2023
e057b76
Merge branch 'rc/v1.6.0' into merge-rc-v1-6-feat-consensus-size-mar30
bogdan-rosianu Mar 30, 2023
6d360bd
fix after merge
bogdan-rosianu Mar 30, 2023
df0b4fd
Merge pull request #5136 from multiversx/merge-rc-v1-6-feat-consensus…
bogdan-rosianu Mar 30, 2023
fbe6f81
Merge branch 'feat/consensus-size-changes' into chain-parameters-noti…
bogdan-rosianu Mar 30, 2023
55b9939
fix init in consensus components
bogdan-rosianu Mar 30, 2023
5601282
extended unit test
bogdan-rosianu Apr 3, 2023
961bb62
fixes after review
bogdan-rosianu Apr 11, 2023
ab675e9
Merge pull request #4927 from multiversx/chain-parameters-notifier
bogdan-rosianu Apr 11, 2023
10d9857
Merge branch 'rc/v1.6.0' into merge-rc-1-6-into-feat-cons-size-changes
bogdan-rosianu May 22, 2023
caef8e1
fixes after merge
bogdan-rosianu May 22, 2023
d8f23ab
fix tests
bogdan-rosianu May 23, 2023
89d3b84
Merge pull request #5264 from multiversx/merge-rc-1-6-into-feat-cons-…
bogdan-rosianu May 23, 2023
cb4f7be
Merge branch 'rc/v1.6.0' into feat/consensus-size-changes
bogdan-rosianu Jun 26, 2023
4580ae4
Merge pull request #5376 from multiversx/merge-rc-v1-6-into-cons-changes
bogdan-rosianu Jun 26, 2023
723f8ac
Merge branch 'rc/v1.6.0' into merge-rc-v1-6-cons-changes-aug11
bogdan-rosianu Aug 11, 2023
08a877c
go fmt + fixes after merge
bogdan-rosianu Aug 11, 2023
32c3f05
Merge pull request #5475 from multiversx/merge-rc-v1-6-cons-changes-a…
bogdan-rosianu Aug 11, 2023
05bd89f
Merge branch 'rc/v1.6.0' into merge-rc-v-6-cns-size-changes-aug24
bogdan-rosianu Aug 24, 2023
49fbaef
Merge pull request #5523 from multiversx/merge-rc-v-6-cns-size-change…
bogdan-rosianu Aug 24, 2023
d5b9d22
Merge branch 'rc/v1.6.0' into merge-rc-1-6-into-feat-cns-size-sep4
bogdan-rosianu Sep 4, 2023
b74dcf2
Merge pull request #5557 from multiversx/merge-rc-1-6-into-feat-cns-s…
bogdan-rosianu Sep 4, 2023
0c19dd3
Merge branch 'rc/v1.7.0' of https://github.com/multiversx/mx-chain-go…
sstanculeanu Dec 14, 2023
980f5ef
fixes after merge
sstanculeanu Dec 14, 2023
068c9bb
Merge pull request #5773 from multiversx/merge_rc170_into_feat_consen…
sstanculeanu Dec 14, 2023
d843e35
Merge branch 'rc/v1.7.0' of https://github.com/multiversx/mx-chain-go…
sstanculeanu Jan 30, 2024
3037288
fixed test
sstanculeanu Jan 30, 2024
9fd067f
Merge pull request #5889 from multiversx/merge_rc170_into_feat_consen…
sstanculeanu Jan 30, 2024
4da0c47
Merge branch 'rc/v1.7.next1' of https://github.com/multiversx/mx-chai…
sstanculeanu May 17, 2024
363bca1
fixes after merge
sstanculeanu May 21, 2024
049f19a
Merge branch 'rc/v1.7.next1' of https://github.com/multiversx/mx-chai…
sstanculeanu May 22, 2024
12b235e
Merge branch 'rc/v1.7.next1' of https://github.com/multiversx/mx-chai…
sstanculeanu May 31, 2024
c2a0007
Merge branch 'rc/v1.7.next1' of https://github.com/multiversx/mx-chai…
sstanculeanu Jul 3, 2024
4f9153f
fixes after merge
sstanculeanu Jul 3, 2024
d16c7fb
fix more tests
sstanculeanu Jul 4, 2024
cd9cd46
Merge branch 'rc/v1.7.next1' of https://github.com/multiversx/mx-chai…
sstanculeanu Jul 4, 2024
fafb7fa
fix TestNodesCoordinator_CustomConsensusGroupSize
sstanculeanu Jul 4, 2024
3950517
Merge pull request #6193 from multiversx/merge_rc17next1_into_feat_co…
AdoAdoAdo Jul 8, 2024
edfc0a0
fix linter issue
ssd04 Aug 12, 2024
e608d64
Merge pull request #6384 from multiversx/merge-rc-1.7.next1-to-rc-1.8.0
ssd04 Aug 14, 2024
0cf55cd
Merge branch 'rc/v1.8.0' into merge-rc-1.8.0-into-consensus-size-changes
ssd04 Aug 14, 2024
028ced7
fix merge conflicts
ssd04 Aug 14, 2024
61db306
Merge pull request #6389 from multiversx/merge-rc-1.8.0-into-consensu…
ssd04 Aug 14, 2024
34e02fe
increase coverage for nodesSetup
danielradu10 Aug 28, 2024
1e329af
fixed golangci-lint error
danielradu10 Aug 28, 2024
b8455ee
new small unit tests for increasing coverage
danielradu10 Aug 28, 2024
adc2d97
new unit tests for common.go file
danielradu10 Aug 28, 2024
169046a
small fix for golangci-lint
danielradu10 Aug 28, 2024
91f6e8f
small fix for coverage
danielradu10 Aug 28, 2024
1c53a7c
fixes after review
danielradu10 Aug 28, 2024
a3d6e1b
fixes after review
danielradu10 Aug 30, 2024
21f14fc
fix after review
danielradu10 Aug 30, 2024
4c37715
small fix after review
danielradu10 Sep 2, 2024
cfab5e3
fixes after review
danielradu10 Sep 3, 2024
7059530
Update sharding/oneShardCoordinator_test.go
danielradu10 Sep 3, 2024
fd44c6d
Merge pull request #6415 from multiversx/increase-sharding-coverage
AdoAdoAdo Sep 3, 2024
53b0d5f
Merge branch 'rc/andromeda' of https://github.com/multiversx/mx-chain…
sstanculeanu Jan 28, 2025
088c57f
Merge pull request #6743 from multiversx/merge_rc_andromeda_into_feat…
sstanculeanu Jan 28, 2025
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
5 changes: 5 additions & 0 deletions cmd/node/config/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@
# Make sure that this is greater than the unbonding period!
SetGuardianEpochsDelay = 2 # TODO: for mainnet should be 20, 2 is just for testing

# ChainParametersByEpoch defines chain operation configurable values that can be modified based on epochs
ChainParametersByEpoch = [
{ EnableEpoch = 0, RoundDuration = 6000, ShardConsensusGroupSize = 7, ShardMinNumNodes = 10, MetachainConsensusGroupSize = 10, MetachainMinNumNodes = 10, Hysteresis = 0.2, Adaptivity = false }
]

[HardwareRequirements]
CPUFlags = ["SSE4", "SSE42"]

Expand Down
7 changes: 0 additions & 7 deletions cmd/node/config/nodesSetup.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
{
"startTime": 0,
"roundDuration": 6000,
"consensusGroupSize": 7,
"minNodesPerShard": 10,
"metaChainConsensusGroupSize": 10,
"metaChainMinNodes": 10,
"hysteresis": 0.2,
"adaptivity": false,
"initialNodes": [
{
"info": "multikey - group1 - legacy delegation",
Expand Down
9 changes: 9 additions & 0 deletions cmd/node/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,14 @@ func readConfigs(ctx *cli.Context, log logger.Logger) (*config.Configs, error) {
}
log.Debug("config", "file", configurationPaths.RoundActivation)

var nodesSetup config.NodesConfig
configurationPaths.Nodes = ctx.GlobalString(nodesFile.Name)
err = core.LoadJsonFile(&nodesSetup, configurationPaths.Nodes)
if err != nil {
return nil, err
}
log.Debug("config", "file", configurationPaths.Nodes)

if ctx.IsSet(port.Name) {
mainP2PConfig.Node.Port = ctx.GlobalString(port.Name)
}
Expand Down Expand Up @@ -267,6 +275,7 @@ func readConfigs(ctx *cli.Context, log logger.Logger) (*config.Configs, error) {
ConfigurationPathsHolder: configurationPaths,
EpochConfig: epochConfig,
RoundConfig: roundConfig,
NodesConfig: &nodesSetup,
}, nil
}

Expand Down
97 changes: 97 additions & 0 deletions common/chainparametersnotifier/chainParametersNotifier.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
package chainparametersnotifier

import (
"sync"

"github.com/multiversx/mx-chain-core-go/core/check"
"github.com/multiversx/mx-chain-go/common"
"github.com/multiversx/mx-chain-go/config"
logger "github.com/multiversx/mx-chain-logger-go"
)

var log = logger.GetOrCreate("common/chainparameters")

type chainParametersNotifier struct {
mutData sync.RWMutex
wasInitialized bool
currentChainParameters config.ChainParametersByEpochConfig
mutHandler sync.RWMutex
handlers []common.ChainParametersSubscriptionHandler
}

// NewChainParametersNotifier creates a new instance of a chainParametersNotifier component
func NewChainParametersNotifier() *chainParametersNotifier {
return &chainParametersNotifier{
wasInitialized: false,
handlers: make([]common.ChainParametersSubscriptionHandler, 0),
}
}

// UpdateCurrentChainParameters should be called whenever new chain parameters become active on the network
func (cpn *chainParametersNotifier) UpdateCurrentChainParameters(params config.ChainParametersByEpochConfig) {
cpn.mutData.Lock()
shouldSkipParams := cpn.wasInitialized && cpn.currentChainParameters.EnableEpoch == params.EnableEpoch
if shouldSkipParams {
cpn.mutData.Unlock()

return
}
cpn.wasInitialized = true
cpn.currentChainParameters = params
cpn.mutData.Unlock()

cpn.mutHandler.RLock()
handlersCopy := make([]common.ChainParametersSubscriptionHandler, len(cpn.handlers))
copy(handlersCopy, cpn.handlers)
cpn.mutHandler.RUnlock()

log.Debug("chainParametersNotifier.UpdateCurrentChainParameters",
"enable epoch", params.EnableEpoch,
"shard consensus group size", params.ShardConsensusGroupSize,
"shard min number of nodes", params.ShardMinNumNodes,
"meta consensus group size", params.MetachainConsensusGroupSize,
"meta min number of nodes", params.MetachainMinNumNodes,
"round duration", params.RoundDuration,
"hysteresis", params.Hysteresis,
"adaptivity", params.Adaptivity,
)

for _, handler := range handlersCopy {
handler.ChainParametersChanged(params)
}
}

// RegisterNotifyHandler will register the provided handler to be called whenever chain parameters have changed
func (cpn *chainParametersNotifier) RegisterNotifyHandler(handler common.ChainParametersSubscriptionHandler) {
if check.IfNil(handler) {
return
}

cpn.mutHandler.Lock()
cpn.handlers = append(cpn.handlers, handler)
cpn.mutHandler.Unlock()

cpn.mutData.RLock()
handler.ChainParametersChanged(cpn.currentChainParameters)
cpn.mutData.RUnlock()
}

// CurrentChainParameters returns the current chain parameters
func (cpn *chainParametersNotifier) CurrentChainParameters() config.ChainParametersByEpochConfig {
cpn.mutData.RLock()
defer cpn.mutData.RUnlock()

return cpn.currentChainParameters
}

// UnRegisterAll removes all registered handlers queue
func (cpn *chainParametersNotifier) UnRegisterAll() {
cpn.mutHandler.Lock()
cpn.handlers = make([]common.ChainParametersSubscriptionHandler, 0)
cpn.mutHandler.Unlock()
}

// IsInterfaceNil returns true if there is no value under the interface
func (cpn *chainParametersNotifier) IsInterfaceNil() bool {
return cpn == nil
}
126 changes: 126 additions & 0 deletions common/chainparametersnotifier/chainParametersNotifier_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
package chainparametersnotifier

import (
"sync"
"testing"

"github.com/multiversx/mx-chain-core-go/core/check"
"github.com/multiversx/mx-chain-go/config"
"github.com/stretchr/testify/require"
)

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

notifier := NewChainParametersNotifier()
require.False(t, check.IfNil(notifier))
}

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

notifier := NewChainParametersNotifier()
require.False(t, check.IfNil(notifier))

chainParams := config.ChainParametersByEpochConfig{
EnableEpoch: 7,
Adaptivity: true,
Hysteresis: 0.7,
}
notifier.UpdateCurrentChainParameters(chainParams)

resultedChainParams := notifier.CurrentChainParameters()
require.NotNil(t, resultedChainParams)

// update with same epoch but other params - should not change (impossible scenario in production, but easier for tests)
chainParams.Hysteresis = 0.8
notifier.UpdateCurrentChainParameters(chainParams)
require.Equal(t, float32(0.7), notifier.CurrentChainParameters().Hysteresis)

chainParams.Hysteresis = 0.8
chainParams.EnableEpoch = 8
notifier.UpdateCurrentChainParameters(chainParams)
require.Equal(t, float32(0.8), notifier.CurrentChainParameters().Hysteresis)
}

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

notifier := NewChainParametersNotifier()
require.False(t, check.IfNil(notifier))

// register a nil handler - should not panic
notifier.RegisterNotifyHandler(nil)

testNotifee := &dummyNotifee{}
notifier.RegisterNotifyHandler(testNotifee)

chainParams := config.ChainParametersByEpochConfig{
ShardMinNumNodes: 37,
}
notifier.UpdateCurrentChainParameters(chainParams)

require.Equal(t, chainParams, testNotifee.receivedChainParameters)
}

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

notifier := NewChainParametersNotifier()
require.False(t, check.IfNil(notifier))

testNotifee := &dummyNotifee{}
notifier.RegisterNotifyHandler(testNotifee)
notifier.UnRegisterAll()

chainParams := config.ChainParametersByEpochConfig{
ShardMinNumNodes: 37,
}
notifier.UpdateCurrentChainParameters(chainParams)

require.Empty(t, testNotifee.receivedChainParameters)
}

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

notifier := NewChainParametersNotifier()

numOperations := 500
wg := sync.WaitGroup{}
wg.Add(numOperations)
for i := 0; i < numOperations; i++ {
go func(idx int) {
switch idx {
case 0:
notifier.RegisterNotifyHandler(&dummyNotifee{})
case 1:
_ = notifier.CurrentChainParameters()
case 2:
notifier.UpdateCurrentChainParameters(config.ChainParametersByEpochConfig{})
case 3:
notifier.UnRegisterAll()
case 4:
_ = notifier.IsInterfaceNil()
}

wg.Done()
}(i % 5)
}

wg.Wait()
}

type dummyNotifee struct {
receivedChainParameters config.ChainParametersByEpochConfig
}

// ChainParametersChanged -
func (dn *dummyNotifee) ChainParametersChanged(chainParameters config.ChainParametersByEpochConfig) {
dn.receivedChainParameters = chainParameters
}

// IsInterfaceNil -
func (dn *dummyNotifee) IsInterfaceNil() bool {
return dn == nil
}
4 changes: 3 additions & 1 deletion common/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -851,6 +851,8 @@ const (
const (
// StorerOrder defines the order of storers to be notified of a start of epoch event
StorerOrder = iota
// ChainParametersOrder defines the order in which ChainParameters is notified of a start of epoch event
ChainParametersOrder
// NodesCoordinatorOrder defines the order in which NodesCoordinator is notified of a start of epoch event
NodesCoordinatorOrder
// ConsensusOrder defines the order in which Consensus is notified of a start of epoch event
Expand Down Expand Up @@ -963,7 +965,7 @@ const PutInStorerMaxTime = time.Second
const DefaultUnstakedEpoch = math.MaxUint32

// InvalidMessageBlacklistDuration represents the time to keep a peer in the black list if it sends a message that
// does not follow the protocol: example not useing the same marshaler as the other peers
// does not follow the protocol: example not using the same marshaler as the other peers
const InvalidMessageBlacklistDuration = time.Second * 3600

// PublicKeyBlacklistDuration represents the time to keep a public key in the black list if it will degrade its
Expand Down
32 changes: 32 additions & 0 deletions common/forking/genericEpochNotifier_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package forking

import (
"sync"
"sync/atomic"
"testing"
"time"

"github.com/multiversx/mx-chain-core-go/core/check"
"github.com/multiversx/mx-chain-core-go/data/block"
"github.com/multiversx/mx-chain-go/common/mock"
"github.com/multiversx/mx-chain-go/testscommon"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -152,3 +154,33 @@ func TestGenericEpochNotifier_CheckEpochInSyncShouldWork(t *testing.T) {
assert.Equal(t, uint32(2), atomic.LoadUint32(&numCalls))
assert.True(t, end.Sub(start) >= handlerWait)
}

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

notifier := NewGenericEpochNotifier()

numOperations := 500
wg := sync.WaitGroup{}
wg.Add(numOperations)
for i := 0; i < numOperations; i++ {
go func(idx int) {
switch idx {
case 0:
notifier.RegisterNotifyHandler(&mock.EpochSubscriberHandlerStub{})
case 1:
_ = notifier.CurrentEpoch()
case 2:
notifier.CheckEpoch(&block.MetaBlock{Epoch: 5})
case 3:
notifier.UnRegisterAll()
case 4:
_ = notifier.IsInterfaceNil()
}

wg.Done()
}(i % 5)
}

wg.Wait()
}
7 changes: 7 additions & 0 deletions common/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/multiversx/mx-chain-core-go/data"
"github.com/multiversx/mx-chain-core-go/data/block"
crypto "github.com/multiversx/mx-chain-crypto-go"
"github.com/multiversx/mx-chain-go/config"
)

// TrieIteratorChannels defines the channels that are being used when iterating the trie nodes
Expand Down Expand Up @@ -372,3 +373,9 @@ type ExecutionOrderGetter interface {
Len() int
IsInterfaceNil() bool
}

// ChainParametersSubscriptionHandler defines the behavior of a chain parameters subscription handler
type ChainParametersSubscriptionHandler interface {
ChainParametersChanged(chainParameters config.ChainParametersByEpochConfig)
IsInterfaceNil() bool
}
Loading
Loading