Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: slightly improve node log lines #1916

Merged
merged 5 commits into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
13 changes: 11 additions & 2 deletions gno.land/cmd/gnoland/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@ import (
"go.uber.org/zap/zapcore"
)

var startGraphic = fmt.Sprintf(`
__ __
____ _____ ____ / /___ _____ ____/ /
/ __ %c/ __ \/ __ \/ / __ %c/ __ \/ __ /
/ /_/ / / / / /_/ / / /_/ / / / / /_/ /
\__, /_/ /_/\____/_/\__,_/_/ /_/\__,_/
Copy link
Member

Choose a reason for hiding this comment

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

nit picking, but...

doesn't match my water bottle because that one says gno.land (emphasis on the full stop), pls fix 😉

/____/
`, '`', '`')

gfanton marked this conversation as resolved.
Show resolved Hide resolved
type startCfg struct {
gnoRootDir string
skipFailingGenesisTxs bool
Expand Down Expand Up @@ -268,13 +277,13 @@ func execStart(c *startCfg, io commands.IO) error {
}
cfg.LocalApp = gnoApp

io.Println(startGraphic)

gnoNode, err := node.DefaultNewNode(cfg, logger)
if err != nil {
return fmt.Errorf("error in creating node: %w", err)
}

fmt.Fprintln(io.Err(), "Node created.")

if c.skipStart {
io.ErrPrintln("'--skip-start' is set. Exiting.")
return nil
Expand Down
69 changes: 30 additions & 39 deletions gno.land/cmd/gnoland/start_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,52 +3,43 @@ package main
import (
"bytes"
"context"
"os"
"path/filepath"
"strings"
"testing"
"time"

"github.com/gnolang/gno/tm2/pkg/commands"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

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

cases := []struct {
args []string
}{
{[]string{"start", "--skip-start", "--skip-failing-genesis-txs"}},
// {[]string{"--skip-start"}},
// FIXME: test seems flappy as soon as we have multiple cases.
}
os.Chdir(filepath.Join("..", "..")) // go to repo's root dir

for _, tc := range cases {
tc := tc
name := strings.Join(tc.args, " ")
t.Run(name, func(t *testing.T) {
t.Parallel()

mockOut := new(bytes.Buffer)
mockErr := new(bytes.Buffer)
io := commands.NewTestIO()
io.SetOut(commands.WriteNopCloser(mockOut))
io.SetErr(commands.WriteNopCloser(mockErr))
cmd := newRootCmd(io)

t.Logf(`Running "gnoland %s"`, strings.Join(tc.args, " "))
err := cmd.ParseAndRun(context.Background(), tc.args)
require.NoError(t, err)

stdout := mockOut.String()
stderr := mockErr.String()

require.Contains(t, stderr, "Node created.", "failed to create node")
require.Contains(t, stderr, "'--skip-start' is set. Exiting.", "not exited with skip-start")
require.NotContains(t, stdout, "panic:")
})
}
var (
nodeDir = t.TempDir()

args = []string{
"start",
"--skip-start",
"--skip-failing-genesis-txs",
"--data-dir",
nodeDir,
}
)

// Prepare the IO
mockOut := new(bytes.Buffer)
mockErr := new(bytes.Buffer)
io := commands.NewTestIO()
io.SetOut(commands.WriteNopCloser(mockOut))
io.SetErr(commands.WriteNopCloser(mockErr))

// Create and run the command
ctx, cancelFn := context.WithTimeout(context.Background(), 5*time.Second)
defer cancelFn()

cmd := newRootCmd(io)
require.NoError(t, cmd.ParseAndRun(ctx, args))

// Make sure the directory is created
assert.DirExists(t, nodeDir)
}

// TODO: test various configuration files?
13 changes: 7 additions & 6 deletions gno.land/pkg/gnoland/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

"github.com/gnolang/gno/gno.land/pkg/sdk/vm"
"github.com/gnolang/gno/gnovm/pkg/gnoenv"
"github.com/gnolang/gno/tm2/pkg/amino"
abci "github.com/gnolang/gno/tm2/pkg/bft/abci/types"
dbm "github.com/gnolang/gno/tm2/pkg/db"
"github.com/gnolang/gno/tm2/pkg/log"
Expand Down Expand Up @@ -155,18 +154,20 @@
}
}
// Run genesis txs.
for i, tx := range genState.Txs {
for _, tx := range genState.Txs {

Check warning on line 157 in gno.land/pkg/gnoland/app.go

View check run for this annotation

Codecov / codecov/patch

gno.land/pkg/gnoland/app.go#L157

Added line #L157 was not covered by tests
res := baseApp.Deliver(tx)
if res.IsErr() {
ctx.Logger().Error("LOG", "log", res.Log)
ctx.Logger().Error(fmt.Sprintf("#%d", i), "value", string(amino.MustMarshalJSON(tx)))
ctx.Logger().Error(
"Unable to deliver genesis tx",
"log", res.Log,
"error", res.Error,
"gas-used", res.GasUsed,
)

Check warning on line 165 in gno.land/pkg/gnoland/app.go

View check run for this annotation

Codecov / codecov/patch

gno.land/pkg/gnoland/app.go#L160-L165

Added lines #L160 - L165 were not covered by tests

// NOTE: comment out to ignore.
if !skipFailingGenesisTxs {
panic(res.Log)
}
} else {
ctx.Logger().Info("SUCCESS:", "value", string(amino.MustMarshalJSON(tx)))
}
}
// Done!
Expand Down
8 changes: 2 additions & 6 deletions gno.land/pkg/sdk/vm/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,6 @@ func (vm *VMKeeper) AddPackage(ctx sdk.Context, msg MsgAddPackage) error {
defer m2.Release()
m2.RunMemPackage(memPkg, true)

ctx.Logger().Info("CPUCYCLES", "addpkg", m2.Cycles)
return nil
}

Expand Down Expand Up @@ -285,7 +284,7 @@ func (vm *VMKeeper) Call(ctx sdk.Context, msg MsgCall) (res string, err error) {
m.Release()
}()
rtvs := m.Eval(xn)
ctx.Logger().Info("CPUCYCLES call", "num-cycles", m.Cycles)

for i, rtv := range rtvs {
res = res + rtv.String()
if i < len(rtvs)-1 {
Expand Down Expand Up @@ -349,7 +348,6 @@ func (vm *VMKeeper) Run(ctx sdk.Context, msg MsgRun) (res string, err error) {
})
defer m.Release()
_, pv := m.RunMemPackage(memPkg, false)
ctx.Logger().Info("CPUCYCLES", "addpkg", m.Cycles)

m2 := gno.NewMachineWithOptions(
gno.MachineOptions{
Expand All @@ -370,9 +368,7 @@ func (vm *VMKeeper) Run(ctx sdk.Context, msg MsgRun) (res string, err error) {
m2.Release()
}()
m2.RunMain()
ctx.Logger().Info("CPUCYCLES call",
"cycles", m2.Cycles,
)

res = buf.String()
return res, nil
}
Expand Down
62 changes: 53 additions & 9 deletions tm2/pkg/bft/consensus/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -947,8 +947,15 @@ func (cs *ConsensusState) defaultDecideProposal(height int64, round int) {
part := blockParts.GetPart(i)
cs.sendInternalMessage(msgInfo{&BlockPartMessage{cs.Height, cs.Round, part}, ""})
}
cs.Logger.Info("Signed proposal", "height", height, "round", round, "proposal", proposal)
cs.Logger.Debug(fmt.Sprintf("Signed proposal block: %v", block))

cs.Logger.Info(
"Signed proposal",
"height", height,
"round", round,
"proposal block ID", proposal.BlockID.String(),
"proposal round", proposal.POLRound,
"proposal timestamp", proposal.Timestamp.Unix(),
)
} else if !cs.replayMode {
cs.Logger.Error("enterPropose: Error signing proposal", "height", height, "round", round, "err", err)
}
Expand Down Expand Up @@ -1310,9 +1317,13 @@ func (cs *ConsensusState) finalizeCommit(height int64) {
panic(fmt.Sprintf("+2/3 committed an invalid block: %v", err))
}

cs.Logger.Info(fmt.Sprintf("Finalizing commit of block with %d txs", block.NumTxs),
"height", block.Height, "hash", block.Hash(), "root", block.AppHash)
cs.Logger.Info(fmt.Sprintf("%v", block))
cs.Logger.Info(
"Finalizing commit of block",
"root", block.AppHash,
"height", block.Height,
"hash", block.Hash(),
"num txs", block.NumTxs,
)

fail.Fail() // XXX

Expand Down Expand Up @@ -1415,7 +1426,16 @@ func (cs *ConsensusState) defaultSetProposal(proposal *types.Proposal) error {
if cs.ProposalBlockParts == nil {
cs.ProposalBlockParts = types.NewPartSetFromHeader(proposal.BlockID.PartsHeader)
}
cs.Logger.Info("Received proposal", "proposal", proposal)

cs.Logger.Info(
"Received proposal",
"height", proposal.Height,
"round", proposal.Round,
"proposal block ID", proposal.BlockID.String(),
"proposal round", proposal.POLRound,
"proposal timestamp", proposal.Timestamp.Unix(),
)

return nil
}

Expand Down Expand Up @@ -1573,7 +1593,13 @@ func (cs *ConsensusState) addVote(vote *types.Vote, peerID p2p.ID) (added bool,
switch vote.Type {
case types.PrevoteType:
prevotes := cs.Votes.Prevotes(vote.Round)
cs.Logger.Info("Added to prevote", "vote", vote, "prevotes", prevotes.StringShort())
cs.Logger.Debug(
"Added to prevote",
"type", vote.Type,
"vote height", vote.Height,
"vote round", vote.Round,
"prevotes", prevotes.StringShort(),
)

// If +2/3 prevotes for a block or nil for *any* round:
if blockID, ok := prevotes.TwoThirdsMajority(); ok {
Expand Down Expand Up @@ -1638,7 +1664,13 @@ func (cs *ConsensusState) addVote(vote *types.Vote, peerID p2p.ID) (added bool,

case types.PrecommitType:
precommits := cs.Votes.Precommits(vote.Round)
cs.Logger.Info("Added to precommit", "vote", vote, "precommits", precommits.StringShort())
cs.Logger.Debug(
"Added to precommit",
"type", vote.Type,
"vote height", vote.Height,
"vote round", vote.Round,
"precommits", precommits.StringShort(),
)

blockID, ok := precommits.TwoThirdsMajority()
if ok {
Expand Down Expand Up @@ -1713,7 +1745,19 @@ func (cs *ConsensusState) signAddVote(type_ types.SignedMsgType, hash []byte, he
vote, err := cs.signVote(type_, hash, header)
if err == nil {
cs.sendInternalMessage(msgInfo{&VoteMessage{vote}, ""})
cs.Logger.Info("Signed and pushed vote", "height", cs.Height, "round", cs.Round, "vote", vote, "err", err)

cs.Logger.Info(
"Signed and pushed vote",
"height", cs.Height,
"round", cs.Round,
"type", vote.Type,
"timestamp", vote.Timestamp.String(),
"height", vote.Height,
"round", vote.Round,
"validator address", vote.ValidatorAddress,
"validator index", vote.ValidatorIndex,
)

return vote
}
// if !cs.replayMode {
Expand Down
7 changes: 6 additions & 1 deletion tm2/pkg/p2p/switch.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,12 @@ func (sw *Switch) OnStop() {
// NOTE: Broadcast uses goroutines, so order of broadcast may not be preserved.
func (sw *Switch) Broadcast(chID byte, msgBytes []byte) chan bool {
startTime := time.Now()
sw.Logger.Debug("Broadcast", "channel", chID, "msgBytes", fmt.Sprintf("%X", msgBytes))

sw.Logger.Debug(
"Broadcast",
"channel", chID,
"value", fmt.Sprintf("%X", msgBytes),
)

peers := sw.peers.List()
var wg sync.WaitGroup
Expand Down
Loading