Skip to content

Commit 64e0a79

Browse files
Remove context from GetDONTime (#1471)
* Use node time * Update execution.go * Remove ctx * Use Node Mode for clockTimeGet * Undo secondary hook * Use mode
1 parent 91ec077 commit 64e0a79

File tree

6 files changed

+31
-31
lines changed

6 files changed

+31
-31
lines changed

pkg/workflows/wasm/host/execution.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,8 @@ func (e *execution[T]) switchModes(_ *wasmtime.Caller, mode int32) {
166166
e.mode = sdkpb.Mode(mode)
167167
}
168168

169+
// clockTimeGet is the default time.Now() which is also called by Go many times.
170+
// This implementation uses Node Mode to not have to wait for OCR rounds.
169171
func (e *execution[T]) clockTimeGet(caller *wasmtime.Caller, id int32, precision int64, resultTimestamp int32) int32 {
170172
donTime, err := e.timeFetcher.GetTime(e.mode)
171173
if err != nil {

pkg/workflows/wasm/host/mock_execution_helper_test.go

Lines changed: 14 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/workflows/wasm/host/module.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ type ExecutionHelper interface {
100100

101101
GetNodeTime() time.Time
102102

103-
GetDONTime(ctx context.Context) (time.Time, error)
103+
GetDONTime() (time.Time, error)
104104

105105
EmitUserLog(log string) error
106106
}

pkg/workflows/wasm/host/standard_test.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ func TestStandardCapabilityCallsAreAsync(t *testing.T) {
7979
mockExecutionHelper.EXPECT().GetNodeTime().RunAndReturn(func() time.Time {
8080
return time.Now()
8181
}).Maybe()
82-
mockExecutionHelper.EXPECT().GetDONTime(mock.Anything).RunAndReturn(func(ctx context.Context) (time.Time, error) {
82+
mockExecutionHelper.EXPECT().GetDONTime().RunAndReturn(func() (time.Time, error) {
8383
return time.Now(), nil
8484
}).Maybe()
8585
m := makeTestModule(t)
@@ -131,7 +131,7 @@ func TestStandardModeSwitch(t *testing.T) {
131131
})
132132

133133
// We want to make sure time.Now() is called at least twice in DON mode and once in node Mode
134-
mockExecutionHelper.EXPECT().GetDONTime(mock.Anything).RunAndReturn(func(ctx context.Context) (time.Time, error) {
134+
mockExecutionHelper.EXPECT().GetDONTime().RunAndReturn(func() (time.Time, error) {
135135
if nodeCall {
136136
donCall2 = true
137137
} else {
@@ -168,7 +168,7 @@ func TestStandardModeSwitch(t *testing.T) {
168168
mockExecutionHelper.EXPECT().GetNodeTime().RunAndReturn(func() time.Time {
169169
return time.Now()
170170
}).Maybe()
171-
mockExecutionHelper.EXPECT().GetDONTime(mock.Anything).RunAndReturn(func(ctx context.Context) (time.Time, error) {
171+
mockExecutionHelper.EXPECT().GetDONTime().RunAndReturn(func() (time.Time, error) {
172172
return time.Now(), nil
173173
}).Maybe()
174174
mockExecutionHelper.EXPECT().CallCapability(mock.Anything, mock.Anything).RunAndReturn(func(_ context.Context, request *pb.CapabilityRequest) (*pb.CapabilityResponse, error) {
@@ -193,7 +193,7 @@ func TestStandardModeSwitch(t *testing.T) {
193193
mockExecutionHelper.EXPECT().GetNodeTime().RunAndReturn(func() time.Time {
194194
return time.Now()
195195
}).Maybe()
196-
mockExecutionHelper.EXPECT().GetDONTime(mock.Anything).RunAndReturn(func(ctx context.Context) (time.Time, error) {
196+
mockExecutionHelper.EXPECT().GetDONTime().RunAndReturn(func() (time.Time, error) {
197197
return time.Now(), nil
198198
}).Maybe()
199199
mockExecutionHelper.EXPECT().CallCapability(mock.Anything, mock.Anything).RunAndReturn(func(_ context.Context, request *pb.CapabilityRequest) (*pb.CapabilityResponse, error) {
@@ -228,7 +228,7 @@ func TestStandardLogging(t *testing.T) {
228228
mockExecutionHelper.EXPECT().GetNodeTime().RunAndReturn(func() time.Time {
229229
return time.Now()
230230
}).Maybe()
231-
mockExecutionHelper.EXPECT().GetDONTime(mock.Anything).RunAndReturn(func(ctx context.Context) (time.Time, error) {
231+
mockExecutionHelper.EXPECT().GetDONTime().RunAndReturn(func() (time.Time, error) {
232232
return time.Now(), nil
233233
}).Maybe()
234234
mockExecutionHelper.EXPECT().EmitUserLog(mock.Anything).RunAndReturn(func(s string) error {
@@ -346,7 +346,7 @@ func TestStandardRandom(t *testing.T) {
346346
gte100Exec.EXPECT().GetNodeTime().RunAndReturn(func() time.Time {
347347
return time.Now()
348348
}).Maybe()
349-
gte100Exec.EXPECT().GetDONTime(mock.Anything).RunAndReturn(func(ctx context.Context) (time.Time, error) {
349+
gte100Exec.EXPECT().GetDONTime().RunAndReturn(func() (time.Time, error) {
350350
return time.Now(), nil
351351
}).Maybe()
352352
// RunAndReturn
@@ -376,7 +376,7 @@ func TestStandardRandom(t *testing.T) {
376376
lt100Exec.EXPECT().GetNodeTime().RunAndReturn(func() time.Time {
377377
return time.Now()
378378
}).Maybe()
379-
lt100Exec.EXPECT().GetDONTime(mock.Anything).RunAndReturn(func(ctx context.Context) (time.Time, error) {
379+
lt100Exec.EXPECT().GetDONTime().RunAndReturn(func() (time.Time, error) {
380380
return time.Now(), nil
381381
}).Maybe()
382382

@@ -400,7 +400,7 @@ func TestStandardRandom(t *testing.T) {
400400
gte100Exec2.EXPECT().GetNodeTime().RunAndReturn(func() time.Time {
401401
return time.Now()
402402
}).Maybe()
403-
gte100Exec2.EXPECT().GetDONTime(mock.Anything).RunAndReturn(func(ctx context.Context) (time.Time, error) {
403+
gte100Exec2.EXPECT().GetDONTime().RunAndReturn(func() (time.Time, error) {
404404
return time.Now(), nil
405405
}).Maybe()
406406

@@ -576,7 +576,7 @@ func runSecretTest(t *testing.T, m *module, secretResponse *pb.SecretResponse) *
576576
mockExecutionHelper.EXPECT().GetNodeTime().RunAndReturn(func() time.Time {
577577
return time.Now()
578578
}).Maybe()
579-
mockExecutionHelper.EXPECT().GetDONTime(mock.Anything).RunAndReturn(func(ctx context.Context) (time.Time, error) {
579+
mockExecutionHelper.EXPECT().GetDONTime().RunAndReturn(func() (time.Time, error) {
580580
return time.Now(), nil
581581
}).Maybe()
582582

pkg/workflows/wasm/host/time.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ func (t *timeFetcher) runLoop() {
6464

6565
switch mode {
6666
case sdkpb.Mode_MODE_DON:
67-
donTime, err = t.executor.GetDONTime(t.ctx)
67+
donTime, err = t.executor.GetDONTime()
6868
default:
6969
donTime = t.executor.GetNodeTime()
7070
}

pkg/workflows/wasm/host/time_test.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"testing"
77
"time"
88

9-
"github.com/stretchr/testify/mock"
109
"github.com/stretchr/testify/require"
1110

1211
"github.com/smartcontractkit/chainlink-common/pkg/workflows/sdk/v2/pb"
@@ -34,7 +33,7 @@ func TestTimeFetcher_GetTime_DON(t *testing.T) {
3433

3534
mockExec := NewMockExecutionHelper(t)
3635
expected := time.Now()
37-
mockExec.EXPECT().GetDONTime(mock.Anything).Return(expected, nil)
36+
mockExec.EXPECT().GetDONTime().Return(expected, nil)
3837

3938
tf := newTimeFetcher(ctx, mockExec)
4039
tf.Start()
@@ -49,7 +48,7 @@ func TestTimeFetcher_GetTime_DON_Error(t *testing.T) {
4948
defer cancel()
5049

5150
mockExec := NewMockExecutionHelper(t)
52-
mockExec.EXPECT().GetDONTime(mock.Anything).Return(time.Time{}, errors.New("don error"))
51+
mockExec.EXPECT().GetDONTime().Return(time.Time{}, errors.New("don error"))
5352

5453
tf := newTimeFetcher(ctx, mockExec)
5554
tf.Start()
@@ -63,7 +62,7 @@ func TestTimeFetcher_ContextCancelledBeforeRequest(t *testing.T) {
6362
cancel()
6463

6564
mockExec := NewMockExecutionHelper(t)
66-
mockExec.EXPECT().GetDONTime(mock.Anything).Return(time.Time{}, context.Canceled).Maybe()
65+
mockExec.EXPECT().GetDONTime().Return(time.Time{}, context.Canceled).Maybe()
6766

6867
tf := newTimeFetcher(ctx, mockExec)
6968

@@ -86,7 +85,7 @@ func TestTimeFetcher_ContextCancelledDuringResponse(t *testing.T) {
8685
defer cancel()
8786

8887
mockExec := NewMockExecutionHelper(t)
89-
mockExec.EXPECT().GetDONTime(mock.Anything).Run(func(context.Context) {
88+
mockExec.EXPECT().GetDONTime().Run(func() {
9089
time.Sleep(20 * time.Millisecond) // force timeout
9190
}).Return(time.Time{}, nil)
9291

0 commit comments

Comments
 (0)