Skip to content

Commit cb64dc7

Browse files
feat: introducing lazy chain loading
Chains are loaded lazily instead of eager, this means chains will only be loaded when it is being used, this means users are not forced to provide any secrets for chains if they are not used upfront and avoid loading huge amount of chains that are never used. This change also means we can deprecate `ChainOverrides` feature as we no longer have to tell CLD what chains to load. This lazy loading is hidden under the feature flag CLD_LAZY_BLOCKCHAINS However there is a migration needed to take advantage of lazy laoding as i want to maintain backwards compatibility. eg ``` // Previously: env.BlockChains.EVMChains() // Preferred: env.Chains().EVMChains() ```
1 parent 47aa751 commit cb64dc7

16 files changed

Lines changed: 1838 additions & 100 deletions

File tree

.changeset/empty-words-tickle.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
"chainlink-deployments-framework": minor
3+
---
4+
5+
feat(chain): introduce lazy chain loading
6+
7+
Feature toggle under CLD_LAZY_BLOCKCHAINS environment variable to enable lazy loading of chains.
8+
Migration guide:
9+
10+
- Previously: env.BlockChains.EVMChains()
11+
- Preferred: env.Chains().EVMChains()
12+
13+
By using the newer Chains() method, you can now access newer features such as loading the chains lazily, which is useful for large environments.

chain/blockchain.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ var _ BlockChain = ton.Chain{}
2626
var _ BlockChain = tron.Chain{}
2727
var _ BlockChain = canton.Chain{}
2828

29+
// Compile-time checks that both BlockChains and LazyBlockChains implement BlockChainCollection
30+
var _ BlockChainCollection = BlockChains{}
31+
var _ BlockChainCollection = (*LazyBlockChains)(nil)
32+
2933
// BlockChain is an interface that represents a chain.
3034
// A chain can be an EVM chain, Solana chain Aptos chain or others.
3135
type BlockChain interface {
@@ -37,6 +41,22 @@ type BlockChain interface {
3741
Family() string
3842
}
3943

44+
// BlockChainCollection defines the common interface for accessing blockchain instances.
45+
// Both BlockChains and LazyBlockChains implement this interface.
46+
type BlockChainCollection interface {
47+
GetBySelector(selector uint64) (BlockChain, error)
48+
Exists(selector uint64) bool
49+
ExistsN(selectors ...uint64) bool
50+
All() iter.Seq2[uint64, BlockChain]
51+
EVMChains() map[uint64]evm.Chain
52+
SolanaChains() map[uint64]solana.Chain
53+
AptosChains() map[uint64]aptos.Chain
54+
SuiChains() map[uint64]sui.Chain
55+
TonChains() map[uint64]ton.Chain
56+
TronChains() map[uint64]tron.Chain
57+
ListChainSelectors(options ...ChainSelectorsOption) []uint64
58+
}
59+
4060
// BlockChains represents a collection of chains.
4161
// It provides querying capabilities for different types of chains.
4262
type BlockChains struct {

0 commit comments

Comments
 (0)