Skip to content

Commit

Permalink
FEATURE: Efficiency Refactoring and Slot Selection for Staking Contra…
Browse files Browse the repository at this point in the history
…cts (#321)

* uses dictionaries for approved and staked

* update proposed getter

* added panic for approved nodes not in ID table and name changes

* adds movesPending list and candidate node list

* adds tests for candidate list

* add unstaking request event and candidate utility function

* role specific candidate lists and limits

* add candidate remove test

* pr comments and update staking contract:

* Adds slot limits and random slot selection using candidate node list (#328)

* merge from pending moves

* add preconditions and transactions

* add new staking changes

* add tests for slot selection

* get tests passing with merged changes

* add slot over limit test

* more comments and clearer conditionals

* remove test dependency workarounds

* update proposed Node IDs and add event

* iterate through pending list and update dependencies

* make ci

* remove upgrade transaction

* remove removeNode

* add updates to role counts

* update dependencies

* make ci

* include approved access nodes in proposed node IDs

* PR comments
  • Loading branch information
joshuahannan authored Feb 2, 2023
1 parent 732f378 commit 276863c
Show file tree
Hide file tree
Showing 38 changed files with 2,613 additions and 1,862 deletions.
652 changes: 536 additions & 116 deletions contracts/FlowIDTableStaking.cdc

Large diffs are not rendered by default.

1,063 changes: 0 additions & 1,063 deletions contracts/FlowIDTableStaking_old.cdc

This file was deleted.

2 changes: 1 addition & 1 deletion contracts/testContracts/TestFlowIDTableStaking.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,6 @@ pub contract FlowIDTableStaking {
return <-create NodeDelegator(id: 1, nodeID: nodeID)
}

init(_ epochTokenPayout: UFix64, _ rewardCut: UFix64) {
init(_ epochTokenPayout: UFix64, _ rewardCut: UFix64, _ candidateLimits: {UInt8: UInt64}) {
}
}
6 changes: 1 addition & 5 deletions lib/go/contracts/contracts.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,11 +182,7 @@ func FlowServiceAccount(fungibleTokenAddress, flowTokenAddress, flowFeesAddress,
func FlowIDTableStaking(fungibleTokenAddress, flowTokenAddress, flowFeesAddress string, latest bool) []byte {
var code string

if latest {
code = assets.MustAssetString(flowIdentityTableFilename)
} else {
code = assets.MustAssetString("FlowIDTableStaking_old.cdc")
}
code = assets.MustAssetString(flowIdentityTableFilename)

code = strings.ReplaceAll(code, placeholderFungibleTokenAddress, withHexPrefix(fungibleTokenAddress))
code = strings.ReplaceAll(code, placeholderFlowTokenAddress, withHexPrefix(flowTokenAddress))
Expand Down
2 changes: 1 addition & 1 deletion lib/go/contracts/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/onflow/flow-core-contracts/lib/go/contracts

go 1.19
go 1.18

require (
github.com/kevinburke/go-bindata v3.23.0+incompatible
Expand Down
35 changes: 6 additions & 29 deletions lib/go/contracts/internal/assets/assets.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/go/templates/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/onflow/flow-core-contracts/lib/go/templates

go 1.19
go 1.18

require (
github.com/kevinburke/go-bindata v3.23.0+incompatible
Expand Down
63 changes: 60 additions & 3 deletions lib/go/templates/idtable_staking_templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ const (

removeNodeFilename = "idTableStaking/admin/remove_node.cdc"
endStakingFilename = "idTableStaking/admin/end_staking.cdc"
removeUnapprovedNodesFilename = "idTableStaking/admin/remove_unapproved_nodes.cdc"
removeInvalidNodesFilename = "idTableStaking/admin/remove_invalid_nodes.cdc"
setApprovedNodesFilename = "idTableStaking/admin/set_approved_nodes.cdc"
addApprovedNodesFilename = "idTableStaking/admin/add_approved_nodes.cdc"
addApproveAndLimitsFilename = "idTableStaking/admin/add_approved_and_limits.cdc"
removeApprovedNodesFilename = "idTableStaking/admin/remove_approved_nodes.cdc"
payRewardsFilename = "idTableStaking/admin/pay_rewards.cdc"
moveTokensFilename = "idTableStaking/admin/move_tokens.cdc"
Expand All @@ -27,6 +28,9 @@ const (
capabilityEndEpochFilename = "idTableStaking/admin/capability_end_epoch.cdc"
transferFeesAdminFilename = "idTableStaking/admin/transfer_fees_admin.cdc"
setNonOperationalFilename = "idTableStaking/admin/set_non_operational.cdc"
setCandidateLimitsFilename = "idTableStaking/admin/change_candidate_limits.cdc"
setNodeWeightFilename = "idTableStaking/admin/set_node_weight.cdc"
setSlotLimitsFilename = "idTableStaking/admin/set_slot_limits.cdc"

// for testing only
scaleRewardsTestFilename = "idTableStaking/admin/scale_rewards_test.cdc"
Expand All @@ -44,6 +48,7 @@ const (

registerManyNodesFilename = "idTableStaking/node/register_many_nodes.cdc"

// Scripts
getTableFilename = "idTableStaking/scripts/get_table.cdc"
currentTableFilename = "idTableStaking/scripts/get_current_table.cdc"
proposedTableFilename = "idTableStaking/scripts/get_proposed_table.cdc"
Expand All @@ -70,6 +75,10 @@ const (
totalStakedFilename = "idTableStaking/scripts/get_total_staked.cdc"
rewardRatioFilename = "idTableStaking/scripts/get_node_type_ratio.cdc"
weeklyPayoutFilename = "idTableStaking/scripts/get_weekly_payout.cdc"
getCandidateLimitsFilename = "idTableStaking/scripts/get_candidate_limits.cdc"
getCandidateNodesFilename = "idTableStaking/scripts/get_candidate_nodes.cdc"
getSlotLimitsFilename = "idTableStaking/scripts/get_slot_limits.cdc"
getRoleCountsFilename = "idTableStaking/scripts/get_role_counts.cdc"
)

// Admin Templates -----------------------------------------------------------
Expand Down Expand Up @@ -104,8 +113,8 @@ func GenerateEndStakingScript(env Environment) []byte {
return []byte(ReplaceAddresses(code, env))
}

func GenerateRemoveUnapprovedNodesScript(env Environment) []byte {
code := assets.MustAssetString(removeUnapprovedNodesFilename)
func GenerateRemoveInvalidNodesScript(env Environment) []byte {
code := assets.MustAssetString(removeInvalidNodesFilename)

return []byte(ReplaceAddresses(code, env))
}
Expand All @@ -122,6 +131,12 @@ func GenerateAddApprovedNodesScript(env Environment) []byte {
return []byte(ReplaceAddresses(code, env))
}

func GenerateAddApprovedAndLimitsScript(env Environment) []byte {
code := assets.MustAssetString(addApproveAndLimitsFilename)

return []byte(ReplaceAddresses(code, env))
}

func GenerateRemoveApprovedNodesScript(env Environment) []byte {
code := assets.MustAssetString(removeApprovedNodesFilename)

Expand Down Expand Up @@ -215,6 +230,24 @@ func GenerateSetNonOperationalScript(env Environment) []byte {
return []byte(ReplaceAddresses(code, env))
}

func GenerateSetCandidateLimitsScript(env Environment) []byte {
code := assets.MustAssetString(setCandidateLimitsFilename)

return []byte(ReplaceAddresses(code, env))
}

func GenerateSetNodeWeightScript(env Environment) []byte {
code := assets.MustAssetString(setNodeWeightFilename)

return []byte(ReplaceAddresses(code, env))
}

func GenerateSetSlotLimitsScript(env Environment) []byte {
code := assets.MustAssetString(setSlotLimitsFilename)

return []byte(ReplaceAddresses(code, env))
}

// For testing only
func GenerateScaleRewardsTestScript(env Environment) []byte {
code := assets.MustAssetString(scaleRewardsTestFilename)
Expand Down Expand Up @@ -491,6 +524,30 @@ func GenerateGetNonOperationalListScript(env Environment) []byte {
return []byte(ReplaceAddresses(code, env))
}

func GenerateGetCandidateLimitsScript(env Environment) []byte {
code := assets.MustAssetString(getCandidateLimitsFilename)

return []byte(ReplaceAddresses(code, env))
}

func GenerateGetCandidateNodesScript(env Environment) []byte {
code := assets.MustAssetString(getCandidateNodesFilename)

return []byte(ReplaceAddresses(code, env))
}

func GenerateGetSlotLimitsScript(env Environment) []byte {
code := assets.MustAssetString(getSlotLimitsFilename)

return []byte(ReplaceAddresses(code, env))
}

func GenerateGetRoleCountsScript(env Environment) []byte {
code := assets.MustAssetString(getRoleCountsFilename)

return []byte(ReplaceAddresses(code, env))
}

// For testing

func GenerateRegisterManyNodesScript(env Environment) []byte {
Expand Down
Loading

0 comments on commit 276863c

Please sign in to comment.