Skip to content

Commit

Permalink
fix(federated validation): make subnet gateway use federated power to…
Browse files Browse the repository at this point in the history
… calculate power table.
  • Loading branch information
raulk committed Mar 16, 2024
1 parent 8018ff3 commit f2fcf40
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions contracts/src/gateway/router/TopDownFinalityFacet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pragma solidity ^0.8.23;

import {GatewayActorModifiers} from "../../lib/LibGatewayActorStorage.sol";
import {ParentFinality} from "../../structs/CrossNet.sol";
import {Validator, ValidatorInfo, StakingChangeRequest, Membership} from "../../structs/Subnet.sol";
import {PermissionMode, Validator, ValidatorInfo, StakingChangeRequest, Membership} from "../../structs/Subnet.sol";
import {LibGateway} from "../../lib/LibGateway.sol";

import {FilAddress} from "fevmate/utils/FilAddress.sol";
Expand Down Expand Up @@ -51,20 +51,28 @@ contract TopDownFinalityFacet is GatewayActorModifiers {
// confirm the change
s.validatorsTracker.confirmChange(configurationNumber);

// get the active validators
// Get active validators and populate the new power table.
address[] memory validators = s.validatorsTracker.validators.listActiveValidators();
uint256 vLength = validators.length;
Validator[] memory vs = new Validator[](vLength);
for (uint256 i; i < vLength; ) {
address addr = validators[i];
ValidatorInfo storage info = s.validatorsTracker.validators.validators[addr];
vs[i] = Validator({weight: info.confirmedCollateral, addr: addr, metadata: info.metadata});

// Extract the consensus weight for validator.
uint256 weight = info.confirmedCollateral;
if (s.validatorsTracker.validators.permissionMode == PermissionMode.Federated) {
// Use the explicit federated power for power accounting if in Federated permissioning mode.
weight = info.federatedPower;
}

vs[i] = Validator({weight: weight, addr: addr, metadata: info.metadata});
unchecked {
++i;
}
}

// update membership with the applied changes
// update membership with the resulting power table.
LibGateway.updateMembership(Membership({configurationNumber: configurationNumber, validators: vs}));
return configurationNumber;
}
Expand Down

0 comments on commit f2fcf40

Please sign in to comment.