Skip to content

Commit

Permalink
Merge pull request #385 from jhkimqd/jihwan/gasprice-logic
Browse files Browse the repository at this point in the history
refactor: change monitor gas price logic calculation
  • Loading branch information
jhkimqd authored Oct 3, 2024
2 parents 6e5ed41 + 00b7d33 commit fcb54d8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
13 changes: 11 additions & 2 deletions cmd/monitor/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"math/big"
"strconv"
"strings"
"sync"
"time"
Expand Down Expand Up @@ -567,8 +568,16 @@ func renderMonitorUI(ctx context.Context, ec *ethclient.Client, ms *monitorStatu
}
ms.BlocksLock.RUnlock()
renderedBlocks = renderedBlocksTemp
renderedBlocksMeanGasPrice := metrics.GetMeanGasPricePerBlock(renderedBlocks)
// First initialization will render no gas price because the GasPriceChart will have no data.
if renderedBlocksMeanGasPrice == nil {
skeleton.Current.Text = ui.GetCurrentText(skeleton.Current, ms.HeadBlock, "--", ms.PeerCount, ms.ChainID, rpcUrl)
} else {
// Under normal cases, the gas price will be derived from the last element of the GasPriceChart with 2 decimal places precision.
gasPriceStr := strconv.FormatFloat(renderedBlocksMeanGasPrice[len(renderedBlocksMeanGasPrice)-1]/1000000000, 'f', 2, 64)
skeleton.Current.Text = ui.GetCurrentText(skeleton.Current, ms.HeadBlock, gasPriceStr, ms.PeerCount, ms.ChainID, rpcUrl)
}

skeleton.Current.Text = ui.GetCurrentText(skeleton.Current, ms.HeadBlock, ms.GasPrice, ms.PeerCount, ms.ChainID, rpcUrl)
if txPoolStatusSupported {
skeleton.TxPool.Text = ui.GetTxPoolText(skeleton.TxPool, ms.TxPoolStatus.pending, ms.TxPoolStatus.queued)
}
Expand All @@ -578,7 +587,7 @@ func renderMonitorUI(ctx context.Context, ec *ethclient.Client, ms *monitorStatu
}

skeleton.TxPerBlockChart.Data = metrics.GetTxsPerBlock(renderedBlocks)
skeleton.GasPriceChart.Data = metrics.GetMeanGasPricePerBlock(renderedBlocks)
skeleton.GasPriceChart.Data = renderedBlocksMeanGasPrice // equivalent to metrics.GetMeanGasPricePerBlock(renderedBlocks)
skeleton.BlockSizeChart.Data = metrics.GetSizePerBlock(renderedBlocks)
// skeleton.pendingTxChart.Data = metrics.GetUnclesPerBlock(renderedBlocks)
skeleton.PendingTxChart.Data = observedPendingTxs.getValues(25)
Expand Down
4 changes: 2 additions & 2 deletions cmd/monitor/ui/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ type UiSkeleton struct {
Receipts *widgets.List
}

func GetCurrentText(widget *widgets.Paragraph, headBlock, gasPrice *big.Int, peerCount uint64, chainID *big.Int, rpcURL string) string {
func GetCurrentText(widget *widgets.Paragraph, headBlock *big.Int, gasPrice string, peerCount uint64, chainID *big.Int, rpcURL string) string {
// First column
height := fmt.Sprintf("Height: %s", headBlock.String())
timeInfo := fmt.Sprintf("Time: %s", time.Now().Format("02 Jan 06 15:04:05 MST"))
gasPriceString := fmt.Sprintf("Gas Price: %s gwei", new(big.Int).Div(gasPrice, metrics.UnitShannon).String())
gasPriceString := fmt.Sprintf("Gas Price: %s gwei", gasPrice)
peers := fmt.Sprintf("Peers: %d", peerCount)

// Second column
Expand Down

0 comments on commit fcb54d8

Please sign in to comment.