forked from TrueCloudLab/frostfs-node
[#708] morph/client: Add epoch block getter from netmap
Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
parent
7e43af3de3
commit
7146afcd28
3 changed files with 57 additions and 0 deletions
|
@ -40,6 +40,7 @@ type cfg struct {
|
||||||
epochSnapshotMethod, // get network map snapshot by epoch method name
|
epochSnapshotMethod, // get network map snapshot by epoch method name
|
||||||
updateStateMethod, // update state method name for invocation
|
updateStateMethod, // update state method name for invocation
|
||||||
epochMethod, // get epoch number method name
|
epochMethod, // get epoch number method name
|
||||||
|
epochBlockMethod, // get epoch number method name
|
||||||
updateInnerRing, // update innerring method name
|
updateInnerRing, // update innerring method name
|
||||||
setConfigMethod, // set config method name
|
setConfigMethod, // set config method name
|
||||||
configMethod string // get config value method name
|
configMethod string // get config value method name
|
||||||
|
@ -49,6 +50,7 @@ const (
|
||||||
defaultAddPeerMethod = "addPeer" // default add peer method name
|
defaultAddPeerMethod = "addPeer" // default add peer method name
|
||||||
defaultConfigMethod = "config" // default get config value method name
|
defaultConfigMethod = "config" // default get config value method name
|
||||||
defaultEpochMethod = "epoch" // default get epoch number method name
|
defaultEpochMethod = "epoch" // default get epoch number method name
|
||||||
|
defaultEpochBlockMethod = "epochBlock" // default get epoch block number method name
|
||||||
defaultInnerRingListMethod = "innerRingList" // default get innerring list method name
|
defaultInnerRingListMethod = "innerRingList" // default get innerring list method name
|
||||||
defaultNetMapCandidateMethod = "netmapCandidates" // default get network candidates method name
|
defaultNetMapCandidateMethod = "netmapCandidates" // default get network candidates method name
|
||||||
defaultNetMapMethod = "netmap" // default get network map method name
|
defaultNetMapMethod = "netmap" // default get network map method name
|
||||||
|
@ -66,6 +68,7 @@ func defaultConfig() *cfg {
|
||||||
addPeerMethod: defaultAddPeerMethod,
|
addPeerMethod: defaultAddPeerMethod,
|
||||||
configMethod: defaultConfigMethod,
|
configMethod: defaultConfigMethod,
|
||||||
epochMethod: defaultEpochMethod,
|
epochMethod: defaultEpochMethod,
|
||||||
|
epochBlockMethod: defaultEpochBlockMethod,
|
||||||
innerRingList: defaultInnerRingListMethod,
|
innerRingList: defaultInnerRingListMethod,
|
||||||
netMapCandidatesMethod: defaultNetMapCandidateMethod,
|
netMapCandidatesMethod: defaultNetMapCandidateMethod,
|
||||||
netMapMethod: defaultNetMapMethod,
|
netMapMethod: defaultNetMapMethod,
|
||||||
|
|
|
@ -22,6 +22,22 @@ func (e EpochValues) Number() int64 {
|
||||||
return e.num
|
return e.num
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// EpochBlockArgs groups the arguments of
|
||||||
|
// get epoch block number test invoke call.
|
||||||
|
type EpochBlockArgs struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
// EpochBlockValues groups the stack parameters
|
||||||
|
// returned by get epoch block number test invoke.
|
||||||
|
type EpochBlockValues struct {
|
||||||
|
block int64
|
||||||
|
}
|
||||||
|
|
||||||
|
// Block return the block number of NeoFS epoch.
|
||||||
|
func (e EpochBlockValues) Block() int64 {
|
||||||
|
return e.block
|
||||||
|
}
|
||||||
|
|
||||||
// Epoch performs the test invoke of get epoch number
|
// Epoch performs the test invoke of get epoch number
|
||||||
// method of NeoFS Netmap contract.
|
// method of NeoFS Netmap contract.
|
||||||
func (c *Client) Epoch(_ EpochArgs) (*EpochValues, error) {
|
func (c *Client) Epoch(_ EpochArgs) (*EpochValues, error) {
|
||||||
|
@ -47,3 +63,28 @@ func (c *Client) Epoch(_ EpochArgs) (*EpochValues, error) {
|
||||||
num: num,
|
num: num,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// LastEpochBlock performs the test invoke of get epoch block number
|
||||||
|
// method of NeoFS Netmap contract.
|
||||||
|
func (c *Client) LastEpochBlock(_ EpochBlockArgs) (*EpochBlockValues, error) {
|
||||||
|
items, err := c.client.TestInvoke(c.epochBlockMethod)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("could not perform test invocation (%s): %w",
|
||||||
|
c.epochBlockMethod, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if ln := len(items); ln != 1 {
|
||||||
|
return nil, fmt.Errorf("unexpected stack item count (%s): %d",
|
||||||
|
c.epochBlockMethod, ln)
|
||||||
|
}
|
||||||
|
|
||||||
|
block, err := client.IntFromStackItem(items[0])
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("could not get number from stack item (%s): %w",
|
||||||
|
c.epochBlockMethod, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return &EpochBlockValues{
|
||||||
|
block: block,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
|
@ -18,3 +18,16 @@ func (w *Wrapper) Epoch() (uint64, error) {
|
||||||
|
|
||||||
return uint64(vals.Number()), nil
|
return uint64(vals.Number()), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// LastEpochBlock receives block number of current NeoFS epoch
|
||||||
|
// through the Netmap contract call.
|
||||||
|
func (w *Wrapper) LastEpochBlock() (uint32, error) {
|
||||||
|
args := netmap.EpochBlockArgs{}
|
||||||
|
|
||||||
|
vals, err := w.client.LastEpochBlock(args)
|
||||||
|
if err != nil {
|
||||||
|
return 0, fmt.Errorf("(%T) could not get epoch block number: %w", w, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return uint32(vals.Block()), nil
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue