Skip to content

Commit

Permalink
Merge branch 'develop' into AUTO-2862
Browse files Browse the repository at this point in the history
  • Loading branch information
FelixFan1992 authored Jul 6, 2023
2 parents 125393f + 1ec921f commit 26739ff
Show file tree
Hide file tree
Showing 20 changed files with 2,268 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ contract KeeperRegistryLogicA2_1 is
if (triggerType == Trigger.CONDITION) {
callData = abi.encodeWithSelector(CHECK_SELECTOR, checkData);
} else {
callData = abi.encodeWithSelector(CHECK_LOG_SELECTOR, checkData);
callData = bytes.concat(CHECK_LOG_SELECTOR, checkData);
}
gasUsed = gasleft();
(bool success, bytes memory result) = upkeep.target.call{gas: s_storage.checkGasLimit}(callData);
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ keeper_registrar_wrapper1_2: ../../contracts/solc/v0.8.6/KeeperRegistrar.abi ../
keeper_registrar_wrapper2_0: ../../contracts/solc/v0.8.6/KeeperRegistrar2_0.abi ../../contracts/solc/v0.8.6/KeeperRegistrar2_0.bin 647f125c2f0dafabcdc545cb77b15dc2ec3ea9429357806813179b1fd555c2d2
keeper_registry_logic1_3: ../../contracts/solc/v0.8.6/KeeperRegistryLogic1_3.abi ../../contracts/solc/v0.8.6/KeeperRegistryLogic1_3.bin e1bee66ce7cd0085469f923c46f0eddb58fd45dec207def1bb383b37e413a6ca
keeper_registry_logic2_0: ../../contracts/solc/v0.8.6/KeeperRegistryLogic2_0.abi ../../contracts/solc/v0.8.6/KeeperRegistryLogic2_0.bin ba5c23c495c4e1e487560ed56d917632f0047266c06fda4af9edbcda5aca99fa
keeper_registry_logic_a_wrapper_2_1: ../../contracts/solc/v0.8.16/KeeperRegistryLogicA2_1.abi ../../contracts/solc/v0.8.16/KeeperRegistryLogicA2_1.bin 8c9629e0dc5ad39c45f7b088198862d927916c2b1d58d1febc51ffdc90a095e5
keeper_registry_logic_a_wrapper_2_1: ../../contracts/solc/v0.8.16/KeeperRegistryLogicA2_1.abi ../../contracts/solc/v0.8.16/KeeperRegistryLogicA2_1.bin 291df07cfa8d6dd2392c6c7425b0fbb0e0b0cf8a9facfde0c17fc0135ee16b83
keeper_registry_logic_b_wrapper_2_1: ../../contracts/solc/v0.8.16/KeeperRegistryLogicB2_1.abi ../../contracts/solc/v0.8.16/KeeperRegistryLogicB2_1.bin ef97a4c6fa4552b2b19cbfec688253941ec4b5ad27879cddb93183bf829d7e4a
keeper_registry_wrapper1_1: ../../contracts/solc/v0.7/KeeperRegistry1_1.abi ../../contracts/solc/v0.7/KeeperRegistry1_1.bin 6ce079f2738f015f7374673a2816e8e9787143d00b780ea7652c8aa9ad9e1e20
keeper_registry_wrapper1_2: ../../contracts/solc/v0.8.6/KeeperRegistry1_2.abi ../../contracts/solc/v0.8.6/KeeperRegistry1_2.bin 41faf687ad6a5171cc91e627244d0b3d6f62d393c418ca22d4ba7fc921fd32c6
Expand Down
10 changes: 3 additions & 7 deletions core/services/ocr2/plugins/ocr2keeper/evm21/abi.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,9 @@ func (rp *evmRegistryPackerV2_1) UnpackCheckResult(key ocr2keepers.UpkeepKey, ra
rawPerformData := *abi.ConvertType(out[1], new([]byte)).(*[]byte)
result.FailureReason = *abi.ConvertType(out[2], new(uint8)).(*uint8)
result.GasUsed = *abi.ConvertType(out[3], new(*big.Int)).(**big.Int)
result.FastGasWei = *abi.ConvertType(out[4], new(*big.Int)).(**big.Int)
result.LinkNative = *abi.ConvertType(out[5], new(*big.Int)).(**big.Int)
result.ExecuteGas = *abi.ConvertType(out[4], new(uint32)).(*uint32)
result.FastGasWei = *abi.ConvertType(out[5], new(*big.Int)).(**big.Int)
result.LinkNative = *abi.ConvertType(out[6], new(*big.Int)).(**big.Int)

if !upkeepNeeded {
result.Eligible = false
Expand All @@ -84,11 +85,6 @@ func (rp *evmRegistryPackerV2_1) UnpackCheckResult(key ocr2keepers.UpkeepKey, ra
result.PerformData = rawPerformData
}

// This is a default placeholder which is used since we do not get the execute gas
// from checkUpkeep result. This field is overwritten later from the execute gas
// we have for an upkeep in memory. TODO (AUTO-1482): Refactor this
result.ExecuteGas = 5_000_000

return result, nil
}

Expand Down
8 changes: 4 additions & 4 deletions core/services/ocr2/plugins/ocr2keeper/evm21/abi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func TestUnpackTransmitTxInputErrors(t *testing.T) {
abi, err := abi.JSON(strings.NewReader(iregistry21.IKeeperRegistryMasterABI))
assert.Nil(t, err)

packer := &evmRegistryPackerV2_1{abi: abi}
packer := NewEvmRegistryPackerV2_1(abi)
_, err = packer.UnpackTransmitTxInput(hexutil.MustDecode(test.RawData))
assert.NotNil(t, err)
})
Expand All @@ -57,7 +57,7 @@ func TestUnpackPerformResult(t *testing.T) {
}
for _, test := range tests {
t.Run(test.Name, func(t *testing.T) {
packer := &evmRegistryPackerV2_1{abi: registryABI}
packer := NewEvmRegistryPackerV2_1(registryABI)
rs, err := packer.UnpackPerformResult(test.RawData)
assert.Nil(t, err)
assert.True(t, rs)
Expand Down Expand Up @@ -106,7 +106,7 @@ func TestUnpackCheckCallbackResult(t *testing.T) {
}
for _, test := range tests {
t.Run(test.Name, func(t *testing.T) {
packer := &evmRegistryPackerV2_1{abi: registryABI}
packer := NewEvmRegistryPackerV2_1(registryABI)
needed, pd, failureReason, gasUsed, err := packer.UnpackCheckCallbackResult(test.CallbackResp)

if test.ErrorString != "" {
Expand Down Expand Up @@ -154,7 +154,7 @@ func TestUnpackLogTriggerConfig(t *testing.T) {
},
}

packer := &evmRegistryPackerV2_1{abi: keeperRegistryABI}
packer := NewEvmRegistryPackerV2_1(keeperRegistryABI)

for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func setupEVMRegistry(t *testing.T) *EvmRegistry {
registry: mockRegistry,
abi: keeperRegistryABI,
active: make(map[string]activeUpkeep),
packer: &evmRegistryPackerV2_1{abi: keeperRegistryABI},
packer: NewEvmRegistryPackerV2_1(keeperRegistryABI),
headFunc: func(ocr2keepers.BlockKey) {},
chLog: make(chan logpoller.Log, 1000),
mercury: &MercuryConfig{
Expand Down
6 changes: 3 additions & 3 deletions core/services/ocr2/plugins/ocr2keeper/evm21/log_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ type LogProvider struct {
}

func LogProviderFilterName(addr common.Address) string {
return logpoller.FilterName("OCR2KeeperRegistry - LogProvider", addr)
return logpoller.FilterName("KeepersRegistry LogProvider", addr)
}

func NewLogProvider(
Expand All @@ -60,7 +60,7 @@ func NewLogProvider(
return nil, err
}

abi, err := abi.JSON(strings.NewReader(iregistry21.IKeeperRegistryMasterABI))
keeperABI, err := abi.JSON(strings.NewReader(iregistry21.IKeeperRegistryMasterABI))
if err != nil {
return nil, fmt.Errorf("%w: %s", ErrABINotParsable, err)
}
Expand Down Expand Up @@ -88,7 +88,7 @@ func NewLogProvider(
lookbackBlocks: lookbackBlocks,
registry: contract,
client: client,
packer: NewEvmRegistryPackerV2_1(abi),
packer: NewEvmRegistryPackerV2_1(keeperABI),
txCheckBlockCache: pluginutils.NewCache[string](time.Hour),
cacheCleaner: pluginutils.NewIntervalCacheCleaner[string](time.Minute),
}, nil
Expand Down
43 changes: 43 additions & 0 deletions core/services/ocr2/plugins/ocr2keeper/evm21/logprovider/abi.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package logprovider

import (
"math/big"

"github.com/ethereum/go-ethereum/accounts/abi"

"github.com/smartcontractkit/chainlink/v2/core/chains/evm/logpoller"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/i_log_automation"
)

type LogDataPacker interface {
PackLogData(log logpoller.Log) ([]byte, error)
}

type logEventsPacker struct {
abi abi.ABI
}

func NewLogEventsPacker(logDataABI abi.ABI) *logEventsPacker {
return &logEventsPacker{abi: logDataABI}
}

func (p *logEventsPacker) PackLogData(log logpoller.Log) ([]byte, error) {
topics := [][32]byte{}
for _, topic := range log.GetTopics() {
topics = append(topics, topic)
}
b, err := p.abi.Pack("checkLog", &i_log_automation.Log{
Index: big.NewInt(log.LogIndex),
TxIndex: big.NewInt(0), // TODO
TxHash: log.TxHash,
BlockNumber: big.NewInt(log.BlockNumber),
BlockHash: log.BlockHash,
Source: log.Address,
Topics: topics,
Data: log.Data,
})
if err != nil {
return nil, err
}
return b[4:], nil
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package logprovider

import (
"crypto/sha256"
"encoding/hex"
"fmt"
"math/big"

ocr2keepers "github.com/smartcontractkit/ocr2keepers/pkg"
)

// TODO: remove this file, these types should come from ocr2keepers

type ConfiguredUpkeep struct {
// ID uniquely identifies the upkeep
ID ocr2keepers.UpkeepIdentifier
// Type is the event type required to initiate the upkeep
Type int
// Config is configuration data specific to the type
Config interface{}
}

type UpkeepPayload struct {
// ID uniquely identifies the upkeep payload
ID string
// Upkeep is all the information that identifies the upkeep
Upkeep ConfiguredUpkeep
// CheckData is the data used to check the upkeep
CheckData []byte
// Trigger is the event that triggered the upkeep to be checked
Trigger Trigger
}

func NewUpkeepPayload(uid *big.Int, tp int, trigger Trigger, checkData []byte) UpkeepPayload {
p := UpkeepPayload{
Upkeep: ConfiguredUpkeep{
ID: ocr2keepers.UpkeepIdentifier(uid.Bytes()),
Type: tp,
},
Trigger: trigger,
CheckData: checkData,
}
p.ID = p.GenerateID()
return p
}

func (p UpkeepPayload) GenerateID() string {
id := fmt.Sprintf("%s:%s", p.Upkeep.ID, p.Trigger)
idh := sha256.Sum256([]byte(id))
return hex.EncodeToString(idh[:])
}

type Trigger struct {
// BlockNumber is the block number of the corresponding block
BlockNumber int64
// BlockHash is the block hash of the corresponding block
BlockHash string
// Extension is the extensions data that can differ between triggers.
// e.g. for tx hash and log id for log triggers.
Extension interface{}
}

func NewTrigger(blockNumber int64, blockHash string, extension interface{}) Trigger {
return Trigger{
BlockNumber: blockNumber,
BlockHash: blockHash,
Extension: extension,
}
}

func (t Trigger) String() string {
return fmt.Sprintf("%d:%s:%+v", t.BlockNumber, t.BlockHash, t.Extension)
}
Loading

0 comments on commit 26739ff

Please sign in to comment.