diff --git a/contracts-abi/abi/ValidatorRegistry.abi b/contracts-abi/abi/ValidatorRegistry.abi index 448252050..a79880cbc 100644 --- a/contracts-abi/abi/ValidatorRegistry.abi +++ b/contracts-abi/abi/ValidatorRegistry.abi @@ -9,6 +9,11 @@ "name": "getNumberOfStakedValidators", "inputs": [], "outputs": [ + { + "name": "", + "type": "uint256", + "internalType": "uint256" + }, { "name": "", "type": "uint256", @@ -56,6 +61,11 @@ "name": "", "type": "bytes[]", "internalType": "bytes[]" + }, + { + "name": "", + "type": "uint256", + "internalType": "uint256" } ], "stateMutability": "view" @@ -186,6 +196,19 @@ ], "stateMutability": "view" }, + { + "type": "function", + "name": "stakedValsetVersion", + "inputs": [], + "outputs": [ + { + "name": "", + "type": "uint256", + "internalType": "uint256" + } + ], + "stateMutability": "view" + }, { "type": "function", "name": "transferOwnership", diff --git a/contracts-abi/clients/ValidatorRegistry/ValidatorRegistry.go b/contracts-abi/clients/ValidatorRegistry/ValidatorRegistry.go index 467749651..3aa7f09c8 100644 --- a/contracts-abi/clients/ValidatorRegistry/ValidatorRegistry.go +++ b/contracts-abi/clients/ValidatorRegistry/ValidatorRegistry.go @@ -31,7 +31,7 @@ var ( // ValidatorregistryMetaData contains all meta data concerning the Validatorregistry contract. var ValidatorregistryMetaData = &bind.MetaData{ - ABI: "[{\"type\":\"constructor\",\"inputs\":[],\"stateMutability\":\"nonpayable\"},{\"type\":\"function\",\"name\":\"getNumberOfStakedValidators\",\"inputs\":[],\"outputs\":[{\"name\":\"\",\"type\":\"uint256\",\"internalType\":\"uint256\"}],\"stateMutability\":\"view\"},{\"type\":\"function\",\"name\":\"getStakedAmount\",\"inputs\":[{\"name\":\"valBLSPubKey\",\"type\":\"bytes\",\"internalType\":\"bytes\"}],\"outputs\":[{\"name\":\"\",\"type\":\"uint256\",\"internalType\":\"uint256\"}],\"stateMutability\":\"view\"},{\"type\":\"function\",\"name\":\"getStakedValidators\",\"inputs\":[{\"name\":\"start\",\"type\":\"uint256\",\"internalType\":\"uint256\"},{\"name\":\"end\",\"type\":\"uint256\",\"internalType\":\"uint256\"}],\"outputs\":[{\"name\":\"\",\"type\":\"bytes[]\",\"internalType\":\"bytes[]\"}],\"stateMutability\":\"view\"},{\"type\":\"function\",\"name\":\"getUnstakingAmount\",\"inputs\":[{\"name\":\"valBLSPubKey\",\"type\":\"bytes\",\"internalType\":\"bytes\"}],\"outputs\":[{\"name\":\"\",\"type\":\"uint256\",\"internalType\":\"uint256\"}],\"stateMutability\":\"view\"},{\"type\":\"function\",\"name\":\"initialize\",\"inputs\":[{\"name\":\"_minStake\",\"type\":\"uint256\",\"internalType\":\"uint256\"},{\"name\":\"_unstakePeriodBlocks\",\"type\":\"uint256\",\"internalType\":\"uint256\"},{\"name\":\"_owner\",\"type\":\"address\",\"internalType\":\"address\"}],\"outputs\":[],\"stateMutability\":\"nonpayable\"},{\"type\":\"function\",\"name\":\"isStaked\",\"inputs\":[{\"name\":\"valBLSPubKey\",\"type\":\"bytes\",\"internalType\":\"bytes\"}],\"outputs\":[{\"name\":\"\",\"type\":\"bool\",\"internalType\":\"bool\"}],\"stateMutability\":\"view\"},{\"type\":\"function\",\"name\":\"minStake\",\"inputs\":[],\"outputs\":[{\"name\":\"\",\"type\":\"uint256\",\"internalType\":\"uint256\"}],\"stateMutability\":\"view\"},{\"type\":\"function\",\"name\":\"owner\",\"inputs\":[],\"outputs\":[{\"name\":\"\",\"type\":\"address\",\"internalType\":\"address\"}],\"stateMutability\":\"view\"},{\"type\":\"function\",\"name\":\"renounceOwnership\",\"inputs\":[],\"outputs\":[],\"stateMutability\":\"nonpayable\"},{\"type\":\"function\",\"name\":\"stake\",\"inputs\":[{\"name\":\"valBLSPubKeys\",\"type\":\"bytes[]\",\"internalType\":\"bytes[]\"}],\"outputs\":[],\"stateMutability\":\"payable\"},{\"type\":\"function\",\"name\":\"stakeOriginators\",\"inputs\":[{\"name\":\"\",\"type\":\"bytes\",\"internalType\":\"bytes\"}],\"outputs\":[{\"name\":\"\",\"type\":\"address\",\"internalType\":\"address\"}],\"stateMutability\":\"view\"},{\"type\":\"function\",\"name\":\"transferOwnership\",\"inputs\":[{\"name\":\"newOwner\",\"type\":\"address\",\"internalType\":\"address\"}],\"outputs\":[],\"stateMutability\":\"nonpayable\"},{\"type\":\"function\",\"name\":\"unstake\",\"inputs\":[{\"name\":\"blsPubKeys\",\"type\":\"bytes[]\",\"internalType\":\"bytes[]\"}],\"outputs\":[],\"stateMutability\":\"nonpayable\"},{\"type\":\"function\",\"name\":\"unstakeBlockNums\",\"inputs\":[{\"name\":\"\",\"type\":\"bytes\",\"internalType\":\"bytes\"}],\"outputs\":[{\"name\":\"\",\"type\":\"uint256\",\"internalType\":\"uint256\"}],\"stateMutability\":\"view\"},{\"type\":\"function\",\"name\":\"unstakePeriodBlocks\",\"inputs\":[],\"outputs\":[{\"name\":\"\",\"type\":\"uint256\",\"internalType\":\"uint256\"}],\"stateMutability\":\"view\"},{\"type\":\"function\",\"name\":\"unstakingBalances\",\"inputs\":[{\"name\":\"\",\"type\":\"bytes\",\"internalType\":\"bytes\"}],\"outputs\":[{\"name\":\"\",\"type\":\"uint256\",\"internalType\":\"uint256\"}],\"stateMutability\":\"view\"},{\"type\":\"function\",\"name\":\"withdraw\",\"inputs\":[{\"name\":\"blsPubKeys\",\"type\":\"bytes[]\",\"internalType\":\"bytes[]\"}],\"outputs\":[],\"stateMutability\":\"nonpayable\"},{\"type\":\"event\",\"name\":\"Initialized\",\"inputs\":[{\"name\":\"version\",\"type\":\"uint64\",\"indexed\":false,\"internalType\":\"uint64\"}],\"anonymous\":false},{\"type\":\"event\",\"name\":\"OwnershipTransferred\",\"inputs\":[{\"name\":\"previousOwner\",\"type\":\"address\",\"indexed\":true,\"internalType\":\"address\"},{\"name\":\"newOwner\",\"type\":\"address\",\"indexed\":true,\"internalType\":\"address\"}],\"anonymous\":false},{\"type\":\"event\",\"name\":\"StakeWithdrawn\",\"inputs\":[{\"name\":\"txOriginator\",\"type\":\"address\",\"indexed\":true,\"internalType\":\"address\"},{\"name\":\"valBLSPubKey\",\"type\":\"bytes\",\"indexed\":false,\"internalType\":\"bytes\"},{\"name\":\"amount\",\"type\":\"uint256\",\"indexed\":false,\"internalType\":\"uint256\"}],\"anonymous\":false},{\"type\":\"event\",\"name\":\"Staked\",\"inputs\":[{\"name\":\"txOriginator\",\"type\":\"address\",\"indexed\":true,\"internalType\":\"address\"},{\"name\":\"valBLSPubKey\",\"type\":\"bytes\",\"indexed\":false,\"internalType\":\"bytes\"},{\"name\":\"amount\",\"type\":\"uint256\",\"indexed\":false,\"internalType\":\"uint256\"}],\"anonymous\":false},{\"type\":\"event\",\"name\":\"Unstaked\",\"inputs\":[{\"name\":\"txOriginator\",\"type\":\"address\",\"indexed\":true,\"internalType\":\"address\"},{\"name\":\"valBLSPubKey\",\"type\":\"bytes\",\"indexed\":false,\"internalType\":\"bytes\"},{\"name\":\"amount\",\"type\":\"uint256\",\"indexed\":false,\"internalType\":\"uint256\"}],\"anonymous\":false},{\"type\":\"error\",\"name\":\"InvalidInitialization\",\"inputs\":[]},{\"type\":\"error\",\"name\":\"NotInitializing\",\"inputs\":[]},{\"type\":\"error\",\"name\":\"OwnableInvalidOwner\",\"inputs\":[{\"name\":\"owner\",\"type\":\"address\",\"internalType\":\"address\"}]},{\"type\":\"error\",\"name\":\"OwnableUnauthorizedAccount\",\"inputs\":[{\"name\":\"account\",\"type\":\"address\",\"internalType\":\"address\"}]},{\"type\":\"error\",\"name\":\"ReentrancyGuardReentrantCall\",\"inputs\":[]}]", + ABI: "[{\"type\":\"constructor\",\"inputs\":[],\"stateMutability\":\"nonpayable\"},{\"type\":\"function\",\"name\":\"getNumberOfStakedValidators\",\"inputs\":[],\"outputs\":[{\"name\":\"\",\"type\":\"uint256\",\"internalType\":\"uint256\"},{\"name\":\"\",\"type\":\"uint256\",\"internalType\":\"uint256\"}],\"stateMutability\":\"view\"},{\"type\":\"function\",\"name\":\"getStakedAmount\",\"inputs\":[{\"name\":\"valBLSPubKey\",\"type\":\"bytes\",\"internalType\":\"bytes\"}],\"outputs\":[{\"name\":\"\",\"type\":\"uint256\",\"internalType\":\"uint256\"}],\"stateMutability\":\"view\"},{\"type\":\"function\",\"name\":\"getStakedValidators\",\"inputs\":[{\"name\":\"start\",\"type\":\"uint256\",\"internalType\":\"uint256\"},{\"name\":\"end\",\"type\":\"uint256\",\"internalType\":\"uint256\"}],\"outputs\":[{\"name\":\"\",\"type\":\"bytes[]\",\"internalType\":\"bytes[]\"},{\"name\":\"\",\"type\":\"uint256\",\"internalType\":\"uint256\"}],\"stateMutability\":\"view\"},{\"type\":\"function\",\"name\":\"getUnstakingAmount\",\"inputs\":[{\"name\":\"valBLSPubKey\",\"type\":\"bytes\",\"internalType\":\"bytes\"}],\"outputs\":[{\"name\":\"\",\"type\":\"uint256\",\"internalType\":\"uint256\"}],\"stateMutability\":\"view\"},{\"type\":\"function\",\"name\":\"initialize\",\"inputs\":[{\"name\":\"_minStake\",\"type\":\"uint256\",\"internalType\":\"uint256\"},{\"name\":\"_unstakePeriodBlocks\",\"type\":\"uint256\",\"internalType\":\"uint256\"},{\"name\":\"_owner\",\"type\":\"address\",\"internalType\":\"address\"}],\"outputs\":[],\"stateMutability\":\"nonpayable\"},{\"type\":\"function\",\"name\":\"isStaked\",\"inputs\":[{\"name\":\"valBLSPubKey\",\"type\":\"bytes\",\"internalType\":\"bytes\"}],\"outputs\":[{\"name\":\"\",\"type\":\"bool\",\"internalType\":\"bool\"}],\"stateMutability\":\"view\"},{\"type\":\"function\",\"name\":\"minStake\",\"inputs\":[],\"outputs\":[{\"name\":\"\",\"type\":\"uint256\",\"internalType\":\"uint256\"}],\"stateMutability\":\"view\"},{\"type\":\"function\",\"name\":\"owner\",\"inputs\":[],\"outputs\":[{\"name\":\"\",\"type\":\"address\",\"internalType\":\"address\"}],\"stateMutability\":\"view\"},{\"type\":\"function\",\"name\":\"renounceOwnership\",\"inputs\":[],\"outputs\":[],\"stateMutability\":\"nonpayable\"},{\"type\":\"function\",\"name\":\"stake\",\"inputs\":[{\"name\":\"valBLSPubKeys\",\"type\":\"bytes[]\",\"internalType\":\"bytes[]\"}],\"outputs\":[],\"stateMutability\":\"payable\"},{\"type\":\"function\",\"name\":\"stakeOriginators\",\"inputs\":[{\"name\":\"\",\"type\":\"bytes\",\"internalType\":\"bytes\"}],\"outputs\":[{\"name\":\"\",\"type\":\"address\",\"internalType\":\"address\"}],\"stateMutability\":\"view\"},{\"type\":\"function\",\"name\":\"stakedValsetVersion\",\"inputs\":[],\"outputs\":[{\"name\":\"\",\"type\":\"uint256\",\"internalType\":\"uint256\"}],\"stateMutability\":\"view\"},{\"type\":\"function\",\"name\":\"transferOwnership\",\"inputs\":[{\"name\":\"newOwner\",\"type\":\"address\",\"internalType\":\"address\"}],\"outputs\":[],\"stateMutability\":\"nonpayable\"},{\"type\":\"function\",\"name\":\"unstake\",\"inputs\":[{\"name\":\"blsPubKeys\",\"type\":\"bytes[]\",\"internalType\":\"bytes[]\"}],\"outputs\":[],\"stateMutability\":\"nonpayable\"},{\"type\":\"function\",\"name\":\"unstakeBlockNums\",\"inputs\":[{\"name\":\"\",\"type\":\"bytes\",\"internalType\":\"bytes\"}],\"outputs\":[{\"name\":\"\",\"type\":\"uint256\",\"internalType\":\"uint256\"}],\"stateMutability\":\"view\"},{\"type\":\"function\",\"name\":\"unstakePeriodBlocks\",\"inputs\":[],\"outputs\":[{\"name\":\"\",\"type\":\"uint256\",\"internalType\":\"uint256\"}],\"stateMutability\":\"view\"},{\"type\":\"function\",\"name\":\"unstakingBalances\",\"inputs\":[{\"name\":\"\",\"type\":\"bytes\",\"internalType\":\"bytes\"}],\"outputs\":[{\"name\":\"\",\"type\":\"uint256\",\"internalType\":\"uint256\"}],\"stateMutability\":\"view\"},{\"type\":\"function\",\"name\":\"withdraw\",\"inputs\":[{\"name\":\"blsPubKeys\",\"type\":\"bytes[]\",\"internalType\":\"bytes[]\"}],\"outputs\":[],\"stateMutability\":\"nonpayable\"},{\"type\":\"event\",\"name\":\"Initialized\",\"inputs\":[{\"name\":\"version\",\"type\":\"uint64\",\"indexed\":false,\"internalType\":\"uint64\"}],\"anonymous\":false},{\"type\":\"event\",\"name\":\"OwnershipTransferred\",\"inputs\":[{\"name\":\"previousOwner\",\"type\":\"address\",\"indexed\":true,\"internalType\":\"address\"},{\"name\":\"newOwner\",\"type\":\"address\",\"indexed\":true,\"internalType\":\"address\"}],\"anonymous\":false},{\"type\":\"event\",\"name\":\"StakeWithdrawn\",\"inputs\":[{\"name\":\"txOriginator\",\"type\":\"address\",\"indexed\":true,\"internalType\":\"address\"},{\"name\":\"valBLSPubKey\",\"type\":\"bytes\",\"indexed\":false,\"internalType\":\"bytes\"},{\"name\":\"amount\",\"type\":\"uint256\",\"indexed\":false,\"internalType\":\"uint256\"}],\"anonymous\":false},{\"type\":\"event\",\"name\":\"Staked\",\"inputs\":[{\"name\":\"txOriginator\",\"type\":\"address\",\"indexed\":true,\"internalType\":\"address\"},{\"name\":\"valBLSPubKey\",\"type\":\"bytes\",\"indexed\":false,\"internalType\":\"bytes\"},{\"name\":\"amount\",\"type\":\"uint256\",\"indexed\":false,\"internalType\":\"uint256\"}],\"anonymous\":false},{\"type\":\"event\",\"name\":\"Unstaked\",\"inputs\":[{\"name\":\"txOriginator\",\"type\":\"address\",\"indexed\":true,\"internalType\":\"address\"},{\"name\":\"valBLSPubKey\",\"type\":\"bytes\",\"indexed\":false,\"internalType\":\"bytes\"},{\"name\":\"amount\",\"type\":\"uint256\",\"indexed\":false,\"internalType\":\"uint256\"}],\"anonymous\":false},{\"type\":\"error\",\"name\":\"InvalidInitialization\",\"inputs\":[]},{\"type\":\"error\",\"name\":\"NotInitializing\",\"inputs\":[]},{\"type\":\"error\",\"name\":\"OwnableInvalidOwner\",\"inputs\":[{\"name\":\"owner\",\"type\":\"address\",\"internalType\":\"address\"}]},{\"type\":\"error\",\"name\":\"OwnableUnauthorizedAccount\",\"inputs\":[{\"name\":\"account\",\"type\":\"address\",\"internalType\":\"address\"}]},{\"type\":\"error\",\"name\":\"ReentrancyGuardReentrantCall\",\"inputs\":[]}]", } // ValidatorregistryABI is the input ABI used to generate the binding from. @@ -182,32 +182,33 @@ func (_Validatorregistry *ValidatorregistryTransactorRaw) Transact(opts *bind.Tr // GetNumberOfStakedValidators is a free data retrieval call binding the contract method 0x07258504. // -// Solidity: function getNumberOfStakedValidators() view returns(uint256) -func (_Validatorregistry *ValidatorregistryCaller) GetNumberOfStakedValidators(opts *bind.CallOpts) (*big.Int, error) { +// Solidity: function getNumberOfStakedValidators() view returns(uint256, uint256) +func (_Validatorregistry *ValidatorregistryCaller) GetNumberOfStakedValidators(opts *bind.CallOpts) (*big.Int, *big.Int, error) { var out []interface{} err := _Validatorregistry.contract.Call(opts, &out, "getNumberOfStakedValidators") if err != nil { - return *new(*big.Int), err + return *new(*big.Int), *new(*big.Int), err } out0 := *abi.ConvertType(out[0], new(*big.Int)).(**big.Int) + out1 := *abi.ConvertType(out[1], new(*big.Int)).(**big.Int) - return out0, err + return out0, out1, err } // GetNumberOfStakedValidators is a free data retrieval call binding the contract method 0x07258504. // -// Solidity: function getNumberOfStakedValidators() view returns(uint256) -func (_Validatorregistry *ValidatorregistrySession) GetNumberOfStakedValidators() (*big.Int, error) { +// Solidity: function getNumberOfStakedValidators() view returns(uint256, uint256) +func (_Validatorregistry *ValidatorregistrySession) GetNumberOfStakedValidators() (*big.Int, *big.Int, error) { return _Validatorregistry.Contract.GetNumberOfStakedValidators(&_Validatorregistry.CallOpts) } // GetNumberOfStakedValidators is a free data retrieval call binding the contract method 0x07258504. // -// Solidity: function getNumberOfStakedValidators() view returns(uint256) -func (_Validatorregistry *ValidatorregistryCallerSession) GetNumberOfStakedValidators() (*big.Int, error) { +// Solidity: function getNumberOfStakedValidators() view returns(uint256, uint256) +func (_Validatorregistry *ValidatorregistryCallerSession) GetNumberOfStakedValidators() (*big.Int, *big.Int, error) { return _Validatorregistry.Contract.GetNumberOfStakedValidators(&_Validatorregistry.CallOpts) } @@ -244,32 +245,33 @@ func (_Validatorregistry *ValidatorregistryCallerSession) GetStakedAmount(valBLS // GetStakedValidators is a free data retrieval call binding the contract method 0x7d377923. // -// Solidity: function getStakedValidators(uint256 start, uint256 end) view returns(bytes[]) -func (_Validatorregistry *ValidatorregistryCaller) GetStakedValidators(opts *bind.CallOpts, start *big.Int, end *big.Int) ([][]byte, error) { +// Solidity: function getStakedValidators(uint256 start, uint256 end) view returns(bytes[], uint256) +func (_Validatorregistry *ValidatorregistryCaller) GetStakedValidators(opts *bind.CallOpts, start *big.Int, end *big.Int) ([][]byte, *big.Int, error) { var out []interface{} err := _Validatorregistry.contract.Call(opts, &out, "getStakedValidators", start, end) if err != nil { - return *new([][]byte), err + return *new([][]byte), *new(*big.Int), err } out0 := *abi.ConvertType(out[0], new([][]byte)).(*[][]byte) + out1 := *abi.ConvertType(out[1], new(*big.Int)).(**big.Int) - return out0, err + return out0, out1, err } // GetStakedValidators is a free data retrieval call binding the contract method 0x7d377923. // -// Solidity: function getStakedValidators(uint256 start, uint256 end) view returns(bytes[]) -func (_Validatorregistry *ValidatorregistrySession) GetStakedValidators(start *big.Int, end *big.Int) ([][]byte, error) { +// Solidity: function getStakedValidators(uint256 start, uint256 end) view returns(bytes[], uint256) +func (_Validatorregistry *ValidatorregistrySession) GetStakedValidators(start *big.Int, end *big.Int) ([][]byte, *big.Int, error) { return _Validatorregistry.Contract.GetStakedValidators(&_Validatorregistry.CallOpts, start, end) } // GetStakedValidators is a free data retrieval call binding the contract method 0x7d377923. // -// Solidity: function getStakedValidators(uint256 start, uint256 end) view returns(bytes[]) -func (_Validatorregistry *ValidatorregistryCallerSession) GetStakedValidators(start *big.Int, end *big.Int) ([][]byte, error) { +// Solidity: function getStakedValidators(uint256 start, uint256 end) view returns(bytes[], uint256) +func (_Validatorregistry *ValidatorregistryCallerSession) GetStakedValidators(start *big.Int, end *big.Int) ([][]byte, *big.Int, error) { return _Validatorregistry.Contract.GetStakedValidators(&_Validatorregistry.CallOpts, start, end) } @@ -428,6 +430,37 @@ func (_Validatorregistry *ValidatorregistryCallerSession) StakeOriginators(arg0 return _Validatorregistry.Contract.StakeOriginators(&_Validatorregistry.CallOpts, arg0) } +// StakedValsetVersion is a free data retrieval call binding the contract method 0xd628ee62. +// +// Solidity: function stakedValsetVersion() view returns(uint256) +func (_Validatorregistry *ValidatorregistryCaller) StakedValsetVersion(opts *bind.CallOpts) (*big.Int, error) { + var out []interface{} + err := _Validatorregistry.contract.Call(opts, &out, "stakedValsetVersion") + + if err != nil { + return *new(*big.Int), err + } + + out0 := *abi.ConvertType(out[0], new(*big.Int)).(**big.Int) + + return out0, err + +} + +// StakedValsetVersion is a free data retrieval call binding the contract method 0xd628ee62. +// +// Solidity: function stakedValsetVersion() view returns(uint256) +func (_Validatorregistry *ValidatorregistrySession) StakedValsetVersion() (*big.Int, error) { + return _Validatorregistry.Contract.StakedValsetVersion(&_Validatorregistry.CallOpts) +} + +// StakedValsetVersion is a free data retrieval call binding the contract method 0xd628ee62. +// +// Solidity: function stakedValsetVersion() view returns(uint256) +func (_Validatorregistry *ValidatorregistryCallerSession) StakedValsetVersion() (*big.Int, error) { + return _Validatorregistry.Contract.StakedValsetVersion(&_Validatorregistry.CallOpts) +} + // UnstakeBlockNums is a free data retrieval call binding the contract method 0x2f8836a5. // // Solidity: function unstakeBlockNums(bytes ) view returns(uint256) diff --git a/contracts/contracts/ValidatorRegistry.sol b/contracts/contracts/ValidatorRegistry.sol index fa09888fd..711b0c941 100644 --- a/contracts/contracts/ValidatorRegistry.sol +++ b/contracts/contracts/ValidatorRegistry.sol @@ -145,8 +145,10 @@ contract ValidatorRegistry is OwnableUpgradeable, ReentrancyGuardUpgradeable { return unstakingBalances[valBLSPubKey]; } - function getNumberOfStakedValidators() external view returns (uint256) { - return stakedBalances.length(); + /// @return numStakedValidators uint number of currently staked validators. + /// @return stakedValsetVersion uint version of the staked valset at the time of query. + function getNumberOfStakedValidators() external view returns (uint256, uint256) { + return (stakedBalances.length(), stakedValsetVersion); } /// @dev Returns an array of staked validator BLS pubkeys within the specified range. Ordering is unspecified. @@ -154,8 +156,6 @@ contract ValidatorRegistry is OwnableUpgradeable, ReentrancyGuardUpgradeable { /// /// @return set of staked validator BLS pubkeys. /// @return stakedValsetVersion uint version of the staked valset at the time of query. - /// This enables optimistic locking during batch queries. If all queries in a batch return the same stakedValsetVersion, - /// the aggregate staked valset is valid. Otherwise handling is left to the user. function getStakedValidators(uint256 start, uint256 end) external view returns (bytes[] memory, uint256) { require(start < end, "Invalid range"); require(end <= stakedBalances.length(), "Range exceeds staked balances length"); diff --git a/contracts/test/ValidatorRegistryTest.sol b/contracts/test/ValidatorRegistryTest.sol index 5946c51cc..8986eeb7d 100644 --- a/contracts/test/ValidatorRegistryTest.sol +++ b/contracts/test/ValidatorRegistryTest.sol @@ -240,7 +240,10 @@ contract ValidatorRegistryTest is Test { (bytes[] memory validators, uint256 stakedValsetVersion) = validatorRegistry.getStakedValidators(0, 2); assertEq(stakedValsetVersion, 1); assertEq(validators.length, 2); - assertEq(validatorRegistry.getNumberOfStakedValidators(), 2); + uint256 numStakedValidators; + (numStakedValidators, stakedValsetVersion) = validatorRegistry.getNumberOfStakedValidators(); + assertEq(stakedValsetVersion, 1); + assertEq(numStakedValidators, 2); assertEq(validators[0], user1BLSKey); assertEq(validators[1], user2BLSKey); @@ -261,7 +264,9 @@ contract ValidatorRegistryTest is Test { (validators, stakedValsetVersion) = validatorRegistry.getStakedValidators(0, 102); assertEq(stakedValsetVersion, 1 + 100); assertEq(validators.length, 102); - assertEq(validatorRegistry.getNumberOfStakedValidators(), 102); + (numStakedValidators, stakedValsetVersion) = validatorRegistry.getNumberOfStakedValidators(); + assertEq(stakedValsetVersion, 1 + 100); + assertEq(numStakedValidators, 102); assertEq(validators[0], user1BLSKey); assertEq(validators[1], user2BLSKey); @@ -278,9 +283,11 @@ contract ValidatorRegistryTest is Test { function testGetStakedValidatorsWithUnstakingInProgress() public { testMultiStake(); - uint256 numStakedValidators = validatorRegistry.getNumberOfStakedValidators(); + (uint256 numStakedValidators, uint256 stakedValsetVersion) = validatorRegistry.getNumberOfStakedValidators(); assertEq(numStakedValidators, 2); - (bytes[] memory validators, uint256 stakedValsetVersion) = validatorRegistry.getStakedValidators(0, numStakedValidators); + assertEq(stakedValsetVersion, 1); + bytes[] memory validators; + (validators, stakedValsetVersion) = validatorRegistry.getStakedValidators(0, numStakedValidators); assertEq(validators.length, 2); assertEq(stakedValsetVersion, 1); @@ -294,8 +301,9 @@ contract ValidatorRegistryTest is Test { assertTrue(validatorRegistry.unstakeBlockNums(user1BLSKey) > 0); vm.stopPrank(); - numStakedValidators = validatorRegistry.getNumberOfStakedValidators(); + (numStakedValidators, stakedValsetVersion) = validatorRegistry.getNumberOfStakedValidators(); assertEq(numStakedValidators, 1); + assertEq(stakedValsetVersion, 2); (validators, stakedValsetVersion) = validatorRegistry.getStakedValidators(0, numStakedValidators); assertEq(validators.length, 1); assertEq(stakedValsetVersion, 2); @@ -309,8 +317,9 @@ contract ValidatorRegistryTest is Test { keys[0] = user1BLSKey; validatorRegistry.withdraw(keys); vm.stopPrank(); - numStakedValidators = validatorRegistry.getNumberOfStakedValidators(); + (numStakedValidators, stakedValsetVersion) = validatorRegistry.getNumberOfStakedValidators(); assertEq(numStakedValidators, 1); + assertEq(stakedValsetVersion, 2); (validators, stakedValsetVersion) = validatorRegistry.getStakedValidators(0, numStakedValidators); assertEq(validators.length, 1); assertEq(stakedValsetVersion, 2);