onflow / flow-core-contracts

Cadence smart contracts that define core functionality of the Flow protocol
https://onflow.org
The Unlicense
85 stars 47 forks source link

Allow admin to adjust node weights #312

Closed pgebheim closed 1 year ago

pgebheim commented 1 year ago

Automated Slot Assignment allows nodes to be added to the network in a permissionless manner. This opens the network up to nodes being allowed within the private p2p network, where they can transmit messages to the other active node types. These nodes all have baseline BFT protections, and as such the permissionless node types (starting with access nodes), should not be able to do anything affecting block production. However, any node within the network can potentially deliver large numbers of messages to all other nodes, and could enagage in some sort of DoS-type attack on individual nodes in the network.

To handle this, there is a need to build out an automated slashing framework where nodes can have their stake slash or weight reduced in response to behavior on the network. This would stack on top of individual operators' ability to block traffic from certain nodes in the network, and allow they network as a whole to respond.

In order to begin with a barebones implementation, we suggest that the existing staking admin should be able to adjust a node's weight via a service account transaction. Currently, the admin has an override to forcibly remove a node from the staking table (removeNode). This function actually deletes the nodes record from the staking table, taking with it all bookkeeping for rewards.

To improve upon this we suggest adding a new function setNodeWeight which will allow the staking admin to adjust the weight of specific Node ID.

joshuahannan commented 1 year ago

This should be relatively straightforward. Just provide the node ID and the weight, then the contract borrows the node object and sets the new weight via a setter function

pgebheim commented 1 year ago

Yeah simple to implement. Do you agree with the approach or should we look at doing something different?

This solves the problem for now but we will probably wanna address all slashing conditions in an upcoming discussion of how these contracts should be structured in the long run.

joshuahannan commented 1 year ago

Are you saying that it solves the problem of needing to remove the node from the network in the middle of the epoch? I don't think it would actually solve that problem, because the weight has no affect on anything in the smart contract or the network. If the weight is set to zero, the node would still remain in the identity table in the smart contract, their stake wouldn't be unstaked, and nothing would change about the protocol state as far as I am aware.

joshuahannan commented 1 year ago

closing this because we are merging soon