Skip to content

Commit 09ba7f3

Browse files
authored
Merge branch 'feat/supernova-async-exec' into fix-race-execution
2 parents 82892b5 + 1e217d8 commit 09ba7f3

32 files changed

+528
-147
lines changed

cmd/node/config/config.toml

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,30 @@
6464
]
6565

6666
ProcessConfigsByRound = [
67-
{ EnableRound = 0, MaxRoundsWithoutNewBlockReceived = 10, MaxRoundsWithoutCommittedBlock = 10, RoundModulusTriggerWhenSyncIsStuck = 20, MaxSyncWithErrorsAllowed = 10, MaxRoundsToKeepUnprocessedMiniBlocks = 300, MaxRoundsToKeepUnprocessedTransactions = 300},
68-
{ EnableRound = 440, MaxRoundsWithoutNewBlockReceived = 100, MaxRoundsWithoutCommittedBlock = 100, RoundModulusTriggerWhenSyncIsStuck = 200, MaxSyncWithErrorsAllowed = 100, MaxRoundsToKeepUnprocessedMiniBlocks = 3000, MaxRoundsToKeepUnprocessedTransactions = 3000 },
67+
{
68+
EnableRound = 0,
69+
MaxRoundsWithoutNewBlockReceived = 10,
70+
MaxRoundsWithoutCommittedBlock = 10,
71+
RoundModulusTriggerWhenSyncIsStuck = 20,
72+
MaxSyncWithErrorsAllowed = 10,
73+
MaxRoundsToKeepUnprocessedMiniBlocks = 300,
74+
MaxRoundsToKeepUnprocessedTransactions = 300,
75+
NumFloodingRoundsFastReacting = 10,
76+
NumFloodingRoundsSlowReacting = 2,
77+
NumFloodingRoundsOutOfSpecs = 2
78+
},
79+
{
80+
EnableRound = 440,
81+
MaxRoundsWithoutNewBlockReceived = 100,
82+
MaxRoundsWithoutCommittedBlock = 100,
83+
RoundModulusTriggerWhenSyncIsStuck = 200,
84+
MaxSyncWithErrorsAllowed = 100,
85+
MaxRoundsToKeepUnprocessedMiniBlocks = 3000,
86+
MaxRoundsToKeepUnprocessedTransactions = 3000,
87+
NumFloodingRoundsFastReacting = 100,
88+
NumFloodingRoundsSlowReacting = 20,
89+
NumFloodingRoundsOutOfSpecs = 20
90+
}
6991
]
7092

7193
EpochStartConfigsByEpoch = [
@@ -610,7 +632,6 @@
610632
[Antiflood.FastReacting.BlackList]
611633
ThresholdNumMessagesPerInterval = 1000
612634
ThresholdSizePerInterval = 8388608 #8MB/s
613-
NumFloodingRounds = 10
614635
PeerBanDurationInSeconds = 300
615636

616637
[Antiflood.SlowReacting]
@@ -625,7 +646,6 @@
625646
[Antiflood.SlowReacting.BlackList]
626647
ThresholdNumMessagesPerInterval = 10000
627648
ThresholdSizePerInterval = 37748736 # 36MB/interval
628-
NumFloodingRounds = 2
629649
PeerBanDurationInSeconds = 3600
630650

631651
[Antiflood.OutOfSpecs]
@@ -640,7 +660,6 @@
640660
[Antiflood.OutOfSpecs.BlackList]
641661
ThresholdNumMessagesPerInterval = 3600
642662
ThresholdSizePerInterval = 12582912 # 12MB/interval
643-
NumFloodingRounds = 2
644663
PeerBanDurationInSeconds = 3600
645664

646665
[Antiflood.PeerMaxOutput]

common/configs/commonConfigs.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const (
1818
var ErrEmptyCommonConfigsByEpoch = errors.New("empty common configs by epoch")
1919

2020
// ErrEmptyCommonConfigsByRound signals that an empty common configs by round has been provided
21-
var ErrEmptyCommonConfigsByRound = errors.New("empty common configs by epoch")
21+
var ErrEmptyCommonConfigsByRound = errors.New("empty common configs by round")
2222

2323
type commonConfigs struct {
2424
orderedEpochStartConfigByEpoch []config.EpochStartConfigByEpoch
@@ -140,7 +140,7 @@ func checkConsensusConfigsByEpoch(configsByEpoch []config.ConsensusConfigByEpoch
140140
return nil
141141
}
142142

143-
// GetMaxMetaNoncesBehind returns the max meta nonces behind by epoch
143+
// GetGracePeriodRoundsByEpoch returns the grace period rounds by epoch
144144
func (cc *commonConfigs) GetGracePeriodRoundsByEpoch(epoch uint32) uint32 {
145145
for i := len(cc.orderedEpochStartConfigByEpoch) - 1; i >= 0; i-- {
146146
if cc.orderedEpochStartConfigByEpoch[i].EnableEpoch <= epoch {
@@ -151,7 +151,7 @@ func (cc *commonConfigs) GetGracePeriodRoundsByEpoch(epoch uint32) uint32 {
151151
return defaultGracePeriodRounds // this should not happen
152152
}
153153

154-
// GetExtraDelayForRequestBlockInfoInMs returns the max meta nonces behind by epoch
154+
// GetExtraDelayForRequestBlockInfoInMs returns the extra delay for request block info by epoch
155155
func (cc *commonConfigs) GetExtraDelayForRequestBlockInfoInMs(epoch uint32) uint32 {
156156
for i := len(cc.orderedEpochStartConfigByEpoch) - 1; i >= 0; i-- {
157157
if cc.orderedEpochStartConfigByEpoch[i].EnableEpoch <= epoch {

common/configs/commonConfigs_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ func TestNewCommonConfigsHandler(t *testing.T) {
1414
t.Run("should return error for empty config by epoch", func(t *testing.T) {
1515
t.Parallel()
1616

17-
pce, err := configs.NewCommonConfigsHandler(nil, nil, nil)
17+
pce, err := configs.NewCommonConfigsHandler(nil, []config.EpochStartConfigByRound{}, []config.ConsensusConfigByEpoch{})
1818
require.Nil(t, pce)
1919
require.Equal(t, configs.ErrEmptyCommonConfigsByEpoch, err)
2020
})
2121

2222
t.Run("should return error for empty config by round", func(t *testing.T) {
2323
t.Parallel()
2424

25-
pce, err := configs.NewCommonConfigsHandler([]config.EpochStartConfigByEpoch{}, nil, nil)
25+
pce, err := configs.NewCommonConfigsHandler([]config.EpochStartConfigByEpoch{{EnableEpoch: 0}}, nil, []config.ConsensusConfigByEpoch{{EnableEpoch: 0}})
2626
require.Nil(t, pce)
2727
require.Equal(t, configs.ErrEmptyCommonConfigsByRound, err)
2828
})

common/configs/consts.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package configs
2+
3+
const (
4+
minRoundsToKeepUnprocessedData = uint64(1)
5+
minFloodingRounds = 2
6+
)
7+
8+
const (
9+
defaultMaxMetaNoncesBehind = 15
10+
defaultMaxMetaNoncesBehindForGlobalStuck = 30
11+
defaultMaxShardNoncesBehind = 15
12+
defaultMaxRoundsWithoutNewBlockReceived = 10
13+
defaultMaxRoundsWithoutCommittedBlock = 10
14+
defaultRoundModulusTriggerWhenSyncIsStuck = 20
15+
defaultMaxSyncWithErrorsAllowed = 20
16+
defaultMaxRoundsToKeepUnprocessedMiniBlocks = 3000
17+
defaultMaxRoundsToKeepUnprocessedTransactions = 3000
18+
defaultNumFloodingRoundsFastReacting = 20
19+
defaultNumFloodingRoundsSlowReacting = 20
20+
defaultNumFloodingRoundsOutOfSpecs = 20
21+
)

common/configs/dto/dto.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package dto
2+
3+
// ConfigVariable defines a config variable name
4+
type ConfigVariable string
5+
6+
const (
7+
// NumFloodingRoundsFastReacting defines variable name for NumFloodingRoundsFastReacting
8+
NumFloodingRoundsFastReacting ConfigVariable = "NumFloodingRoundsFastReacting"
9+
// NumFloodingRoundsSlowReacting defines variable name for NumFloodingRoundsSlowReacting
10+
NumFloodingRoundsSlowReacting ConfigVariable = "NumFloodingRoundsSlowReacting"
11+
// NumFloodingRoundsOutOfSpecs defines variable name for NumFloodingRoundsOutOfSpecs
12+
NumFloodingRoundsOutOfSpecs ConfigVariable = "NumFloodingRoundsOutOfSpecs"
13+
)

common/configs/errors.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package configs
2+
3+
import "errors"
4+
5+
// ErrEmptyProcessConfigsByEpoch signals that an empty process configs by epoch has been provided
6+
var ErrEmptyProcessConfigsByEpoch = errors.New("empty process configs by epoch")
7+
8+
// ErrEmptyProcessConfigsByRound signals that an empty process configs by round has been provided
9+
var ErrEmptyProcessConfigsByRound = errors.New("empty process configs by round")
10+
11+
// ErrDuplicatedEpochConfig signals that a duplicated config section has been provided
12+
var ErrDuplicatedEpochConfig = errors.New("duplicated epoch config")
13+
14+
// ErrDuplicatedRoundConfig signals that a duplicated config section has been provided
15+
var ErrDuplicatedRoundConfig = errors.New("duplicated round config")
16+
17+
// ErrMissingEpochZeroConfig signals that epoch zero configuration is missing
18+
var ErrMissingEpochZeroConfig = errors.New("missing configuration for epoch 0")
19+
20+
// ErrMissingRoundZeroConfig signals that base round configuration is missing
21+
var ErrMissingRoundZeroConfig = errors.New("missing base configuration for round")

common/configs/processConfigs.go

Lines changed: 56 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,42 @@
11
package configs
22

33
import (
4-
"errors"
54
"fmt"
65
"sort"
76

7+
"github.com/multiversx/mx-chain-core-go/core/check"
8+
"github.com/multiversx/mx-chain-go/common/configs/dto"
89
"github.com/multiversx/mx-chain-go/config"
910
"github.com/multiversx/mx-chain-go/process"
11+
logger "github.com/multiversx/mx-chain-logger-go"
1012
)
1113

12-
const minRoundsToKeepUnprocessedData = uint64(1)
13-
14-
const (
15-
defaultMaxMetaNoncesBehind = 15
16-
defaultMaxMetaNoncesBehindForGlobalStuck = 30
17-
defaultMaxShardNoncesBehind = 15
18-
defaultMaxRoundsWithoutNewBlockReceived = 10
19-
defaultMaxRoundsWithoutCommittedBlock = 10
20-
defaultRoundModulusTriggerWhenSyncIsStuck = 20
21-
defaultMaxSyncWithErrorsAllowed = 20
22-
defaultMaxRoundsToKeepUnprocessedMiniBlocks = 3000
23-
defaultMaxRoundsToKeepUnprocessedTransactions = 3000
24-
)
25-
26-
// ErrEmptyProcessConfigsByEpoch signals that an empty process configs by epoch has been provided
27-
var ErrEmptyProcessConfigsByEpoch = errors.New("empty process configs by epoch")
28-
29-
// ErrEmptyProcessConfigsByRound signals that an empty process configs by round has been provided
30-
var ErrEmptyProcessConfigsByRound = errors.New("empty process configs by round")
31-
32-
// ErrDuplicatedEpochConfig signals that a duplicated config section has been provided
33-
var ErrDuplicatedEpochConfig = errors.New("duplicated epoch config")
34-
35-
// ErrDuplicatedRoundConfig signals that a duplicated config section has been provided
36-
var ErrDuplicatedRoundConfig = errors.New("duplicated round config")
37-
38-
// ErrMissingEpochZeroConfig signals that epoch zero configuration is missing
39-
var ErrMissingEpochZeroConfig = errors.New("missing configuration for epoch 0")
14+
var log = logger.GetOrCreate("processConfigs")
4015

41-
// ErrMissingRoundZeroConfig signals that base round configuration is missing
42-
var ErrMissingRoundZeroConfig = errors.New("missing base configuration for round")
16+
type configByRoundSelector[T any] func(config.ProcessConfigByRound) T
17+
type configVariableHandler struct {
18+
valueSelector configByRoundSelector[uint64]
19+
defaultValue uint64
20+
}
4321

4422
// processConfigsByEpoch holds the process configuration for epoch changes
4523
type processConfigsByEpoch struct {
4624
orderedConfigByEpoch []config.ProcessConfigByEpoch
4725
orderedConfigByRound []config.ProcessConfigByRound
26+
roundNotifier process.RoundNotifier
27+
variablesMap map[dto.ConfigVariable]configVariableHandler
4828
}
4929

5030
// NewProcessConfigsHandler creates a new process configs by epoch component
5131
func NewProcessConfigsHandler(
5232
configsByEpoch []config.ProcessConfigByEpoch,
5333
configsByRound []config.ProcessConfigByRound,
34+
roundNotifier process.RoundNotifier,
5435
) (*processConfigsByEpoch, error) {
36+
if check.IfNil(roundNotifier) {
37+
return nil, fmt.Errorf("%w in NewProcessConfigsHandler", process.ErrNilRoundNotifier)
38+
}
39+
5540
err := checkConfigsByEpoch(configsByEpoch)
5641
if err != nil {
5742
return nil, err
@@ -65,6 +50,8 @@ func NewProcessConfigsHandler(
6550
pce := &processConfigsByEpoch{
6651
orderedConfigByEpoch: make([]config.ProcessConfigByEpoch, len(configsByEpoch)),
6752
orderedConfigByRound: make([]config.ProcessConfigByRound, len(configsByRound)),
53+
roundNotifier: roundNotifier,
54+
variablesMap: initCfgVarMap(),
6855
}
6956

7057
// sort the config values in ascending order
@@ -142,10 +129,24 @@ func checkRoundConfigValues(cfg config.ProcessConfigByRound) error {
142129
return fmt.Errorf("%w for MaxRoundsToKeepUnprocessedMiniBlocks, received %d, min expected %d",
143130
process.ErrInvalidValue, cfg.MaxRoundsToKeepUnprocessedMiniBlocks, minRoundsToKeepUnprocessedData)
144131
}
132+
if cfg.NumFloodingRoundsFastReacting < minFloodingRounds {
133+
return fmt.Errorf("%w for NumFloodingRoundsFastReacting, received %d, min expected %d",
134+
process.ErrInvalidValue, cfg.NumFloodingRoundsFastReacting, minFloodingRounds)
135+
}
136+
if cfg.NumFloodingRoundsSlowReacting < minFloodingRounds {
137+
return fmt.Errorf("%w for NumFloodingRoundsSlowReacting, received %d, min expected %d",
138+
process.ErrInvalidValue, cfg.NumFloodingRoundsSlowReacting, minFloodingRounds)
139+
}
140+
if cfg.NumFloodingRoundsOutOfSpecs < minFloodingRounds {
141+
return fmt.Errorf("%w for NumFloodingRoundsOutOfSpecs, received %d, min expected %d",
142+
process.ErrInvalidValue, cfg.NumFloodingRoundsOutOfSpecs, minFloodingRounds)
143+
}
145144

146145
return nil
147146
}
148147

148+
// TODO: We should probably get rid of all these functions and use only GetValue func, similar to how enableEpochsHandler works
149+
149150
// GetMaxMetaNoncesBehindByEpoch returns the max meta nonces behind by epoch
150151
func (pce *processConfigsByEpoch) GetMaxMetaNoncesBehindByEpoch(epoch uint32) uint32 {
151152
for i := len(pce.orderedConfigByEpoch) - 1; i >= 0; i-- {
@@ -182,7 +183,7 @@ func (pce *processConfigsByEpoch) GetMaxShardNoncesBehindByEpoch(epoch uint32) u
182183
func getConfigValueByRound[T any](
183184
configs []config.ProcessConfigByRound,
184185
round uint64,
185-
selector func(config.ProcessConfigByRound) T,
186+
selector configByRoundSelector[T],
186187
defaultValue T,
187188
) T {
188189
for i := len(configs) - 1; i >= 0; i-- {
@@ -266,6 +267,29 @@ func (pce *processConfigsByEpoch) GetMaxRoundsToKeepUnprocessedTransactions(roun
266267
)
267268
}
268269

270+
// GetValue returns the value of the provided variable for the current round
271+
func (pce *processConfigsByEpoch) GetValue(variable dto.ConfigVariable) uint64 {
272+
return pce.getValueByRound(variable, pce.roundNotifier.CurrentRound())
273+
}
274+
275+
func (pce *processConfigsByEpoch) getValueByRound(
276+
variable dto.ConfigVariable,
277+
round uint64,
278+
) uint64 {
279+
cfgVarHandler, ok := pce.variablesMap[variable]
280+
if !ok {
281+
log.Warn("processConfigsByEpoch.getValueByRound: variable not found in pce.variablesMap", "variable", variable)
282+
return 0
283+
}
284+
285+
return getConfigValueByRound(
286+
pce.orderedConfigByRound,
287+
round,
288+
cfgVarHandler.valueSelector,
289+
cfgVarHandler.defaultValue,
290+
)
291+
}
292+
269293
// IsInterfaceNil checks if the instance is nil
270294
func (pce *processConfigsByEpoch) IsInterfaceNil() bool {
271295
return pce == nil

0 commit comments

Comments
 (0)