Skip to content

Commit

Permalink
morph: Fix estimations announcements
Browse files Browse the repository at this point in the history
Some contract methods still require regular (non-notary) calls.

Signed-off-by: Pavel Karpy <[email protected]>
  • Loading branch information
carpawell committed Aug 4, 2023
1 parent aeab4ca commit e6fa650
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 10 deletions.
14 changes: 9 additions & 5 deletions cmd/neofs-node/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,16 @@ const (
)

func initContainerService(c *cfg) {
// container wrapper that tries to invoke notary
// requests if chain is configured so
// container wrapper that invokes notary
// requests with the (empty) Alphabet signature
wrap, err := cntClient.NewFromMorph(c.cfgMorph.client, c.cfgContainer.scriptHash, 0)
fatalOnErr(err)

c.shared.cnrClient = wrap

// container wrapper that always sends non-notary
// requests
wrapperNoNotary, err := cntClient.NewFromMorph(c.cfgMorph.client, c.cfgContainer.scriptHash, 0)
wrapperNoNotary, err := cntClient.NewFromMorph(c.cfgMorph.client, c.cfgContainer.scriptHash, 0, cntClient.DisableNotarySigning())
fatalOnErr(err)

cnrSrc := cntClient.AsContainerSource(wrap)
Expand Down Expand Up @@ -527,18 +527,20 @@ func (d *localStorageLoad) Iterate(f loadcontroller.UsedSpaceFilter, h loadcontr
return fmt.Errorf("list containers on engine failure: %w", err)
}

d.log.Debug(fmt.Sprintf("DEBUG: iterating local containers: %d found", len(idList)))

for i := range idList {
sz, err := engine.ContainerSize(d.engine, idList[i])
if err != nil {
d.log.Debug("failed to calculate container size in storage engine",
d.log.Debug("DEBUG: failed to calculate container size in storage engine",
zap.Stringer("cid", idList[i]),
zap.String("error", err.Error()),
)

continue
}

d.log.Debug("container size in storage engine calculated successfully",
d.log.Debug("DEBUG: container size in storage engine calculated successfully",
zap.Uint64("size", sz),
zap.Stringer("cid", idList[i]),
)
Expand All @@ -548,10 +550,12 @@ func (d *localStorageLoad) Iterate(f loadcontroller.UsedSpaceFilter, h loadcontr
a.SetValue(sz)

if f != nil && !f(a) {
d.log.Debug(fmt.Sprintf("DEBUG: skipping bad estimations values: %d size, %s container", sz, idList[i]))
continue
}

if err := h(a); err != nil {
d.log.Debug(fmt.Sprintf("DEBUG: iterating %s container by storage handling failed", idList[i]))
return err
}
}
Expand Down
21 changes: 18 additions & 3 deletions pkg/morph/client/container/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ func NewFromMorph(cli *client.Client, contract util.Uint160, fee fixedn.Fixed8,
o.staticOpts = append(o.staticOpts, client.WithCustomFee(putNamedMethod, o.feePutNamed))
}

if !o.disableNotarySigning {
o.staticOpts = append(o.staticOpts, client.TryNotary())
}

sc, err := client.NewStatic(cli, contract, fee, o.staticOpts...)
if err != nil {
return nil, fmt.Errorf("can't create container static client: %w", err)
Expand All @@ -85,13 +89,24 @@ type opts struct {
feePutNamedSet bool
feePutNamed fixedn.Fixed8

disableNotarySigning bool

staticOpts []client.StaticClientOption
}

func defaultOpts() *opts {
var o = new(opts)
o.staticOpts = append(o.staticOpts, client.TryNotary())
return o
return new(opts)
}

// DisableNotarySigning returns option to disable
// notary request signing. With that option, every
// call will be created, signed with provided key
// (a single regular sign) and sent to the side
// chain.
func DisableNotarySigning() Option {
return func(o *opts) {
o.disableNotarySigning = true
}
}

// AsAlphabet returns option to sign main TX
Expand Down
18 changes: 17 additions & 1 deletion pkg/services/container/announcement/load/controller/calls.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package loadcontroller

import (
"context"
"fmt"
"log"

"github.com/nspcc-dev/neofs-sdk-go/container"
"go.uber.org/zap"
Expand Down Expand Up @@ -38,9 +40,13 @@ type announceContext struct {
// Each call acquires an announcement context for an Epoch parameter.
// At the very end of the operation, the context is released.
func (c *Controller) Start(prm StartPrm) {
log.Printf(fmt.Sprintf("DEBUG: starting processing estimations for %d epoch", prm.Epoch))

Check failure on line 43 in pkg/services/container/announcement/load/controller/calls.go

View workflow job for this annotation

GitHub Actions / lint

SA1006: printf-style function with dynamic format string and no further arguments should use print-style function instead (staticcheck)

// acquire announcement
execCtx := c.acquireAnnouncement(prm)
if execCtx == nil {
execCtx.log.Debug(fmt.Sprintf("DEBUG: context is nil for %d epoch, do nothing", prm.Epoch))

return
}

Expand Down Expand Up @@ -187,6 +193,8 @@ type stopContext struct {
// Each call acquires a report context for an Epoch parameter.
// At the very end of the operation, the context is released.
func (c *Controller) Stop(prm StopPrm) {
c.opts.log.Debug(fmt.Sprintf("stopping estimations in %d epoch", prm.Epoch))

execCtx := c.acquireReport(prm)
if execCtx == nil {
return
Expand Down Expand Up @@ -265,6 +273,8 @@ func (c *stopContext) report() {
err error
)

c.ctrl.opts.log.Debug(fmt.Sprintf("DEBUG: reporiting stop ctx for %d epoch", c.commonContext.epoch))

// initialize iterator over locally accumulated announcements
localIterator, err = c.ctrl.prm.AnnouncementAccumulator.InitIterator(c.ctx)
if err != nil {
Expand All @@ -285,10 +295,16 @@ func (c *stopContext) report() {
return
}

f := func(se container.SizeEstimation) error {
err := resultWriter.Put(se)
c.ctrl.opts.log.Debug(fmt.Sprintf("DEBUG: writing final results for %d epoch: size %d, cid: %s: error %s", c.commonContext.epoch, se.Value(), se.Container(), err))
return err
}

// iterate over all accumulated announcements and write them to the target
err = localIterator.Iterate(
usedSpaceFilterEpochEQ(c.epoch),
resultWriter.Put,
f,
)
if err != nil {
c.log.Debug("iterator over local announcements aborted",
Expand Down
15 changes: 14 additions & 1 deletion pkg/services/container/announcement/load/storage/storage.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package loadstorage

import (
"log"
"sort"
"sync"

Expand Down Expand Up @@ -66,6 +67,8 @@ func (s *Storage) Put(a container.SizeEstimation) error {
s.mtx.Lock()

{
log.Printf("DEBUG: save estimation: %d, in %d epoch, for %s container", a.Value(), a.Epoch(), a.Container())

key := storageKey{
epoch: a.Epoch(),
cid: a.Container().EncodeToString(),
Expand Down Expand Up @@ -101,16 +104,26 @@ func (s *Storage) Iterate(f loadcontroller.UsedSpaceFilter, h loadcontroller.Use
s.mtx.RLock()

{
for _, v := range s.mItems {
log.Printf("DEBUG: iterating estimations by in-mem storage")

for k, v := range s.mItems {
log.Printf("DEBUG: iterating %s container with %d value in %d epoch", v.announcement.Container(), v.announcement.Value(), k.epoch)

if f(v.announcement) {
// calculate estimation based on 90th percentile
v.announcement.SetValue(finalEstimation(v.sizes))

if err = h(v.announcement); err != nil {
log.Printf("DEBUG: iterate estimation for %d epoch with error: %s", k.epoch, err)

break
}
} else {
log.Printf("DEBUG: wrong epoch: %d", v.announcement.Epoch())
}
}

log.Printf("DEBUG: finished iterating estimations by in-mem storage")
}

s.mtx.RUnlock()
Expand Down

0 comments on commit e6fa650

Please sign in to comment.