Skip to content
Open
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
7 changes: 7 additions & 0 deletions .changeset/empty-words-tickle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"chainlink-deployments-framework": minor
---

feat(chain): introduce lazy chain loading

feature toggle under CLD_LAZY_BLOCKCHAINS environment variable to enable lazy loading of chains.
20 changes: 20 additions & 0 deletions chain/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ var _ BlockChain = sui.Chain{}
var _ BlockChain = ton.Chain{}
var _ BlockChain = tron.Chain{}

// Compile-time checks that both BlockChains and LazyBlockChains implement BlockChainCollection
var _ BlockChainCollection = BlockChains{}
var _ BlockChainCollection = (*LazyBlockChains)(nil)

// BlockChain is an interface that represents a chain.
// A chain can be an EVM chain, Solana chain Aptos chain or others.
type BlockChain interface {
Expand All @@ -35,6 +39,22 @@ type BlockChain interface {
Family() string
}

// BlockChainCollection defines the common interface for accessing blockchain instances.
// Both BlockChains and LazyBlockChains implement this interface.
type BlockChainCollection interface {
GetBySelector(selector uint64) (BlockChain, error)
Exists(selector uint64) bool
ExistsN(selectors ...uint64) bool
All() iter.Seq2[uint64, BlockChain]
EVMChains() map[uint64]evm.Chain
SolanaChains() map[uint64]solana.Chain
AptosChains() map[uint64]aptos.Chain
SuiChains() map[uint64]sui.Chain
TonChains() map[uint64]ton.Chain
TronChains() map[uint64]tron.Chain
Comment on lines +49 to +54
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a way to make this more generic? Just thinking every time we want to add a new chain family we will need to update the interface 🤔 Instead if we could have some Chains generic map that could accept any type of chain could be useful (although not sure how practical is this because of how different the <chain_family>.Chain structs are 🤔 )

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good question, when i initially designed the blockchain type, this was one of the question, then we come to a conclusion where we shouldnt try to make it generic since each chain is so different.

I also remember there was a doc somewhere in Chainlink channel from Connor about the attempt to consolidate the chains, basically it says dont since they are so different.

ListChainSelectors(options ...ChainSelectorsOption) []uint64
}

// BlockChains represents a collection of chains.
// It provides querying capabilities for different types of chains.
type BlockChains struct {
Expand Down
Loading