-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Some renaming, pull migrations closer to code
- Loading branch information
1 parent
bfec573
commit 4d7eae6
Showing
16 changed files
with
346 additions
and
118 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
39 changes: 39 additions & 0 deletions
39
core/capabilities/ccip/deployment/migrations/1_initial_deploy.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,39 @@ | ||
package migrations | ||
|
||
import ( | ||
"github.com/ethereum/go-ethereum/common" | ||
|
||
ccipdeployment "github.com/smartcontractkit/chainlink/v2/core/capabilities/ccip/deployment" | ||
"github.com/smartcontractkit/chainlink/v2/core/deployment" | ||
) | ||
|
||
// We expect the migration input to be unique per migration. | ||
// TODO: Maybe there's a generics approach here? | ||
func Apply0001(env deployment.Environment, c ccipdeployment.DeployCCIPContractConfig) (deployment.MigrationOutput, error) { | ||
ab, err := ccipdeployment.DeployCCIPContracts(env, c) | ||
if err != nil { | ||
// If we fail here, just throw away the addresses. | ||
// TODO: if expensive could consider partial recovery | ||
env.Logger.Errorw("Failed to deploy CCIP contracts", "err", err, "addresses", ab) | ||
return deployment.MigrationOutput{}, err | ||
} | ||
state, err := ccipdeployment.GenerateOnchainState(env, ab) | ||
if err != nil { | ||
return deployment.MigrationOutput{}, err | ||
} | ||
js, err := ccipdeployment.GenerateJobSpecs(common.Address{}) | ||
if err != nil { | ||
return deployment.MigrationOutput{}, err | ||
} | ||
proposal, err := ccipdeployment.GenerateAcceptOwnershipProposal(env, env.AllChainSelectors(), state) | ||
if err != nil { | ||
return deployment.MigrationOutput{}, err | ||
} | ||
return deployment.MigrationOutput{ | ||
Proposals: []deployment.Proposal{proposal}, | ||
AddressBook: ab, | ||
JobSpecs: map[string][]string{ | ||
"chain-layer": {js.String()}, | ||
}, | ||
}, nil | ||
} |
52 changes: 52 additions & 0 deletions
52
core/capabilities/ccip/deployment/migrations/1_initial_deploy_test.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,52 @@ | ||
package migrations | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
ccipdeployment "github.com/smartcontractkit/chainlink/v2/core/capabilities/ccip/deployment" | ||
"github.com/smartcontractkit/chainlink/v2/core/deployment" | ||
) | ||
|
||
func Test0001_InitialDeploy(t *testing.T) { | ||
t.Skip() // WIP | ||
e := deployment.NewMemoryEnvironment(t, deployment.MemoryEnvironmentConfig{ | ||
Chains: 1, | ||
Nodes: 1, | ||
}) | ||
// Apply migration | ||
output, err := Apply0001(e, ccipdeployment.DeployCCIPContractConfig{}) | ||
require.NoError(t, err) | ||
|
||
state, err := ccipdeployment.GenerateOnchainState(e, output.AddressBook) | ||
require.NoError(t, err) | ||
|
||
// TODO: Validate jobs | ||
// Apply jobs | ||
for nodeIDs, jobs := range output.JobSpecs { | ||
for _, job := range jobs { | ||
_, err := e.Offchain.ProposeJob(context.Background(), nodeIDs, job) | ||
require.NoError(t, err) | ||
} | ||
} | ||
// TODO: Inspect proposal | ||
// Apply proposal | ||
require.NoError(t, ccipdeployment.ApplyProposal(e, output.Proposals[0], state)) | ||
|
||
// TODO: Inspect onchain state | ||
// TODO: Send traffic | ||
|
||
//snap, err := state.Snapshot(e.AllChainSelectors()) | ||
//require.NoError(t, err) | ||
// | ||
//// Assert expect every deployed address to be in the address book. | ||
//for name, chain := range snap.Chains { | ||
// addrs, err := ab.Addresses() | ||
// require.NoError(t, err) | ||
// evmChainID, _ := chainsel.ChainIdFromName(name) | ||
// sel, _ := chainsel.SelectorFromChainId(evmChainID) | ||
// assert.Contains(t, addrs[sel], chain.TokenAdminRegistry.String()) | ||
//} | ||
} |
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,46 @@ | ||
package deployment | ||
|
||
import ( | ||
"math/big" | ||
"time" | ||
|
||
"github.com/ethereum/go-ethereum/common" | ||
chainsel "github.com/smartcontractkit/chain-selectors" | ||
|
||
"github.com/smartcontractkit/chainlink/v2/core/deployment" | ||
) | ||
|
||
func GenerateAcceptOwnershipProposal( | ||
e deployment.Environment, | ||
chains []uint64, | ||
state CCIPOnChainState, | ||
) (deployment.Proposal, error) { | ||
// TODO: Just onramp as an example | ||
var ops []deployment.ManyChainMultiSigOp | ||
for _, sel := range chains { | ||
e.Chains[sel].DeployerKey.NoSend = true | ||
txData, err := state.EvmOnRampsV160[sel].AcceptOwnership(e.Chains[sel].DeployerKey) | ||
if err != nil { | ||
return deployment.Proposal{}, err | ||
} | ||
evmID, err := chainsel.ChainIdFromSelector(sel) | ||
if err != nil { | ||
return deployment.Proposal{}, err | ||
} | ||
ops = append(ops, deployment.ManyChainMultiSigOp{ | ||
ChainId: big.NewInt(int64(evmID)), | ||
MultiSig: common.Address{}, | ||
Nonce: big.NewInt(0), | ||
To: state.EvmOnRampsV160[sel].Address(), | ||
Value: big.NewInt(0), | ||
Data: txData.Data(), | ||
}) | ||
} | ||
// TODO: Real valid until. | ||
return deployment.Proposal{ValidUntil: uint32(time.Now().Unix()), Ops: ops}, nil | ||
} | ||
|
||
func ApplyProposal(env deployment.Environment, p deployment.Proposal, state CCIPOnChainState) error { | ||
// TODO | ||
return nil | ||
} |
Oops, something went wrong.