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
5 changes: 0 additions & 5 deletions .changeset/new-ants-hide.md

This file was deleted.

5 changes: 0 additions & 5 deletions .changeset/sharp-garlics-cry.md

This file was deleted.

12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# Changelog Chainlink Core

## 2.66.0

### Minor Changes

- [#23751](https://github.com/smartcontractkit/chainlink/pull/23751) [`5a65b1d`](https://github.com/smartcontractkit/chainlink/commit/5a65b1d26d7dce35596330fb56bc8c70b02a202c) - Minor bump to start next version

### Patch Changes

- [#23734](https://github.com/smartcontractkit/chainlink/pull/23734) [`fa897c3`](https://github.com/smartcontractkit/chainlink/commit/fa897c3d55f584de6ece6255c061b8ef6904d0d5) - Removing deprecated Cosmos support #nops #removed

- [#23695](https://github.com/smartcontractkit/chainlink/pull/23695) [`ea1ed53`](https://github.com/smartcontractkit/chainlink/commit/ea1ed53b9b16645c4a5da40baeaac30760f58292) - #added add bridge-cache fallback for UseConnectionManager bridge tasks

## 2.65.0

### Minor Changes
Expand Down
5 changes: 3 additions & 2 deletions config_docs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/smartcontractkit/chainlink/v2/core/config/docs"
)
Expand All @@ -18,10 +19,10 @@ var (

func TestConfigDocs(t *testing.T) {
config, err := docs.GenerateConfig()
assert.NoError(t, err, "invalid config docs")
require.NoError(t, err, "invalid config docs")
assert.Equal(t, configMD, config, "docs/CONFIG.md is out of date. Run 'make config-docs' to regenerate.")

secrets, err := docs.GenerateSecrets()
assert.NoError(t, err, "invalid secrets docs")
require.NoError(t, err, "invalid secrets docs")
assert.Equal(t, secretsMD, secrets, "docs/SECRETS.md is out of date. Run 'make config-docs' to regenerate.")
}
14 changes: 9 additions & 5 deletions core/auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,23 @@ package auth
import (
"crypto/sha3"
"encoding/hex"
"errors"
"fmt"
"hash"

pkgerrors "github.com/pkg/errors"

"github.com/smartcontractkit/chainlink/v2/core/utils"
)

var (
// ErrorAuthFailed is a generic authentication failed - but not because of
// ErrAuthFailed is a generic authentication failed - but not because of
// some system failure on our behalf (i.e. HTTP 5xx), more detail is not
// given
ErrorAuthFailed = pkgerrors.New("Authentication failed")
ErrAuthFailed = errors.New("authentication failed")

// ErrorAuthFailed is retained for backward compatibility.
//
// Deprecated: use ErrAuthFailed instead.
ErrorAuthFailed = ErrAuthFailed //nolint:errname // backward compatibility
)

// Token is used for API authentication.
Expand Down Expand Up @@ -58,7 +62,7 @@ func HashedSecret(ta *Token, salt string) (string, error) {
hasher := hash.Hash(sha3.New256())
_, err := hasher.Write(hashInput(ta, salt))
if err != nil {
return "", pkgerrors.Wrap(err, "error writing external initiator authentication to hasher")
return "", fmt.Errorf("error writing external initiator authentication to hasher: %w", err)
}
return hex.EncodeToString(hasher.Sum(nil)), nil
}
4 changes: 2 additions & 2 deletions core/bridges/bridge_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ type BridgeTypeRequest struct {
}

// GetID returns the ID of this structure for jsonapi serialization.
func (bt BridgeTypeRequest) GetID() string {
func (bt *BridgeTypeRequest) GetID() string {
return bt.Name.String()
}

// GetName returns the pluralized "type" of this structure for jsonapi serialization.
func (bt BridgeTypeRequest) GetName() string {
func (bt *BridgeTypeRequest) GetName() string {
return "bridges"
}

Expand Down
2 changes: 1 addition & 1 deletion core/bridges/bridge_type_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func TestBridgeTypeRequest(t *testing.T) {
assert.Equal(t, "bridges", r.GetName())
assert.Equal(t, "test-bridge-name", r.GetID())
const validID = "abc123foo_bar-test"
assert.NoError(t, r.SetID(validID))
require.NoError(t, r.SetID(validID))
assert.Equal(t, validID, r.GetID())
assert.Error(t, r.SetID("abc123.,<>/.foobar"))
}
Expand Down
34 changes: 17 additions & 17 deletions core/bridges/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,40 +150,40 @@ func (c *Cache) UpdateBridgeType(ctx context.Context, bt *BridgeType, btr *Bridg
return nil
}

func (c *Cache) GetCachedResponse(ctx context.Context, dotId string, specId int32, maxElapsed time.Duration) ([]byte, error) {
func (c *Cache) GetCachedResponse(ctx context.Context, dotID string, specID int32, maxElapsed time.Duration) ([]byte, error) {
// prefer to get latest value from cache
cached, inCache := c.latestValue(dotId, specId)
cached, inCache := c.latestValue(dotID, specID)
if inCache && cached.FinishedAt.After(time.Now().Add(-maxElapsed)) {
return cached.Value, nil
}

response, finishedAt, err := c.GetCachedResponseWithFinished(ctx, dotId, specId, maxElapsed)
response, finishedAt, err := c.GetCachedResponseWithFinished(ctx, dotID, specID, maxElapsed)
if err != nil {
return nil, err
}

c.setValue(dotId, specId, BridgeResponse{
DotID: dotId,
SpecID: specId,
c.setValue(dotID, specID, BridgeResponse{
DotID: dotID,
SpecID: specID,
Value: response,
FinishedAt: finishedAt,
})

return response, nil
}

func (c *Cache) UpsertBridgeResponse(ctx context.Context, dotId string, specId int32, response []byte) error {
func (c *Cache) UpsertBridgeResponse(ctx context.Context, dotID string, specID int32, response []byte) error {
upsertTime := time.Now()

// catch the rare case of a save race
cached, inCache := c.latestValue(dotId, specId)
cached, inCache := c.latestValue(dotID, specID)
if inCache && cached.FinishedAt.After(upsertTime) {
return nil
}

c.setValue(dotId, specId, BridgeResponse{
DotID: dotId,
SpecID: specId,
c.setValue(dotID, specID, BridgeResponse{
DotID: dotID,
SpecID: specID,
Value: response,
FinishedAt: upsertTime,
})
Expand Down Expand Up @@ -215,22 +215,22 @@ func (c *Cache) doBulkUpsert(ctx context.Context) {
}
}

func (c *Cache) latestValue(dotId string, specId int32) (BridgeResponse, bool) {
func (c *Cache) latestValue(dotID string, specID int32) (BridgeResponse, bool) {
c.mu.RLock()
defer c.mu.RUnlock()

cached, inCache := c.bridgeLastValueCache[responseKey(dotId, specId)]
cached, inCache := c.bridgeLastValueCache[responseKey(dotID, specID)]

return cached, inCache
}

func (c *Cache) setValue(dotId string, specId int32, resp BridgeResponse) {
func (c *Cache) setValue(dotID string, specID int32, resp BridgeResponse) {
c.mu.Lock()
defer c.mu.Unlock()

c.bridgeLastValueCache[responseKey(dotId, specId)] = resp
c.bridgeLastValueCache[responseKey(dotID, specID)] = resp
}

func responseKey(dotId string, specId int32) string {
return fmt.Sprintf("%s||%d", dotId, specId)
func responseKey(dotID string, specID int32) string {
return fmt.Sprintf("%s||%d", dotID, specID)
}
30 changes: 16 additions & 14 deletions core/bridges/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,12 @@ func TestBridgeCache_Type(t *testing.T) {
nameB := bridges.BridgeName("B")
nameC := bridges.BridgeName("C")

initialExpected := []bridges.BridgeType{
{Name: nameA},
{Name: nameB},
}
initialExpected := make([]bridges.BridgeType, 0, 3)
initialExpected = append(initialExpected,
bridges.BridgeType{Name: nameA},
bridges.BridgeType{Name: nameB},
)
//nolint:gocritic // append into a separate slice so initialExpected stays len 2
finalExpected := append(initialExpected, bridges.BridgeType{Name: nameC})

mORM.On("FindBridges", mock.Anything, []bridges.BridgeName{nameA, nameB}).Return(initialExpected, nil)
Expand Down Expand Up @@ -92,7 +94,7 @@ func TestBridgeCache_Type(t *testing.T) {
}

mORM.On("CreateBridgeType", mock.Anything, expected).Return(nil)
assert.NoError(t, cache.CreateBridgeType(ctx, expected))
require.NoError(t, cache.CreateBridgeType(ctx, expected))

result, err := cache.FindBridge(ctx, bridge)

Expand Down Expand Up @@ -142,19 +144,19 @@ func TestBridgeCache_Response(t *testing.T) {
cache := bridges.NewCache(mORM, lggr, bridges.DefaultUpsertInterval)

ctx := t.Context()
dotId := "test"
specId := int32(42)
dotID := "test"
specID := int32(42)
responseData := []byte("test")

mORM.On("GetCachedResponseWithFinished", mock.Anything, dotId, specId, time.Second).
mORM.On("GetCachedResponseWithFinished", mock.Anything, dotID, specID, time.Second).
Return(responseData, time.Now(), nil)

response, err := cache.GetCachedResponse(ctx, dotId, specId, time.Second)
response, err := cache.GetCachedResponse(ctx, dotID, specID, time.Second)

require.NoError(t, err)
assert.Equal(t, responseData, response)

response, err = cache.GetCachedResponse(ctx, dotId, specId, time.Second)
response, err = cache.GetCachedResponse(ctx, dotID, specID, time.Second)

require.NoError(t, err)
assert.Equal(t, responseData, response)
Expand All @@ -174,18 +176,18 @@ func TestBridgeCache_Response(t *testing.T) {
require.NoError(t, cache.Start(t.Context()))

ctx := t.Context()
dotId := "test"
specId := int32(42)
dotID := "test"
specID := int32(42)
expected := []byte("test")
chBulkUpsertCalled := make(chan struct{}, 1)

mORM.On("BulkUpsertBridgeResponse", mock.Anything, mock.Anything).Return(nil).Run(func(_ mock.Arguments) {
chBulkUpsertCalled <- struct{}{}
})

require.NoError(t, cache.UpsertBridgeResponse(ctx, dotId, specId, expected))
require.NoError(t, cache.UpsertBridgeResponse(ctx, dotID, specID, expected))

response, err := cache.GetCachedResponse(ctx, dotId, specId, time.Second)
response, err := cache.GetCachedResponse(ctx, dotID, specID, time.Second)

require.NoError(t, err)
assert.Equal(t, expected, response)
Expand Down
2 changes: 1 addition & 1 deletion core/bridges/external_initiator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func TestNewExternalInitiator(t *testing.T) {
URL: &url,
}
ei, err := bridges.NewExternalInitiator(eia, eir)
assert.NoError(t, err)
require.NoError(t, err)
assert.NotEqual(t, ei.HashedSecret, eia.Secret)
assert.Equal(t, ei.AccessKey, eia.AccessKey)
}
Expand Down
Loading
Loading