Skip to content

Commit 57bfb43

Browse files
authored
Merge branch 'feat/testnet-fixes' into nodes-coordinator-underflow-fix
2 parents d5537de + a1cc8c6 commit 57bfb43

73 files changed

Lines changed: 1478 additions & 331 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/CLI.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ GLOBAL OPTIONS:
7474
--repopulate-tokens-supplies Boolean flag for repopulating the tokens supplies database. It will delete the current data, iterate over the entire trie and add he new obtained supplies
7575
--p2p-prometheus-metrics Boolean option for enabling the /debug/metrics/prometheus route for p2p prometheus metrics
7676
--state-accesses-types-to-collect value String slice option for enabling collecting specified state accesses types. Can be (READ, WRITE)
77+
--print-prettified-header Boolean option for enabling the logging of prettified headers in consensus
7778
--help, -h show help
7879
--version, -v print the version
7980

cmd/node/config/config.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,12 @@
619619
Type = "SizeLRU"
620620
SizeInBytes = 52428800 # 50MB
621621

622+
[QuarantinedHeadersCache]
623+
Name = "QuarantinedHeadersCache"
624+
Capacity = 100
625+
Type = "SizeLRU"
626+
SizeInBytes = 10485760 # 10MB
627+
622628
[PostProcessTransactionsCache]
623629
Name = "PostProcessTransactionsCache"
624630
Capacity = 250000

cmd/node/flags.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,12 @@ var (
416416
Name: "state-accesses-types-to-collect",
417417
Usage: "String slice option for enabling collecting specified state accesses types. Can be (READ, WRITE)",
418418
}
419+
420+
// printPrettifiedHeader defines a flag for enabling prettified header logging
421+
printPrettifiedHeader = cli.BoolFlag{
422+
Name: "print-prettified-header",
423+
Usage: "Boolean option for enabling the logging of prettified headers in consensus",
424+
}
419425
)
420426

421427
func getFlags() []cli.Flag {
@@ -479,6 +485,7 @@ func getFlags() []cli.Flag {
479485
repopulateTokensSupplies,
480486
p2pPrometheusMetrics,
481487
stateAccessesTypesToCollect,
488+
printPrettifiedHeader,
482489
}
483490
}
484491

@@ -508,6 +515,7 @@ func getFlagsConfig(ctx *cli.Context, log logger.Logger) *config.ContextFlagsCon
508515
flagsConfig.OperationMode = ctx.GlobalString(operationMode.Name)
509516
flagsConfig.RepopulateTokensSupplies = ctx.GlobalBool(repopulateTokensSupplies.Name)
510517
flagsConfig.P2PPrometheusMetricsEnabled = ctx.GlobalBool(p2pPrometheusMetrics.Name)
518+
flagsConfig.PrintPrettifiedHeader = ctx.GlobalBool(printPrettifiedHeader.Name)
511519

512520
if ctx.GlobalBool(noKey.Name) {
513521
log.Warn("the provided -no-key option is deprecated and will soon be removed. To start a node without " +

common/common.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,21 @@ func PrepareTimestampBasedOnHeaderData(headerTimestamp uint64, headerEpoch uint3
302302
return timestampSec, timestampMs, nil
303303
}
304304

305+
// LogPrettifiedHeader logs the prettified representation of the provided header or an error if prettification fails
306+
func LogPrettifiedHeader(header data.HeaderHandler, sentOrReceived string, version string, configsHandler CommonConfigsHandler) {
307+
if !configsHandler.PrintPrettifiedHeader() {
308+
return
309+
}
310+
311+
headerOutput, err := PrettifyStruct(header)
312+
message := fmt.Sprintf("Proposed header %s %s", sentOrReceived, version)
313+
if err != nil {
314+
log.Debug(message, "error", err)
315+
} else {
316+
log.Debug(message, "header", headerOutput)
317+
}
318+
}
319+
305320
// PrettifyStruct returns a JSON string representation of a struct, converting byte slices to hex
306321
// and formatting big number values into readable strings. Useful for logging or debugging.
307322
func PrettifyStruct(x interface{}) (string, error) {

common/common_test.go

Lines changed: 206 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,34 @@ func TestPrettifyStruct(t *testing.T) {
505505
t.Log("MetaBlock", prettified)
506506

507507
})
508+
509+
t.Run("with headers V3", func(t *testing.T) {
510+
t.Parallel()
511+
512+
header := &block.HeaderV3{}
513+
prettified, err := common.PrettifyStruct(header)
514+
require.NoError(t, err)
515+
t.Log("HeaderV3", prettified)
516+
517+
meta := &block.MetaBlockV3{}
518+
prettified, err = common.PrettifyStruct(meta)
519+
require.NoError(t, err)
520+
t.Log("MetaBlockV3", prettified)
521+
})
522+
523+
t.Run("with complete headers V3", func(t *testing.T) {
524+
t.Parallel()
525+
526+
header := createMockShardHeaderV3()
527+
prettified, err := common.PrettifyStruct(header)
528+
require.NoError(t, err)
529+
t.Log("HeaderV3", prettified)
530+
531+
meta := createMockMetaHeaderV3()
532+
prettified, err = common.PrettifyStruct(meta)
533+
require.NoError(t, err)
534+
t.Log("MetaBlockV3", prettified)
535+
})
508536
}
509537

510538
func TestGetLastBaseExecutionResultHandler(t *testing.T) {
@@ -689,6 +717,184 @@ func TestPrepareLogEventsKey(t *testing.T) {
689717
require.Equal(t, "logsLogsX", string(logs))
690718
}
691719

720+
func createMockMetaHeaderV3() *block.MetaBlockV3 {
721+
return &block.MetaBlockV3{
722+
Nonce: 42,
723+
Epoch: 2,
724+
Round: 15,
725+
TimestampMs: 123456789,
726+
PrevHash: []byte("prev_hash"),
727+
PrevRandSeed: []byte("prev_seed"),
728+
RandSeed: []byte("new_seed"),
729+
ChainID: []byte("chain-id"),
730+
SoftwareVersion: []byte("v1.0.0"),
731+
LeaderSignature: []byte("leader_signature"),
732+
733+
MiniBlockHeaders: []block.MiniBlockHeader{
734+
{Hash: []byte("meta-to-s0"), SenderShardID: core.MetachainShardId, ReceiverShardID: 0},
735+
{Hash: []byte("meta-to-s1"), SenderShardID: core.MetachainShardId, ReceiverShardID: 1},
736+
},
737+
738+
ShardInfo: []block.ShardData{
739+
{
740+
ShardID: 0,
741+
Round: 10,
742+
Nonce: 41,
743+
Epoch: 1,
744+
HeaderHash: []byte("shard0-hash"),
745+
ShardMiniBlockHeaders: []block.MiniBlockHeader{
746+
{SenderShardID: 0, ReceiverShardID: 1, Hash: []byte("s0-to-s1")},
747+
},
748+
},
749+
{
750+
ShardID: 1,
751+
Round: 11,
752+
Nonce: 40,
753+
Epoch: 1,
754+
HeaderHash: []byte("shard1-hash"),
755+
ShardMiniBlockHeaders: []block.MiniBlockHeader{
756+
{SenderShardID: 1, ReceiverShardID: 0, Hash: []byte("s1-to-s0")},
757+
},
758+
},
759+
},
760+
ShardInfoProposal: []block.ShardDataProposal{
761+
{ShardID: 0, HeaderHash: []byte("shard-0-hash"), Nonce: 41, Round: 10, Epoch: 1},
762+
{ShardID: 1, HeaderHash: []byte("shard-1-hash"), Nonce: 40, Round: 11, Epoch: 1},
763+
},
764+
ExecutionResults: []*block.MetaExecutionResult{
765+
{
766+
ExecutionResult: &block.BaseMetaExecutionResult{
767+
BaseExecutionResult: &block.BaseExecutionResult{
768+
HeaderHash: []byte("hdr-hash-10"),
769+
HeaderNonce: 39,
770+
HeaderRound: 10,
771+
HeaderEpoch: 1,
772+
RootHash: []byte("root-hash-10"),
773+
},
774+
AccumulatedFeesInEpoch: big.NewInt(1000),
775+
DevFeesInEpoch: big.NewInt(100),
776+
ValidatorStatsRootHash: []byte("validator-stats-root-hash"),
777+
},
778+
AccumulatedFees: big.NewInt(1000),
779+
DeveloperFees: big.NewInt(100),
780+
ReceiptsHash: []byte("receipts hash"),
781+
},
782+
{
783+
ExecutionResult: &block.BaseMetaExecutionResult{
784+
BaseExecutionResult: &block.BaseExecutionResult{
785+
HeaderHash: []byte("hdr-hash-11"),
786+
HeaderNonce: 40,
787+
HeaderRound: 11,
788+
HeaderEpoch: 1,
789+
RootHash: []byte("root-hash-11"),
790+
},
791+
AccumulatedFeesInEpoch: big.NewInt(2000),
792+
DevFeesInEpoch: big.NewInt(200),
793+
ValidatorStatsRootHash: []byte("validator-stats-root-hash-1"),
794+
},
795+
AccumulatedFees: big.NewInt(2000),
796+
DeveloperFees: big.NewInt(200),
797+
ReceiptsHash: []byte("receipts-hash-1"),
798+
},
799+
{
800+
ExecutionResult: &block.BaseMetaExecutionResult{
801+
BaseExecutionResult: &block.BaseExecutionResult{
802+
HeaderHash: []byte("hdr-hash-last"),
803+
HeaderNonce: 41,
804+
HeaderRound: 12,
805+
HeaderEpoch: 2,
806+
RootHash: []byte("root-hash-last"),
807+
},
808+
AccumulatedFeesInEpoch: big.NewInt(3000),
809+
DevFeesInEpoch: big.NewInt(300),
810+
ValidatorStatsRootHash: []byte("validator-stats-root-hash-2"),
811+
},
812+
AccumulatedFees: big.NewInt(3000),
813+
DeveloperFees: big.NewInt(300),
814+
ReceiptsHash: []byte("receipts-hash-2"),
815+
},
816+
},
817+
818+
LastExecutionResult: &block.MetaExecutionResultInfo{
819+
NotarizedInRound: 14,
820+
ExecutionResult: &block.BaseMetaExecutionResult{
821+
BaseExecutionResult: &block.BaseExecutionResult{
822+
HeaderHash: []byte("hdr-hash-last"),
823+
HeaderNonce: 41,
824+
HeaderRound: 12,
825+
HeaderEpoch: 2,
826+
RootHash: []byte("root-hash-last"),
827+
},
828+
AccumulatedFeesInEpoch: big.NewInt(3000),
829+
DevFeesInEpoch: big.NewInt(300),
830+
ValidatorStatsRootHash: []byte("validator-stats-root-hash-2"),
831+
},
832+
},
833+
}
834+
}
835+
836+
func createMockShardHeaderV3() *block.HeaderV3 {
837+
var hdrNonce = uint64(56)
838+
var hdrRound = uint64(67)
839+
var hdrEpoch = uint32(78)
840+
return &block.HeaderV3{
841+
Nonce: hdrNonce,
842+
PrevHash: []byte("prev hash"),
843+
PrevRandSeed: []byte("prev rand seed"),
844+
RandSeed: []byte("rand seed"),
845+
ShardID: uint32(1),
846+
TimestampMs: 0,
847+
Round: hdrRound,
848+
Epoch: hdrEpoch,
849+
BlockBodyType: block.TxBlock,
850+
LeaderSignature: []byte("signature"),
851+
MiniBlockHeaders: nil,
852+
PeerChanges: nil,
853+
MetaBlockHashes: nil,
854+
TxCount: 0,
855+
ChainID: []byte("chain ID"),
856+
SoftwareVersion: []byte("version"),
857+
LastExecutionResult: &block.ExecutionResultInfo{
858+
ExecutionResult: &block.BaseExecutionResult{
859+
HeaderHash: []byte("header hash"),
860+
HeaderNonce: hdrNonce - 1,
861+
HeaderRound: hdrRound - 1,
862+
HeaderEpoch: hdrEpoch,
863+
RootHash: []byte("root hash"),
864+
},
865+
NotarizedInRound: hdrRound - 1,
866+
},
867+
ExecutionResults: []*block.ExecutionResult{
868+
{
869+
BaseExecutionResult: &block.BaseExecutionResult{
870+
HeaderHash: []byte("header hash"),
871+
HeaderNonce: hdrNonce - 3,
872+
HeaderRound: hdrRound - 3,
873+
HeaderEpoch: hdrEpoch - 1,
874+
RootHash: []byte("root hash"),
875+
},
876+
},
877+
{
878+
BaseExecutionResult: &block.BaseExecutionResult{
879+
HeaderHash: []byte("header hash"),
880+
HeaderNonce: hdrNonce - 2,
881+
HeaderRound: hdrRound - 2,
882+
HeaderEpoch: hdrEpoch - 1,
883+
RootHash: []byte("root hash"),
884+
},
885+
},
886+
{
887+
BaseExecutionResult: &block.BaseExecutionResult{
888+
HeaderHash: []byte("header hash"),
889+
HeaderNonce: hdrNonce - 1,
890+
HeaderRound: hdrRound - 1,
891+
HeaderEpoch: hdrEpoch,
892+
RootHash: []byte("root hash"),
893+
},
894+
},
895+
},
896+
}
897+
}
692898
func TestGetMiniBlockHeadersFromExecResult(t *testing.T) {
693899
t.Parallel()
694900

common/configs/commonConfigs.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ type commonConfigs struct {
3838
orderedEpochStartConfigByRound []config.EpochStartConfigByRound
3939
orderedConsensusConfigByEpoch []config.ConsensusConfigByEpoch
4040
orderedConsensusConfigByRound []config.ConsensusConfigByRound
41+
printPrettifiedHeader bool
4142
}
4243

4344
// NewCommonConfigsHandler creates a new process configs by epoch component
@@ -46,6 +47,7 @@ func NewCommonConfigsHandler(
4647
configsByRound []config.EpochStartConfigByRound,
4748
consensusConfigByEpoch []config.ConsensusConfigByEpoch,
4849
consensusConfigByRound []config.ConsensusConfigByRound,
50+
printPrettifiedHeader bool,
4951
) (*commonConfigs, error) {
5052
err := checkCommonConfigsByEpoch(configsByEpoch)
5153
if err != nil {
@@ -71,6 +73,7 @@ func NewCommonConfigsHandler(
7173
orderedEpochStartConfigByRound: make([]config.EpochStartConfigByRound, len(configsByRound)),
7274
orderedConsensusConfigByEpoch: make([]config.ConsensusConfigByEpoch, len(consensusConfigByEpoch)),
7375
orderedConsensusConfigByRound: make([]config.ConsensusConfigByRound, len(consensusConfigByRound)),
76+
printPrettifiedHeader: printPrettifiedHeader,
7477
}
7578

7679
// sort the config values in ascending order
@@ -297,6 +300,11 @@ func (cc *commonConfigs) GetActiveTimingBoundaryRound(round uint64) uint64 {
297300
return 0
298301
}
299302

303+
// PrintPrettifiedHeader returns whether prettified headers should be logged
304+
func (cc *commonConfigs) PrintPrettifiedHeader() bool {
305+
return cc.printPrettifiedHeader
306+
}
307+
300308
// IsInterfaceNil checks if the instance is nil
301309
func (cc *commonConfigs) IsInterfaceNil() bool {
302310
return cc == nil

0 commit comments

Comments
 (0)