frostfs-node/pkg/morph/client/netmap/new_epoch.go
2024-12-12 15:30:12 +03:00

40 lines
1 KiB
Go

package netmap
import (
"context"
"fmt"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/morph/client"
)
// NewEpoch updates FrostFS epoch number through
// Netmap contract call.
func (c *Client) NewEpoch(ctx context.Context, epoch uint64) error {
prm := client.InvokePrm{}
prm.SetMethod(newEpochMethod)
prm.SetArgs(epoch)
_, err := c.client.Invoke(ctx, prm)
if err != nil {
return fmt.Errorf("invoke method (%s): %w", newEpochMethod, err)
}
return nil
}
// NewEpochControl updates FrostFS epoch number through
// control notary transaction internally to ensure all
// nodes produce the same transaction with high probability.
// If vub > 0, vub will be used as valid until block value.
func (c *Client) NewEpochControl(ctx context.Context, epoch uint64, vub uint32) (uint32, error) {
prm := client.InvokePrm{}
prm.SetMethod(newEpochMethod)
prm.SetArgs(epoch)
prm.SetControlTX(true)
prm.SetVUB(vub)
res, err := c.client.Invoke(ctx, prm)
if err != nil {
return 0, fmt.Errorf("invoke method (%s): %w", newEpochMethod, err)
}
return res.VUB, nil
}