Skip to content

Commit

Permalink
add logging
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangchiqing committed Nov 5, 2024
1 parent 8b6c091 commit 82dd472
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
19 changes: 17 additions & 2 deletions cmd/util/cmd/re-execute-block/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,11 @@ func init() {
_ = Cmd.MarkPersistentFlagRequired("nodeid")

Cmd.Flags().IntVar(&flagFrom, "from", 0, "from segment")
_ = Cmd.MarkPersistentFlagRequired("from")
}

func run(*cobra.Command, []string) {
err := runWithFlags(flagDatadir, flagExecutionStateDir, flagChunkDataPackDir, flagBootstrapDir, flagExecutionDataDir, flagNodeID, uint64(flagFrom))
err := runWithFlags(flagDatadir, flagChunkDataPackDir, flagExecutionStateDir, flagBootstrapDir, flagExecutionDataDir, flagNodeID, uint64(flagFrom))
if err != nil {
log.Fatal().Err(err).Msg("could not run with flags")
}
Expand All @@ -100,6 +101,15 @@ func runWithFlags(
nodeID string,
height uint64,
) error {
log.Info().
Str("datadir", datadir).
Str("chunkDataPackDir", chunkDataPackDir).
Str("trieDir", trieDir).
Str("bootstrapDir", bootstrapDir).
Str("executionDataDir", executionDataDir).
Str("nodeID", nodeID).
Uint64("height", height).
Msg("re-execute block")

db := common.InitStorage(flagDatadir)
defer db.Close()
Expand Down Expand Up @@ -231,10 +241,15 @@ func ExecuteBlock(
return err
}

_, err = executeBlock(execState, computationManager, context.Background(), block)
log.Info().Msgf("executing block %v", block.Block.Header.ID())

result, err := executeBlock(execState, computationManager, context.Background(), block)
if err != nil {
return err
}

log.Info().Msgf("block %v executed, result ID: %v", block.Block.Header.ID(), result.ID())

return nil
}

Expand Down
8 changes: 8 additions & 0 deletions fvm/evm/handler/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/onflow/cadence/common"
gethCommon "github.com/onflow/go-ethereum/common"
gethTypes "github.com/onflow/go-ethereum/core/types"
"github.com/rs/zerolog/log"
"go.opentelemetry.io/otel/attribute"

"github.com/onflow/flow-go/fvm/environment"
Expand Down Expand Up @@ -399,6 +400,13 @@ func (h *ContractHandler) run(rlpEncodedTx []byte) (*types.Result, error) {
return nil, types.ErrUnexpectedEmptyResult
}

log.Info().
Str("tx_hash", res.TxHash.String()).
Uint64("gas_consumed", res.GasConsumed).
Uint64("cumulative_gas_used", res.CumulativeGasUsed).
Uint64("gas_refund", res.GasRefund).
Msg("executed transaction")

// step 6 - meter gas anyway (even for invalid or failed states)
err = h.meterGasUsage(res)
if err != nil {
Expand Down

0 comments on commit 82dd472

Please sign in to comment.