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

implement zk overflow fix draft #323

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ go 1.21

replace (
github.com/btcsuite/btcd => github.com/btcsuite/btcd v0.23.3
github.com/smartcontractkit/chainlink-common => /Users/felix/Development/chainlink-common
golang/github.com/gogo/protobuf => golang/github.com/gogo/protobuf v1.3.3
)

Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,6 @@ github.com/shirou/gopsutil v3.21.11+incompatible h1:+1+c1VGhc88SSonWP6foOcLhvnKl
github.com/shirou/gopsutil v3.21.11+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA=
github.com/shopspring/decimal v1.3.1 h1:2Usl1nmF/WZucqkFZhnfFYxxxu8LG21F6nPQBE5gKV8=
github.com/shopspring/decimal v1.3.1/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o=
github.com/smartcontractkit/chainlink-common v0.1.7-0.20240401172519-4bfc659b80bf h1:yW8rTFycozLVnXRyOgZWGktnmzoFLxSWh1xPJXsp7vg=
github.com/smartcontractkit/chainlink-common v0.1.7-0.20240401172519-4bfc659b80bf/go.mod h1:kstYjAGqBswdZpl7YkSPeXBDVwaY1VaR6tUMPWl8ykA=
github.com/smartcontractkit/libocr v0.0.0-20240326191951-2bbe9382d052 h1:1WFjrrVrWoQ9UpVMh7Mx4jDpzhmo1h8hFUKd9awIhIU=
github.com/smartcontractkit/libocr v0.0.0-20240326191951-2bbe9382d052/go.mod h1:SJEZCHgMCAzzBvo9vMV2DQ9onfEcIJCYSViyP4JI6c4=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
Expand Down
63 changes: 63 additions & 0 deletions pkg/v3/flows/maliciousupkeep.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package flows

import (
"context"
"fmt"
"log"
"math/big"
"time"

common "github.com/smartcontractkit/chainlink-common/pkg/types/automation"

ocr2keepersv3 "github.com/smartcontractkit/chainlink-automation/pkg/v3"
"github.com/smartcontractkit/chainlink-automation/pkg/v3/postprocessors"
"github.com/smartcontractkit/chainlink-automation/pkg/v3/service"
"github.com/smartcontractkit/chainlink-automation/pkg/v3/telemetry"
"github.com/smartcontractkit/chainlink-automation/pkg/v3/tickers"
"github.com/smartcontractkit/chainlink-automation/pkg/v3/types"
)

// log trigger flow is the happy path entry point for log triggered upkeeps
func newMaliciousUpkeepFlow(
preprocessors []ocr2keepersv3.PreProcessor[*big.Int],
rs types.ResultStore,
rn ocr2keepersv3.Runner,
mup common.MaliciousUpkeepProvider,
maliciousUpkeepReportingInterval time.Duration,
logger *log.Logger,
) service.Recoverable {
post := postprocessors.NewCombinedPostprocessor(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

can these be simplified? the observer below is very complicated.

postprocessors.NewEligiblePostProcessor(rs, telemetry.WrapLogger(logger, "log-trigger-eligible-postprocessor")),
)

obs := ocr2keepersv3.NewRunnableObserver(
preprocessors,
post,
rn,
ObservationProcessLimit,
log.New(logger.Writer(), fmt.Sprintf("[%s | log-trigger-observer]", telemetry.ServiceName), telemetry.LogPkgStdFlags),
)

timeTick := tickers.NewTimeTicker[[]*big.Int](maliciousUpkeepReportingInterval, obs, func(ctx context.Context, _ time.Time) (tickers.Tick[[]*big.Int], error) {
return maliciousUpkeepTick{logger: logger, mup: mup}, nil
}, log.New(logger.Writer(), fmt.Sprintf("[%s | log-trigger-ticker]", telemetry.ServiceName), telemetry.LogPkgStdFlags))

return timeTick
}

type maliciousUpkeepTick struct {
mup common.MaliciousUpkeepProvider
logger *log.Logger
}

func (et maliciousUpkeepTick) Value(ctx context.Context) ([]*big.Int, error) {
if et.mup == nil {
return nil, nil
}

logs, err := et.mup.GetMaliciousUpkeepIds(ctx)

et.logger.Printf("%d logs returned by log provider", len(logs))

return logs, err
}
1 change: 1 addition & 0 deletions pkg/v3/observation.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ var uint256Max, _ = big.NewInt(0).SetString("11579208923731619542357098500868790
// as different nodes would upgrade at different times and would need to understand
// each others' observations meanwhile
type AutomationObservation struct {
MaliciousUpkeepIds []*big.Int
// These are the upkeeps that are eligible and should be performed
Performable []ocr2keepers.CheckResult
// These are the proposals for upkeeps that need a coordinated block to be checked on
Expand Down
17 changes: 17 additions & 0 deletions pkg/v3/observer.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package ocr2keepers
import (
"context"
"log"
"math/big"
"time"

ocr2keepers "github.com/smartcontractkit/chainlink-common/pkg/types/automation"
Expand Down Expand Up @@ -40,6 +41,22 @@ type Observer[T any] struct {
processTimeLimit time.Duration
}

func NewUpkeepIdsObserver(
preprocessors []PreProcessor[*big.Int],
postprocessor PostProcessor[*big.Int],
runner Runner,
processLimit time.Duration,
logger *log.Logger,
) *Observer[*big.Int] {
return &Observer[ocr2keepers.UpkeepPayload]{
lggr: logger,
Preprocessors: preprocessors,
Postprocessor: postprocessor,
processFunc: runner.CheckUpkeeps,
processTimeLimit: processLimit,
}
}

// NewRunnableObserver creates a new Observer with the given pre-processors, post-processor, and runner
func NewRunnableObserver(
preprocessors []PreProcessor[ocr2keepers.UpkeepPayload],
Expand Down
5 changes: 4 additions & 1 deletion pkg/v3/outcome.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ package ocr2keepers
import (
"encoding/json"
"fmt"
"math/big"

"github.com/smartcontractkit/chainlink-automation/pkg/v3/types"
ocr2keepers "github.com/smartcontractkit/chainlink-common/pkg/types/automation"

"github.com/smartcontractkit/chainlink-automation/pkg/v3/types"
)

// NOTE: Any change to these values should keep backwards compatibility in mind
Expand Down Expand Up @@ -39,6 +41,7 @@ const (
// as different nodes would upgrade at different times and would need to understand
// each others' outcome meanwhile
type AutomationOutcome struct {
MaliciousUpkeepIds []*big.Int
// These are the upkeeps that achieved quorum, meaning should be performed on chain
// These require quorum of f+1 nodes
AgreedPerformables []ocr2keepers.CheckResult
Expand Down
9 changes: 7 additions & 2 deletions pkg/v3/plugin/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ import (
"math/cmplx"
"strconv"

commontypes "github.com/smartcontractkit/chainlink-common/pkg/types/automation"
"github.com/smartcontractkit/libocr/offchainreporting2plus/ocr3types"

ocr2keepers "github.com/smartcontractkit/chainlink-automation/pkg/v3"
"github.com/smartcontractkit/chainlink-automation/pkg/v3/config"
"github.com/smartcontractkit/chainlink-automation/pkg/v3/runner"
"github.com/smartcontractkit/chainlink-automation/pkg/v3/types"
commontypes "github.com/smartcontractkit/chainlink-common/pkg/types/automation"
"github.com/smartcontractkit/libocr/offchainreporting2plus/ocr3types"
)

type pluginFactory struct {
Expand All @@ -22,6 +23,7 @@ type pluginFactory struct {
rp commontypes.RecoverableProvider
builder commontypes.PayloadBuilder
getter commontypes.ConditionalUpkeepProvider
mup commontypes.MaliciousUpkeepProvider
runnable types.Runnable
runnerConf runner.RunnerConfig
encoder commontypes.Encoder
Expand All @@ -38,6 +40,7 @@ func NewReportingPluginFactory(
rp commontypes.RecoverableProvider,
builder commontypes.PayloadBuilder,
getter commontypes.ConditionalUpkeepProvider,
mup commontypes.MaliciousUpkeepProvider,
runnable types.Runnable,
runnerConf runner.RunnerConfig,
encoder commontypes.Encoder,
Expand All @@ -53,6 +56,7 @@ func NewReportingPluginFactory(
rp: rp,
builder: builder,
getter: getter,
mup: mup,
runnable: runnable,
runnerConf: runnerConf,
encoder: encoder,
Expand Down Expand Up @@ -106,6 +110,7 @@ func (factory *pluginFactory) NewReportingPlugin(c ocr3types.ReportingPluginConf
factory.builder,
sample,
factory.getter,
factory.mup,
factory.encoder,
factory.upkeepTypeGetter,
factory.workIDGenerator,
Expand Down
3 changes: 3 additions & 0 deletions pkg/v3/plugin/ocr3.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,11 @@ func (plugin *ocr3Plugin) Reports(seqNr uint64, raw ocr3types.Outcome) ([]ocr3ty

plugin.Logger.Printf("%d reports created for sequence number %d", len(reports), seqNr)
prommetrics.AutomationPluginPerformables.WithLabelValues(prommetrics.PluginStepReports).Set(float64(performablesAdded))
// is there a consensus about upkeeps to pause
return reports, nil
}

// ShouldAcceptAttestedReport needs updates if report struct changes
func (plugin *ocr3Plugin) ShouldAcceptAttestedReport(_ context.Context, seqNr uint64, report ocr3types.ReportWithInfo[AutomationReportInfo]) (bool, error) {
plugin.Logger.Printf("inside ShouldAcceptAttestedReport for seqNr %d", seqNr)
upkeeps, err := plugin.ReportEncoder.Extract(report.Report)
Expand All @@ -231,6 +233,7 @@ func (plugin *ocr3Plugin) ShouldAcceptAttestedReport(_ context.Context, seqNr ui
return accept, nil
}

// ShouldTransmitAcceptedReport needs updates if report struct changes
func (plugin *ocr3Plugin) ShouldTransmitAcceptedReport(_ context.Context, seqNr uint64, report ocr3types.ReportWithInfo[AutomationReportInfo]) (bool, error) {
plugin.Logger.Printf("inside ShouldTransmitAcceptedReport for seqNr %d", seqNr)
upkeeps, err := plugin.ReportEncoder.Extract(report.Report)
Expand Down
8 changes: 5 additions & 3 deletions pkg/v3/plugin/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ import (
"fmt"
"log"

ocr2keepers "github.com/smartcontractkit/chainlink-common/pkg/types/automation"
"github.com/smartcontractkit/libocr/offchainreporting2plus/ocr3types"
ocr2plustypes "github.com/smartcontractkit/libocr/offchainreporting2plus/types"

"github.com/smartcontractkit/chainlink-automation/pkg/v3/config"
"github.com/smartcontractkit/chainlink-automation/pkg/v3/coordinator"
"github.com/smartcontractkit/chainlink-automation/pkg/v3/flows"
Expand All @@ -13,9 +17,6 @@ import (
"github.com/smartcontractkit/chainlink-automation/pkg/v3/stores"
"github.com/smartcontractkit/chainlink-automation/pkg/v3/telemetry"
"github.com/smartcontractkit/chainlink-automation/pkg/v3/types"
ocr2keepers "github.com/smartcontractkit/chainlink-common/pkg/types/automation"
"github.com/smartcontractkit/libocr/offchainreporting2plus/ocr3types"
ocr2plustypes "github.com/smartcontractkit/libocr/offchainreporting2plus/types"
)

func newPlugin(
Expand All @@ -27,6 +28,7 @@ func newPlugin(
builder ocr2keepers.PayloadBuilder,
ratio types.Ratio,
getter ocr2keepers.ConditionalUpkeepProvider,
mup ocr2keepers.MaliciousUpkeepProvider,
encoder ocr2keepers.Encoder,
upkeepTypeGetter types.UpkeepTypeGetter,
workIDGenerator types.WorkIDGenerator,
Expand Down
12 changes: 11 additions & 1 deletion pkg/v3/stores/metadata_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ package stores
import (
"context"
"fmt"
"math/big"
"sort"
"sync"
"sync/atomic"
"time"

"github.com/smartcontractkit/chainlink-automation/pkg/v3/types"
commontypes "github.com/smartcontractkit/chainlink-common/pkg/types/automation"

"github.com/smartcontractkit/chainlink-automation/pkg/v3/types"
)

const (
Expand All @@ -35,6 +37,7 @@ type metadataStore struct {
ch chan commontypes.BlockHistory
subscriber commontypes.BlockSubscriber
blockHistory commontypes.BlockHistory
maliciousUpkeeps map[string]bool // use a set? needs order? any other info besides upkeep ids?
blockHistoryMutex sync.RWMutex
conditionalProposals orderedMap
conditionalMutex sync.RWMutex
Expand Down Expand Up @@ -64,6 +67,13 @@ func NewMetadataStore(subscriber commontypes.BlockSubscriber, typeGetter types.U
}, nil
}

func (m *metadataStore) SetMaliciousUpkeeps(ids []*big.Int) {
m.maliciousUpkeeps = make(map[string]bool)
for _, id := range ids {
m.maliciousUpkeeps[id.String()] = true
}
}

func (m *metadataStore) SetBlockHistory(blockHistory commontypes.BlockHistory) {
m.blockHistoryMutex.Lock()
defer m.blockHistoryMutex.Unlock()
Expand Down
2 changes: 2 additions & 0 deletions pkg/v3/types/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (

//go:generate mockery --name LogEventProvider --structname MockLogEventProvider --srcpkg "github.com/smartcontractkit/chainlink-common/pkg/types/automation" --case underscore --filename logeventprovider.generated.go

//go:generate mockery --name MaliciousUpkeepProvider --structname MockMaliciousUpkeepProvider --srcpkg "github.com/smartcontractkit/chainlink-common/pkg/types/automation" --case underscore --filename maliciousupkeepprovider.generated.go

//go:generate mockery --name RecoverableProvider --structname MockRecoverableProvider --srcpkg "github.com/smartcontractkit/chainlink-common/pkg/types/automation" --case underscore --filename recoverableprovider.generated.go

//go:generate mockery --name ConditionalUpkeepProvider --structname MockConditionalUpkeepProvider --srcpkg "github.com/smartcontractkit/chainlink-common/pkg/types/automation" --case underscore --filename conditionalupkeepprovider.generated.go
Expand Down
83 changes: 83 additions & 0 deletions pkg/v3/types/mocks/maliciousupkeepprovider.generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading