Skip to content

Commit

Permalink
deprecate flags, use dynamic on chain values, add tests (#452)
Browse files Browse the repository at this point in the history
### Description

* mark flags as deprecated which will be non functional on L2 
* use values from on chain for lock requirements
* test member add/remove and deregister

#### Other changes

add async conditional check to checks 

### Related issues

- Fixes #451

<!-- start pr-codex -->

---

## PR-Codex overview
This PR focuses on introducing deprecation warnings for certain flags,
updating descriptions for commands, and enhancing validation checks
related to validator and validator group deregistration processes.
Additionally, it improves the handling of locked gold requirements.

### Detailed summary
- Deprecated `blsKey` and `blsPop` flags in various commands.
- Updated descriptions in `ValidatorDeregister` and
`ValidatorGroupDeRegister` classes.
- Added `humanizeRequirements` function to format locked gold
requirements.
- Improved validation checks for deregistration based on time periods.
- Enhanced tests for validator group membership and deregistration
processes.

> ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your
question}`

<!-- end pr-codex -->
  • Loading branch information
aaronmgdr authored Nov 25, 2024
1 parent d5c9204 commit 2283374
Show file tree
Hide file tree
Showing 20 changed files with 404 additions and 160 deletions.
5 changes: 5 additions & 0 deletions .changeset/perfect-pianos-jump.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@celo/celocli': patch
---

Show deprecated warning on flags which will be removed after cel2 launch
5 changes: 5 additions & 0 deletions .changeset/rude-schools-help.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@celo/celocli': patch
---

use onchain values instead of static for lock requirements
12 changes: 6 additions & 6 deletions docs/command-line-interface/validator.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ _See code: [src/commands/validator/deaffiliate.ts](https://github.com/celo-org/d

## `celocli validator:deregister`

Deregister a Validator. Approximately 60 days after the validator is no longer part of any group, it will be possible to deregister the validator and start unlocking the CELO. If you wish to deregister your validator, you must first remove it from it's group, such as by deaffiliating it, then wait the required 60 days before running this command.
Deregister a Validator. Wait the require lock period after the validator is no longer part of any group, then it will be possible to deregister the validator and start unlocking the CELO. If you wish to deregister your validator, you must first remove it from it's group, such as by deaffiliating it, then wait the required days before running this command.

```
USAGE
Expand Down Expand Up @@ -170,11 +170,11 @@ FLAGS
Set it to use a ledger wallet
DESCRIPTION
Deregister a Validator. Approximately 60 days after the validator is no longer part of
any group, it will be possible to deregister the validator and start unlocking the
CELO. If you wish to deregister your validator, you must first remove it from it's
group, such as by deaffiliating it, then wait the required 60 days before running this
command.
Deregister a Validator. Wait the require lock period after the validator is no longer
part of any group, then it will be possible to deregister the validator and start
unlocking the CELO. If you wish to deregister your validator, you must first remove it
from it's group, such as by deaffiliating it, then wait the required days before
running this command.
EXAMPLES
deregister --from 0x47e172f6cfb6c7d01c1574fa3e2be7cc73269d95
Expand Down
10 changes: 5 additions & 5 deletions docs/command-line-interface/validatorgroup.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ _See code: [src/commands/validatorgroup/commission.ts](https://github.com/celo-o

## `celocli validatorgroup:deregister`

Deregister a Validator Group. Approximately 180 days after the validator group is empty, it will be possible to deregister it start unlocking the CELO. If you wish to deregister your validator group, you must first remove all members, then wait the required 180 days before running this command.
Deregister a Validator Group. After the group lock perioid has passed it will be possible to deregister it start unlocking the CELO. If you wish to deregister your validator group, you must first remove all members, then wait the required time before running this command.

```
USAGE
Expand Down Expand Up @@ -114,10 +114,10 @@ FLAGS
Set it to use a ledger wallet
DESCRIPTION
Deregister a Validator Group. Approximately 180 days after the validator group is
empty, it will be possible to deregister it start unlocking the CELO. If you wish to
deregister your validator group, you must first remove all members, then wait the
required 180 days before running this command.
Deregister a Validator Group. After the group lock perioid has passed it will be
possible to deregister it start unlocking the CELO. If you wish to deregister your
validator group, you must first remove all members, then wait the required time before
running this command.
EXAMPLES
deregister --from 0x47e172f6cfb6c7d01c1574fa3e2be7cc73269d95
Expand Down
4 changes: 1 addition & 3 deletions packages/cli/src/base-l2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@ describe('flags', () => {
await help.showHelp(['transfer:celo', '--help'])
expect(stripAnsiCodesFromNestedArray(writeSpy.mock.calls)).toHaveLength(3)
expect(stripAnsiCodesFromNestedArray(writeSpy.mock.calls)[1][0]).toEqual(
expect.stringContaining(
`-n, --node=<value> URL of the node to run commands against or an alias`
)
expect.stringContaining(`-n, --node=<value>`)
)
})
})
Expand Down
2 changes: 2 additions & 0 deletions packages/cli/src/commands/account/authorize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@ export default class Authorize extends BaseCommand {
}),
signer: CustomFlags.address({ required: true }),
blsKey: CustomFlags.blsPublicKey({
deprecated: true,
description:
'The BLS public key that the validator is using for consensus, should pass proof of possession. 96 bytes.',
dependsOn: ['blsPop'],
required: false,
}),
blsPop: CustomFlags.blsProofOfPossession({
deprecated: true,
description:
'The BLS public key proof-of-possession, which consists of a signature on the account address. 48 bytes.',
dependsOn: ['blsKey'],
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/dkg/register.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default class DKGRegister extends BaseCommand {

static flags = {
...BaseCommand.flags,
blsKey: Flags.string({ required: true }),
blsKey: Flags.string({ required: true, deprecated: true }),
address: CustomFlags.address({ required: true, description: 'DKG Contract Address' }),
from: CustomFlags.address({ required: true, description: 'Address of the sender' }),
}
Expand Down
2 changes: 2 additions & 0 deletions packages/cli/src/commands/releasecelo/authorize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@ export default class Authorize extends ReleaseGoldBaseCommand {
required: true,
}),
blsKey: CustomFlags.blsPublicKey({
deprecated: true,
description:
'The BLS public key that the validator is using for consensus, should pass proof of possession. 96 bytes.',
dependsOn: ['blsPop'],
}),
blsPop: CustomFlags.blsProofOfPossession({
deprecated: true,
description:
'The BLS public key proof-of-possession, which consists of a signature on the account address. 48 bytes.',
dependsOn: ['blsKey'],
Expand Down
8 changes: 5 additions & 3 deletions packages/cli/src/commands/validator/affiliate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Flags } from '@oclif/core'
import prompts from 'prompts'
import { BaseCommand } from '../../base'
import { newCheckBuilder } from '../../utils/checks'
import { displaySendTx } from '../../utils/cli'
import { displaySendTx, humanizeRequirements } from '../../utils/cli'
import { CustomArgs, CustomFlags } from '../../utils/command'

export default class ValidatorAffiliate extends BaseCommand {
Expand Down Expand Up @@ -39,12 +39,14 @@ export default class ValidatorAffiliate extends BaseCommand {
.isValidatorGroup(groupAddress)
.runChecks()

const requirements = await validators.getValidatorLockedGoldRequirements()
const { requiredCelo, requiredDays } = humanizeRequirements(requirements)
if (!res.flags.yes) {
const response = await prompts({
type: 'confirm',
name: 'confirmation',
message:
'Are you sure you want to affiliate with this group?\nAffiliating with a Validator Group could result in Locked Gold requirements of up to 10,000 CELO for 60 days. (y/n)',
message: `Are you sure you want to affiliate with this group?
Affiliating with a Validator Group could result in Locked Gold requirements of up to ${requiredCelo} CELO for ${requiredDays}. (y/n)`,
})

if (!response.confirmation) {
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/commands/validator/deregister.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ testWithAnvilL2('validator:deregister', (web3: Web3) => {
" ✔ Account isn't a member of a validator group ",
],
[
" ✔ Enough time has passed since the account was removed from a validator group ",
" ✔ Enough time has passed since the account was removed from a validator group? ",
],
[
"All checks passed",
Expand Down Expand Up @@ -189,7 +189,7 @@ testWithAnvilL2('validator:deregister', (web3: Web3) => {
" ✘ Account isn't a member of a validator group ",
],
[
" ✘ Enough time has passed since the account was removed from a validator group ",
" ✘ Enough time has passed since the account was removed from a validator group? ",
],
]
`)
Expand Down
3 changes: 1 addition & 2 deletions packages/cli/src/commands/validator/deregister.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ import { displaySendTx } from '../../utils/cli'
import { CustomFlags } from '../../utils/command'

export default class ValidatorDeregister extends BaseCommand {
// TODO time period to deregister might have changed for L2 consider adding a wait to show the actual
static description =
"Deregister a Validator. Approximately 60 days after the validator is no longer part of any group, it will be possible to deregister the validator and start unlocking the CELO. If you wish to deregister your validator, you must first remove it from it's group, such as by deaffiliating it, then wait the required 60 days before running this command."
"Deregister a Validator. Wait the require lock period after the validator is no longer part of any group, then it will be possible to deregister the validator and start unlocking the CELO. If you wish to deregister your validator, you must first remove it from it's group, such as by deaffiliating it, then wait the required days before running this command."

static flags = {
...BaseCommand.flags,
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/commands/validator/register.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ export default class ValidatorRegister extends BaseCommand {
...BaseCommand.flags,
from: CustomFlags.address({ required: true, description: 'Address for the Validator' }),
ecdsaKey: CustomFlags.ecdsaPublicKey({ required: true }),
blsKey: CustomFlags.blsPublicKey({ required: false }),
blsSignature: CustomFlags.blsProofOfPossession({ required: false }),
blsKey: CustomFlags.blsPublicKey({ required: false, deprecated: true }),
blsSignature: CustomFlags.blsProofOfPossession({ required: false, deprecated: true }),
yes: Flags.boolean({ description: 'Answer yes to prompt' }),
}

Expand Down
Loading

0 comments on commit 2283374

Please sign in to comment.