Skip to content

feat: validações e emits em ValidatorSelection#2

Open
devfelipenunes wants to merge 1 commit intoRBBNet:feature/bdd-featuresfrom
devfelipenunes:feature/validator-validation-events
Open

feat: validações e emits em ValidatorSelection#2
devfelipenunes wants to merge 1 commit intoRBBNet:feature/bdd-featuresfrom
devfelipenunes:feature/validator-validation-events

Conversation

@devfelipenunes
Copy link
Copy Markdown

Adiciona/ajusta validações e emissões de eventos no contrato ValidatorSelection para melhorar integridade de estado e observabilidade. Arquivo afetado: src/ValidatorSelection.sol

Adiciona/ajusta validações e emissões de eventos no contrato ValidatorSelection para melhorar integridade de estado e observabilidade. Arquivo afetado: src/ValidatorSelection.sol
Copy link
Copy Markdown

@rayangustavo rayangustavo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As validações e emissões de eventos são muito importantes e realmente estavam faltando. Acho que podemos separar o PR só para tratar disso.
Neste tem alteração de formatação, alteração da lógica de uso do lastBlockProposedBy, adição de novas funções para gerenciar os validadores operacionais e elegíveis, novas funções para ler o estado do contrato, além das validações e emissões que era o proposto inicial.

import {UUPSUpgradeable} from "@openzeppelin/contracts/proxy/utils/UUPSUpgradeable.sol";
import {OwnableUpgradeable} from "@openzeppelin-upgradeable/contracts/access/OwnableUpgradeable.sol";

contract ValidatorSelection is IValidatorSelection, Initializable, Governable, OwnableUpgradeable, UUPSUpgradeable {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Acho que pode ser útil manter o IValidatorSelection para scripts futuros.

address[] memory initialElegibleValidators
) internal {
uint256 initialElegibleValidatorsLength = initialElegibleValidators
.length;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Eu manteria o ".length" na mesma linha, acho que neste caso a quebra de linha pode atrapalhar a leitura do código.

.length;
if (initialElegibleValidatorsLength < MIN_NUMBER_OF_VALIDATORS)
revert FewEligibleValidators();
for (uint256 i; i < initialElegibleValidatorsLength; i++) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A lógica deste for loop é similar a das funções de adição de validador elegível, ao invés de repetir o mesmo código aqui, podemos chamar uma destas funções.

_monitorsValidators(proposer, blockNumber);
if (_isAtSelectionBlock(blockNumber)) {
address[] memory selectedValidators = _selectValidators(blockNumber);
address[] memory selectedValidators = _selectValidators(
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Acredito que aqui também seja melhor deixar na mesma linha. Se a função (ou análogo) recebe apenas um parâmetro e a linha não fica muito grande, então podemos deixar na mesma linha.

uint256 numberOfOperationalValidators = operationalValidators.length();
address[] memory auxArray = new address[](numberOfOperationalValidators);
address[] memory auxArray = new address[](
numberOfOperationalValidators
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Acredito que aqui também seja melhor deixar na mesma linha. Se a função (ou análogo) recebe apenas um parâmetro e a linha não fica muito grande, então podemos deixar na mesma linha.

if (!operationalValidators.contains(validator))
revert NotOperationalNode(validator);
operationalValidators.remove(validator);
delete lastBlockProposedBy[validator];
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (!operationalValidators.contains(validator))
revert NotOperationalNode(validator);
operationalValidators.remove(validator);
delete lastBlockProposedBy[validator];
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

error InvalidConfigurationValue(string parameter, uint256 value);
error InvalidValidatorAddress(address validator);
error DuplicateValidator(address validator);
error CannotModifyDuringSelection();
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Esse custom error não está sendo usado.

error InvalidValidatorAddress(address validator);
error DuplicateValidator(address validator);
error CannotModifyDuringSelection();
error CannotRemoveOperationalValidator(address validator);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Esse custom error não está sendo usado.

event EligibleValidatorRemoved(address indexed validator);
event OperationalValidatorAdded(
address indexed validator,
uint256 initialBlock
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

O initialBlock está sendo considerado aqui devido ao uso errado do lastBlockProposedBy, conforme descrito aqui: https://github.com/RBBNet/selecao-validadores/pull/2/changes#r2885214171
Então, fazendo a alteração descrita acima, acredito que o initialBlock deva ser removido.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants