-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchangeset.go
More file actions
156 lines (129 loc) · 4.47 KB
/
Copy pathchangeset.go
File metadata and controls
156 lines (129 loc) · 4.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
package firedrill
import (
"errors"
"fmt"
"slices"
chainselectors "github.com/smartcontractkit/chain-selectors"
cldf_chain "github.com/smartcontractkit/chainlink-deployments-framework/chain"
"github.com/smartcontractkit/chainlink-deployments-framework/changeset/sequenceutils"
cldfdatastore "github.com/smartcontractkit/chainlink-deployments-framework/datastore"
cldf "github.com/smartcontractkit/chainlink-deployments-framework/deployment"
)
var _ cldf.ChangeSetV2[Input] = Changeset{}
// Changeset creates an MCMS signing fire-drill proposal with noop operations per chain.
// It exercises signing and execution pipelines without mutating on-chain configuration.
type Changeset struct{}
// ResolvedSelectors returns the chain selectors VerifyPreconditions and Apply will use.
// When cfg.Selectors is empty, it defaults to every Solana chain in the environment followed by every EVM chain.
func (cfg Config) ResolvedSelectors(e cldf.Environment) []uint64 {
return resolvedSelectors(e, cfg.Selectors)
}
func (Changeset) VerifyPreconditions(e cldf.Environment, input Input) error {
if e.DataStore == nil {
return errors.New("datastore is required for MCMS fire drill")
}
if input.MCMS == nil {
return errors.New("MCMS timelock proposal input is required")
}
if err := input.MCMS.Validate(); err != nil {
return fmt.Errorf("invalid MCMS timelock proposal input: %w", err)
}
selectors := resolvedSelectors(e, input.Cfg.Selectors)
if len(selectors) == 0 {
return errors.New("no chain selectors resolved for MCMS fire drill")
}
byFamily := make(map[string][]ChainInput)
for _, chainSelector := range selectors {
family, err := chainselectors.GetSelectorFamily(chainSelector)
if err != nil {
return err
}
byFamily[family] = append(byFamily[family], ChainInput{
ChainSelector: chainSelector,
MCMS: *input.MCMS,
})
}
families := make([]string, 0, len(byFamily))
for family := range byFamily {
families = append(families, family)
}
slices.Sort(families)
for _, family := range families {
if err := verifyForFamily(family, e, byFamily[family]); err != nil {
return err
}
}
return nil
}
func (Changeset) Apply(e cldf.Environment, input Input) (cldf.ChangesetOutput, error) {
if input.MCMS == nil {
return cldf.ChangesetOutput{}, errors.New("MCMS timelock proposal input is required")
}
selectors := resolvedSelectors(e, input.Cfg.Selectors)
if len(selectors) == 0 {
return cldf.ChangesetOutput{}, errors.New("no chain selectors resolved for MCMS fire drill")
}
deps := Deps{
BlockChains: e.BlockChains,
DataStore: e.DataStore,
}
var agg sequenceutils.OnChainOutput
for _, chainSelector := range selectors {
seq, seqErr := SequenceForChainSelector(chainSelector)
if seqErr != nil {
return buildOutput(e, input.MCMS, agg, fmt.Errorf("chain selector %d: %w", chainSelector, seqErr))
}
var mergeErr error
agg, mergeErr = sequenceutils.ExecuteOnChainSequenceAndMerge(
e.OperationsBundle,
deps,
seq,
ChainInput{
ChainSelector: chainSelector,
MCMS: *input.MCMS,
},
agg,
)
if mergeErr != nil {
return buildOutput(e, input.MCMS, agg, mergeErr)
}
}
return buildOutput(e, input.MCMS, agg, nil)
}
func buildOutput(
e cldf.Environment,
mcmsInput *cldf.MCMSTimelockProposalInput,
agg sequenceutils.OnChainOutput,
err error,
) (cldf.ChangesetOutput, error) {
ds := cldfdatastore.NewMemoryDataStore()
if metaErr := ds.WriteMetadata(agg.Metadata); metaErr != nil {
return cldf.ChangesetOutput{DataStore: ds},
fmt.Errorf("write metadata to datastore: %w", metaErr)
}
partialOutput := cldf.ChangesetOutput{DataStore: ds}
if err != nil {
return partialOutput, err
}
builder := cldf.NewOutputBuilder(e, ds).
WithTimelockProposal(*mcmsInput, agg.BatchOps)
out, buildErr := builder.Build()
if buildErr != nil {
return out, fmt.Errorf("build changeset output: %w", buildErr)
}
if len(out.MCMSTimelockProposals) > 0 {
e.Logger.Infow("MCMS fire drill proposal created", "proposalCount", len(out.MCMSTimelockProposals))
}
return out, nil
}
func resolvedSelectors(e cldf.Environment, selectors []uint64) []uint64 {
if len(selectors) > 0 {
return selectors
}
solSelectors := e.BlockChains.ListChainSelectors(cldf_chain.WithFamily(chainselectors.FamilySolana))
evmSelectors := e.BlockChains.ListChainSelectors(cldf_chain.WithFamily(chainselectors.FamilyEVM))
out := make([]uint64, 0, len(solSelectors)+len(evmSelectors))
out = append(out, solSelectors...)
out = append(out, evmSelectors...)
return out
}