Skip to content

Commit

Permalink
Merge branch 'develop' into rtinianov_wasmDelegate
Browse files Browse the repository at this point in the history
  • Loading branch information
nolag committed Sep 23, 2024
2 parents 58c0db6 + b634d36 commit de0ff7d
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 48 deletions.
15 changes: 10 additions & 5 deletions integration-tests/deployment/address_book.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
var (
ErrInvalidChainSelector = fmt.Errorf("invalid chain selector")
ErrInvalidAddress = fmt.Errorf("invalid address")
ErrChainNotFound = fmt.Errorf("chain not found")
)

// ContractType is a simple string type for identifying contract types.
Expand Down Expand Up @@ -90,7 +91,7 @@ type AddressBookMap struct {
func (m *AddressBookMap) Save(chainSelector uint64, address string, typeAndVersion TypeAndVersion) error {
_, exists := chainsel.ChainBySelector(chainSelector)
if !exists {
return errors.Wrapf(ErrInvalidChainSelector, "chain selector %d not found", chainSelector)
return errors.Wrapf(ErrInvalidChainSelector, "chain selector %d", chainSelector)
}
if address == "" || address == common.HexToAddress("0x0").Hex() {
return errors.Wrap(ErrInvalidAddress, "address cannot be empty")
Expand Down Expand Up @@ -119,11 +120,15 @@ func (m *AddressBookMap) Addresses() (map[uint64]map[string]TypeAndVersion, erro
return m.AddressesByChain, nil
}

func (m *AddressBookMap) AddressesForChain(chain uint64) (map[string]TypeAndVersion, error) {
if _, exists := m.AddressesByChain[chain]; !exists {
return nil, fmt.Errorf("chain %d not found", chain)
func (m *AddressBookMap) AddressesForChain(chainSelector uint64) (map[string]TypeAndVersion, error) {
_, exists := chainsel.ChainBySelector(chainSelector)
if !exists {
return nil, errors.Wrapf(ErrInvalidChainSelector, "chain selector %d", chainSelector)
}
if _, exists := m.AddressesByChain[chainSelector]; !exists {
return nil, errors.Wrapf(ErrChainNotFound, "chain selector %d", chainSelector)
}
return m.AddressesByChain[chain], nil
return m.AddressesByChain[chainSelector], nil
}

// Attention this will mutate existing book
Expand Down
10 changes: 9 additions & 1 deletion integration-tests/deployment/address_book_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,24 @@ func TestAddressBook_Save(t *testing.T) {
err := ab.Save(chainsel.TEST_90000001.Selector, addr1, onRamp100)
require.NoError(t, err)

// Check input validation
// Invalid address
err = ab.Save(chainsel.TEST_90000001.Selector, "asdlfkj", onRamp100)
require.Error(t, err)
assert.Equal(t, errors.Is(err, ErrInvalidAddress), true, "err %s", err)

// Valid chain but not present.
_, err = ab.AddressesForChain(chainsel.TEST_90000002.Selector)
assert.Equal(t, errors.Is(err, ErrChainNotFound), true, "err %s", err)

// Invalid selector
err = ab.Save(0, addr1, onRamp100)
require.Error(t, err)
assert.Equal(t, errors.Is(err, ErrInvalidChainSelector), true)

// Duplicate
err = ab.Save(chainsel.TEST_90000001.Selector, addr1, onRamp100)
require.Error(t, err)

// Zero address
err = ab.Save(chainsel.TEST_90000001.Selector, common.HexToAddress("0x0").Hex(), onRamp100)
require.Error(t, err)
Expand Down
33 changes: 20 additions & 13 deletions integration-tests/deployment/ccip/add_chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package ccipdeployment
import (
"math/big"

"github.com/ethereum/go-ethereum/common"
"github.com/smartcontractkit/ccip-owner-contracts/tools/proposal/mcms"
"github.com/smartcontractkit/ccip-owner-contracts/tools/proposal/timelock"

Expand Down Expand Up @@ -33,7 +34,8 @@ func NewChainInboundProposal(
) (*timelock.MCMSWithTimelockProposal, error) {
// Generate proposal which enables new destination (from test router) on all source chains.
var batches []timelock.BatchChainOperation
metaDataPerChain := make(map[mcms.ChainIdentifier]timelock.MCMSWithTimelockChainMetadata)
metaDataPerChain := make(map[mcms.ChainIdentifier]mcms.ChainMetadata)
timelockAddresses := make(map[mcms.ChainIdentifier]common.Address)
for _, source := range sources {
chain, _ := chainsel.ChainBySelector(source)
enableOnRampDest, err := state.Chains[source].OnRamp.ApplyDestChainConfigUpdates(SimTransactOpts(), []onramp.OnRampDestChainConfigArgs{
Expand Down Expand Up @@ -92,13 +94,15 @@ func NewChainInboundProposal(
},
},
})
metaDataPerChain[mcms.ChainIdentifier(chain.Selector)] = timelock.MCMSWithTimelockChainMetadata{
ChainMetadata: mcms.ChainMetadata{
NonceOffset: 0,
MCMAddress: state.Chains[source].Mcm.Address(),
},
TimelockAddress: state.Chains[source].Timelock.Address(),
opCount, err := state.Chains[source].Mcm.GetOpCount(nil)
if err != nil {
return nil, err
}
metaDataPerChain[mcms.ChainIdentifier(chain.Selector)] = mcms.ChainMetadata{
StartingOpCount: opCount.Uint64(),
MCMAddress: state.Chains[source].Mcm.Address(),
}
timelockAddresses[mcms.ChainIdentifier(chain.Selector)] = state.Chains[source].Timelock.Address()
}

// Home chain new don.
Expand Down Expand Up @@ -146,13 +150,15 @@ func NewChainInboundProposal(
return nil, err
}
homeChain, _ := chainsel.ChainBySelector(homeChainSel)
metaDataPerChain[mcms.ChainIdentifier(homeChain.Selector)] = timelock.MCMSWithTimelockChainMetadata{
ChainMetadata: mcms.ChainMetadata{
NonceOffset: 0,
MCMAddress: state.Chains[homeChainSel].Mcm.Address(),
},
TimelockAddress: state.Chains[homeChainSel].Timelock.Address(),
opCount, err := state.Chains[homeChainSel].Mcm.GetOpCount(nil)
if err != nil {
return nil, err
}
metaDataPerChain[mcms.ChainIdentifier(homeChain.Selector)] = mcms.ChainMetadata{
StartingOpCount: opCount.Uint64(),
MCMAddress: state.Chains[homeChainSel].Mcm.Address(),
}
timelockAddresses[mcms.ChainIdentifier(homeChain.Selector)] = state.Chains[homeChainSel].Timelock.Address()
batches = append(batches, timelock.BatchChainOperation{
ChainIdentifier: mcms.ChainIdentifier(homeChain.Selector),
Batch: []mcms.Operation{
Expand All @@ -175,6 +181,7 @@ func NewChainInboundProposal(
[]mcms.Signature{},
false,
metaDataPerChain,
timelockAddresses,
"blah", // TODO
batches,
timelock.Schedule,
Expand Down
44 changes: 25 additions & 19 deletions integration-tests/deployment/ccip/propose.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ func SignProposal(t *testing.T, env deployment.Environment, proposal *timelock.M
chainSel := mcms.ChainIdentifier(chainselc.Selector)
executorClients[chainSel] = chain.Client
}
realProposal, err := proposal.ToMCMSOnlyProposal()
require.NoError(t, err)
executor, err := realProposal.ToExecutor(executorClients)
executor, err := proposal.ToExecutor(true)
require.NoError(t, err)
payload, err := executor.SigningHash()
require.NoError(t, err)
Expand All @@ -45,15 +43,15 @@ func SignProposal(t *testing.T, env deployment.Environment, proposal *timelock.M
require.NoError(t, err)
mcmSig, err := mcms.NewSignatureFromBytes(sig)
require.NoError(t, err)
executor.Proposal.Signatures = append(executor.Proposal.Signatures, mcmSig)
executor.Proposal.AddSignature(mcmSig)
require.NoError(t, executor.Proposal.Validate())
return executor
}

func ExecuteProposal(t *testing.T, env deployment.Environment, executor *mcms.Executor,
state CCIPOnChainState, sel uint64) {
// Set the root.
tx, err2 := executor.SetRootOnChain(env.Chains[sel].DeployerKey, mcms.ChainIdentifier(sel))
tx, err2 := executor.SetRootOnChain(env.Chains[sel].Client, env.Chains[sel].DeployerKey, mcms.ChainIdentifier(sel))
require.NoError(t, err2)
_, err2 = env.Chains[sel].Confirm(tx)
require.NoError(t, err2)
Expand All @@ -63,7 +61,7 @@ func ExecuteProposal(t *testing.T, env deployment.Environment, executor *mcms.Ex
for _, chainOp := range executor.Operations[mcms.ChainIdentifier(sel)] {
for idx, op := range executor.ChainAgnosticOps {
if bytes.Equal(op.Data, chainOp.Data) && op.To == chainOp.To {
opTx, err3 := executor.ExecuteOnChain(env.Chains[sel].DeployerKey, idx)
opTx, err3 := executor.ExecuteOnChain(env.Chains[sel].Client, env.Chains[sel].DeployerKey, idx)
require.NoError(t, err3)
block, err3 := env.Chains[sel].Confirm(opTx)
require.NoError(t, err3)
Expand Down Expand Up @@ -104,7 +102,8 @@ func GenerateAcceptOwnershipProposal(
) (*timelock.MCMSWithTimelockProposal, error) {
// TODO: Accept rest of contracts
var batches []timelock.BatchChainOperation
metaDataPerChain := make(map[mcms.ChainIdentifier]timelock.MCMSWithTimelockChainMetadata)
metaDataPerChain := make(map[mcms.ChainIdentifier]mcms.ChainMetadata)
timelockAddresses := make(map[mcms.ChainIdentifier]common.Address)
for _, sel := range chains {
chain, _ := chainsel.ChainBySelector(sel)
acceptOnRamp, err := state.Chains[sel].OnRamp.AcceptOwnership(SimTransactOpts())
Expand All @@ -116,13 +115,15 @@ func GenerateAcceptOwnershipProposal(
return nil, err
}
chainSel := mcms.ChainIdentifier(chain.Selector)
metaDataPerChain[chainSel] = timelock.MCMSWithTimelockChainMetadata{
ChainMetadata: mcms.ChainMetadata{
NonceOffset: 0,
MCMAddress: state.Chains[sel].Mcm.Address(),
},
TimelockAddress: state.Chains[sel].Timelock.Address(),
opCount, err := state.Chains[sel].Mcm.GetOpCount(nil)
if err != nil {
return nil, err
}
metaDataPerChain[chainSel] = mcms.ChainMetadata{
MCMAddress: state.Chains[sel].Mcm.Address(),
StartingOpCount: opCount.Uint64(),
}
timelockAddresses[chainSel] = state.Chains[sel].Timelock.Address()
batches = append(batches, timelock.BatchChainOperation{
ChainIdentifier: chainSel,
Batch: []mcms.Operation{
Expand All @@ -139,6 +140,7 @@ func GenerateAcceptOwnershipProposal(
},
})
}

acceptCR, err := state.Chains[homeChain].CapabilityRegistry.AcceptOwnership(SimTransactOpts())
if err != nil {
return nil, err
Expand All @@ -148,13 +150,15 @@ func GenerateAcceptOwnershipProposal(
return nil, err
}
homeChainID := mcms.ChainIdentifier(homeChain)
metaDataPerChain[homeChainID] = timelock.MCMSWithTimelockChainMetadata{
ChainMetadata: mcms.ChainMetadata{
NonceOffset: 0,
MCMAddress: state.Chains[homeChain].Mcm.Address(),
},
TimelockAddress: state.Chains[homeChain].Timelock.Address(),
opCount, err := state.Chains[homeChain].Mcm.GetOpCount(nil)
if err != nil {
return nil, err
}
metaDataPerChain[homeChainID] = mcms.ChainMetadata{
StartingOpCount: opCount.Uint64(),
MCMAddress: state.Chains[homeChain].Mcm.Address(),
}
timelockAddresses[homeChainID] = state.Chains[homeChain].Timelock.Address()
batches = append(batches, timelock.BatchChainOperation{
ChainIdentifier: homeChainID,
Batch: []mcms.Operation{
Expand All @@ -170,12 +174,14 @@ func GenerateAcceptOwnershipProposal(
},
},
})

return timelock.NewMCMSWithTimelockProposal(
"1",
2004259681, // TODO
[]mcms.Signature{},
false,
metaDataPerChain,
timelockAddresses,
"blah", // TODO
batches,
timelock.Schedule, "0s")
Expand Down
20 changes: 13 additions & 7 deletions integration-tests/deployment/ccip/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
"github.com/pkg/errors"

chainsel "github.com/smartcontractkit/chain-selectors"

"github.com/smartcontractkit/chainlink/integration-tests/deployment"
Expand Down Expand Up @@ -35,6 +34,8 @@ import (
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/aggregator_v3_interface"
)

// CCIPChainState holds a Go binding for all the currently deployed CCIP contracts
// on a chain. If a binding is nil, it means here is no such contract on the chain.
type CCIPChainState struct {
OnRamp *onramp.OnRamp
OffRamp *offramp.OffRamp
Expand Down Expand Up @@ -177,12 +178,17 @@ func LoadOnchainState(e deployment.Environment, ab deployment.AddressBook) (CCIP
state := CCIPOnChainState{
Chains: make(map[uint64]CCIPChainState),
}
addresses, err := ab.Addresses()
if err != nil {
return state, errors.Wrap(err, "could not get addresses")
}
for chainSelector, addresses := range addresses {
chainState, err := LoadChainState(e.Chains[chainSelector], addresses)
for chainSelector, chain := range e.Chains {
addresses, err := ab.AddressesForChain(chainSelector)
if err != nil {
// Chain not found in address book, initialize empty
if errors.Is(err, deployment.ErrChainNotFound) {
addresses = make(map[string]deployment.TypeAndVersion)
} else {
return state, err
}
}
chainState, err := LoadChainState(chain, addresses)
if err != nil {
return state, err
}
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ require (
github.com/sethvargo/go-retry v0.2.4
github.com/shopspring/decimal v1.4.0
github.com/slack-go/slack v0.12.2
github.com/smartcontractkit/ccip-owner-contracts v0.0.0-20240910151738-3f318badcfb5
github.com/smartcontractkit/ccip-owner-contracts v0.0.0-20240919155713-f4bf4ae0b9c6
github.com/smartcontractkit/chain-selectors v1.0.23
github.com/smartcontractkit/chainlink-automation v1.0.4
github.com/smartcontractkit/chainlink-ccip v0.0.0-20240920150748-cf2125c094fe
Expand Down
4 changes: 2 additions & 2 deletions integration-tests/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1421,8 +1421,8 @@ github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/slack-go/slack v0.12.2 h1:x3OppyMyGIbbiyFhsBmpf9pwkUzMhthJMRNmNlA4LaQ=
github.com/slack-go/slack v0.12.2/go.mod h1:hlGi5oXA+Gt+yWTPP0plCdRKmjsDxecdHxYQdlMQKOw=
github.com/smartcontractkit/ccip-owner-contracts v0.0.0-20240910151738-3f318badcfb5 h1:m0HuGuVdRHqBBkHJpSR/QBV7gtLB+hFkXZQ9tEkjdzo=
github.com/smartcontractkit/ccip-owner-contracts v0.0.0-20240910151738-3f318badcfb5/go.mod h1:N60/wwocvZ5A3RGmYaMWo0fPFa5tTMlhI9lJ22DRktM=
github.com/smartcontractkit/ccip-owner-contracts v0.0.0-20240919155713-f4bf4ae0b9c6 h1:e4lR/xTK7iOeCniSwH6hdaNZZ/sJs1eYWpnJoz3CXxI=
github.com/smartcontractkit/ccip-owner-contracts v0.0.0-20240919155713-f4bf4ae0b9c6/go.mod h1:nlRI0m23HFMAHf7cKYdE58mPbXsTyY1y3ZLJxnuuoCM=
github.com/smartcontractkit/chain-selectors v1.0.23 h1:D2Eaex4Cw/O7Lg3tX6WklOqnjjIQAEBnutCtksPzVDY=
github.com/smartcontractkit/chain-selectors v1.0.23/go.mod h1:d4Hi+E1zqjy9HqMkjBE5q1vcG9VGgxf5VxiRHfzi2kE=
github.com/smartcontractkit/chainlink-automation v1.0.4 h1:iyW181JjKHLNMnDleI8umfIfVVlwC7+n5izbLSFgjw8=
Expand Down

0 comments on commit de0ff7d

Please sign in to comment.