Skip to content

Commit

Permalink
[INTAUTO-308] - Adding Solana specific chain client and state
Browse files Browse the repository at this point in the history
  • Loading branch information
pablolagreca committed Dec 4, 2024
1 parent 52676f1 commit 50e2fe6
Show file tree
Hide file tree
Showing 50 changed files with 577 additions and 542 deletions.
68 changes: 34 additions & 34 deletions deployment/ccip/changeset/accept_ownership_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ func Test_NewAcceptOwnershipChangeset(t *testing.T) {
dest := allChains[1]

timelocks := map[uint64]*gethwrappers.RBACTimelock{
source: state.Chains[source].Timelock,
dest: state.Chains[dest].Timelock,
source: state.EVMState.Chains[source].Timelock,
dest: state.EVMState.Chains[dest].Timelock,
}

// at this point we have the initial deploys done, now we need to transfer ownership
Expand Down Expand Up @@ -74,23 +74,23 @@ func genTestTransferOwnershipConfig(

// chain contracts
for _, chain := range chains {
timelocksPerChain[chain] = state.Chains[chain].Timelock.Address()
timelocksPerChain[chain] = state.EVMState.Chains[chain].Timelock.Address()
contracts[chain] = []commonchangeset.OwnershipTransferrer{
state.Chains[chain].OnRamp,
state.Chains[chain].OffRamp,
state.Chains[chain].FeeQuoter,
state.Chains[chain].NonceManager,
state.Chains[chain].RMNRemote,
state.EVMState.Chains[chain].OnRamp,
state.EVMState.Chains[chain].OffRamp,
state.EVMState.Chains[chain].FeeQuoter,
state.EVMState.Chains[chain].NonceManager,
state.EVMState.Chains[chain].RMNRemote,
}
}

// home chain
homeChainTimelockAddress := state.Chains[e.HomeChainSel].Timelock.Address()
homeChainTimelockAddress := state.EVMState.Chains[e.HomeChainSel].Timelock.Address()
timelocksPerChain[e.HomeChainSel] = homeChainTimelockAddress
contracts[e.HomeChainSel] = append(contracts[e.HomeChainSel],
state.Chains[e.HomeChainSel].CapabilityRegistry,
state.Chains[e.HomeChainSel].CCIPHome,
state.Chains[e.HomeChainSel].RMNHome,
state.EVMState.Chains[e.HomeChainSel].CapabilityRegistry,
state.EVMState.Chains[e.HomeChainSel].CCIPHome,
state.EVMState.Chains[e.HomeChainSel].RMNHome,
)

return commonchangeset.TransferOwnershipConfig{
Expand All @@ -110,25 +110,25 @@ func genTestAcceptOwnershipConfig(
contracts = make(map[uint64][]commonchangeset.OwnershipAcceptor)
)
for _, chain := range chains {
timelocksPerChain[chain] = state.Chains[chain].Timelock.Address()
proposerMCMses[chain] = state.Chains[chain].ProposerMcm
timelocksPerChain[chain] = state.EVMState.Chains[chain].Timelock.Address()
proposerMCMses[chain] = state.EVMState.Chains[chain].ProposerMcm
contracts[chain] = []commonchangeset.OwnershipAcceptor{
state.Chains[chain].OnRamp,
state.Chains[chain].OffRamp,
state.Chains[chain].FeeQuoter,
state.Chains[chain].NonceManager,
state.Chains[chain].RMNRemote,
state.EVMState.Chains[chain].OnRamp,
state.EVMState.Chains[chain].OffRamp,
state.EVMState.Chains[chain].FeeQuoter,
state.EVMState.Chains[chain].NonceManager,
state.EVMState.Chains[chain].RMNRemote,
}
}

// add home chain contracts.
// this overwrite should be fine.
timelocksPerChain[e.HomeChainSel] = state.Chains[e.HomeChainSel].Timelock.Address()
proposerMCMses[e.HomeChainSel] = state.Chains[e.HomeChainSel].ProposerMcm
timelocksPerChain[e.HomeChainSel] = state.EVMState.Chains[e.HomeChainSel].Timelock.Address()
proposerMCMses[e.HomeChainSel] = state.EVMState.Chains[e.HomeChainSel].ProposerMcm
contracts[e.HomeChainSel] = append(contracts[e.HomeChainSel],
state.Chains[e.HomeChainSel].CapabilityRegistry,
state.Chains[e.HomeChainSel].CCIPHome,
state.Chains[e.HomeChainSel].RMNHome,
state.EVMState.Chains[e.HomeChainSel].CapabilityRegistry,
state.EVMState.Chains[e.HomeChainSel].CCIPHome,
state.EVMState.Chains[e.HomeChainSel].RMNHome,
)

return commonchangeset.AcceptOwnershipConfig{
Expand All @@ -151,26 +151,26 @@ func assertTimelockOwnership(
// check that the ownership has been transferred correctly
for _, chain := range chains {
for _, contract := range []commonchangeset.OwnershipTransferrer{
state.Chains[chain].OnRamp,
state.Chains[chain].OffRamp,
state.Chains[chain].FeeQuoter,
state.Chains[chain].NonceManager,
state.Chains[chain].RMNRemote,
state.EVMState.Chains[chain].OnRamp,
state.EVMState.Chains[chain].OffRamp,
state.EVMState.Chains[chain].FeeQuoter,
state.EVMState.Chains[chain].NonceManager,
state.EVMState.Chains[chain].RMNRemote,
} {
owner, err := contract.Owner(&bind.CallOpts{
Context: ctx,
})
require.NoError(t, err)
require.Equal(t, state.Chains[chain].Timelock.Address(), owner)
require.Equal(t, state.EVMState.Chains[chain].Timelock.Address(), owner)
}
}

// check home chain contracts ownership
homeChainTimelockAddress := state.Chains[e.HomeChainSel].Timelock.Address()
homeChainTimelockAddress := state.EVMState.Chains[e.HomeChainSel].Timelock.Address()
for _, contract := range []commonchangeset.OwnershipTransferrer{
state.Chains[e.HomeChainSel].CapabilityRegistry,
state.Chains[e.HomeChainSel].CCIPHome,
state.Chains[e.HomeChainSel].RMNHome,
state.EVMState.Chains[e.HomeChainSel].CapabilityRegistry,
state.EVMState.Chains[e.HomeChainSel].CCIPHome,
state.EVMState.Chains[e.HomeChainSel].RMNHome,
} {
owner, err := contract.Owner(&bind.CallOpts{
Context: ctx,
Expand Down
22 changes: 11 additions & 11 deletions deployment/ccip/changeset/cs_active_candidate.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ func PromoteAllCandidatesChangeset(
nodes deployment.Nodes,
) (deployment.ChangesetOutput, error) {
promoteCandidateOps, err := promoteAllCandidatesForChainOps(
state.Chains[homeChainSel].CapabilityRegistry,
state.Chains[homeChainSel].CCIPHome,
state.EVMState.Chains[homeChainSel].CapabilityRegistry,
state.EVMState.Chains[homeChainSel].CCIPHome,
newChainSel,
nodes.NonBootstraps(),
)
Expand All @@ -37,10 +37,10 @@ func PromoteAllCandidatesChangeset(

var (
timelocksPerChain = map[uint64]common.Address{
homeChainSel: state.Chains[homeChainSel].Timelock.Address(),
homeChainSel: state.EVMState.Chains[homeChainSel].Timelock.Address(),
}
proposerMCMSes = map[uint64]*gethwrappers.ManyChainMultiSig{
homeChainSel: state.Chains[homeChainSel].ProposerMcm,
homeChainSel: state.EVMState.Chains[homeChainSel].ProposerMcm,
}
)
prop, err := proposalutils.BuildProposalFromBatches(
Expand Down Expand Up @@ -76,15 +76,15 @@ func SetCandidatePluginChangeset(
) (deployment.ChangesetOutput, error) {
ccipOCRParams := DefaultOCRParams(
feedChainSel,
tokenConfig.GetTokenInfo(e.Logger, state.Chains[newChainSel].LinkToken, state.Chains[newChainSel].Weth9),
tokenConfig.GetTokenInfo(e.Logger, state.EVMState.Chains[newChainSel].LinkToken, state.EVMState.Chains[newChainSel].Weth9),
nil,
)
newDONArgs, err := internal.BuildOCR3ConfigForCCIPHome(
ocrSecrets,
state.Chains[newChainSel].OffRamp,
state.EVMState.Chains[newChainSel].OffRamp,
e.Chains[newChainSel],
nodes.NonBootstraps(),
state.Chains[homeChainSel].RMNHome.Address(),
state.EVMState.Chains[homeChainSel].RMNHome.Address(),
ccipOCRParams.OCRParameters,
ccipOCRParams.CommitOffChainConfig,
ccipOCRParams.ExecuteOffChainConfig,
Expand All @@ -100,8 +100,8 @@ func SetCandidatePluginChangeset(

setCandidateMCMSOps, err := setCandidateOnExistingDon(
execConfig,
state.Chains[homeChainSel].CapabilityRegistry,
state.Chains[homeChainSel].CCIPHome,
state.EVMState.Chains[homeChainSel].CapabilityRegistry,
state.EVMState.Chains[homeChainSel].CCIPHome,
newChainSel,
nodes.NonBootstraps(),
)
Expand All @@ -111,10 +111,10 @@ func SetCandidatePluginChangeset(

var (
timelocksPerChain = map[uint64]common.Address{
homeChainSel: state.Chains[homeChainSel].Timelock.Address(),
homeChainSel: state.EVMState.Chains[homeChainSel].Timelock.Address(),
}
proposerMCMSes = map[uint64]*gethwrappers.ManyChainMultiSig{
homeChainSel: state.Chains[homeChainSel].ProposerMcm,
homeChainSel: state.EVMState.Chains[homeChainSel].ProposerMcm,
}
)
prop, err := proposalutils.BuildProposalFromBatches(
Expand Down
52 changes: 26 additions & 26 deletions deployment/ccip/changeset/cs_active_candidate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@ func TestActiveCandidate(t *testing.T) {
if src == dest {
continue
}
latesthdr, err := destChain.Client.HeaderByNumber(testcontext.Get(t), nil)
latesthdr, err := destChain.EVMChain.Client.HeaderByNumber(testcontext.Get(t), nil)
require.NoError(t, err)
block := latesthdr.Number.Uint64()
startBlocks[dest] = &block
msgSentEvent := TestSendRequest(t, e, state, src, dest, false, router.ClientEVM2AnyMessage{
Receiver: common.LeftPadBytes(state.Chains[dest].Receiver.Address().Bytes(), 32),
Receiver: common.LeftPadBytes(state.EVMState.Chains[dest].Receiver.Address().Bytes(), 32),
Data: []byte("hello world"),
TokenAmounts: nil,
FeeToken: common.HexToAddress("0x0"),
Expand All @@ -80,8 +80,8 @@ func TestActiveCandidate(t *testing.T) {

//After commit is reported on all chains, token prices should be updated in FeeQuoter.
for dest := range e.Chains {
linkAddress := state.Chains[dest].LinkToken.Address()
feeQuoter := state.Chains[dest].FeeQuoter
linkAddress := state.EVMState.Chains[dest].LinkToken.Address()
feeQuoter := state.EVMState.Chains[dest].FeeQuoter
timestampedPrice, err := feeQuoter.GetTokenPrice(nil, linkAddress)
require.NoError(t, err)
require.Equal(t, MockLinkPrice, timestampedPrice.Value)
Expand All @@ -93,7 +93,7 @@ func TestActiveCandidate(t *testing.T) {
// compose the transfer ownership and accept ownership changesets
timelocks := make(map[uint64]*gethwrappers.RBACTimelock)
for _, chain := range allChains {
timelocks[chain] = state.Chains[chain].Timelock
timelocks[chain] = state.EVMState.Chains[chain].Timelock
}
_, err = commonchangeset.ApplyChangesets(t, e, timelocks, []commonchangeset.ChangesetApplication{
// note this doesn't have proposals.
Expand All @@ -115,10 +115,10 @@ func TestActiveCandidate(t *testing.T) {
require.NoError(t, err)

// [ACTIVE, CANDIDATE] setup by setting candidate through cap reg
capReg, ccipHome := state.Chains[tenv.HomeChainSel].CapabilityRegistry, state.Chains[tenv.HomeChainSel].CCIPHome
capReg, ccipHome := state.EVMState.Chains[tenv.HomeChainSel].CapabilityRegistry, state.EVMState.Chains[tenv.HomeChainSel].CCIPHome
donID, err := internal.DonIDForChain(capReg, ccipHome, tenv.FeedChainSel)
require.NoError(t, err)
donInfo, err := state.Chains[tenv.HomeChainSel].CapabilityRegistry.GetDON(nil, donID)
donInfo, err := state.EVMState.Chains[tenv.HomeChainSel].CapabilityRegistry.GetDON(nil, donID)
require.NoError(t, err)
require.Equal(t, 5, len(donInfo.NodeP2PIds))
require.Equal(t, uint32(4), donInfo.ConfigCount)
Expand All @@ -142,16 +142,16 @@ func TestActiveCandidate(t *testing.T) {

// this will construct ocr3 configurations for the
// commit and exec plugin we will be using
rmnHomeAddress := state.Chains[tenv.HomeChainSel].RMNHome.Address()
tokenConfig := NewTestTokenConfig(state.Chains[tenv.FeedChainSel].USDFeeds)
rmnHomeAddress := state.EVMState.Chains[tenv.HomeChainSel].RMNHome.Address()
tokenConfig := NewTestTokenConfig(state.EVMState.Chains[tenv.FeedChainSel].USDFeeds)
ccipOCRParams := DefaultOCRParams(
tenv.FeedChainSel,
tokenConfig.GetTokenInfo(e.Logger, state.Chains[tenv.FeedChainSel].LinkToken, state.Chains[tenv.FeedChainSel].Weth9),
tokenConfig.GetTokenInfo(e.Logger, state.EVMState.Chains[tenv.FeedChainSel].LinkToken, state.EVMState.Chains[tenv.FeedChainSel].Weth9),
nil,
)
ocr3ConfigMap, err := internal.BuildOCR3ConfigForCCIPHome(
deployment.XXXGenerateTestOCRSecrets(),
state.Chains[tenv.FeedChainSel].OffRamp,
state.EVMState.Chains[tenv.FeedChainSel].OffRamp,
e.Chains[tenv.FeedChainSel],
nodes.NonBootstraps(),
rmnHomeAddress,
Expand All @@ -163,16 +163,16 @@ func TestActiveCandidate(t *testing.T) {

var (
timelocksPerChain = map[uint64]common.Address{
tenv.HomeChainSel: state.Chains[tenv.HomeChainSel].Timelock.Address(),
tenv.HomeChainSel: state.EVMState.Chains[tenv.HomeChainSel].Timelock.Address(),
}
proposerMCMSes = map[uint64]*gethwrappers.ManyChainMultiSig{
tenv.HomeChainSel: state.Chains[tenv.HomeChainSel].ProposerMcm,
tenv.HomeChainSel: state.EVMState.Chains[tenv.HomeChainSel].ProposerMcm,
}
)
setCommitCandidateOp, err := setCandidateOnExistingDon(
ocr3ConfigMap[cctypes.PluginTypeCCIPCommit],
state.Chains[tenv.HomeChainSel].CapabilityRegistry,
state.Chains[tenv.HomeChainSel].CCIPHome,
state.EVMState.Chains[tenv.HomeChainSel].CapabilityRegistry,
state.EVMState.Chains[tenv.HomeChainSel].CCIPHome,
tenv.FeedChainSel,
nodes.NonBootstraps(),
)
Expand All @@ -183,13 +183,13 @@ func TestActiveCandidate(t *testing.T) {
}}, "set new candidates on commit plugin", 0)
require.NoError(t, err)
setCommitCandidateSigned := commonchangeset.SignProposal(t, e, setCommitCandidateProposal)
commonchangeset.ExecuteProposal(t, e, setCommitCandidateSigned, state.Chains[tenv.HomeChainSel].Timelock, tenv.HomeChainSel)
commonchangeset.ExecuteProposal(t, e, setCommitCandidateSigned, state.EVMState.Chains[tenv.HomeChainSel].Timelock, tenv.HomeChainSel)

// create the op for the commit plugin as well
setExecCandidateOp, err := setCandidateOnExistingDon(
ocr3ConfigMap[cctypes.PluginTypeCCIPExec],
state.Chains[tenv.HomeChainSel].CapabilityRegistry,
state.Chains[tenv.HomeChainSel].CCIPHome,
state.EVMState.Chains[tenv.HomeChainSel].CapabilityRegistry,
state.EVMState.Chains[tenv.HomeChainSel].CCIPHome,
tenv.FeedChainSel,
nodes.NonBootstraps(),
)
Expand All @@ -201,10 +201,10 @@ func TestActiveCandidate(t *testing.T) {
}}, "set new candidates on commit and exec plugins", 0)
require.NoError(t, err)
setExecCandidateSigned := commonchangeset.SignProposal(t, e, setExecCandidateProposal)
commonchangeset.ExecuteProposal(t, e, setExecCandidateSigned, state.Chains[tenv.HomeChainSel].Timelock, tenv.HomeChainSel)
commonchangeset.ExecuteProposal(t, e, setExecCandidateSigned, state.EVMState.Chains[tenv.HomeChainSel].Timelock, tenv.HomeChainSel)

// check setup was successful by confirming number of nodes from cap reg
donInfo, err = state.Chains[tenv.HomeChainSel].CapabilityRegistry.GetDON(nil, donID)
donInfo, err = state.EVMState.Chains[tenv.HomeChainSel].CapabilityRegistry.GetDON(nil, donID)
require.NoError(t, err)
require.Equal(t, 4, len(donInfo.NodeP2PIds))
require.Equal(t, uint32(6), donInfo.ConfigCount)
Expand All @@ -217,32 +217,32 @@ func TestActiveCandidate(t *testing.T) {

// [NEW ACTIVE, NO CANDIDATE] promote to active
// confirm by getting old candidate digest and making sure new active matches
oldCandidateDigest, err := state.Chains[tenv.HomeChainSel].CCIPHome.GetCandidateDigest(nil, donID, uint8(cctypes.PluginTypeCCIPExec))
oldCandidateDigest, err := state.EVMState.Chains[tenv.HomeChainSel].CCIPHome.GetCandidateDigest(nil, donID, uint8(cctypes.PluginTypeCCIPExec))
require.NoError(t, err)

promoteOps, err := promoteAllCandidatesForChainOps(state.Chains[tenv.HomeChainSel].CapabilityRegistry, state.Chains[tenv.HomeChainSel].CCIPHome, tenv.FeedChainSel, nodes.NonBootstraps())
promoteOps, err := promoteAllCandidatesForChainOps(state.EVMState.Chains[tenv.HomeChainSel].CapabilityRegistry, state.EVMState.Chains[tenv.HomeChainSel].CCIPHome, tenv.FeedChainSel, nodes.NonBootstraps())
require.NoError(t, err)
promoteProposal, err := proposalutils.BuildProposalFromBatches(timelocksPerChain, proposerMCMSes, []timelock.BatchChainOperation{{
ChainIdentifier: mcms.ChainIdentifier(tenv.HomeChainSel),
Batch: promoteOps,
}}, "promote candidates and revoke actives", 0)
require.NoError(t, err)
promoteSigned := commonchangeset.SignProposal(t, e, promoteProposal)
commonchangeset.ExecuteProposal(t, e, promoteSigned, state.Chains[tenv.HomeChainSel].Timelock, tenv.HomeChainSel)
commonchangeset.ExecuteProposal(t, e, promoteSigned, state.EVMState.Chains[tenv.HomeChainSel].Timelock, tenv.HomeChainSel)
// [NEW ACTIVE, NO CANDIDATE] done promoting

// [NEW ACTIVE, NO CANDIDATE] check onchain state
newActiveDigest, err := state.Chains[tenv.HomeChainSel].CCIPHome.GetActiveDigest(nil, donID, uint8(cctypes.PluginTypeCCIPExec))
newActiveDigest, err := state.EVMState.Chains[tenv.HomeChainSel].CCIPHome.GetActiveDigest(nil, donID, uint8(cctypes.PluginTypeCCIPExec))
require.NoError(t, err)
require.Equal(t, oldCandidateDigest, newActiveDigest)

newCandidateDigest, err := state.Chains[tenv.HomeChainSel].CCIPHome.GetCandidateDigest(nil, donID, uint8(cctypes.PluginTypeCCIPCommit))
newCandidateDigest, err := state.EVMState.Chains[tenv.HomeChainSel].CCIPHome.GetCandidateDigest(nil, donID, uint8(cctypes.PluginTypeCCIPCommit))
require.NoError(t, err)
require.Equal(t, newCandidateDigest, [32]byte{})
// [NEW ACTIVE, NO CANDIDATE] done checking on chain state

// [NEW ACTIVE, NO CANDIDATE] send successful request on new active
donInfo, err = state.Chains[tenv.HomeChainSel].CapabilityRegistry.GetDON(nil, donID)
donInfo, err = state.EVMState.Chains[tenv.HomeChainSel].CapabilityRegistry.GetDON(nil, donID)
require.NoError(t, err)
require.Equal(t, uint32(8), donInfo.ConfigCount)

Expand Down
Loading

0 comments on commit 50e2fe6

Please sign in to comment.