Skip to content

Commit 4c6deba

Browse files
committed
add logs for debug
1 parent 8a63059 commit 4c6deba

File tree

2 files changed

+52
-4
lines changed

2 files changed

+52
-4
lines changed

protocol/app/app.go

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,9 @@ import (
100100
"github.com/spf13/cast"
101101
"google.golang.org/grpc"
102102

103+
// Project logging helper for consistent logs with context
104+
applog "github.com/dydxprotocol/v4-chain/protocol/lib/log"
105+
103106
// App
104107
appconstants "github.com/dydxprotocol/v4-chain/protocol/app/constants"
105108
"github.com/dydxprotocol/v4-chain/protocol/app/flags"
@@ -355,6 +358,9 @@ type App struct {
355358
VaultKeeper vaultmodulekeeper.Keeper
356359
// this line is used by starport scaffolding # stargate/app/keeperDeclaration
357360

361+
// Instrumentation: store wall-clock when BeginBlock starts for execution duration metrics.
362+
beginBlockStartTime time.Time
363+
358364
ModuleManager *module.Manager
359365
ModuleBasics module.BasicManager
360366

@@ -1816,20 +1822,47 @@ func (app *App) BeginBlocker(ctx sdk.Context) (sdk.BeginBlock, error) {
18161822
proposerAddr := sdk.ConsAddress(ctx.BlockHeader().ProposerAddress)
18171823
middleware.Logger = ctx.Logger().With("proposer_cons_addr", proposerAddr.String())
18181824

1825+
// Record start time and compute consensus lag (header time to now) before execution.
1826+
app.beginBlockStartTime = time.Now()
1827+
consensusLag := app.beginBlockStartTime.Sub(ctx.BlockTime())
1828+
applog.InfoLog(
1829+
ctx,
1830+
"PIERRICK: BeginBlock timing",
1831+
"height", ctx.BlockHeight(),
1832+
"consensus_lag_ms", consensusLag.Milliseconds(),
1833+
)
1834+
18191835
return app.ModuleManager.BeginBlock(ctx)
18201836
}
18211837

18221838
// EndBlocker application updates every end block
18231839
func (app *App) EndBlocker(ctx sdk.Context) (sdk.EndBlock, error) {
1824-
// Measure the lag between current timestamp and the end blocker time stamp
1825-
// as an indicator of whether the node is lagging behind.
1840+
// Measure total lag vs header time for tip heuristic.
18261841
metrics.ModuleMeasureSince(metrics.EndBlocker, metrics.EndBlockerLag, ctx.BlockTime())
18271842

1843+
// Execution duration since BeginBlock start.
1844+
execDurationMs := int64(0)
1845+
if !app.beginBlockStartTime.IsZero() {
1846+
execDurationMs = time.Since(app.beginBlockStartTime).Milliseconds()
1847+
}
1848+
1849+
// Total lag includes consensus delay + execution time.
1850+
totalLag := time.Since(ctx.BlockTime())
1851+
const tipThresholdSeconds = 3
1852+
atTip := totalLag <= tipThresholdSeconds*time.Second
1853+
1854+
applog.InfoLog(
1855+
ctx,
1856+
"PIERRICK: EndBlock timing",
1857+
"height", ctx.BlockHeight(),
1858+
"exec_duration_ms", execDurationMs,
1859+
"total_lag_ms", totalLag.Milliseconds(),
1860+
"at_tip", atTip,
1861+
)
1862+
18281863
ctx = ctx.WithExecMode(lib.ExecModeEndBlock)
18291864

18301865
// Reset the logger for middleware.
1831-
// Note that the middleware is only used by `CheckTx` and `DeliverTx`, and not `EndBlocker`.
1832-
// Panics from `EndBlocker` will not be logged by the middleware and will lead to consensus failures.
18331866
middleware.Logger = app.Logger()
18341867

18351868
response, err := app.ModuleManager.EndBlock(ctx)

protocol/app/process/full_node_process_proposal.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import (
44
abci "github.com/cometbft/cometbft/abci/types"
55
"github.com/cosmos/cosmos-sdk/client"
66
sdk "github.com/cosmos/cosmos-sdk/types"
7+
8+
"github.com/dydxprotocol/v4-chain/protocol/lib/log"
79
)
810

911
// FullNodeProcessProposalHandler is the `ProcessProposal` implementation for full-nodes.
@@ -25,6 +27,14 @@ func FullNodeProcessProposalHandler(
2527
// Always return `abci.ResponseProcessProposal_ACCEPT`
2628
response := &abci.ResponseProcessProposal{Status: abci.ResponseProcessProposal_ACCEPT}
2729

30+
// Entry log to confirm FullNodeProcessProposalHandler invocation.
31+
log.InfoLog(
32+
ctx,
33+
"PIERRICK: FullNodeProcessProposalHandler invoked",
34+
"height", ctx.BlockHeight(),
35+
"num_txs", len(req.Txs),
36+
)
37+
2838
// Update the current block height and consensus round.
2939
if ctx.BlockHeight() != currentBlockHeight {
3040
currentBlockHeight = ctx.BlockHeight()
@@ -36,6 +46,8 @@ func FullNodeProcessProposalHandler(
3646

3747
txs, err := DecodeProcessProposalTxs(ctx, txConfig.TxDecoder(), req, bridgeKeeepr, pricesTxDecoder)
3848
if err != nil {
49+
log.ErrorLogWithError(ctx, "PIERRICK: FullNodeProcessProposalHandler decode failed; returning ACCEPT", err)
50+
log.InfoLog(ctx, "PIERRICK: FullNodeProcessProposalHandler returning", "status", response.Status.String())
3951
return response, nil
4052
}
4153

@@ -44,6 +56,8 @@ func FullNodeProcessProposalHandler(
4456
// would fail due to missing index prices.
4557
err = txs.ProposedOperationsTx.Validate()
4658
if err != nil {
59+
log.ErrorLogWithError(ctx, "PIERRICK: FullNodeProcessProposalHandler ProposedOperationsTx.Validate failed; returning ACCEPT", err)
60+
log.InfoLog(ctx, "PIERRICK: FullNodeProcessProposalHandler returning", "status", response.Status.String())
4761
return response, nil
4862
}
4963

@@ -52,6 +66,7 @@ func FullNodeProcessProposalHandler(
5266
clobKeeper.RecordMevMetrics(ctx, stakingKeeper, perpetualKeeper, txs.ProposedOperationsTx.msg)
5367
}
5468

69+
log.InfoLog(ctx, "PIERRICK: FullNodeProcessProposalHandler returning", "status", response.Status.String())
5570
return response, nil
5671
}
5772
}

0 commit comments

Comments
 (0)