Skip to content

Commit 6e64b6a

Browse files
authored
Allows reset Epoch during staking auction and adds function to update networking address (#227)
* removing added field * remove address check * remove access node requirement * adds approved list and node id hex restriction * reset epoch during staking auction * adds updateNetworkingAddress function to all contracts * fix error message
1 parent 6c18941 commit 6e64b6a

16 files changed

+299
-20
lines changed

contracts/FlowIDTableStaking.cdc

+18-1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ pub contract FlowIDTableStaking {
4747
pub event RewardsPaid(nodeID: String, amount: UFix64)
4848
pub event UnstakedTokensWithdrawn(nodeID: String, amount: UFix64)
4949
pub event RewardTokensWithdrawn(nodeID: String, amount: UFix64)
50+
pub event NetworkingAddressUpdated(nodeID: String, newAddress: String)
5051

5152
/// Delegator Events
5253
pub event NewDelegatorCreated(nodeID: String, delegatorID: UInt32)
@@ -163,7 +164,7 @@ pub contract FlowIDTableStaking {
163164
FlowIDTableStaking.isValidNodeID(id): "The node ID must have only numbers and lowercase hex characters"
164165
FlowIDTableStaking.nodes[id] == nil: "The ID cannot already exist in the record"
165166
role >= UInt8(1) && role <= UInt8(5): "The role must be 1, 2, 3, 4, or 5"
166-
networkingAddress.length > 0 && networkingAddress.length <= 510: "The networkingAddress must be less than 255 bytes (510 hex characters)"
167+
networkingAddress.length > 0 && networkingAddress.length <= 510: "The networkingAddress must be less than 510 characters"
167168
networkingKey.length == 128: "The networkingKey length must be exactly 64 bytes (128 hex characters)"
168169
stakingKey.length == 192: "The stakingKey length must be exactly 96 bytes (192 hex characters)"
169170
!FlowIDTableStaking.getNetworkingAddressClaimed(address: networkingAddress): "The networkingAddress cannot have already been claimed"
@@ -417,6 +418,22 @@ pub contract FlowIDTableStaking {
417418
self.id = id
418419
}
419420

421+
/// Change the node's networking address to a new one
422+
pub fun updateNetworkingAddress(_ newAddress: String) {
423+
pre {
424+
FlowIDTableStaking.stakingEnabled(): "Cannot update networking address if the staking auction isn't in progress"
425+
newAddress.length > 0 && newAddress.length <= 510: "The networkingAddress must be less than 510 characters"
426+
!FlowIDTableStaking.getNetworkingAddressClaimed(address: newAddress): "The networkingAddress cannot have already been claimed"
427+
}
428+
429+
// Borrow the node's record from the staking contract
430+
let nodeRecord = FlowIDTableStaking.borrowNodeRecord(self.id)
431+
432+
nodeRecord.networkingAddress = newAddress
433+
434+
emit NetworkingAddressUpdated(nodeID: self.id, newAddress: newAddress)
435+
}
436+
420437
/// Add new tokens to the system to stake during the next epoch
421438
pub fun stakeNewTokens(_ tokens: @FungibleToken.Vault) {
422439
pre {

contracts/FlowStakingCollection.cdc

+16
Original file line numberDiff line numberDiff line change
@@ -597,6 +597,22 @@ pub contract FlowStakingCollection {
597597
// If they are staking for a delegator, they provide the node ID for the node they are delegating to
598598
// and their delegator ID to specify that it is for their delegator object
599599
600+
/// Updates the stored networking address for the specified node
601+
pub fun updateNetworkingAddress(nodeID: String, newAddress: String) {
602+
pre {
603+
self.doesStakeExist(nodeID: nodeID, delegatorID: nil): "Specified stake does not exist in this collection"
604+
}
605+
606+
// If the node is stored in the collection, borrow it
607+
if let node = self.borrowNode(nodeID) {
608+
node.updateNetworkingAddress(newAddress)
609+
} else {
610+
// Use the node stored in the locked account
611+
let node = self.tokenHolder!.borrow()!.borrowStaker()
612+
node.updateNetworkingAddress(newAddress)
613+
}
614+
}
615+
600616
/// Function to stake new tokens for an existing Stake or Delegation record in the StakingCollection
601617
pub fun stakeNewTokens(nodeID: String, delegatorID: UInt32?, amount: UFix64) {
602618
pre {

contracts/LockedTokens.cdc

+12
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,18 @@ pub contract LockedTokens {
403403
return managerRef.nodeStaker != nil
404404
}
405405

406+
/// Change node networking address
407+
pub fun updateNetworkingAddress(_ newAddress: String) {
408+
let tokenManagerRef = self.tokenManager.borrow()!
409+
410+
assert(
411+
self.nodeObjectExists(tokenManagerRef),
412+
message: "Cannot change networking address if there is no node object!"
413+
)
414+
415+
tokenManagerRef.nodeStaker?.updateNetworkingAddress(newAddress)
416+
}
417+
406418
/// Stakes new locked tokens
407419
pub fun stakeNewTokens(amount: UFix64) {
408420
let tokenManagerRef = self.tokenManager.borrow()!

contracts/epochs/FlowEpoch.cdc

+9-3
Original file line numberDiff line numberDiff line change
@@ -427,9 +427,15 @@ pub contract FlowEpoch {
427427
"Invalid startView and endView configuration"
428428
}
429429

430-
// force reset the QC and DKG
431-
FlowEpoch.borrowClusterQCAdmin().forceStopVoting()
432-
FlowEpoch.borrowDKGAdmin().forceEndDKG()
430+
if FlowEpoch.currentEpochPhase == EpochPhase.STAKINGAUCTION {
431+
// Since we are resetting the epoch, we do not need to
432+
// start epoch setup also. We only need to end the staking auction
433+
FlowEpoch.borrowStakingAdmin().endStakingAuction()
434+
} else {
435+
// force reset the QC and DKG
436+
FlowEpoch.borrowClusterQCAdmin().forceStopVoting()
437+
FlowEpoch.borrowDKGAdmin().forceEndDKG()
438+
}
433439

434440
FlowEpoch.calculateAndSetRewards(newPayout)
435441

contracts/testContracts/TestFlowIDTableStaking.cdc

+4
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,10 @@ pub contract FlowIDTableStaking {
108108
self.id = id
109109
}
110110

111+
pub fun updateNetworkingAddress(_ newAddress: String) {
112+
113+
}
114+
111115
/// Add new tokens to the system to stake during the next epoch
112116
pub fun stakeNewTokens(_ tokens: @FungibleToken.Vault) {
113117

lib/go/contracts/internal/assets/assets.go

+15-15
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/go/templates/idtable_staking_templates.go

+10-1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ const (
3535
unstakeAllFilename = "idTableStaking/node/unstake_all.cdc"
3636
withdrawUnstakedTokensFilename = "idTableStaking/node/withdraw_unstaked_tokens.cdc"
3737
withdrawRewardedTokensFilename = "idTableStaking/node/withdraw_rewarded_tokens.cdc"
38+
updateNetworkingAddressFilename = "idTableStaking/node/update_networking_address.cdc"
3839
addPublicNodeCapabilityFilename = "idTableStaking/node/node_add_capability.cdc"
3940

4041
registerManyNodesFilename = "idTableStaking/node/register_many_nodes.cdc"
@@ -191,7 +192,7 @@ func GenerateScaleRewardsTestScript(env Environment) []byte {
191192
return []byte(replaceAddresses(code, env))
192193
}
193194

194-
// Staker Templates -------------------------------------------------------------
195+
// Node Templates -------------------------------------------------------------
195196

196197
// GenerateRegisterNodeScript creates a script that creates a new
197198
// node struct and stores it in the Node records
@@ -257,6 +258,14 @@ func GenerateWithdrawRewardedTokensScript(env Environment) []byte {
257258
return []byte(replaceAddresses(code, env))
258259
}
259260

261+
// GenerateUpdateNetworkingAddressScript creates a script changes the networking address
262+
// for an existing node operator
263+
func GenerateUpdateNetworkingAddressScript(env Environment) []byte {
264+
code := assets.MustAssetString(updateNetworkingAddressFilename)
265+
266+
return []byte(replaceAddresses(code, env))
267+
}
268+
260269
func GenerateAddPublicNodeCapabilityScript(env Environment) []byte {
261270
code := assets.MustAssetString(addPublicNodeCapabilityFilename)
262271

0 commit comments

Comments
 (0)