-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ir: maintain container placement in container contract
After nspcc-dev/neofs-contract#438 Container contract now has API for container-side placement/verification operations. But building placement vectors and updating when needed is still a complex operation that should be done on a Go application side. This commit adds such a responsibility for Alphabet nodes. For simplicity, updating is done every epoch and once for _every_ container if netmap has been changed. Additional optimization can be considered. Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
- Loading branch information
Showing
5 changed files
with
153 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package processors | ||
|
||
import ( | ||
"fmt" | ||
|
||
cnrcli "github.com/nspcc-dev/neofs-node/pkg/morph/client/container" | ||
cid "github.com/nspcc-dev/neofs-sdk-go/container/id" | ||
"github.com/nspcc-dev/neofs-sdk-go/netmap" | ||
) | ||
|
||
// UpdatePlacementVectors updates placement vectors after a container placement | ||
// change in Container contract. Empty vectors drops container vectors from the | ||
// contract. | ||
func UpdatePlacementVectors(cID cid.ID, cnrCli *cnrcli.Client, vectors [][]netmap.NodeInfo, replicas []uint32) error { | ||
for i, vector := range vectors { | ||
err := cnrCli.AddNextEpochNodes(cID, i, pubKeys(vector)) | ||
if err != nil { | ||
return fmt.Errorf("can't add %d placement vector to Container contract: %w", i, err) | ||
} | ||
} | ||
|
||
err := cnrCli.CommitContainerListUpdate(cID, replicas) | ||
if err != nil { | ||
return fmt.Errorf("can't commit container list to Container contract: %w", err) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func pubKeys(nodes []netmap.NodeInfo) [][]byte { | ||
res := make([][]byte, 0, len(nodes)) | ||
for _, node := range nodes { | ||
res = append(res, node.PublicKey()) | ||
} | ||
|
||
return res | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters