Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting P-Chain blockchain id constant #562

Merged
merged 5 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

Large diffs are not rendered by default.

48 changes: 39 additions & 9 deletions abi-bindings/go/staking/PoAValidatorManager/PoAValidatorManager.go

Large diffs are not rendered by default.

8 changes: 3 additions & 5 deletions contracts/staking/ValidatorManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ abstract contract ValidatorManager is Initializable, ContextUpgradeable, IValida
/// @custom:storage-location erc7201:avalanche-icm.storage.ValidatorManager

struct ValidatorManagerStorage {
/// @notice The blockchainID of the P-Chain.
bytes32 _pChainBlockchainID;
/// @notice The subnetID associated with this validator manager.
bytes32 _subnetID;
/// @notice The number of seconds after which to reset the churn tracker.
Expand Down Expand Up @@ -62,6 +60,7 @@ abstract contract ValidatorManager is Initializable, ContextUpgradeable, IValida
uint64 public constant MAXIMUM_REGISTRATION_EXPIRY_LENGTH = 2 days;
uint32 public constant ADDRESS_LENGTH = 20; // This is only used as a packed uint32
uint8 public constant BLS_PUBLIC_KEY_LENGTH = 48;
bytes32 public constant P_CHAIN_BLOCKCHAIN_ID = bytes32(0);

// solhint-disable ordering
function _getValidatorManagerStorage()
Expand Down Expand Up @@ -96,7 +95,6 @@ abstract contract ValidatorManager is Initializable, ContextUpgradeable, IValida
onlyInitializing
{
ValidatorManagerStorage storage $ = _getValidatorManagerStorage();
$._pChainBlockchainID = settings.pChainBlockchainID;
$._subnetID = settings.subnetID;

require(
Expand Down Expand Up @@ -451,12 +449,12 @@ abstract contract ValidatorManager is Initializable, ContextUpgradeable, IValida
view
returns (WarpMessage memory)
{
ValidatorManagerStorage storage $ = _getValidatorManagerStorage();
(WarpMessage memory warpMessage, bool valid) =
WARP_MESSENGER.getVerifiedWarpMessage(messageIndex);
require(valid, "ValidatorManager: invalid warp message");
// Must match to P-Chain blockchain id, which is 0.
require(
warpMessage.sourceChainID == $._pChainBlockchainID,
warpMessage.sourceChainID == P_CHAIN_BLOCKCHAIN_ID,
"ValidatorManager: invalid source chain ID"
);
require(
Expand Down
1 change: 0 additions & 1 deletion contracts/staking/interfaces/IValidatorManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ event ValidatorWeightUpdate(
);

struct ValidatorManagerSettings {
bytes32 pChainBlockchainID;
bytes32 subnetID;
uint64 churnPeriodSeconds;
uint8 maximumChurnPercentage;
Expand Down
6 changes: 0 additions & 6 deletions contracts/staking/tests/ERC20TokenStakingManagerTests.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ contract ERC20TokenStakingManagerTest is PoSValidatorManagerTest {
app.initialize(
PoSValidatorManagerSettings({
baseSettings: ValidatorManagerSettings({
pChainBlockchainID: P_CHAIN_BLOCKCHAIN_ID,
subnetID: DEFAULT_SUBNET_ID,
churnPeriodSeconds: DEFAULT_CHURN_PERIOD,
maximumChurnPercentage: DEFAULT_MAXIMUM_CHURN_PERCENTAGE
Expand All @@ -60,7 +59,6 @@ contract ERC20TokenStakingManagerTest is PoSValidatorManagerTest {
app.initialize(
PoSValidatorManagerSettings({
baseSettings: ValidatorManagerSettings({
pChainBlockchainID: P_CHAIN_BLOCKCHAIN_ID,
subnetID: DEFAULT_SUBNET_ID,
churnPeriodSeconds: DEFAULT_CHURN_PERIOD,
maximumChurnPercentage: DEFAULT_MAXIMUM_CHURN_PERCENTAGE
Expand All @@ -83,7 +81,6 @@ contract ERC20TokenStakingManagerTest is PoSValidatorManagerTest {
app.initialize(
PoSValidatorManagerSettings({
baseSettings: ValidatorManagerSettings({
pChainBlockchainID: P_CHAIN_BLOCKCHAIN_ID,
subnetID: DEFAULT_SUBNET_ID,
churnPeriodSeconds: DEFAULT_CHURN_PERIOD,
maximumChurnPercentage: DEFAULT_MAXIMUM_CHURN_PERCENTAGE
Expand All @@ -105,7 +102,6 @@ contract ERC20TokenStakingManagerTest is PoSValidatorManagerTest {
app.initialize(
PoSValidatorManagerSettings({
baseSettings: ValidatorManagerSettings({
pChainBlockchainID: P_CHAIN_BLOCKCHAIN_ID,
subnetID: DEFAULT_SUBNET_ID,
churnPeriodSeconds: DEFAULT_CHURN_PERIOD,
maximumChurnPercentage: DEFAULT_MAXIMUM_CHURN_PERCENTAGE
Expand All @@ -127,7 +123,6 @@ contract ERC20TokenStakingManagerTest is PoSValidatorManagerTest {
app.initialize(
PoSValidatorManagerSettings({
baseSettings: ValidatorManagerSettings({
pChainBlockchainID: P_CHAIN_BLOCKCHAIN_ID,
subnetID: DEFAULT_SUBNET_ID,
churnPeriodSeconds: DEFAULT_CHURN_PERIOD,
maximumChurnPercentage: DEFAULT_MAXIMUM_CHURN_PERCENTAGE
Expand All @@ -150,7 +145,6 @@ contract ERC20TokenStakingManagerTest is PoSValidatorManagerTest {
app.initialize(
PoSValidatorManagerSettings({
baseSettings: ValidatorManagerSettings({
pChainBlockchainID: P_CHAIN_BLOCKCHAIN_ID,
subnetID: DEFAULT_SUBNET_ID,
churnPeriodSeconds: DEFAULT_CHURN_PERIOD,
maximumChurnPercentage: DEFAULT_MAXIMUM_CHURN_PERCENTAGE
Expand Down
6 changes: 0 additions & 6 deletions contracts/staking/tests/NativeTokenStakingManagerTests.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ contract NativeTokenStakingManagerTest is PoSValidatorManagerTest {
app.initialize(
PoSValidatorManagerSettings({
baseSettings: ValidatorManagerSettings({
pChainBlockchainID: P_CHAIN_BLOCKCHAIN_ID,
subnetID: DEFAULT_SUBNET_ID,
churnPeriodSeconds: DEFAULT_CHURN_PERIOD,
maximumChurnPercentage: DEFAULT_MAXIMUM_CHURN_PERCENTAGE
Expand All @@ -52,7 +51,6 @@ contract NativeTokenStakingManagerTest is PoSValidatorManagerTest {
app.initialize(
PoSValidatorManagerSettings({
baseSettings: ValidatorManagerSettings({
pChainBlockchainID: P_CHAIN_BLOCKCHAIN_ID,
subnetID: DEFAULT_SUBNET_ID,
churnPeriodSeconds: DEFAULT_CHURN_PERIOD,
maximumChurnPercentage: DEFAULT_MAXIMUM_CHURN_PERCENTAGE
Expand All @@ -74,7 +72,6 @@ contract NativeTokenStakingManagerTest is PoSValidatorManagerTest {
app.initialize(
PoSValidatorManagerSettings({
baseSettings: ValidatorManagerSettings({
pChainBlockchainID: P_CHAIN_BLOCKCHAIN_ID,
subnetID: DEFAULT_SUBNET_ID,
churnPeriodSeconds: DEFAULT_CHURN_PERIOD,
maximumChurnPercentage: DEFAULT_MAXIMUM_CHURN_PERCENTAGE
Expand All @@ -95,7 +92,6 @@ contract NativeTokenStakingManagerTest is PoSValidatorManagerTest {
app.initialize(
PoSValidatorManagerSettings({
baseSettings: ValidatorManagerSettings({
pChainBlockchainID: P_CHAIN_BLOCKCHAIN_ID,
subnetID: DEFAULT_SUBNET_ID,
churnPeriodSeconds: DEFAULT_CHURN_PERIOD,
maximumChurnPercentage: DEFAULT_MAXIMUM_CHURN_PERCENTAGE
Expand All @@ -116,7 +112,6 @@ contract NativeTokenStakingManagerTest is PoSValidatorManagerTest {
app.initialize(
PoSValidatorManagerSettings({
baseSettings: ValidatorManagerSettings({
pChainBlockchainID: P_CHAIN_BLOCKCHAIN_ID,
subnetID: DEFAULT_SUBNET_ID,
churnPeriodSeconds: DEFAULT_CHURN_PERIOD,
maximumChurnPercentage: DEFAULT_MAXIMUM_CHURN_PERCENTAGE
Expand All @@ -138,7 +133,6 @@ contract NativeTokenStakingManagerTest is PoSValidatorManagerTest {
app.initialize(
PoSValidatorManagerSettings({
baseSettings: ValidatorManagerSettings({
pChainBlockchainID: P_CHAIN_BLOCKCHAIN_ID,
subnetID: DEFAULT_SUBNET_ID,
churnPeriodSeconds: DEFAULT_CHURN_PERIOD,
maximumChurnPercentage: DEFAULT_MAXIMUM_CHURN_PERCENTAGE
Expand Down
1 change: 0 additions & 1 deletion contracts/staking/tests/PoAValidatorManagerTests.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ contract PoAValidatorManagerTest is ValidatorManagerTest {
app = new PoAValidatorManager(ICMInitializable.Allowed);
app.initialize(
ValidatorManagerSettings({
pChainBlockchainID: P_CHAIN_BLOCKCHAIN_ID,
subnetID: DEFAULT_SUBNET_ID,
churnPeriodSeconds: DEFAULT_CHURN_PERIOD,
maximumChurnPercentage: DEFAULT_MAXIMUM_CHURN_PERCENTAGE
Expand Down
4 changes: 1 addition & 3 deletions contracts/staking/tests/ValidatorManagerTests.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ import {
// TODO: Remove this once all unit tests implemented
// solhint-disable no-empty-blocks
abstract contract ValidatorManagerTest is Test {
bytes32 public constant P_CHAIN_BLOCKCHAIN_ID =
bytes32(hex"0000000000000000000000000000000000000000000000000000000000000000");
bytes32 public constant DEFAULT_SUBNET_ID =
bytes32(hex"1234567812345678123456781234567812345678123456781234567812345678");
bytes32 public constant DEFAULT_NODE_ID =
Expand Down Expand Up @@ -388,7 +386,7 @@ abstract contract ValidatorManagerTest is Test {
abi.encodeWithSelector(IWarpMessenger.getVerifiedWarpMessage.selector, uint32(0)),
abi.encode(
WarpMessage({
sourceChainID: P_CHAIN_BLOCKCHAIN_ID,
sourceChainID: validatorManager.P_CHAIN_BLOCKCHAIN_ID(),
originSenderAddress: address(0),
payload: expectedPayload
}),
Expand Down