Skip to content

Commit 09ebc1a

Browse files
authored
BCI-3127: write lastConfigDigest to rdd (#419)
1 parent 485e601 commit 09ebc1a

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

.tool-versions

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ mockery 2.22.1
99
golangci-lint 1.55.0
1010
actionlint 1.6.12
1111
shellcheck 0.8.0
12-
scarb 2.5.4
12+
scarb 2.6.3
1313
postgres 15.1
1414

1515
# Kubernetes

packages-ts/starknet-gauntlet-ocr2/src/commands/ocr2/setConfig.ts

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import fs from 'fs'
12
import {
23
CONTRACT_TYPES,
34
AfterExecute,
@@ -122,7 +123,7 @@ const makeContractInput = async (
122123
input.offchainConfig,
123124
input.secret,
124125
)
125-
let onchainConfig = [] // onchain config should be empty array for input (generate onchain)
126+
const onchainConfig = [] // onchain config should be empty array for input (generate onchain)
126127
return [oracles, input.f, onchainConfig, 2, bytesToFelts(offchainConfig)]
127128
}
128129

@@ -172,16 +173,36 @@ const afterExecute: AfterExecute<SetConfigInput, ContractInput> = (context, inpu
172173
if (!txInfo.isSuccess()) {
173174
return { successfulConfiguration: false }
174175
}
175-
const eventData = txInfo.events[0].data
176-
177176
const events = context.contract.parseEvents(txInfo)
178177
const event = events[events.length - 1]['ConfigSet']
179178
const offchainConfig = decodeOffchainConfigFromEventData(event.offchain_config as BigNumberish[])
179+
180180
try {
181181
// remove cfg keys from user input
182182
delete input.user.offchainConfig.configPublicKeys
183183
assert.deepStrictEqual(offchainConfig, input.user.offchainConfig)
184184
deps.logger.success('Configuration was successfully set')
185+
186+
// write lastConfigDigest back to RDD
187+
const configDigest = `0x0${(event.latest_config_digest as bigint).toString(16)}`
188+
deps.logger.info(`ℹ️ lastConfigDigest to save in RDD: ${configDigest}`)
189+
if (context.flags.rdd) {
190+
deps.logger.info(
191+
`ℹ️ RDD file ${context.flags.rdd} found! Will automatically update lastConfigDigest for you`,
192+
)
193+
const rdd = getRDD(context.flags.rdd)
194+
const newConfig = { ...rdd.config, ...{ lastConfigDigest: configDigest } }
195+
const newRdd = { ...rdd, ...{ config: newConfig } }
196+
fs.writeFileSync(context.flags.rdd, JSON.stringify(newRdd, null, 2))
197+
deps.logger.info(
198+
`✅ RDD file ${context.flags.rdd} updated. Please reformat RDD (run ./bin/generate and ./bin/degenerate) as needed`,
199+
)
200+
} else {
201+
deps.logger.info(
202+
`❗❗ no rdd file input, you must manually update lastConfigDigest in rdd yourself`,
203+
)
204+
}
205+
185206
return { successfulConfiguration: true }
186207
} catch (e) {
187208
deps.logger.error('Configuration set is different than provided')

0 commit comments

Comments
 (0)