Skip to content

Commit

Permalink
Merge branch 'develop' into fix/updateRatLimitConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
jhweintraub committed Dec 2, 2024
2 parents a00ea27 + 86d5f99 commit 79bd48c
Show file tree
Hide file tree
Showing 18 changed files with 767 additions and 43 deletions.
5 changes: 5 additions & 0 deletions .changeset/cool-penguins-raise.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"chainlink": minor
---

#updated Remove custom ed25519 private to public key conversion.
4 changes: 2 additions & 2 deletions core/scripts/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ require (
github.com/kr/pretty v0.3.1 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/kylelemons/godebug v1.1.0 // indirect
github.com/leanovate/gopter v0.2.10-0.20210127095200-9abe2343507a // indirect
github.com/leanovate/gopter v0.2.11 // indirect
github.com/leodido/go-urn v1.4.0 // indirect
github.com/lib/pq v1.10.9 // indirect
github.com/libp2p/go-buffer-pool v0.1.0 // indirect
Expand Down Expand Up @@ -299,7 +299,7 @@ require (
github.com/smartcontractkit/chain-selectors v1.0.31 // indirect
github.com/smartcontractkit/chainlink-ccip v0.0.0-20241128080738-06bef8620ac6 // indirect
github.com/smartcontractkit/chainlink-cosmos v0.5.2-0.20241017133723-5277829bd53f // indirect
github.com/smartcontractkit/chainlink-data-streams v0.1.1-0.20241114154055-8d29ea018b57 // indirect
github.com/smartcontractkit/chainlink-data-streams v0.1.1-0.20241202141438-a90db35252db // indirect
github.com/smartcontractkit/chainlink-feeds v0.1.1 // indirect
github.com/smartcontractkit/chainlink-protos/job-distributor v0.6.0 // indirect
github.com/smartcontractkit/chainlink-protos/orchestrator v0.3.0 // indirect
Expand Down
169 changes: 165 additions & 4 deletions core/scripts/go.sum

Large diffs are not rendered by default.

21 changes: 21 additions & 0 deletions core/services/feeds/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,27 @@ func (s *service) DeleteJob(ctx context.Context, args *DeleteJobArgs) (int64, er
logger.Errorw("Failed to push metrics for job proposal deletion", "err", err)
}

// auto-cancellation for Workflow specs
if !proposal.ExternalJobID.Valid {
logger.Infow("ExternalJobID is null", "id", proposal.ID, "name", proposal.Name)
return proposal.ID, nil
}
job, err := s.jobORM.FindJobByExternalJobID(ctx, proposal.ExternalJobID.UUID)
if err != nil {
// NOTE: at this stage, we don't know if this job is of Workflow type
// so we don't want to return an error
logger.Infow("FindJobByExternalJobID failed", "id", proposal.ID, "externalJobID", proposal.ExternalJobID.UUID, "name", proposal.Name)
return proposal.ID, nil
}
if job.WorkflowSpecID != nil { // this is a Workflow job
specID := int64(*job.WorkflowSpecID)
if err := s.CancelSpec(ctx, proposal.ID); err != nil {
logger.Errorw("Failed to auto-cancel workflow spec", "id", specID, "err", err, "name", job.Name)
return 0, fmt.Errorf("failed to auto-cancel workflow spec %d: %w", specID, err)
}
logger.Infow("Successfully auto-cancelled a workflow spec", "id", specID)
}

return proposal.ID, nil
}

Expand Down
47 changes: 46 additions & 1 deletion core/services/feeds/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1306,12 +1306,25 @@ func Test_Service_DeleteJob(t *testing.T) {
}

approved = feeds.JobProposal{
ID: 1,
ID: 321,
FeedsManagerID: 1,
RemoteUUID: remoteUUID,
ExternalJobID: uuid.NullUUID{UUID: uuid.New(), Valid: true},
Status: feeds.JobProposalStatusApproved,
}

wfSpecID = int32(4321)
workflowJob = job.Job{
ID: 1,
WorkflowSpecID: &wfSpecID,
}
spec = &feeds.JobProposalSpec{
ID: 20,
Status: feeds.SpecStatusApproved,
JobProposalID: approved.ID,
Version: 1,
}

httpTimeout = *commonconfig.MustNewDuration(1 * time.Second)
)

Expand All @@ -1328,6 +1341,7 @@ func Test_Service_DeleteJob(t *testing.T) {
svc.orm.On("GetJobProposalByRemoteUUID", mock.Anything, approved.RemoteUUID).Return(&approved, nil)
svc.orm.On("DeleteProposal", mock.Anything, approved.ID).Return(nil)
svc.orm.On("CountJobProposalsByStatus", mock.Anything).Return(&feeds.JobProposalCounts{}, nil)
svc.jobORM.On("FindJobByExternalJobID", mock.Anything, approved.ExternalJobID.UUID).Return(job.Job{}, sql.ErrNoRows)
},
args: args,
wantID: approved.ID,
Expand Down Expand Up @@ -1371,6 +1385,37 @@ func Test_Service_DeleteJob(t *testing.T) {
args: args,
wantErr: "DeleteProposal failed",
},
{
name: "Delete workflow-spec with auto-cancellation",
before: func(svc *TestService) {
svc.orm.On("GetJobProposalByRemoteUUID", mock.Anything, approved.RemoteUUID).Return(&approved, nil)
svc.orm.On("DeleteProposal", mock.Anything, approved.ID).Return(nil)
svc.orm.On("CountJobProposalsByStatus", mock.Anything).Return(&feeds.JobProposalCounts{}, nil)
svc.jobORM.On("FindJobByExternalJobID", mock.Anything, approved.ExternalJobID.UUID).Return(workflowJob, nil)

// mocks for CancelSpec()
svc.orm.On("GetSpec", mock.Anything, approved.ID).Return(spec, nil)
svc.orm.On("GetJobProposal", mock.Anything, approved.ID).Return(&approved, nil)
svc.connMgr.On("GetClient", mock.Anything).Return(svc.fmsClient, nil)

svc.orm.On("CancelSpec", mock.Anything, approved.ID).Return(nil)
svc.jobORM.On("FindJobByExternalJobID", mock.Anything, approved.ExternalJobID.UUID).Return(workflowJob, nil)
svc.spawner.On("DeleteJob", mock.Anything, mock.Anything, workflowJob.ID).Return(nil)

svc.fmsClient.On("CancelledJob",
mock.MatchedBy(func(ctx context.Context) bool { return true }),
&proto.CancelledJobRequest{
Uuid: approved.RemoteUUID.String(),
Version: int64(spec.Version),
},
).Return(&proto.CancelledJobResponse{}, nil)
svc.orm.On("CountJobProposalsByStatus", mock.Anything).Return(&feeds.JobProposalCounts{}, nil)
svc.orm.On("WithDataSource", mock.Anything).Return(feeds.ORM(svc.orm))
svc.jobORM.On("WithDataSource", mock.Anything).Return(job.ORM(svc.jobORM))
},
args: args,
wantID: approved.ID,
},
}

for _, tc := range testCases {
Expand Down
10 changes: 2 additions & 8 deletions core/services/keystore/keys/csakey/key_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func (raw Raw) Key() KeyV2 {
privKey := ed25519.PrivateKey(raw)
return KeyV2{
privateKey: &privKey,
PublicKey: ed25519PubKeyFromPrivKey(privKey),
PublicKey: privKey.Public().(ed25519.PublicKey),
}
}

Expand Down Expand Up @@ -66,7 +66,7 @@ func MustNewV2XXXTestingOnly(k *big.Int) KeyV2 {
privKey := ed25519.NewKeyFromSeed(seed)
return KeyV2{
privateKey: &privKey,
PublicKey: ed25519PubKeyFromPrivKey(privKey),
PublicKey: privKey.Public().(ed25519.PublicKey),
Version: 2,
}
}
Expand All @@ -90,9 +90,3 @@ func (k KeyV2) String() string {
func (k KeyV2) GoString() string {
return k.String()
}

func ed25519PubKeyFromPrivKey(privKey ed25519.PrivateKey) ed25519.PublicKey {
publicKey := make([]byte, ed25519.PublicKeySize)
copy(publicKey, privKey[32:])
return publicKey
}
4 changes: 1 addition & 3 deletions core/services/keystore/keys/solkey/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,9 @@ type Raw []byte
// Key gets the Key
func (raw Raw) Key() Key {
privKey := ed25519.NewKeyFromSeed(raw)
pubKey := make([]byte, ed25519.PublicKeySize)
copy(pubKey, privKey[ed25519.PublicKeySize:])
return Key{
privkey: privKey,
pubKey: pubKey,
pubKey: privKey.Public().(ed25519.PublicKey),
}
}

Expand Down
22 changes: 22 additions & 0 deletions core/services/llo/evm/report_codec_premium_legacy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,28 @@ import (
"github.com/smartcontractkit/chainlink-data-streams/llo"
)

func FuzzReportCodecPremiumLegacy_Decode(f *testing.F) {
f.Add([]byte("not a protobuf"))
f.Add([]byte{0x0a, 0x00}) // empty protobuf
f.Add([]byte{0x0a, 0x02, 0x08, 0x01}) // invalid protobuf
f.Add(([]byte)(nil))
f.Add([]byte{})

validReport := newValidPremiumLegacyReport()
feedID := [32]uint8{0x1, 0x2, 0x3, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}
cd := llotypes.ChannelDefinition{Opts: llotypes.ChannelOpts(fmt.Sprintf(`{"baseUSDFee":"10.50","expirationWindow":60,"feedId":"0x%x","multiplier":10}`, feedID))}

codec := ReportCodecPremiumLegacy{logger.NullLogger, 100002}

validEncodedReport, err := codec.Encode(tests.Context(f), validReport, cd)
require.NoError(f, err)
f.Add(validEncodedReport)

f.Fuzz(func(t *testing.T, data []byte) {
codec.Decode(data) //nolint:errcheck // test that it doesn't panic, don't care about errors
})
}

func newValidPremiumLegacyReport() llo.Report {
return llo.Report{
ConfigDigest: types.ConfigDigest{1, 2, 3},
Expand Down
19 changes: 19 additions & 0 deletions core/services/llo/plugin_scoped_retirement_report_cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,25 @@ import (
llotypes "github.com/smartcontractkit/chainlink-common/pkg/types/llo"
)

func FuzzPluginScopedRetirementReportCache_CheckAttestedRetirementReport(f *testing.F) {
f.Add([]byte("not a protobuf"))
f.Add([]byte{0x0a, 0x00}) // empty protobuf
f.Add([]byte{0x0a, 0x02, 0x08, 0x01}) // invalid protobuf
f.Add(([]byte)(nil))
f.Add([]byte{})

rrc := &mockRetirementReportCache{}
v := &mockVerifier{}
c := &mockCodec{}
psrrc := NewPluginScopedRetirementReportCache(rrc, v, c)

exampleDigest := ocr2types.ConfigDigest{1}

f.Fuzz(func(t *testing.T, data []byte) {
psrrc.CheckAttestedRetirementReport(exampleDigest, data) //nolint:errcheck // test that it doesn't panic, don't care about errors
})
}

type mockRetirementReportCache struct {
arr []byte
cfg Config
Expand Down
29 changes: 28 additions & 1 deletion deployment/environment/devenv/jd.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type JDConfig struct {
WSRPC string
Creds credentials.TransportCredentials
Auth oauth2.TokenSource
GAP string
NodeInfo []NodeInfo
}

Expand All @@ -44,14 +45,40 @@ func authTokenInterceptor(source oauth2.TokenSource) grpc.UnaryClientInterceptor
}
}

func gapTokenInterceptor(token string) grpc.UnaryClientInterceptor {
return func(
ctx context.Context,
method string,
req, reply any,
cc *grpc.ClientConn,
invoker grpc.UnaryInvoker,
opts ...grpc.CallOption,
) error {
return invoker(
metadata.AppendToOutgoingContext(ctx, "x-authorization-github-jwt", "Bearer "+token),
method, req, reply, cc, opts...,
)
}
}

func NewJDConnection(cfg JDConfig) (*grpc.ClientConn, error) {
opts := []grpc.DialOption{}
interceptors := []grpc.UnaryClientInterceptor{}

if cfg.Creds != nil {
opts = append(opts, grpc.WithTransportCredentials(cfg.Creds))
}
if cfg.Auth != nil {
opts = append(opts, grpc.WithUnaryInterceptor(authTokenInterceptor(cfg.Auth)))
interceptors = append(interceptors, authTokenInterceptor(cfg.Auth))
}
if cfg.GAP != "" {
interceptors = append(interceptors, gapTokenInterceptor(cfg.GAP))
}

if len(interceptors) > 0 {
opts = append(opts, grpc.WithChainUnaryInterceptor(interceptors...))
}

conn, err := grpc.NewClient(cfg.GRPC, opts...)
if err != nil {
return nil, fmt.Errorf("failed to connect Job Distributor service. Err: %w", err)
Expand Down
4 changes: 2 additions & 2 deletions deployment/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ require (
github.com/kr/pretty v0.3.1 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/kylelemons/godebug v1.1.0 // indirect
github.com/leanovate/gopter v0.2.10-0.20210127095200-9abe2343507a // indirect
github.com/leanovate/gopter v0.2.11 // indirect
github.com/leodido/go-urn v1.4.0 // indirect
github.com/lib/pq v1.10.9 // indirect
github.com/libp2p/go-buffer-pool v0.1.0 // indirect
Expand Down Expand Up @@ -402,7 +402,7 @@ require (
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/smartcontractkit/chainlink-automation v0.8.1 // indirect
github.com/smartcontractkit/chainlink-cosmos v0.5.2-0.20241017133723-5277829bd53f // indirect
github.com/smartcontractkit/chainlink-data-streams v0.1.1-0.20241114154055-8d29ea018b57 // indirect
github.com/smartcontractkit/chainlink-data-streams v0.1.1-0.20241202141438-a90db35252db // indirect
github.com/smartcontractkit/chainlink-feeds v0.1.1 // indirect
github.com/smartcontractkit/chainlink-protos/orchestrator v0.3.0 // indirect
github.com/smartcontractkit/chainlink-solana v1.1.1-0.20241127201057-3c9282e39749 // indirect
Expand Down
Loading

0 comments on commit 79bd48c

Please sign in to comment.