Skip to content
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
10 changes: 10 additions & 0 deletions cmd/termui/presenter/blockInfoGetters.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,13 @@ func (psh *PresenterStatusHandler) GetAvgDurationProposedBlockReceivedOrSentFrom
func (psh *PresenterStatusHandler) GetAvgDurationProofReceivedFromProposedBlockReceivedOrSent() uint64 {
return psh.getFromCacheAsUint64(common.MetricAvgReceivedProof)
}

// GetNumTrackedBlocks returns how many blocks are currently tracked by txPool
func (psh *PresenterStatusHandler) GetNumTrackedBlocks() uint64 {
return psh.getFromCacheAsUint64(common.MetricNumTrackedBlocks)
}

// GetNumTrackedAccounts returns how many accounts are currently tracked by txPool
func (psh *PresenterStatusHandler) GetNumTrackedAccounts() uint64 {
return psh.getFromCacheAsUint64(common.MetricNumTrackedAccounts)
}
22 changes: 22 additions & 0 deletions cmd/termui/presenter/blockInfoGetters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,28 @@ func TestPresenterStatusHandler_GetAvgProofReceived(t *testing.T) {
assert.Equal(t, proofMs, result)
}

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

numTrackedBlocks := uint64(100)
presenterStatusHandler := NewPresenterStatusHandler()
presenterStatusHandler.SetUInt64Value(common.MetricNumTrackedBlocks, numTrackedBlocks)
result := presenterStatusHandler.GetNumTrackedBlocks()

assert.Equal(t, numTrackedBlocks, result)
}

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

numTrackedAccounts := uint64(100)
presenterStatusHandler := NewPresenterStatusHandler()
presenterStatusHandler.SetUInt64Value(common.MetricNumTrackedAccounts, numTrackedAccounts)
result := presenterStatusHandler.GetNumTrackedAccounts()

assert.Equal(t, numTrackedAccounts, result)
}

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

Expand Down
2 changes: 2 additions & 0 deletions cmd/termui/view/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ type Presenter interface {
GetDurationProofReceivedFromProposedBlockReceivedOrSent() uint64
GetAvgDurationProposedBlockReceivedOrSentFromRoundStart() uint64
GetAvgDurationProofReceivedFromProposedBlockReceivedOrSent() uint64
GetNumTrackedBlocks() uint64
GetNumTrackedAccounts() uint64
GetIsSyncing() uint64
GetTxPoolLoad() uint64
GetNonce() uint64
Expand Down
24 changes: 13 additions & 11 deletions cmd/termui/view/termuic/termuiRenders/widgetsRender.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,8 +299,8 @@ func computeRedundancyStr(redundancyLevel int64, redundancyIsMainActive string)
}

func (wr *WidgetsRender) prepareBlockInfo() {
// 8 rows and one column
numRows := 9
// 10 rows and one column
numRows := 10

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

update comment as well on L302

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

rows := make([][]string, numRows)

currentBlockHeight := wr.presenter.GetNonce()
Expand Down Expand Up @@ -343,27 +343,29 @@ func (wr *WidgetsRender) prepareBlockInfo() {
}
}

currentRoundTimestamp := wr.presenter.GetCurrentRoundTimestamp()
rows[8] = []string{fmt.Sprintf("Current round timestamp: %d", currentRoundTimestamp)}

durationStartRoundToSentOrReceivedBlock := float64(wr.presenter.GetDurationProposedBlockReceivedOrSentFromRoundStart()) / conversionFactorToSeconds
durationSentOrReceivedBlockToReceivedSignatures := float64(wr.presenter.GetDurationProofReceivedFromProposedBlockReceivedOrSent()) / conversionFactorToSeconds
durationSentOrReceivedBlockToReceivedProof := float64(wr.presenter.GetDurationProofReceivedFromProposedBlockReceivedOrSent()) / conversionFactorToSeconds

rows[6] = []string{
fmt.Sprintf("Received proposed block: %.6f sec | Received signatures: %.6f sec",
fmt.Sprintf("Received proposed block: %.6f sec | Received proof: %.6f sec",
durationStartRoundToSentOrReceivedBlock,
durationSentOrReceivedBlockToReceivedSignatures),
durationSentOrReceivedBlockToReceivedProof),
}

durationStartRoundToSentOrReceivedBlock = float64(wr.presenter.GetAvgDurationProposedBlockReceivedOrSentFromRoundStart()) / conversionFactorToSeconds
durationSentOrReceivedBlockToReceivedSignatures = float64(wr.presenter.GetAvgDurationProofReceivedFromProposedBlockReceivedOrSent()) / conversionFactorToSeconds
durationSentOrReceivedBlockToReceivedProof = float64(wr.presenter.GetAvgDurationProofReceivedFromProposedBlockReceivedOrSent()) / conversionFactorToSeconds

rows[7] = []string{
fmt.Sprintf("Avg Received proposed block: %.6f sec | Avg Received signatures: %.6f sec",
fmt.Sprintf("Avg Received proposed block: %.6f sec | Avg Received proof: %.6f sec",
durationStartRoundToSentOrReceivedBlock,
durationSentOrReceivedBlockToReceivedSignatures),
durationSentOrReceivedBlockToReceivedProof),
}

currentRoundTimestamp := wr.presenter.GetCurrentRoundTimestamp()
rows[8] = []string{fmt.Sprintf("Current round timestamp: %d", currentRoundTimestamp)}

rows[9] = []string{fmt.Sprintf("Num tracked blocks: %d, Num tracked accounts: %d", wr.presenter.GetNumTrackedBlocks(), wr.presenter.GetNumTrackedAccounts())}

wr.blockInfo.Title = "Block info:"
wr.blockInfo.RowSeparator = false
wr.blockInfo.Rows = rows
Expand Down
9 changes: 5 additions & 4 deletions cmd/termui/view/termuic/termuiRenders/widgetsRender_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ func TestPrepareBlockInfo(t *testing.T) {
presenterStatusHandler.SetUInt64Value(common.MetricReceivedProof, 3_000_000)
presenterStatusHandler.SetUInt64Value(common.MetricAvgReceivedOrSentProposedBlock, 1_000_000)
presenterStatusHandler.SetUInt64Value(common.MetricAvgReceivedProof, 1_500_000)
presenterStatusHandler.SetUInt64Value(common.MetricNumTrackedBlocks, 100)

wr := &WidgetsRender{
presenter: presenterStatusHandler,
Expand All @@ -77,16 +78,16 @@ func TestPrepareBlockInfo(t *testing.T) {

require.Equal(t, "Block info:", wr.blockInfo.Title)
require.False(t, wr.blockInfo.RowSeparator)
require.Len(t, wr.blockInfo.Rows, 9)
require.Len(t, wr.blockInfo.Rows, 10)

// Example: check one row
require.Contains(t, wr.blockInfo.Rows[0][0], fmt.Sprintf("Current block height: %d, size: %s", 42, "2.00 KB"))
require.Contains(t, wr.blockInfo.Rows[2][0], "hash")
require.Contains(t, wr.blockInfo.Rows[4][0], "Consensus state: ProposedBlock")
require.Contains(t, wr.blockInfo.Rows[5][0], "Consensus round state: Success")
require.Contains(t, wr.blockInfo.Rows[6][0], "Received proposed block: 0.002000 sec | Received signatures: 0.003000 sec")
require.Contains(t, wr.blockInfo.Rows[7][0], "Avg Received proposed block: 0.001000 sec | Avg Received signatures: 0.001500 sec")
require.Contains(t, wr.blockInfo.Rows[6][0], "Received proposed block: 0.002000 sec | Received proof: 0.003000 sec")
require.Contains(t, wr.blockInfo.Rows[7][0], "Avg Received proposed block: 0.001000 sec | Avg Received proof: 0.001500 sec")
require.Contains(t, wr.blockInfo.Rows[8][0], "Current round timestamp: 123456")
require.Contains(t, wr.blockInfo.Rows[3][0], "Cross check: cross123, final nonce: 99")

require.Contains(t, wr.blockInfo.Rows[9][0], "Num tracked blocks: 100")
}
6 changes: 6 additions & 0 deletions common/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,12 @@ const MetricAvgReceivedOrSentProposedBlock = "erd_consensus_average_received_or_
// has been sent or has reached the current node until proof was received.
const MetricAvgReceivedProof = "erd_consensus_average_received_sent_proof"

// MetricNumTrackedBlocks is the metric that specifies how many blocks are tracked by the txPool
const MetricNumTrackedBlocks = "erd_num_tracked_blocks"

// MetricNumTrackedAccounts is the metric that specifies how many accounts are tracked by the txPool
const MetricNumTrackedAccounts = "erd_num_tracked_accounts"

// MetricCreatedProposedBlock is the metric that specifies the percent of the block subround used for header and body
// creation (0 meaning that the block was created in no-time and 100 meaning that the block creation used all the
// subround spare duration)
Expand Down
2 changes: 2 additions & 0 deletions dataRetriever/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,8 @@ type ShardedDataCacherNotifier interface {
Keys() [][]byte
IsInterfaceNil() bool
CleanupSelfShardTxCache(accountsProvider common.AccountNonceProvider, randomness uint64, maxNum int, cleanupLoopMaximumDuration time.Duration)
GetNumTrackedBlocks() uint64
GetNumTrackedAccounts() uint64
OnExecutedBlock(blockHeader data.HeaderHandler) error
}

Expand Down
12 changes: 12 additions & 0 deletions dataRetriever/shardedData/shardedData.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,18 @@ func (sd *shardedData) CleanupSelfShardTxCache(_ common.AccountNonceProvider, _
log.Warn("shardedData.CleanupSelfShardTxCache() should not have been called")
}

// GetNumTrackedBlocks returns 0 (only to satisfy the interface dataRetriever.ShardedDataCacherNotifier)
func (sd *shardedData) GetNumTrackedBlocks() uint64 {
log.Warn("shardedData.GetNumTrackedBlocks() should not have been called")
return 0
}

// GetNumTrackedAccounts returns 0 (only to satisfy the interface dataRetriever.ShardedDataCacherNotifier)
func (sd *shardedData) GetNumTrackedAccounts() uint64 {
log.Warn("shardedData.GetNumTrackedAccounts() should not have been called")
return 0
}

// OnExecutedBlock does nothing (only to satisfy the interface dataRetriever.ShardedDataCacherNotifier)
func (sd *shardedData) OnExecutedBlock(_ data.HeaderHandler) error {
log.Warn("shardedData.OnExecutedBlock() should not have been called")
Expand Down
12 changes: 12 additions & 0 deletions dataRetriever/txpool/shardedTxPool.go
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,18 @@ func (txPool *shardedTxPool) CleanupSelfShardTxCache(accountsProvider common.Acc
)
}

// GetNumTrackedBlocks returns the number of blocks being tracked by the underlying TxCache
func (txPool *shardedTxPool) GetNumTrackedBlocks() uint64 {
cache := txPool.getSelfShardTxCache()
return cache.GetTrackerDiagnosis().GetNumTrackedBlocks()
}

// GetNumTrackedAccounts returns the number of accounts being tracked by the underlying TxCache
func (txPool *shardedTxPool) GetNumTrackedAccounts() uint64 {
cache := txPool.getSelfShardTxCache()
return cache.GetTrackerDiagnosis().GetNumTrackedAccounts()
}

// OnProposedBlock notifies the underlying TxCache
func (txPool *shardedTxPool) OnProposedBlock(blockHash []byte, blockBody *block.Body, blockHeader data.HeaderHandler, accountsProvider common.AccountNonceAndBalanceProvider, latestExecutedHash []byte) error {
cache := txPool.getSelfShardTxCache()
Expand Down
107 changes: 107 additions & 0 deletions dataRetriever/txpool/shardedTxPool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,113 @@ func TestShardedTxPool_getSelfShardTxCache(t *testing.T) {
require.Equal(t, pool.getTxCache("2"), pool.getSelfShardTxCache())
}

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

poolAsInterface, _ := newTxPoolToTest()
pool := poolAsInterface.(*shardedTxPool)

txCache := pool.getSelfShardTxCache()

numOfBlocks := 10
accountsProvider := txcachemocks.NewAccountNonceAndBalanceProviderMock()

for i := 1; i < numOfBlocks+1; i++ {
err := txCache.OnProposedBlock(
[]byte(fmt.Sprintf("hash%d", i)),
&block.Body{},
&block.Header{
Nonce: uint64(i),
PrevHash: []byte(fmt.Sprintf("hash%d", i-1)),
RootHash: []byte("rootHash0"),
},
accountsProvider,
[]byte("hash0"),
)
require.Nil(t, err)
}

require.Equal(t, uint64(numOfBlocks), pool.GetNumTrackedBlocks())
}

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

poolAsInterface, _ := newTxPoolToTest()
pool := poolAsInterface.(*shardedTxPool)

txCache := pool.getSelfShardTxCache()

accountsProvider := txcachemocks.NewAccountNonceAndBalanceProviderMock()
accountsProvider.GetRootHashCalled = func() ([]byte, error) {
return []byte("rootHash0"), nil
}
accountsProvider.SetNonce([]byte("alice"), 1)
accountsProvider.SetNonce([]byte("bob"), 40)
accountsProvider.SetNonce([]byte("carol"), 7)

pool.AddData([]byte("hash1"), createTx("alice", 1), 0, "0")
pool.AddData([]byte("hash2"), createTx("alice", 2), 0, "0")
pool.AddData([]byte("hash3"), createTx("alice", 3), 0, "0")

pool.AddData([]byte("hash4"), createTx("bob", 40), 0, "0")
pool.AddData([]byte("hash5"), createTx("bob", 41), 0, "0")
pool.AddData([]byte("hash6"), createTx("bob", 42), 0, "0")

pool.AddData([]byte("hash7"), createTx("carol", 7), 0, "0")
pool.AddData([]byte("hash8"), createTx("carol", 8), 0, "0")
miniblocks := []*block.MiniBlock{
{
TxHashes: [][]byte{
[]byte("hash1"),
[]byte("hash2"),
[]byte("hash3"),
},
SenderShardID: 0,
ReceiverShardID: 0,
Type: block.TxBlock,
},
{
TxHashes: [][]byte{
[]byte("hash4"),
[]byte("hash5"),
[]byte("hash6"),
},
SenderShardID: 0,
ReceiverShardID: 0,
Type: block.TxBlock,
},
{
TxHashes: [][]byte{
[]byte("hash7"),
[]byte("hash8"),
},
SenderShardID: 0,
ReceiverShardID: 0,
Type: block.TxBlock,
},
}

execHdr := &block.Header{Nonce: 1, RootHash: []byte("rootHash0")}
_ = txCache.OnExecutedBlock(execHdr)

err := txCache.OnProposedBlock(
[]byte("hash0"),
&block.Body{
MiniBlocks: miniblocks,
},
&block.Header{
Nonce: uint64(1),
PrevHash: []byte("hash0"),
RootHash: []byte("rootHash0"),
},
accountsProvider,
[]byte("hash0"),
)
require.Nil(t, err)
require.Equal(t, uint64(3), pool.GetNumTrackedAccounts())
}

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

Expand Down
3 changes: 3 additions & 0 deletions process/block/shardblock.go
Original file line number Diff line number Diff line change
Expand Up @@ -1075,6 +1075,9 @@ func (sp *shardProcessor) CommitBlock(
return err
}

sp.appStatusHandler.SetUInt64Value(common.MetricNumTrackedBlocks, sp.dataPool.Transactions().GetNumTrackedBlocks())

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be called also for metaBlock ?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, there is no Mempool on meta, so there is no SelectTransactions. We wouldn't have what to track here

sp.appStatusHandler.SetUInt64Value(common.MetricNumTrackedAccounts, sp.dataPool.Transactions().GetNumTrackedAccounts())

err = sp.dataPool.Transactions().OnExecutedBlock(headerHandler)
if err != nil {
log.Debug("dataPool.Transactions().OnExecutedBlock()", "error", err)
Expand Down
10 changes: 10 additions & 0 deletions testscommon/shardedDataCacheNotifierMock.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,3 +151,13 @@ func (sd *ShardedDataCacheNotifierMock) OnExecutedBlock(blockHeader data.HeaderH
func (mock *ShardedDataCacheNotifierMock) IsInterfaceNil() bool {
return mock == nil
}

// GetNumTrackedBlocks -
func (sd *ShardedDataCacheNotifierMock) GetNumTrackedBlocks() uint64 {
return 0
}

// GetNumTrackedAccounts -
func (sd *ShardedDataCacheNotifierMock) GetNumTrackedAccounts() uint64 {
return 0
}
20 changes: 20 additions & 0 deletions testscommon/shardedDataStub.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ type ShardedDataStub struct {
GetCountsCalled func() counting.CountsWithSize
KeysCalled func() [][]byte
CleanupSelfShardTxCacheCalled func(session interface{}, randomness uint64, maxNum int, cleanupLoopMaximumDuration time.Duration)
GetNumTrackedBlocksCalled func() uint64
GetNumTrackedAccountsCalled func() uint64
OnExecutedBlockCalled func(blockHeader data.HeaderHandler) error
}

Expand Down Expand Up @@ -139,6 +141,24 @@ func (sd *ShardedDataStub) CleanupSelfShardTxCache(accountsProvider common.Accou
}
}

// GetNumTrackedBlocks -
func (sd *ShardedDataStub) GetNumTrackedBlocks() uint64 {
if sd.GetNumTrackedBlocksCalled != nil {
return sd.GetNumTrackedBlocksCalled()
}

return 0
}

// GetNumTrackedAccounts -
func (sd *ShardedDataStub) GetNumTrackedAccounts() uint64 {
if sd.GetNumTrackedAccountsCalled != nil {
return sd.GetNumTrackedAccountsCalled()
}

return 0
}

// OnExecutedBlock -
func (sd *ShardedDataStub) OnExecutedBlock(blockHeader data.HeaderHandler) error {
if sd.OnExecutedBlockCalled != nil {
Expand Down
Loading