Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
21 changes: 14 additions & 7 deletions pkg/workflows/dontime/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@ package dontime

import (
"context"
"fmt"
"time"

"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/types/known/durationpb"

"github.com/smartcontractkit/libocr/offchainreporting2plus/ocr3types"

"github.com/smartcontractkit/chainlink-common/pkg/logger"
"github.com/smartcontractkit/chainlink-common/pkg/services"
"github.com/smartcontractkit/chainlink-common/pkg/types/core"
"github.com/smartcontractkit/chainlink-common/pkg/workflows/dontime/pb"
"github.com/smartcontractkit/libocr/offchainreporting2plus/ocr3types"
)

const (
Expand Down Expand Up @@ -73,13 +73,10 @@ func (o *Factory) NewReportingPlugin(_ context.Context, config ocr3types.Reporti
configProto.MinTimeIncrease = int64(defaultMinTimeIncrease)
}

updatedOffchainConfig, err := proto.Marshal(&configProto)
plugin, err := NewPlugin(o.store, config, &configProto, o.lggr)
if err != nil {
return nil, ocr3types.ReportingPluginInfo{}, fmt.Errorf("failed to re-marshal updated configProto: %w", err)
return nil, ocr3types.ReportingPluginInfo{}, err
}
config.OffchainConfig = updatedOffchainConfig

plugin, err := NewPlugin(o.store, config, o.lggr)
pluginInfo := ocr3types.ReportingPluginInfo{
Name: "DON Time Plugin",
Limits: ocr3types.ReportingPluginLimits{
Expand All @@ -90,6 +87,16 @@ func (o *Factory) NewReportingPlugin(_ context.Context, config ocr3types.Reporti
MaxReportCount: int(configProto.MaxReportCount),
},
}
o.lggr.Infow("DON Time Plugin created with config",
"maxQueryLengthBytes", configProto.MaxQueryLengthBytes,
"maxObservationLengthBytes", configProto.MaxObservationLengthBytes,
"maxOutcomeLengthBytes", configProto.MaxOutcomeLengthBytes,
"maxReportLengthBytes", configProto.MaxReportLengthBytes,
"maxReportCount", configProto.MaxReportCount,
"maxBatchSize", configProto.MaxBatchSize,
"executionRemovalTime", configProto.ExecutionRemovalTime.AsDuration(),
"minTimeIncrease", configProto.MinTimeIncrease,
)
return plugin, pluginInfo, err
}

Expand Down
7 changes: 1 addition & 6 deletions pkg/workflows/dontime/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,7 @@ type Plugin struct {

var _ ocr3types.ReportingPlugin[[]byte] = (*Plugin)(nil)

func NewPlugin(store *Store, config ocr3types.ReportingPluginConfig, lggr logger.Logger) (*Plugin, error) {
offchainCfg := &pb.Config{}
err := proto.Unmarshal(config.OffchainConfig, offchainCfg)
if err != nil {
return nil, err
}
func NewPlugin(store *Store, config ocr3types.ReportingPluginConfig, offchainCfg *pb.Config, lggr logger.Logger) (*Plugin, error) {
if offchainCfg.MaxBatchSize == 0 {
return nil, errors.New("batch size cannot be 0")
}
Expand Down
35 changes: 20 additions & 15 deletions pkg/workflows/dontime/plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,26 @@ import (
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/types/known/durationpb"

"github.com/smartcontractkit/chainlink-common/pkg/logger"
"github.com/smartcontractkit/chainlink-common/pkg/workflows/dontime/pb"
"github.com/smartcontractkit/libocr/offchainreporting2/types"
"github.com/smartcontractkit/libocr/offchainreporting2plus/ocr3types"

"github.com/smartcontractkit/chainlink-common/pkg/logger"
"github.com/smartcontractkit/chainlink-common/pkg/workflows/dontime/pb"
)

func newTestPluginConfig(t *testing.T) ocr3types.ReportingPluginConfig {
offChainCfg := &pb.Config{
func newTestPluginOffchainConfig(t *testing.T) *pb.Config {
return &pb.Config{
MaxQueryLengthBytes: defaultMaxPhaseOutputBytes,
MaxObservationLengthBytes: defaultMaxPhaseOutputBytes,
MaxReportLengthBytes: defaultMaxPhaseOutputBytes,
MaxBatchSize: defaultBatchSize,
MinTimeIncrease: int64(defaultMinTimeIncrease),
ExecutionRemovalTime: durationpb.New(defaultExecutionRemovalTime),
}
}

func newTestPluginConfig(t *testing.T) ocr3types.ReportingPluginConfig {
offChainCfg := newTestPluginOffchainConfig(t)

offChainCfgBytes, err := proto.Marshal(offChainCfg)
if err != nil {
Expand All @@ -43,10 +48,10 @@ func newTestPluginConfig(t *testing.T) ocr3types.ReportingPluginConfig {
func TestPlugin_Observation(t *testing.T) {
lggr := logger.Test(t)
store := NewStore(DefaultRequestTimeout)
config := newTestPluginConfig(t)
config, offchainCfg := newTestPluginConfig(t), newTestPluginOffchainConfig(t)
ctx := t.Context()

plugin, err := NewPlugin(store, config, lggr)
plugin, err := NewPlugin(store, config, offchainCfg, lggr)
require.NoError(t, err)

outcomeCtx := ocr3types.OutcomeContext{
Expand Down Expand Up @@ -80,12 +85,12 @@ func TestPlugin_Observation(t *testing.T) {

func TestPlugin_ValidateObservation(t *testing.T) {
lggr := logger.Test(t)
config := newTestPluginConfig(t)
config, offchainCfg := newTestPluginConfig(t), newTestPluginOffchainConfig(t)
ctx := t.Context()

t.Run("Valid Observation", func(t *testing.T) {
store := NewStore(DefaultRequestTimeout)
plugin, err := NewPlugin(store, config, lggr)
plugin, err := NewPlugin(store, config, offchainCfg, lggr)
require.NoError(t, err)

outcomeCtx := ocr3types.OutcomeContext{
Expand Down Expand Up @@ -113,7 +118,7 @@ func TestPlugin_ValidateObservation(t *testing.T) {

t.Run("Invalid sequence number", func(t *testing.T) {
store := NewStore(DefaultRequestTimeout)
plugin, err := NewPlugin(store, config, lggr)
plugin, err := NewPlugin(store, config, offchainCfg, lggr)
require.NoError(t, err)

outcomeCtx := ocr3types.OutcomeContext{
Expand All @@ -138,10 +143,10 @@ func TestPlugin_ValidateObservation(t *testing.T) {
func TestPlugin_Outcome(t *testing.T) {
lggr := logger.Test(t)
store := NewStore(DefaultRequestTimeout)
config := newTestPluginConfig(t)
config, offchainCfg := newTestPluginConfig(t), newTestPluginOffchainConfig(t)
ctx := t.Context()

plugin, err := NewPlugin(store, config, lggr)
plugin, err := NewPlugin(store, config, offchainCfg, lggr)
require.NoError(t, err)

query, err := plugin.Query(ctx, ocr3types.OutcomeContext{PreviousOutcome: []byte("")})
Expand Down Expand Up @@ -211,11 +216,11 @@ func TestPlugin_Outcome(t *testing.T) {
func TestPlugin_FinishedExecutions(t *testing.T) {
lggr := logger.Test(t)
store := NewStore(DefaultRequestTimeout)
config := newTestPluginConfig(t)
config, offchainCfg := newTestPluginConfig(t), newTestPluginOffchainConfig(t)
ctx := t.Context()

transmitter := NewTransmitter(lggr, store, "")
plugin, err := NewPlugin(store, config, lggr)
plugin, err := NewPlugin(store, config, offchainCfg, lggr)
require.NoError(t, err)

query, err := plugin.Query(ctx, ocr3types.OutcomeContext{PreviousOutcome: []byte("")})
Expand Down Expand Up @@ -286,10 +291,10 @@ func TestPlugin_FinishedExecutions(t *testing.T) {
func TestPlugin_ExpiredRequest(t *testing.T) {
lggr := logger.Test(t)
store := NewStore(0)
config := newTestPluginConfig(t)
config, offchainCfg := newTestPluginConfig(t), newTestPluginOffchainConfig(t)
ctx := t.Context()

plugin, err := NewPlugin(store, config, lggr)
plugin, err := NewPlugin(store, config, offchainCfg, lggr)
require.NoError(t, err)

outcomeCtx := ocr3types.OutcomeContext{
Expand Down
Loading