Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
15 changes: 9 additions & 6 deletions pkg/cmd/run_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"os"
"os/signal"
"path/filepath"
"runtime"
"strings"
"syscall"
"time"
Expand All @@ -21,12 +22,12 @@
"github.com/evstack/ev-node/node"
rollconf "github.com/evstack/ev-node/pkg/config"
genesispkg "github.com/evstack/ev-node/pkg/genesis"
"github.com/evstack/ev-node/pkg/p2p"
"github.com/evstack/ev-node/pkg/p2p/key"
"github.com/evstack/ev-node/pkg/signer"
"github.com/evstack/ev-node/pkg/signer/file"
)

const DefaultMaxBlobSize = 2 * 1024 * 1024 // 2MB
const DefaultMaxBlobSize = 1.5 * 1024 * 1024 // 1.5MB

// ParseConfig is an helpers that loads the node configuration and validates it.
func ParseConfig(cmd *cobra.Command) (rollconf.Config, error) {
Expand Down Expand Up @@ -82,7 +83,7 @@
executor coreexecutor.Executor,
sequencer coresequencer.Sequencer,
da coreda.DA,
p2pClient *p2p.Client,
nodeKey *key.NodeKey,
datastore datastore.Batching,
nodeConfig rollconf.Config,
genesis genesispkg.Genesis,
Expand Down Expand Up @@ -138,7 +139,7 @@
sequencer,
da,
signer,
p2pClient,
nodeKey,

Check failure on line 142 in pkg/cmd/run_node.go

View workflow job for this annotation

GitHub Actions / lint / golangci-lint

cannot use nodeKey (variable of type *key.NodeKey) as *"github.com/evstack/ev-node/pkg/p2p".Client value in argument to node.NewNode

Check failure on line 142 in pkg/cmd/run_node.go

View workflow job for this annotation

GitHub Actions / test / Run Unit Tests

cannot use nodeKey (variable of type *key.NodeKey) as *"github.com/evstack/ev-node/pkg/p2p".Client value in argument to node.NewNode
genesis,
datastore,
metrics,
Expand All @@ -155,8 +156,10 @@
go func() {
defer func() {
if r := recover(); r != nil {
err := fmt.Errorf("node panicked: %v", r)
logger.Error().Interface("panic", r).Msg("Recovered from panic in node")
buf := make([]byte, 1024)
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The buffer size of 1024 bytes for capturing the stack trace might be too small for complex panics, potentially leading to truncated and incomplete stack traces. This would hinder debugging, which is contrary to the goal of this PR. It's recommended to use a larger buffer. For example, Go's net/http server uses a 64KB buffer for panic recovery.

Suggested change
buf := make([]byte, 1024)
buf := make([]byte, 64*1024)

n := runtime.Stack(buf, false)
err := fmt.Errorf("node panicked: %v\nstack trace:\n%s", r, buf[:n])
logger.Error().Interface("panic", r).Str("stacktrace", string(buf[:n])).Msg("Recovered from panic in node")
select {
case errCh <- err:
default:
Expand Down
18 changes: 13 additions & 5 deletions test/e2e/sut_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,25 +76,33 @@ func (s *SystemUnderTest) RunCmd(cmd string, args ...string) (string, error) {
}

// ExecCmd starts a process for the given command and manages it cleanup on test end.
func (s *SystemUnderTest) ExecCmd(cmd string, args ...string) {
func (s *SystemUnderTest) ExecCmd(cmd string, args ...string) *os.Process {
return s.ExecCmdWithLogPrefix("", cmd, args...)
}

// ExecCmdWithLogPrefix same as ExecCmd but prepends the given prefix to the log output
func (s *SystemUnderTest) ExecCmdWithLogPrefix(prefix, cmd string, args ...string) *os.Process {

executable := locateExecutable(cmd)
c := exec.Command( //nolint:gosec // used by tests only
executable,
args...,
)
c.Dir = WorkDir
s.watchLogs(c)
s.watchLogs(prefix, c)

err := c.Start()
require.NoError(s.t, err)
if s.debug {
s.logf("Exec cmd (pid: %d): %s %s", c.Process.Pid, executable, strings.Join(c.Args, " "))
s.logf("Exec cmd (pid: %d): %s %s", c.Process.Pid, executable, strings.Join(args, " "))
}
// cleanup when stopped
s.awaitProcessCleanup(c)
return c.Process
}

// AwaitNodeUp waits until a node is operational by checking both liveness and readiness.
// Fails tests when node is not up within the specified timeout.
func (s *SystemUnderTest) AwaitNodeUp(t *testing.T, rpcAddr string, timeout time.Duration) {
t.Helper()
t.Logf("Await node is up: %s", rpcAddr)
Expand Down Expand Up @@ -168,7 +176,7 @@ func (s *SystemUnderTest) awaitProcessCleanup(cmd *exec.Cmd) {
}()
}

func (s *SystemUnderTest) watchLogs(cmd *exec.Cmd) {
func (s *SystemUnderTest) watchLogs(prefix string, cmd *exec.Cmd) {
errReader, err := cmd.StderrPipe()
require.NoError(s.t, err)
outReader, err := cmd.StdoutPipe()
Expand All @@ -178,7 +186,7 @@ func (s *SystemUnderTest) watchLogs(cmd *exec.Cmd) {
logDir := filepath.Join(WorkDir, "testnet")
require.NoError(s.t, os.MkdirAll(logDir, 0o750))
testName := strings.ReplaceAll(s.t.Name(), "/", "-")
logfileName := filepath.Join(logDir, fmt.Sprintf("exec-%s-%s-%d.out", filepath.Base(cmd.Args[0]), testName, time.Now().UnixNano()))
logfileName := filepath.Join(logDir, prefix+fmt.Sprintf("exec-%s-%s-%d.out", filepath.Base(cmd.Args[0]), testName, time.Now().UnixNano()))
logfile, err := os.Create(logfileName)
require.NoError(s.t, err)
errReader = io.NopCloser(io.TeeReader(errReader, logfile))
Expand Down
Loading