Skip to content

Commit

Permalink
blockfetcher: check container and network Magic
Browse files Browse the repository at this point in the history
Close #3644

Signed-off-by: Ekaterina Pavlova <[email protected]>
  • Loading branch information
AliceInHunterland committed Nov 27, 2024
1 parent 81a63d8 commit 2861f3a
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions pkg/services/blockfetcher/blockfetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,15 @@ import (
"fmt"
"io"
"net/url"
"strconv"
"strings"
"sync"
"sync/atomic"
"time"

"github.com/nspcc-dev/neofs-sdk-go/container"
cid "github.com/nspcc-dev/neofs-sdk-go/container/id"

"github.com/nspcc-dev/neo-go/pkg/config"
"github.com/nspcc-dev/neo-go/pkg/core/block"
gio "github.com/nspcc-dev/neo-go/pkg/io"
Expand Down Expand Up @@ -190,14 +194,36 @@ func (bfs *Service) Start() error {
return nil
}
bfs.log.Info("starting NeoFS BlockFetcher service")

var err error
var (
containerID cid.ID
containerObj container.Container
err error
)
bfs.ctx, bfs.ctxCancel = context.WithCancel(context.Background())
if err = bfs.pool.Dial(context.Background()); err != nil {
bfs.isActive.CompareAndSwap(true, false)
return fmt.Errorf("failed to dial NeoFS pool: %w", err)
}

err = containerID.DecodeString(bfs.cfg.ContainerID)
if err != nil {
bfs.isActive.CompareAndSwap(true, false)
return fmt.Errorf("failed to decode container ID: %w", err)
}

bfs.retry(func() error {
containerObj, err = bfs.pool.ContainerGet(bfs.ctx, containerID, client.PrmContainerGet{})
return err
})
if err != nil {
bfs.isActive.CompareAndSwap(true, false)
return fmt.Errorf("failed to get container: %w", err)
}
containerMagic := containerObj.Attribute("Magic")
if containerMagic != strconv.Itoa(int(bfs.chain.GetConfig().Magic)) {
bfs.isActive.CompareAndSwap(true, false)
return fmt.Errorf("container magic mismatch: expected %d, got %s", bfs.chain.GetConfig().Magic, containerMagic)
}
// Start routine that manages Service shutdown process.
go bfs.exiter()

Expand Down

0 comments on commit 2861f3a

Please sign in to comment.