-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* log event provider (wip) * fixes 2.1 integration * log event provider + buffer * log event provider: integration test * adding a temp copy from ocr2keepers * increase timeout to stablize test TODO: figure this out w/o timeouts at all * use log struct for check data * move log event provider int test into evm21 * extract 2.1 int tests * aligned default config should fix backfill test instability * fixes and tests * lint * extract logprovider package * extract log packer * stablize test * apply lookback buffer after rate limiting * stablize tests * log struct packing
- Loading branch information
Showing
17 changed files
with
2,265 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
core/services/ocr2/plugins/ocr2keeper/evm21/logprovider/abi.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
73 changes: 73 additions & 0 deletions
73
core/services/ocr2/plugins/ocr2keeper/evm21/logprovider/basetypes_copy.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
Oops, something went wrong.