Skip to content

Commit

Permalink
feat(keystone/scripts): deploy custom compute action with default config
Browse files Browse the repository at this point in the history
  • Loading branch information
MStreet3 committed Oct 10, 2024
1 parent 515b739 commit 606980d
Showing 1 changed file with 50 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,12 @@ var (
Signer: "dbce9a6df8a04d54e52a109d01ee9b5d32873b1d2436cf7b7fae61fd6eca46f8",
},
}

defaultComputeModuleConfig = map[string]any{
"defaultTickInterval": "100ms",
"defaultTimeout": "300ms",
"defaultMaxMemoryMBs": int64(64),
}
)

type deployAndInitializeCapabilitiesRegistryCommand struct{}
Expand Down Expand Up @@ -190,9 +196,30 @@ func peerToNode(nopID uint32, p peer) (kcr.CapabilitiesRegistryNodeParams, error
}, nil
}

func newCapabilityConfig() *capabilitiespb.CapabilityConfig {
// newCapabilityConfig returns a new capability config with the default config set as empty.
// Override the empty default config with functional options.
func newCapabilityConfig(opts ...func(*values.Map)) *capabilitiespb.CapabilityConfig {
dc := values.EmptyMap()
for _, opt := range opts {
opt(dc)
}

return &capabilitiespb.CapabilityConfig{
DefaultConfig: values.Proto(values.EmptyMap()).GetMapValue(),
DefaultConfig: values.ProtoMap(dc),
}
}

// withDefaultConfig returns a function that sets the default config for a capability by merging
// the provided map with the existing default config. This is a shallow merge.
func withDefaultConfig(m map[string]any) func(*values.Map) {
return func(dc *values.Map) {
overrides, err := values.NewMap(m)
if err != nil {
panic(err)
}
for k, v := range overrides.Underlying {
dc.Underlying[k] = v
}
}
}

Expand Down Expand Up @@ -259,6 +286,16 @@ func (c *deployAndInitializeCapabilitiesRegistryCommand) Run(args []string) {
panic(err)
}

computeAction := kcr.CapabilitiesRegistryCapability{
LabelledName: "custom-compute",
Version: "1.0.0",
CapabilityType: uint8(1), // action
}
aid, err := reg.GetHashedCapabilityId(&bind.CallOpts{}, computeAction.LabelledName, computeAction.Version)
if err != nil {
panic(err)
}

writeChain := kcr.CapabilitiesRegistryCapability{
LabelledName: "write_ethereum-testnet-sepolia",
Version: "1.0.0",
Expand Down Expand Up @@ -295,6 +332,7 @@ func (c *deployAndInitializeCapabilitiesRegistryCommand) Run(args []string) {
aptosWriteChain,
ocr,
cronTrigger,
computeAction,
})
if err != nil {
log.Printf("failed to call AddCapabilities: %s", err)
Expand Down Expand Up @@ -380,6 +418,12 @@ func (c *deployAndInitializeCapabilitiesRegistryCommand) Run(args []string) {
panic(err)
}

computeCfg := newCapabilityConfig(withDefaultConfig(defaultComputeModuleConfig))
ccfgb, err := proto.Marshal(computeCfg)
if err != nil {
panic(err)
}

cfgs := []kcr.CapabilitiesRegistryCapabilityConfiguration{
{
CapabilityId: ocrid,
Expand All @@ -389,6 +433,10 @@ func (c *deployAndInitializeCapabilitiesRegistryCommand) Run(args []string) {
CapabilityId: ctid,
Config: ccb,
},
{
CapabilityId: aid,
Config: ccfgb,
},
}
_, err = reg.AddDON(env.Owner, ps, cfgs, true, true, 2)
if err != nil {
Expand Down

0 comments on commit 606980d

Please sign in to comment.