Skip to content

Commit ab502e9

Browse files
committed
return error in NewExecutor constructor
1 parent 71faa82 commit ab502e9

6 files changed

Lines changed: 22 additions & 11 deletions

File tree

block/internal/executing/executor.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,9 @@ func NewExecutor(
9393
logger zerolog.Logger,
9494
options common.BlockOptions,
9595
errorCh chan<- error,
96-
) *Executor {
96+
) (*Executor, error) {
9797
if signer == nil {
98-
panic("signer cannot be nil")
98+
return nil, errors.New("signer cannot be nil")
9999
}
100100

101101
return &Executor{
@@ -114,7 +114,7 @@ func NewExecutor(
114114
txNotifyCh: make(chan struct{}, 1),
115115
errorCh: errorCh,
116116
logger: logger.With().Str("component", "executor").Logger(),
117-
}
117+
}, nil
118118
}
119119

120120
// Start begins the execution component

block/internal/executing/executor_lazy_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func TestLazyMode_ProduceBlockLogic(t *testing.T) {
5050
hb := &mockBroadcaster[*types.SignedHeader]{}
5151
db := &mockBroadcaster[*types.Data]{}
5252

53-
exec := NewExecutor(
53+
exec, err := NewExecutor(
5454
memStore,
5555
mockExec,
5656
mockSeq,
@@ -65,6 +65,7 @@ func TestLazyMode_ProduceBlockLogic(t *testing.T) {
6565
common.DefaultBlockOptions(),
6666
make(chan error, 1),
6767
)
68+
require.NoError(t, err)
6869

6970
// Initialize state
7071
initStateRoot := []byte("init_root")
@@ -157,7 +158,7 @@ func TestRegularMode_ProduceBlockLogic(t *testing.T) {
157158
hb := &mockBroadcaster[*types.SignedHeader]{}
158159
db := &mockBroadcaster[*types.Data]{}
159160

160-
exec := NewExecutor(
161+
exec, err := NewExecutor(
161162
memStore,
162163
mockExec,
163164
mockSeq,
@@ -172,6 +173,7 @@ func TestRegularMode_ProduceBlockLogic(t *testing.T) {
172173
common.DefaultBlockOptions(),
173174
make(chan error, 1),
174175
)
176+
require.NoError(t, err)
175177

176178
// Initialize state
177179
initStateRoot := []byte("init_root")

block/internal/executing/executor_logic_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ func TestProduceBlock_EmptyBatch_SetsEmptyDataHash(t *testing.T) {
7171
hb := &mockBroadcaster[*types.SignedHeader]{}
7272
db := &mockBroadcaster[*types.Data]{}
7373

74-
exec := NewExecutor(
74+
exec, err := NewExecutor(
7575
memStore,
7676
mockExec,
7777
mockSeq,
@@ -86,6 +86,7 @@ func TestProduceBlock_EmptyBatch_SetsEmptyDataHash(t *testing.T) {
8686
common.DefaultBlockOptions(),
8787
make(chan error, 1),
8888
)
89+
require.NoError(t, err)
8990

9091
// Expect InitChain to be called
9192
initStateRoot := []byte("init_root")
@@ -156,7 +157,7 @@ func TestPendingLimit_SkipsProduction(t *testing.T) {
156157
hb := &mockBroadcaster[*types.SignedHeader]{}
157158
db := &mockBroadcaster[*types.Data]{}
158159

159-
exec := NewExecutor(
160+
exec, err := NewExecutor(
160161
memStore,
161162
mockExec,
162163
mockSeq,
@@ -171,6 +172,7 @@ func TestPendingLimit_SkipsProduction(t *testing.T) {
171172
common.DefaultBlockOptions(),
172173
make(chan error, 1),
173174
)
175+
require.NoError(t, err)
174176

175177
mockExec.EXPECT().InitChain(mock.Anything, mock.AnythingOfType("time.Time"), gen.InitialHeight, gen.ChainID).
176178
Return([]byte("i0"), uint64(1024), nil).Once()

block/internal/executing/executor_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ func TestExecutor_BroadcasterIntegration(t *testing.T) {
6464
require.NoError(t, err)
6565

6666
// Create executor with broadcasters
67-
executor := NewExecutor(
67+
executor, err := NewExecutor(
6868
memStore,
6969
nil, // nil executor (we're not testing execution)
7070
nil, // nil sequencer (we're not testing sequencing)
@@ -79,6 +79,7 @@ func TestExecutor_BroadcasterIntegration(t *testing.T) {
7979
common.DefaultBlockOptions(),
8080
make(chan error, 1),
8181
)
82+
require.NoError(t, err)
8283

8384
// Verify broadcasters are set
8485
assert.NotNil(t, executor.headerBroadcaster)
@@ -119,7 +120,7 @@ func TestExecutor_NilBroadcasters(t *testing.T) {
119120
require.NoError(t, err)
120121

121122
// Create executor with nil broadcasters (light node scenario)
122-
executor := NewExecutor(
123+
executor, err := NewExecutor(
123124
memStore,
124125
nil, // nil executor
125126
nil, // nil sequencer
@@ -134,6 +135,7 @@ func TestExecutor_NilBroadcasters(t *testing.T) {
134135
common.DefaultBlockOptions(),
135136
make(chan error, 1),
136137
)
138+
require.NoError(t, err)
137139

138140
// Verify broadcasters are nil
139141
assert.Nil(t, executor.headerBroadcaster)

block/internal/executing/reaper_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func newTestExecutor(t *testing.T) *Executor {
3232
s, err := noop.NewNoopSigner(priv)
3333
require.NoError(t, err)
3434

35-
exec := NewExecutor(
35+
exec, err := NewExecutor(
3636
nil, // store (unused)
3737
nil, // core executor (unused)
3838
nil, // sequencer (unused)
@@ -52,6 +52,8 @@ func newTestExecutor(t *testing.T) *Executor {
5252
common.DefaultBlockOptions(),
5353
make(chan error, 1), // error channel
5454
)
55+
require.NoError(t, err)
56+
5557
return exec
5658
}
5759

block/node.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ func NewAggregatorNode(
203203
// error channel for critical failures
204204
errorCh := make(chan error, 1)
205205

206-
executor := executing.NewExecutor(
206+
executor, err := executing.NewExecutor(
207207
store,
208208
exec,
209209
sequencer,
@@ -218,6 +218,9 @@ func NewAggregatorNode(
218218
blockOpts,
219219
errorCh,
220220
)
221+
if err != nil {
222+
return nil, fmt.Errorf("failed to create executor: %w", err)
223+
}
221224

222225
// Create DA submitter for aggregator nodes (with signer for submission)
223226
daSubmitter := submitting.NewDASubmitter(da, config, genesis, blockOpts, logger)

0 commit comments

Comments
 (0)