Skip to content

Commit 436b8b8

Browse files
authored
Merge branch 'feat/testnet-fixes' into miniblock-inclusion-checks
2 parents 3a49028 + 5adab78 commit 436b8b8

93 files changed

Lines changed: 2844 additions & 323 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

cmd/node/config/config.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1158,6 +1158,7 @@
11581158
NumCrossShardPeers = 2
11591159
NumTotalPeers = 3 # NumCrossShardPeers + num intra shard
11601160
NumFullHistoryPeers = 3
1161+
RequestProofByNonceDelayMs = 100 # delay proof requests by nonce to allow the header to be received first
11611162

11621163
[HeartbeatV2]
11631164
PeerAuthenticationTimeBetweenSendsInSec = 600 # 10min TODO: change this for mainnet/devnet/testnet

cmd/node/config/enableEpochs.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,13 @@
372372
# RelayedTransactionsV1V2DisableEpoch represents the epoch when relayed transactions v1 and v2 are disabled
373373
RelayedTransactionsV1V2DisableEpoch = 1
374374

375+
# FullShardDataValidationEnableEpoch represents the epoch when NumPendingMiniBlocks and LastIncludedMetaNonce
376+
# in meta ShardData are enforced during verification; before it, these two fields are skipped.
377+
FullShardDataValidationEnableEpoch = 1
378+
379+
# ConsumedGasInEconomicsFixEnableEpoch represents the epoch when consumed gas in accumulated economics is fixed
380+
ConsumedGasInEconomicsFixEnableEpoch = 1
381+
375382
# BLSMultiSignerEnableEpoch represents the activation epoch for different types of BLS multi-signers
376383
BLSMultiSignerEnableEpoch = [
377384
{ EnableEpoch = 0, Type = "no-KOSK" },

common/constants.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -812,6 +812,9 @@ const (
812812
// MetricRelayedTransactionsV1V2DisableEpoch represents the epoch when relayed transactions v1 and v2 are disabled
813813
MetricRelayedTransactionsV1V2DisableEpoch = "erd_relayed_transactions_v1_v2_disable_epoch"
814814

815+
// MetricConsumedGasInEconomicsFixEnableEpoch represents the epoch when consumed gas for accumulated fees is fixed
816+
MetricConsumedGasInEconomicsFixEnableEpoch = "erd_consumed_gas_in_economics_fix_enable_epoch"
817+
815818
// MetricTailInflationEnableEpoch represents the epoch when tail inflation is enabled
816819
MetricTailInflationEnableEpoch = "erd_tail_inflation_enable_epoch"
817820

@@ -1331,6 +1334,8 @@ const (
13311334
AutomaticActivationOfNodesDisableFlag core.EnableEpochFlag = "AutomaticActivationOfNodesDisableFlag"
13321335
FixGetBalanceFlag core.EnableEpochFlag = "FixGetBalanceFlag"
13331336
RelayedTransactionsV1V2DisableFlag core.EnableEpochFlag = "RelayedTransactionsV1V2DisableFlag"
1337+
FullShardDataValidationFlag core.EnableEpochFlag = "FullShardDataValidationFlag"
1338+
ConsumedGasInEconomicsFlag core.EnableEpochFlag = "ConsumedGasInEconomicsFlag"
13341339
// all new flags must be added to createAllFlagsMap method, as part of enableEpochsHandler allFlagsDefined
13351340
)
13361341

common/enablers/enableEpochsHandler.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1002,6 +1002,20 @@ func (handler *enableEpochsHandler) createAllFlagsMap() {
10021002
activationEpoch: handler.enableEpochsConfig.RelayedTransactionsV1V2DisableEpoch,
10031003
activationEpochName: "RelayedTransactionsV1V2DisableEpoch",
10041004
},
1005+
common.FullShardDataValidationFlag: {
1006+
isActiveInEpoch: func(epoch uint32) bool {
1007+
return epoch >= handler.enableEpochsConfig.FullShardDataValidationEnableEpoch
1008+
},
1009+
activationEpoch: handler.enableEpochsConfig.FullShardDataValidationEnableEpoch,
1010+
activationEpochName: "FullShardDataValidationEnableEpoch",
1011+
},
1012+
common.ConsumedGasInEconomicsFlag: {
1013+
isActiveInEpoch: func(epoch uint32) bool {
1014+
return epoch >= handler.enableEpochsConfig.ConsumedGasInEconomicsFixEnableEpoch
1015+
},
1016+
activationEpoch: handler.enableEpochsConfig.ConsumedGasInEconomicsFixEnableEpoch,
1017+
activationEpochName: "ConsumedGasInEconomicsFixEnableEpoch",
1018+
},
10051019
}
10061020
}
10071021

common/enablers/enableEpochsHandler_test.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,9 @@ func createEnableEpochsConfig() config.EnableEpochs {
136136
BarnardOpcodesEnableEpoch: 116,
137137
AutomaticActivationOfNodesDisableEpoch: 117,
138138
RelayedTransactionsV1V2DisableEpoch: 118,
139-
SupernovaEnableEpoch: 119,
139+
FullShardDataValidationEnableEpoch: 119,
140+
ConsumedGasInEconomicsFixEnableEpoch: 120,
141+
SupernovaEnableEpoch: 121,
140142
}
141143
}
142144

@@ -344,6 +346,7 @@ func TestEnableEpochsHandler_IsFlagEnabled(t *testing.T) {
344346
require.True(t, handler.IsFlagEnabled(common.AndromedaFlag))
345347
require.True(t, handler.IsFlagEnabled(common.DynamicESDTFlag))
346348
require.True(t, handler.IsFlagEnabled(common.RelayedTransactionsV1V2DisableFlag))
349+
require.True(t, handler.IsFlagEnabled(common.FullShardDataValidationFlag))
347350
require.True(t, handler.IsFlagEnabled(common.SupernovaFlag))
348351
}
349352

@@ -481,6 +484,8 @@ func TestEnableEpochsHandler_GetActivationEpoch(t *testing.T) {
481484
require.Equal(t, cfg.AutomaticActivationOfNodesDisableEpoch, handler.GetActivationEpoch(common.AutomaticActivationOfNodesDisableFlag))
482485
require.Equal(t, cfg.FixGetBalanceEnableEpoch, handler.GetActivationEpoch(common.FixGetBalanceFlag))
483486
require.Equal(t, cfg.RelayedTransactionsV1V2DisableEpoch, handler.GetActivationEpoch(common.RelayedTransactionsV1V2DisableFlag))
487+
require.Equal(t, cfg.FullShardDataValidationEnableEpoch, handler.GetActivationEpoch(common.FullShardDataValidationFlag))
488+
require.Equal(t, cfg.ConsumedGasInEconomicsFixEnableEpoch, handler.GetActivationEpoch(common.ConsumedGasInEconomicsFlag))
484489
require.Equal(t, cfg.SupernovaEnableEpoch, handler.GetActivationEpoch(common.SupernovaFlag))
485490
}
486491

config/config.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -808,9 +808,10 @@ type TrieSyncConfig struct {
808808

809809
// RequesterConfig represents the config options to be used when setting up the requester instances
810810
type RequesterConfig struct {
811-
NumCrossShardPeers uint32
812-
NumTotalPeers uint32
813-
NumFullHistoryPeers uint32
811+
NumCrossShardPeers uint32
812+
NumTotalPeers uint32
813+
NumFullHistoryPeers uint32
814+
RequestProofByNonceDelayMs uint32
814815
}
815816

816817
// ChainParametersByEpochConfig holds chain parameters that are configurable based on epochs

config/epochConfig.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,8 @@ type EnableEpochs struct {
135135
FixGetBalanceEnableEpoch uint32
136136
AutomaticActivationOfNodesDisableEpoch uint32
137137
RelayedTransactionsV1V2DisableEpoch uint32
138+
FullShardDataValidationEnableEpoch uint32
139+
ConsumedGasInEconomicsFixEnableEpoch uint32
138140
BLSMultiSignerEnableEpoch []MultiSignerConfig
139141
}
140142

config/tomlConfig_test.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1307,8 +1307,11 @@ func TestEnableEpochConfig(t *testing.T) {
13071307
# RelayedTransactionsV1V2DisableEpoch represents the epoch when relayed transactions v1 and v2 are disabled
13081308
RelayedTransactionsV1V2DisableEpoch = 113
13091309
1310+
# ConsumedGasInEconomicsFixEnableEpoch represents the epoch when consumed gas in accumulated economics is fixed
1311+
ConsumedGasInEconomicsFixEnableEpoch = 114
1312+
13101313
# SupernovaEnableEpoch represents the epoch when sub-second finality will be enabled
1311-
SupernovaEnableEpoch = 114
1314+
SupernovaEnableEpoch = 115
13121315
13131316
# MaxNodesChangeEnableEpoch holds configuration for changing the maximum number of nodes and the enabling epoch
13141317
MaxNodesChangeEnableEpoch = [
@@ -1442,7 +1445,8 @@ func TestEnableEpochConfig(t *testing.T) {
14421445
AutomaticActivationOfNodesDisableEpoch: 111,
14431446
FixGetBalanceEnableEpoch: 112,
14441447
RelayedTransactionsV1V2DisableEpoch: 113,
1445-
SupernovaEnableEpoch: 114,
1448+
ConsumedGasInEconomicsFixEnableEpoch: 114,
1449+
SupernovaEnableEpoch: 115,
14461450
MaxNodesChangeEnableEpoch: []MaxNodesChangeConfig{
14471451
{
14481452
EpochEnable: 44,

consensus/spos/worker.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -608,6 +608,10 @@ func (wrk *Worker) doJobOnMessageWithHeader(cnsMsg *consensus.Message) error {
608608
return fmt.Errorf("%w : received header from consensus topic is invalid",
609609
err)
610610
}
611+
if wrk.enableEpochsHandler.IsFlagEnabledInEpoch(common.AndromedaFlag, header.GetEpoch()) {
612+
return fmt.Errorf("%w : received header on consensus topic after andromeda",
613+
ErrInvalidHeader)
614+
}
611615

612616
var valStatsRootHash []byte
613617
metaHeader, ok := header.(data.MetaHeaderHandler)

dataRetriever/requestHandlers/requestHandler.go

Lines changed: 57 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,17 @@ const uniqueEquivalentProofSuffix = "eqp"
3838
// TODO move the keys definitions that are whitelisted in core and use them in InterceptedData implementations, Identifiers() function
3939

4040
type resolverRequestHandler struct {
41-
mutEpoch sync.RWMutex
42-
epoch uint32
43-
shardID uint32
44-
maxTxsToRequest int
45-
requestersFinder dataRetriever.RequestersFinder
46-
requestedItemsHandler dataRetriever.RequestedItemsHandler
47-
whiteList dataRetriever.WhiteListHandler
48-
sweepTime time.Time
49-
requestInterval time.Duration
50-
mutSweepTime sync.Mutex
41+
mutEpoch sync.RWMutex
42+
epoch uint32
43+
shardID uint32
44+
maxTxsToRequest int
45+
requestersFinder dataRetriever.RequestersFinder
46+
requestedItemsHandler dataRetriever.RequestedItemsHandler
47+
whiteList dataRetriever.WhiteListHandler
48+
sweepTime time.Time
49+
requestInterval time.Duration
50+
requestProofByNonceDelay time.Duration
51+
mutSweepTime sync.Mutex
5152

5253
trieHashesAccumulator map[string]struct{}
5354
lastTrieRequestTime time.Time
@@ -62,6 +63,7 @@ func NewResolverRequestHandler(
6263
maxTxsToRequest int,
6364
shardID uint32,
6465
requestInterval time.Duration,
66+
requestProofByNonceDelay time.Duration,
6567
) (*resolverRequestHandler, error) {
6668

6769
if check.IfNil(finder) {
@@ -81,14 +83,15 @@ func NewResolverRequestHandler(
8183
}
8284

8385
rrh := &resolverRequestHandler{
84-
requestersFinder: finder,
85-
requestedItemsHandler: requestedItemsHandler,
86-
epoch: uint32(0), // will be updated after creation of the request handler
87-
shardID: shardID,
88-
maxTxsToRequest: maxTxsToRequest,
89-
whiteList: whiteList,
90-
requestInterval: requestInterval,
91-
trieHashesAccumulator: make(map[string]struct{}),
86+
requestersFinder: finder,
87+
requestedItemsHandler: requestedItemsHandler,
88+
epoch: uint32(0), // will be updated after creation of the request handler
89+
shardID: shardID,
90+
maxTxsToRequest: maxTxsToRequest,
91+
whiteList: whiteList,
92+
requestInterval: requestInterval,
93+
requestProofByNonceDelay: requestProofByNonceDelay,
94+
trieHashesAccumulator: make(map[string]struct{}),
9295
}
9396

9497
rrh.sweepTime = time.Now()
@@ -1002,46 +1005,50 @@ func (rrh *resolverRequestHandler) RequestEquivalentProofByNonce(headerShard uin
10021005

10031006
// RequestEquivalentProofByNonceForEpoch asks for equivalent proof for the provided header nonce and epoch
10041007
func (rrh *resolverRequestHandler) RequestEquivalentProofByNonceForEpoch(headerShard uint32, headerNonce uint64, epoch uint32) {
1005-
key := common.GetEquivalentProofNonceShardKey(headerNonce, headerShard)
1006-
if !rrh.testIfRequestIsNeeded([]byte(key), uniqueEquivalentProofSuffix) {
1007-
return
1008-
}
1008+
go func(requestEpoch uint32) {
1009+
key := common.GetEquivalentProofNonceShardKey(headerNonce, headerShard)
1010+
if !rrh.testIfRequestIsNeeded([]byte(key), uniqueEquivalentProofSuffix) {
1011+
return
1012+
}
10091013

1010-
log.Debug("requesting equivalent proof by nonce from network",
1011-
"headerNonce", headerNonce,
1012-
"headerShard", headerShard,
1013-
"epoch", epoch,
1014-
)
1014+
time.Sleep(rrh.requestProofByNonceDelay)
10151015

1016-
requester, err := rrh.getEquivalentProofsRequester(headerShard)
1017-
if err != nil {
1018-
log.Error("RequestEquivalentProofByNonceForEpoch.getEquivalentProofsRequester",
1019-
"error", err.Error(),
1016+
log.Debug("requesting equivalent proof by nonce from network",
10201017
"headerNonce", headerNonce,
1018+
"headerShard", headerShard,
1019+
"epoch", epoch,
10211020
)
1022-
return
1023-
}
10241021

1025-
proofsRequester, ok := requester.(EquivalentProofsRequester)
1026-
if !ok {
1027-
log.Warn("wrong assertion type when creating equivalent proofs requester")
1028-
return
1029-
}
1022+
requester, err := rrh.getEquivalentProofsRequester(headerShard)
1023+
if err != nil {
1024+
log.Error("RequestEquivalentProofByNonceForEpoch.getEquivalentProofsRequester",
1025+
"error", err.Error(),
1026+
"headerNonce", headerNonce,
1027+
)
1028+
return
1029+
}
10301030

1031-
rrh.whiteList.Add([][]byte{[]byte(key)})
1031+
proofsRequester, ok := requester.(EquivalentProofsRequester)
1032+
if !ok {
1033+
log.Warn("wrong assertion type when creating equivalent proofs requester")
1034+
return
1035+
}
10321036

1033-
err = proofsRequester.RequestDataFromNonce([]byte(key), epoch)
1034-
if err != nil {
1035-
log.Debug("RequestEquivalentProofByNonceForEpoch.RequestDataFromNonce",
1036-
"error", err.Error(),
1037-
"headerNonce", headerNonce,
1038-
"headerShard", headerShard,
1039-
"epoch", epoch,
1040-
)
1041-
return
1042-
}
1037+
rrh.whiteList.Add([][]byte{[]byte(key)})
1038+
1039+
err = proofsRequester.RequestDataFromNonce([]byte(key), epoch)
1040+
if err != nil {
1041+
log.Debug("RequestEquivalentProofByNonceForEpoch.RequestDataFromNonce",
1042+
"error", err.Error(),
1043+
"headerNonce", headerNonce,
1044+
"headerShard", headerShard,
1045+
"epoch", epoch,
1046+
)
1047+
return
1048+
}
10431049

1044-
rrh.addRequestedItems([][]byte{[]byte(key)}, uniqueEquivalentProofSuffix)
1050+
rrh.addRequestedItems([][]byte{[]byte(key)}, uniqueEquivalentProofSuffix)
1051+
}(epoch)
10451052
}
10461053

10471054
func (rrh *resolverRequestHandler) getEquivalentProofsRequester(headerShard uint32) (dataRetriever.Requester, error) {

0 commit comments

Comments
 (0)