[#239] pool/tree: Update tree service client
All checks were successful
DCO / DCO (pull_request) Successful in 7m22s
Tests and linters / Tests (1.21) (pull_request) Successful in 7m23s
Tests and linters / Tests (1.22) (pull_request) Successful in 7m17s
Tests and linters / Lint (pull_request) Successful in 9m22s

Update tree service to fix split tree problem.
Tree intermediate nodes can be duplicated so we must handle this.

Signed-off-by: Denis Kirillov <d.kirillov@yadro.com>
This commit is contained in:
Denis Kirillov 2024-07-11 17:18:28 +03:00
parent c4ff8a6cda
commit bf717e7472
9 changed files with 37 additions and 59 deletions

2
go.mod
View file

@ -5,7 +5,6 @@ go 1.21
require (
git.frostfs.info/TrueCloudLab/frostfs-api-go/v2 v2.16.1-0.20240530152826-2f6d3209e1d3
git.frostfs.info/TrueCloudLab/frostfs-contract v0.0.0-20230307110621-19a8ef2d02fb
git.frostfs.info/TrueCloudLab/frostfs-crypto v0.6.0
git.frostfs.info/TrueCloudLab/hrw v1.2.1
git.frostfs.info/TrueCloudLab/tzhash v1.8.0
github.com/antlr4-go/antlr/v4 v4.13.0
@ -22,6 +21,7 @@ require (
)
require (
git.frostfs.info/TrueCloudLab/frostfs-crypto v0.6.0 // indirect
git.frostfs.info/TrueCloudLab/rfc6979 v0.4.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 // indirect

View file

@ -126,7 +126,7 @@ type GetNodesParams struct {
type GetSubTreeParams struct {
CID cid.ID
TreeID string
RootID uint64
RootID []uint64
Depth uint32
BearerToken []byte
Order SubTreeSort
@ -308,12 +308,7 @@ func (p *Pool) GetNodes(ctx context.Context, prm GetNodesParams) ([]*grpcService
},
}
if err := p.signRequest(request.Body, func(key, sign []byte) {
request.Signature = &grpcService.Signature{
Key: key,
Sign: sign,
}
}); err != nil {
if err := p.signRequest(request); err != nil {
return nil, err
}
@ -410,12 +405,7 @@ func (p *Pool) GetSubTree(ctx context.Context, prm GetSubTreeParams) (*SubTreeRe
request.Body.OrderBy.Direction = grpcService.GetSubTreeRequest_Body_Order_None
}
if err := p.signRequest(request.Body, func(key, sign []byte) {
request.Signature = &grpcService.Signature{
Key: key,
Sign: sign,
}
}); err != nil {
if err := p.signRequest(request); err != nil {
return nil, err
}
@ -445,12 +435,7 @@ func (p *Pool) AddNode(ctx context.Context, prm AddNodeParams) (uint64, error) {
BearerToken: prm.BearerToken,
},
}
if err := p.signRequest(request.Body, func(key, sign []byte) {
request.Signature = &grpcService.Signature{
Key: key,
Sign: sign,
}
}); err != nil {
if err := p.signRequest(request); err != nil {
return 0, err
}
@ -482,12 +467,7 @@ func (p *Pool) AddNodeByPath(ctx context.Context, prm AddNodeByPathParams) (uint
},
}
if err := p.signRequest(request.Body, func(key, sign []byte) {
request.Signature = &grpcService.Signature{
Key: key,
Sign: sign,
}
}); err != nil {
if err := p.signRequest(request); err != nil {
return 0, err
}
@ -527,12 +507,7 @@ func (p *Pool) MoveNode(ctx context.Context, prm MoveNodeParams) error {
},
}
if err := p.signRequest(request.Body, func(key, sign []byte) {
request.Signature = &grpcService.Signature{
Key: key,
Sign: sign,
}
}); err != nil {
if err := p.signRequest(request); err != nil {
return err
}
@ -558,12 +533,7 @@ func (p *Pool) RemoveNode(ctx context.Context, prm RemoveNodeParams) error {
BearerToken: prm.BearerToken,
},
}
if err := p.signRequest(request.Body, func(key, sign []byte) {
request.Signature = &grpcService.Signature{
Key: key,
Sign: sign,
}
}); err != nil {
if err := p.signRequest(request); err != nil {
return err
}

View file

@ -1,25 +1,38 @@
package tree
import (
crypto "git.frostfs.info/TrueCloudLab/frostfs-crypto"
"google.golang.org/protobuf/proto"
frostfsecdsa "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/crypto/ecdsa"
tree "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/pool/tree/service"
)
func (p *Pool) signData(buf []byte, f func(key, sign []byte)) error {
sign, err := crypto.Sign(&p.key.PrivateKey, buf)
type message interface {
SignedDataSize() int
ReadSignedData([]byte) ([]byte, error)
GetSignature() *tree.Signature
SetSignature(*tree.Signature)
}
// signMessage uses the pool key and signs any protobuf
// message that was generated for the TreeService by the
// protoc-gen-go-frostfs generator. Returns any errors directly.
func (p *Pool) signRequest(m message) error {
binBody, err := m.ReadSignedData(nil)
if err != nil {
return err
}
f(p.key.PublicKey().Bytes(), sign)
keySDK := frostfsecdsa.Signer(p.key.PrivateKey)
data, err := keySDK.Sign(binBody)
if err != nil {
return err
}
rawPub := make([]byte, keySDK.Public().MaxEncodedSize())
rawPub = rawPub[:keySDK.Public().Encode(rawPub)]
m.SetSignature(&tree.Signature{
Key: rawPub,
Sign: data,
})
return nil
}
func (p *Pool) signRequest(requestBody proto.Message, f func(key, sign []byte)) error {
buf, err := proto.Marshal(requestBody)
if err != nil {
return err
}
return p.signData(buf, f)
}

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View file

@ -1,6 +1,6 @@
#!/bin/bash
REVISION="b3695411d907c3c65485bab04f9ff8479a72906b"
REVISION="00a88b99368d7141380f65d9cb446f1e4771ba01"
echo "tree service revision ${REVISION}"
@ -9,11 +9,6 @@ echo "tree service revision ${REVISION}"
FILES=$(curl -s https://git.frostfs.info/TrueCloudLab/frostfs-node/src/commit/${REVISION}/pkg/services/tree | sed -n "s,.*\"/TrueCloudLab/frostfs-node/src/commit/${REVISION}/pkg/services/tree/\([^.]*\.pb\.go\)\".*,\1,p")
for file in $FILES; do
if [[ $file == *"frostfs"* ]]; then
echo "skip '$file'"
continue
else
echo "sync '$file' in tree service"
fi
echo "sync '$file' in tree service"
curl -s "https://git.frostfs.info/TrueCloudLab/frostfs-node/raw/commit/${REVISION}/pkg/services/tree/${file}" -o "./pool/tree/service/${file}"
done