-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Upgrade to sdk rc10 #807
Merged
Merged
Upgrade to sdk rc10 #807
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
eddc129
resolver: Replace resolver with NNS contract bindings
smallhive 5c4073a
layer: Use gate private key instead of anonymous
smallhive 48b7ebc
*: Update SDK to the latest version
smallhive b79745f
*: Remove pool's deprecated methods
smallhive 7080a3d
authmate: Init authmate with layer.NeoFS interface
smallhive 33f4258
api: Fix eACL setup with multipart upload
smallhive 65e7899
api: Use anonymous key
smallhive cac5b70
changelog: Updated changelog
smallhive 0775e3b
layer: Remove unused gateKey field
smallhive 4a66ae8
layer: Remove gateSigner
smallhive 99525d8
layer: User anonSigner
smallhive cb7d1e5
neofs: Add maxObjectSize as parameter in constructor
smallhive File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
package resolver | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"sync" | ||
|
||
"github.com/nspcc-dev/neo-go/pkg/rpcclient" | ||
"github.com/nspcc-dev/neo-go/pkg/rpcclient/invoker" | ||
"github.com/nspcc-dev/neo-go/pkg/util" | ||
rpcNNS "github.com/nspcc-dev/neofs-contract/rpc/nns" | ||
cid "github.com/nspcc-dev/neofs-sdk-go/container/id" | ||
) | ||
|
||
const ( | ||
nnsContract = int32(1) | ||
) | ||
|
||
// Container is a wrapper for the [Resolver]. It allows to update resolvers in runtime, without service restarting. | ||
// | ||
// The Container should be used like regular [Resolver]. | ||
type Container struct { | ||
mu sync.RWMutex | ||
resolver Resolver | ||
} | ||
|
||
// Resolve looks up the container id by its name via NNS contract. | ||
// The method calls inline resolver. | ||
func (r *Container) Resolve(ctx context.Context, name string) (cid.ID, error) { | ||
r.mu.RLock() | ||
defer r.mu.RUnlock() | ||
|
||
return r.resolver.Resolve(ctx, name) | ||
} | ||
|
||
// UpdateResolvers allows to update resolver in runtime. Resolvers will be created from scratch. | ||
func (r *Container) UpdateResolvers(ctx context.Context, endpoint string) error { | ||
newResolver, err := NewResolver(ctx, endpoint) | ||
if err != nil { | ||
return fmt.Errorf("resolver reinit: %w", err) | ||
} | ||
|
||
r.mu.Lock() | ||
r.resolver = newResolver | ||
r.mu.Unlock() | ||
|
||
return nil | ||
} | ||
|
||
// NewContainer is a constructor for the [Container]. | ||
func NewContainer(ctx context.Context, endpoint string) (*Container, error) { | ||
newResolver, err := NewResolver(ctx, endpoint) | ||
if err != nil { | ||
return nil, fmt.Errorf("resolver reinit: %w", err) | ||
} | ||
|
||
return &Container{ | ||
resolver: newResolver, | ||
}, nil | ||
} | ||
|
||
// NewResolver returns resolver depending on corresponding endpoint. | ||
// | ||
// If endpoint is empty, [NoOpResolver] will be returned. | ||
func NewResolver(ctx context.Context, endpoint string) (Resolver, error) { | ||
if endpoint == "" { | ||
return NewNoOpResolver(), nil | ||
} | ||
|
||
cl, err := rpcClient(ctx, endpoint) | ||
if err != nil { | ||
return nil, fmt.Errorf("rpcclient: %w", err) | ||
} | ||
|
||
nnsHash, err := systemContractHash(cl, nnsContract) | ||
if err != nil { | ||
return nil, fmt.Errorf("nns contract: %w", err) | ||
} | ||
|
||
inv := invoker.New(cl, nil) | ||
nnsReader := rpcNNS.NewReader(inv, nnsHash) | ||
return NewNNSResolver(nnsReader), nil | ||
} | ||
|
||
func systemContractHash(cl *rpcclient.Client, id int32) (util.Uint160, error) { | ||
c, err := cl.GetContractStateByID(id) | ||
if err != nil { | ||
return util.Uint160{}, fmt.Errorf("GetContractStateByID [%d]: %w", id, err) | ||
} | ||
|
||
return c.Hash, nil | ||
} | ||
|
||
func rpcClient(ctx context.Context, endpoint string) (*rpcclient.Client, error) { | ||
cl, err := rpcclient.New(ctx, endpoint, rpcclient.Options{}) | ||
if err != nil { | ||
return nil, fmt.Errorf("new: %w", err) | ||
} | ||
|
||
err = cl.Init() | ||
if err != nil { | ||
return nil, fmt.Errorf("init: %w", err) | ||
} | ||
|
||
return cl, nil | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's supposed to be a feature, see #271. Although I don't quite understand it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On current
master
it doesn't work:In the gate logs:
In any case, we have to sign requests. Many client calls requires
Signer
as an explicit parameter. I tend to think it doesn't matter what key it should be either a gate key or an anonymous one.But the gate key we have to have because all our sessions were created for the gate key. And we need to sign requests by it
I also agreed with comment in #271 because we can't create container with random key, because containerPut is not a free operation. Signer is required and must not be nil. The account corresponding to the specified Signer will be charged for the operation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It can be used for reads, I guess.