Skip to content

Commit

Permalink
Bump automation and common
Browse files Browse the repository at this point in the history
  • Loading branch information
ferglor committed Jan 13, 2024
1 parent 00e4095 commit 3d54786
Show file tree
Hide file tree
Showing 31 changed files with 256 additions and 213 deletions.
4 changes: 2 additions & 2 deletions core/scripts/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ require (
github.com/olekukonko/tablewriter v0.0.5
github.com/pelletier/go-toml/v2 v2.1.1
github.com/shopspring/decimal v1.3.1
github.com/smartcontractkit/chainlink-automation v1.0.2-0.20240108155417-ab9c7c5afca8
github.com/smartcontractkit/chainlink-common v0.1.7-0.20240111184312-1755c71029a2
github.com/smartcontractkit/chainlink-automation v1.0.2-0.20240113015130-84658baa36b8
github.com/smartcontractkit/chainlink-common v0.1.7-0.20240112182818-306f99b807df
github.com/smartcontractkit/chainlink-vrf v0.0.0-20231120191722-fef03814f868
github.com/smartcontractkit/chainlink/v2 v2.0.0-00010101000000-000000000000
github.com/smartcontractkit/libocr v0.0.0-20231130143053-c5102a9c0fb7
Expand Down
8 changes: 4 additions & 4 deletions core/scripts/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1162,10 +1162,10 @@ github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/smartcontractkit/caigo v0.0.0-20230621050857-b29a4ca8c704 h1:T3lFWumvbfM1u/etVq42Afwq/jtNSBSOA8n5jntnNPo=
github.com/smartcontractkit/caigo v0.0.0-20230621050857-b29a4ca8c704/go.mod h1:2QuJdEouTWjh5BDy5o/vgGXQtR4Gz8yH1IYB5eT7u4M=
github.com/smartcontractkit/chainlink-automation v1.0.2-0.20240108155417-ab9c7c5afca8 h1:8tWkC7oBuDcW2QhT7gPLDE8vG/a2tM3Ew/y6BYtqdKU=
github.com/smartcontractkit/chainlink-automation v1.0.2-0.20240108155417-ab9c7c5afca8/go.mod h1:2pHTAzJaiMalcI35YwrFLMYt32MBLn2FFbRIvh/qnCM=
github.com/smartcontractkit/chainlink-common v0.1.7-0.20240111184312-1755c71029a2 h1:RxqRG2FCAZkozR3spOjLf66jldXIt8/vYrPjHviAwqo=
github.com/smartcontractkit/chainlink-common v0.1.7-0.20240111184312-1755c71029a2/go.mod h1:f+0ei9N4PlTJHu7pbGzEjTnBUr45syPdGFu5+31lS5Q=
github.com/smartcontractkit/chainlink-automation v1.0.2-0.20240113015130-84658baa36b8 h1:eVNid1FD2QqyCasAWBvONb6S1KBdsVWp4FJXVzAuRb8=
github.com/smartcontractkit/chainlink-automation v1.0.2-0.20240113015130-84658baa36b8/go.mod h1:vnmYuAl0v0WpAu2mbMK1s/yBxLPNNP1Zl9K7Z+kHHB8=
github.com/smartcontractkit/chainlink-common v0.1.7-0.20240112182818-306f99b807df h1:J5e8CK13znCyjn+en9TbN/2d1rLrYS9CA+jFspEgWmk=
github.com/smartcontractkit/chainlink-common v0.1.7-0.20240112182818-306f99b807df/go.mod h1:f+0ei9N4PlTJHu7pbGzEjTnBUr45syPdGFu5+31lS5Q=
github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20231218175426-6e0427c661e5 h1:kBnmjv3fxU7krVIqZFvo1m4F6qBc4vPURQFX/mcChhI=
github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20231218175426-6e0427c661e5/go.mod h1:EoM7wQ81mov7wsUzG4zEnnr0EH0POEo/I0hRDg433TU=
github.com/smartcontractkit/chainlink-data-streams v0.0.0-20231204152908-a6e3fe8ff2a1 h1:xYqRgZO0nMSO8CBCMR0r3WA+LZ4kNL8a6bnbyk/oBtQ=
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"math/big"
"sync"

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

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

"github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ocr2keeper/evmregistry/v21/core"
Expand All @@ -18,7 +20,7 @@ type ActiveUpkeepList interface {
// Remove removes entries from the list
Remove(id ...*big.Int) int
// View returns the list of IDs of the given type
View(...ocr2keepers.UpkeepType) []*big.Int
View(...types.UpkeepType) []*big.Int
// IsActive returns true if the given ID is of an active upkeep
IsActive(id *big.Int) bool
Size() int
Expand Down Expand Up @@ -81,7 +83,7 @@ func (al *activeList) Remove(ids ...*big.Int) int {
}

// View returns the list of IDs of the given type
func (al *activeList) View(upkeepTypes ...ocr2keepers.UpkeepType) []*big.Int {
func (al *activeList) View(upkeepTypes ...types.UpkeepType) []*big.Int {
al.lock.RLock()
defer al.lock.RUnlock()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"sort"
"testing"

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

"github.com/stretchr/testify/require"

ocr2keepers "github.com/smartcontractkit/chainlink-common/pkg/types/automation"
Expand All @@ -14,18 +16,18 @@ import (

func TestActiveUpkeepList(t *testing.T) {
logIDs := []ocr2keepers.UpkeepIdentifier{
core.GenUpkeepID(ocr2keepers.LogTrigger, "0"),
core.GenUpkeepID(ocr2keepers.LogTrigger, "1"),
core.GenUpkeepID(ocr2keepers.LogTrigger, "2"),
core.GenUpkeepID(ocr2keepers.LogTrigger, "3"),
core.GenUpkeepID(ocr2keepers.LogTrigger, "4"),
core.GenUpkeepID(types.LogTrigger, "0"),
core.GenUpkeepID(types.LogTrigger, "1"),
core.GenUpkeepID(types.LogTrigger, "2"),
core.GenUpkeepID(types.LogTrigger, "3"),
core.GenUpkeepID(types.LogTrigger, "4"),
}
conditionalIDs := []ocr2keepers.UpkeepIdentifier{
core.GenUpkeepID(ocr2keepers.ConditionTrigger, "0"),
core.GenUpkeepID(ocr2keepers.ConditionTrigger, "1"),
core.GenUpkeepID(ocr2keepers.ConditionTrigger, "2"),
core.GenUpkeepID(ocr2keepers.ConditionTrigger, "3"),
core.GenUpkeepID(ocr2keepers.ConditionTrigger, "4"),
core.GenUpkeepID(types.ConditionTrigger, "0"),
core.GenUpkeepID(types.ConditionTrigger, "1"),
core.GenUpkeepID(types.ConditionTrigger, "2"),
core.GenUpkeepID(types.ConditionTrigger, "3"),
core.GenUpkeepID(types.ConditionTrigger, "4"),
}

tests := []struct {
Expand Down Expand Up @@ -70,15 +72,15 @@ func TestActiveUpkeepList(t *testing.T) {
for _, id := range tc.remove {
require.False(t, al.IsActive(id))
}
logIds := al.View(ocr2keepers.LogTrigger)
logIds := al.View(types.LogTrigger)
require.Equal(t, len(tc.expectedLogIds), len(logIds))
sort.Slice(logIds, func(i, j int) bool {
return logIds[i].Cmp(logIds[j]) < 0
})
for i := range logIds {
require.Equal(t, tc.expectedLogIds[i], logIds[i])
}
conditionalIds := al.View(ocr2keepers.ConditionTrigger)
conditionalIds := al.View(types.ConditionTrigger)
require.Equal(t, len(tc.expectedConditionalIds), len(conditionalIds))
sort.Slice(conditionalIds, func(i, j int) bool {
return conditionalIds[i].Cmp(conditionalIds[j]) < 0
Expand All @@ -98,7 +100,7 @@ func TestActiveUpkeepList_error(t *testing.T) {
al.items["-1"] = true
al.items["100"] = true

keys := al.View(ocr2keepers.ConditionTrigger)
keys := al.View(types.ConditionTrigger)
require.Equal(t, []*big.Int{big.NewInt(100)}, keys)
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"math/big"
"testing"

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

"github.com/ethereum/go-ethereum/common"
"github.com/stretchr/testify/assert"

Expand Down Expand Up @@ -35,7 +37,7 @@ func TestWorkID(t *testing.T) {
},
{
name: "happy flow with extension",
upkeepID: GenUpkeepID(ocr2keepers.LogTrigger, "12345").String(),
upkeepID: GenUpkeepID(types.LogTrigger, "12345").String(),
trigger: ocr2keepers.Trigger{
BlockNumber: 123,
BlockHash: common.HexToHash("0xabcdef"),
Expand Down Expand Up @@ -96,7 +98,7 @@ func TestNewUpkeepPayload(t *testing.T) {
tests := []struct {
name string
upkeepID *big.Int
upkeepType ocr2keepers.UpkeepType
upkeepType types.UpkeepType
trigger ocr2keepers.Trigger
check []byte
errored bool
Expand All @@ -105,7 +107,7 @@ func TestNewUpkeepPayload(t *testing.T) {
{
name: "happy flow no extension",
upkeepID: big.NewInt(111),
upkeepType: ocr2keepers.ConditionTrigger,
upkeepType: types.ConditionTrigger,
trigger: ocr2keepers.Trigger{
BlockNumber: 11,
BlockHash: common.HexToHash("0x11111"),
Expand All @@ -116,7 +118,7 @@ func TestNewUpkeepPayload(t *testing.T) {
{
name: "happy flow with extension",
upkeepID: big.NewInt(111),
upkeepType: ocr2keepers.LogTrigger,
upkeepType: types.LogTrigger,
trigger: ocr2keepers.Trigger{
BlockNumber: 11,
BlockHash: common.HexToHash("0x11111"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ package core
import (
"math/big"

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

"github.com/ethereum/go-ethereum/common"

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

// GenUpkeepID generates an ocr2keepers.UpkeepIdentifier with a specific UpkeepType and some random string
func GenUpkeepID(uType ocr2keepers.UpkeepType, rand string) ocr2keepers.UpkeepIdentifier {
func GenUpkeepID(uType types.UpkeepType, rand string) ocr2keepers.UpkeepIdentifier {
b := append([]byte{1}, common.LeftPadBytes([]byte{uint8(uType)}, 15)...)
b = append(b, []byte(rand)...)
b = common.RightPadBytes(b, 32-len(b))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import (
"math/big"
"strings"

"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/smartcontractkit/chainlink-automation/pkg/v3/types"

ocr2keepers "github.com/smartcontractkit/chainlink-common/pkg/types/automation"
"github.com/ethereum/go-ethereum/accounts/abi"

"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/automation_utils_2_1"
)
Expand All @@ -33,13 +33,13 @@ func PackTrigger(id *big.Int, trig triggerWrapper) ([]byte, error) {
return nil, ErrInvalidUpkeepID
}
switch upkeepType {
case ocr2keepers.ConditionTrigger:
case types.ConditionTrigger:
trig := automation_utils_2_1.KeeperRegistryBase21ConditionalTrigger{
BlockNum: trig.BlockNum,
BlockHash: trig.BlockHash,
}
trigger, err = utilsABI.Pack("_conditionalTrigger", &trig)
case ocr2keepers.LogTrigger:
case types.LogTrigger:
logTrig := automation_utils_2_1.KeeperRegistryBase21LogTrigger{
BlockNum: trig.BlockNum,
BlockHash: trig.BlockHash,
Expand Down Expand Up @@ -70,7 +70,7 @@ func UnpackTrigger(id *big.Int, raw []byte) (triggerWrapper, error) {
return triggerWrapper{}, ErrInvalidUpkeepID
}
switch upkeepType {
case ocr2keepers.ConditionTrigger:
case types.ConditionTrigger:
unpacked, err := utilsABI.Methods["_conditionalTrigger"].Inputs.Unpack(raw)
if err != nil {
return triggerWrapper{}, fmt.Errorf("%w: failed to unpack conditional trigger", err)
Expand All @@ -84,7 +84,7 @@ func UnpackTrigger(id *big.Int, raw []byte) (triggerWrapper, error) {
}
copy(triggerW.BlockHash[:], converted.BlockHash[:])
return triggerW, nil
case ocr2keepers.LogTrigger:
case types.LogTrigger:
unpacked, err := utilsABI.Methods["_logTrigger"].Inputs.Unpack(raw)
if err != nil {
return triggerWrapper{}, fmt.Errorf("%w: failed to unpack log trigger", err)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package core
import (
"math/big"

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

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

Expand All @@ -17,17 +19,17 @@ const (

// GetUpkeepType returns the upkeep type from the given ID.
// it follows the same logic as the contract, but performs it locally.
func GetUpkeepType(id ocr2keepers.UpkeepIdentifier) ocr2keepers.UpkeepType {
func GetUpkeepType(id ocr2keepers.UpkeepIdentifier) types.UpkeepType {
for i := upkeepTypeStartIndex; i < upkeepTypeByteIndex; i++ {
if id[i] != 0 { // old id
return ocr2keepers.ConditionTrigger
return types.ConditionTrigger
}
}
typeByte := id[upkeepTypeByteIndex]
return ocr2keepers.UpkeepType(typeByte)
return types.UpkeepType(typeByte)
}

func getUpkeepTypeFromBigInt(id *big.Int) (ocr2keepers.UpkeepType, bool) {
func getUpkeepTypeFromBigInt(id *big.Int) (types.UpkeepType, bool) {
uid := &ocr2keepers.UpkeepIdentifier{}
ok := uid.FromBigInt(id)
return GetUpkeepType(*uid), ok
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"math/big"
"testing"

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

"github.com/stretchr/testify/assert"

ocr2keepers "github.com/smartcontractkit/chainlink-common/pkg/types/automation"
Expand All @@ -13,35 +15,35 @@ func TestGetUpkeepType(t *testing.T) {
tests := []struct {
name string
upkeepID []byte
upkeepType ocr2keepers.UpkeepType
upkeepType types.UpkeepType
}{
{
"zeroed id",
big.NewInt(0).Bytes(),
ocr2keepers.ConditionTrigger,
types.ConditionTrigger,
},
{
"old id",
[]byte("5820911532554020907796191562093071158274499580927271776163559390280294438608"),
ocr2keepers.ConditionTrigger,
types.ConditionTrigger,
},
{
"condition trigger",
GenUpkeepID(ocr2keepers.ConditionTrigger, "").BigInt().Bytes(),
ocr2keepers.ConditionTrigger,
GenUpkeepID(types.ConditionTrigger, "").BigInt().Bytes(),
types.ConditionTrigger,
},
{
"log trigger",
GenUpkeepID(ocr2keepers.LogTrigger, "111").BigInt().Bytes(),
ocr2keepers.LogTrigger,
GenUpkeepID(types.LogTrigger, "111").BigInt().Bytes(),
types.LogTrigger,
},
{
"log trigger id",
func() []byte {
id, _ := big.NewInt(0).SetString("32329108151019397958065800113404894502874153543356521479058624064899121404671", 10)
return id.Bytes()
}(),
ocr2keepers.LogTrigger,
types.LogTrigger,
},
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"fmt"
"math/big"

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

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

"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/automation_utils_2_1"
Expand Down Expand Up @@ -65,7 +67,7 @@ func (e reportEncoder) Encode(results ...ocr2keepers.CheckResult) ([]byte, error
BlockHash: result.Trigger.BlockHash,
}
switch core.GetUpkeepType(result.UpkeepID) {
case ocr2keepers.LogTrigger:
case types.LogTrigger:
triggerW.TxHash = result.Trigger.LogTriggerExtension.TxHash
triggerW.LogIndex = result.Trigger.LogTriggerExtension.Index
triggerW.LogBlockHash = result.Trigger.LogTriggerExtension.BlockHash
Expand Down Expand Up @@ -107,7 +109,7 @@ func (e reportEncoder) Extract(raw []byte) ([]ocr2keepers.ReportedUpkeep, error)
triggerW.BlockHash,
)
switch core.GetUpkeepType(*id) {
case ocr2keepers.LogTrigger:
case types.LogTrigger:
trigger.LogTriggerExtension = &ocr2keepers.LogTriggerExtension{}
trigger.LogTriggerExtension.TxHash = triggerW.TxHash
trigger.LogTriggerExtension.Index = triggerW.LogIndex
Expand Down
Loading

0 comments on commit 3d54786

Please sign in to comment.