Skip to content

Commit

Permalink
Fix/ops review fixes (#198)
Browse files Browse the repository at this point in the history
* Serialize local config before comparison

* Env and flags checks + cleanup

* Read RDD from environment if --rdd flag is missing

Also, add appropriate defaults for RDD to network-specific env files

* Moving preparation for diff in a separate function

* Reading RDD from env

* Referencing issue and workaround message

Co-authored-by: Domino Valdano <[email protected]>
  • Loading branch information
sdrug and reductionista authored Mar 9, 2022
1 parent 35d4908 commit c36a496
Show file tree
Hide file tree
Showing 10 changed files with 57 additions and 50 deletions.
11 changes: 11 additions & 0 deletions packages-ts/gauntlet-terra-contracts/networks/.env.mainnet
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
NODE_URL=
CHAIN_ID=columbus-5
DEFAULT_GAS_PRICE=0.5
RDD=../reference-data-directory/directory-terra-mainnet.json

LINK=
BILLING_ACCESS_CONTROLLER=
REQUESTER_ACCESS_CONTROLLER=

CW4_GROUP=
CW3_FLEX_MULTISIG=
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
NODE_URL=https://bombay-lcd.terra.dev
CHAIN_ID=bombay-12
DEFAULT_GAS_PRICE=0.5
RDD=../reference-data-directory/directory-terra-testnet-bombay.json

LINK=terra167ccv2h0z7k0p8j6qpuzwsgu5au5qvfwgmkjsl
BILLING_ACCESS_CONTROLLER=terra1anfm045fgautt6mm5wc7uk6njx30n3cwlgvv8p
REQUESTER_ACCESS_CONTROLLER=terra1urknnpgcmgvptdmhdvex53hl72prwgcnn49t47
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { TransactionResponse, RDD } from '@chainlink/gauntlet-terra'
import { CATEGORIES } from '../../../../lib/constants'
import { AbstractInstruction, instructionToCommand, BeforeExecute } from '../../../abstract/executionWrapper'
import { serializeOffchainConfig, deserializeConfig } from '../../../../lib/encoding'
import { getOffchainConfigInput, OffchainConfig } from '../proposeOffchainConfig'
import { getOffchainConfigInput, OffchainConfig, prepareOffchainConfigForDiff } from '../proposeOffchainConfig'
import { getLatestOCRConfigEvent, longsInObjToNumbers, printDiff } from '../../../../lib/inspection'
import assert from 'assert'

Expand All @@ -24,7 +24,13 @@ const makeCommandInput = async (flags: any, args: string[]): Promise<CommandInpu
if (flags.input) return flags.input as CommandInput
const { rdd: rddPath, secret } = flags

if (!rddPath) throw new Error('RDD flag is required. Provide it with --rdd flag')
if (!secret) {
throw new Error('--secret flag is required.')
}

if (!process.env.SECRET) {
throw new Error('SECRET is not set in env!')
}

const rdd = RDD.getRDD(rddPath)
const contract = args[0]
Expand Down Expand Up @@ -57,23 +63,15 @@ const beforeExecute: BeforeExecute<CommandInput, ContractInput> = (context) => a
logger.success('RDD Generated configuration matches with onchain proposal configuration')

// Config in Proposal
const offchainConfigInProposal = await deserializeConfig(Buffer.from(proposal.offchain_config, 'base64'))
const configInProposal = longsInObjToNumbers({
...offchainConfigInProposal,
offchainPublicKeys: offchainConfigInProposal.offchainPublicKeys?.map((key) => Buffer.from(key).toString('hex')),
f: proposal.f,
})
const offchainConfigInProposal = deserializeConfig(Buffer.from(proposal.offchain_config, 'base64'))
const configInProposal = prepareOffchainConfigForDiff(offchainConfigInProposal, { f: proposal.f })

// Config in contract
const event = await getLatestOCRConfigEvent(context.provider, context.contract)
const offchainConfigInContract = event?.offchain_config
? await deserializeConfig(Buffer.from(event.offchain_config[0], 'base64'))
? deserializeConfig(Buffer.from(event.offchain_config[0], 'base64'))
: ({} as OffchainConfig)
const configInContract = longsInObjToNumbers({
...offchainConfigInContract,
offchainPublicKeys: offchainConfigInContract.offchainPublicKeys?.map((key) => Buffer.from(key).toString('hex')),
f: event?.f[0],
})
const configInContract = prepareOffchainConfigForDiff(offchainConfigInContract, { f: event?.f[0] })

logger.info('Review the configuration difference from contract and proposal: green - added, red - deleted.')
printDiff(configInContract, configInProposal)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@ const makeCommandInput = async (flags: any, args: string[]): Promise<CommandInpu

const { rdd: rddPath } = flags

if (!rddPath) {
throw new Error('No RDD flag provided!')
}

const rdd = RDD.getRDD(rddPath)
const contract = args[0]
const aggregator = rdd.contracts[contract]
Expand Down Expand Up @@ -82,16 +78,14 @@ const beforeExecute: BeforeExecute<CommandInput, ContractInput> = (context) => a
f: event?.f[0],
transmitters: event?.transmitters,
signers: event?.signers.map((s) => Buffer.from(s, 'hex').toString('base64')),
onchain_config: event?.onchain_config[0],
// todo: add payees to set_config event (https://github.com/smartcontractkit/chainlink-terra/issues/180)
payees: event?.payees,
}

const proposedConfig = {
f: context.contractInput.f,
transmitters: context.contractInput.transmitters,
signers: context.contractInput.signers,
payees: context.contractInput.payees,
onchain_config: context.contractInput.onchain_config,
}

logger.info('Review the proposed changes below: green - added, red - deleted.')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { AbstractInstruction, instructionToCommand, BeforeExecute, AfterExecute
import { time, BN } from '@chainlink/gauntlet-core/dist/utils'
import { ORACLES_MAX_LENGTH } from '../../../lib/constants'
import { CATEGORIES } from '../../../lib/constants'
import { getLatestOCRConfigEvent, printDiff } from '../../../lib/inspection'
import { getLatestOCRConfigEvent, longsInObjToNumbers, printDiff } from '../../../lib/inspection'
import { serializeOffchainConfig, deserializeConfig, generateSecretWords } from '../../../lib/encoding'
import { logger, prompt } from '@chainlink/gauntlet-core/dist/utils'

Expand Down Expand Up @@ -89,15 +89,23 @@ export const getOffchainConfigInput = (rdd: any, contract: string): OffchainConf
return input
}

export const prepareOffchainConfigForDiff = (config: OffchainConfig, extra?: Object) => {
return longsInObjToNumbers({
...config,
...(extra || {}),
offchainPublicKeys: config.offchainPublicKeys?.map((key) => Buffer.from(key).toString('hex')),
})
}

const makeCommandInput = async (flags: any, args: string[]): Promise<CommandInput> => {
if (flags.input) return flags.input as CommandInput

const { rdd: rddPath, randomSecret } = flags

if (!rddPath) {
throw new Error('No RDD flag provided!')
if (!process.env.SECRET) {
throw new Error('SECRET is not set in env!')
}

const { rdd: rddPath, randomSecret } = flags

const rdd = RDD.getRDD(rddPath)
const contract = args[0]

Expand All @@ -110,24 +118,19 @@ const makeCommandInput = async (flags: any, args: string[]): Promise<CommandInpu
}

const beforeExecute: BeforeExecute<CommandInput, ContractInput> = (context) => async () => {
// Config in contract
const event = await getLatestOCRConfigEvent(context.provider, context.contract)
const offchainConfig = event?.offchain_config
? await deserializeConfig(Buffer.from(event.offchain_config[0], 'base64'))
const offchainConfigInContract = event?.offchain_config
? deserializeConfig(Buffer.from(event.offchain_config[0], 'base64'))
: ({} as OffchainConfig)
const configInContract = prepareOffchainConfigForDiff(offchainConfigInContract, { f: event?.f })

const contractOffchainConfig = {
...offchainConfig,
offchainPublicKeys: offchainConfig.offchainPublicKeys?.map((key) => Buffer.from(key).toString('hex')),
f: event?.f,
}

const proposedOffchainConfig = {
...context.input.offchainConfig,
configPublicKeys: undefined,
}
// Proposed config
const proposedOffchainConfig = deserializeConfig(Buffer.from(context.contractInput.offchain_config, 'base64'))
const proposedConfig = prepareOffchainConfigForDiff(proposedOffchainConfig)

logger.info('Review the proposed changes below: green - added, red - deleted.')
printDiff(contractOffchainConfig, proposedOffchainConfig)
printDiff(configInContract, proposedConfig)

logger.info(
`Important: The following secret was used to encode offchain config. You will need to provide it to approve the config proposal:
Expand All @@ -143,6 +146,7 @@ const makeContractInput = async (input: CommandInput): Promise<ContractInput> =>
process.env.SECRET!,
input.randomSecret,
)

return {
id: input.proposalId,
offchain_config_version: 2,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ const validateInput = (input: CommandInput): boolean => true

const beforeExecute: BeforeExecute<CommandInput, ContractInput> = (context) => async (signer) => {
const currentOwner = await context.provider.wasm.contractQuery(context.contract, 'owner' as any)
if (!context.flags.rdd) {
throw new Error(`No RDD flag provided!`)
}
const contract = RDD.getContractFromRDD(RDD.getRDD(context.flags.rdd), context.contract)
logger.info(`Accepting Ownership Transfer of contract of type "${contract.type}":
- Contract: ${contract.address} ${contract.description ? '- ' + contract.description : ''}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@ const validateInput = (input: CommandInput): boolean => {

const beforeExecute: BeforeExecute<CommandInput, ContractInput> = (context) => async () => {
const currentOwner = await context.provider.wasm.contractQuery(context.contract, 'owner' as any)
if (!context.flags.rdd) {
throw new Error(`No RDD flag provided!`)
}
const contract = RDD.getContractFromRDD(RDD.getRDD(context.flags.rdd), context.contract)
logger.info(`Proposing Ownership Transfer of contract of type "${contract.type}":
- Contract: ${contract.address} ${contract.description ? '- ' + contract.description : ''}
Expand Down
5 changes: 2 additions & 3 deletions packages-ts/gauntlet-terra-contracts/src/lib/args.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
// Doesn't work as expected - https://github.com/smartcontractkit/chainlink-terra/issues/199
// As a workaround, default RDD flag is set from env in gauntlet-terra/src/lib/rdd.ts
export const defaultFlags = {
delta: 'delta.json',
codeIdsPath: './codeIds',
artifactsPath: './artifacts',
// TODO: when enabled it will overwrite --rdd flag always, not just when -rdd flag missing
// Default path is set as next to chainlink-terra repo folder
// rdd: '../../../../../reference-data-directory/directory-${network}.json',
}
2 changes: 1 addition & 1 deletion packages-ts/gauntlet-terra-contracts/src/lib/encoding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export const generateSecretWords = async (): Promise<string> => {
}

export const deserializeConfig = (buffer: Buffer): OffchainConfig => {
const proto = new Proto.Protobuf({ descriptor: descriptor })
const proto = new Proto.Protobuf({ descriptor })
const offchain = proto.decode('offchainreporting2_config.OffchainConfigProto', buffer)
const reportingPluginConfig = proto.decode(
'offchainreporting2_config.ReportingPluginConfig',
Expand Down
7 changes: 6 additions & 1 deletion packages-ts/gauntlet-terra/src/lib/rdd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@ import { existsSync, readFileSync } from 'fs'
import { join } from 'path'

export const getRDD = (path: string, fileDescription: string = 'RDD'): any => {
let pathToUse
path = path || process.env.RDD
if (!path) {
throw new Error(`No reference data directory specified! Must pass in the '--rdd' flag or set the 'RDD' env var`)
}

// test whether the file exists as a relative path or an absolute path
let pathToUse
if (existsSync(path)) {
pathToUse = path
} else if (existsSync(join(process.cwd(), path))) {
Expand Down

0 comments on commit c36a496

Please sign in to comment.