From 48926949a65a25656e73b29f690f365eff63ab11 Mon Sep 17 00:00:00 2001 From: Michael Street <5597260+MStreet3@users.noreply.github.com> Date: Thu, 9 Jan 2025 15:39:00 -0500 Subject: [PATCH] feat(keystone/changeset): add capabilities and add nops as mcms proposals --- .../keystone/changeset/internal/deploy.go | 61 +++++++++++++------ 1 file changed, 42 insertions(+), 19 deletions(-) diff --git a/deployment/keystone/changeset/internal/deploy.go b/deployment/keystone/changeset/internal/deploy.go index b52d269518d..33b36d647ef 100644 --- a/deployment/keystone/changeset/internal/deploy.go +++ b/deployment/keystone/changeset/internal/deploy.go @@ -416,10 +416,14 @@ type RegisterCapabilitiesRequest struct { Env *deployment.Environment RegistryChainSelector uint64 DonToCapabilities map[string][]capabilities_registry.CapabilitiesRegistryCapability + + // if UseMCMS is true, a batch proposal is returned and no transaction is confirmed on chain. + UseMCMS bool } type RegisterCapabilitiesResponse struct { DonToCapabilities map[string][]RegisteredCapability + Ops *timelock.BatchChainOperation } type RegisteredCapability struct { @@ -492,11 +496,14 @@ func RegisterCapabilities(lggr logger.Logger, req RegisterCapabilitiesRequest) ( lggr.Warn("no new capabilities to register") return &RegisterCapabilitiesResponse{}, nil } - // not using mcms; ignore proposals - _, err = AddCapabilities(lggr, &contracts, registryChain, capabilities, false) + + batches, err := AddCapabilities(lggr, &contracts, registryChain, capabilities, req.UseMCMS) if err != nil { return nil, fmt.Errorf("failed to add capabilities: %w", err) } + + resp.Ops = batches + return resp, nil } @@ -504,10 +511,12 @@ type RegisterNOPSRequest struct { Env *deployment.Environment RegistryChainSelector uint64 Nops []capabilities_registry.CapabilitiesRegistryNodeOperator + UseMCMS bool } type RegisterNOPSResponse struct { Nops []*capabilities_registry.CapabilitiesRegistryNodeOperatorAdded + Ops *timelock.BatchChainOperation } func RegisterNOPS(ctx context.Context, lggr logger.Logger, req RegisterNOPSRequest) (*RegisterNOPSResponse, error) { @@ -550,26 +559,40 @@ func RegisterNOPS(ctx context.Context, lggr logger.Logger, req RegisterNOPSReque err = deployment.DecodeErr(capabilities_registry.CapabilitiesRegistryABI, err) return nil, fmt.Errorf("failed to call AddNodeOperators: %w", err) } - // for some reason that i don't understand, the confirm must be called before the WaitMined or the latter will hang - // (at least for a simulated backend chain) - _, err = registryChain.Confirm(tx) - if err != nil { - return nil, fmt.Errorf("failed to confirm AddNodeOperators confirm transaction %s: %w", tx.Hash().String(), err) - } - receipt, err := bind.WaitMined(ctx, registryChain.Client, tx) - if err != nil { - return nil, fmt.Errorf("failed to mine AddNodeOperators confirm transaction %s: %w", tx.Hash().String(), err) - } - if len(receipt.Logs) != len(nops) { - return nil, fmt.Errorf("expected %d log entries for AddNodeOperators, got %d", len(nops), len(receipt.Logs)) - } - for i, log := range receipt.Logs { - o, err := registry.ParseNodeOperatorAdded(*log) + if !req.UseMCMS { + // for some reason that i don't understand, the confirm must be called before the WaitMined or the latter will hang + // (at least for a simulated backend chain) + _, err = registryChain.Confirm(tx) if err != nil { - return nil, fmt.Errorf("failed to parse log %d for operator added: %w", i, err) + return nil, fmt.Errorf("failed to confirm AddNodeOperators confirm transaction %s: %w", tx.Hash().String(), err) + } + + receipt, err := bind.WaitMined(ctx, registryChain.Client, tx) + if err != nil { + return nil, fmt.Errorf("failed to mine AddNodeOperators confirm transaction %s: %w", tx.Hash().String(), err) + } + if len(receipt.Logs) != len(nops) { + return nil, fmt.Errorf("expected %d log entries for AddNodeOperators, got %d", len(nops), len(receipt.Logs)) + } + for i, log := range receipt.Logs { + o, err := registry.ParseNodeOperatorAdded(*log) + if err != nil { + return nil, fmt.Errorf("failed to parse log %d for operator added: %w", i, err) + } + resp.Nops = append(resp.Nops, o) + } + } else { + resp.Ops = &timelock.BatchChainOperation{ + ChainIdentifier: mcms.ChainIdentifier(registryChain.Selector), + Batch: []mcms.Operation{ + { + To: registry.Address(), + Data: tx.Data(), + Value: big.NewInt(0), + }, + }, } - resp.Nops = append(resp.Nops, o) } return resp, nil