[#240] pool/tree: Update tree service client
All checks were successful
DCO / DCO (pull_request) Successful in 1m3s
Tests and linters / Tests (1.21) (pull_request) Successful in 1m26s
Tests and linters / Tests (1.20) (pull_request) Successful in 1m38s
Tests and linters / Lint (pull_request) Successful in 2m54s

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 8412b075a5
commit fba909b12e
9 changed files with 37 additions and 59 deletions

2
go.mod
View file

@ -5,7 +5,6 @@ go 1.20
require ( require (
git.frostfs.info/TrueCloudLab/frostfs-api-go/v2 v2.16.1-0.20240306101814-c1c7b344b9c0 git.frostfs.info/TrueCloudLab/frostfs-api-go/v2 v2.16.1-0.20240306101814-c1c7b344b9c0
git.frostfs.info/TrueCloudLab/frostfs-contract v0.0.0-20230307110621-19a8ef2d02fb 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/hrw v1.2.1
git.frostfs.info/TrueCloudLab/tzhash v1.8.0 git.frostfs.info/TrueCloudLab/tzhash v1.8.0
github.com/antlr4-go/antlr/v4 v4.13.0 github.com/antlr4-go/antlr/v4 v4.13.0
@ -21,6 +20,7 @@ require (
) )
require ( require (
git.frostfs.info/TrueCloudLab/frostfs-crypto v0.6.0 // indirect
git.frostfs.info/TrueCloudLab/rfc6979 v0.4.0 // indirect git.frostfs.info/TrueCloudLab/rfc6979 v0.4.0 // indirect
github.com/benbjohnson/clock v1.1.0 // indirect github.com/benbjohnson/clock v1.1.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect github.com/davecgh/go-spew v1.1.1 // indirect

View file

@ -126,7 +126,7 @@ type GetNodesParams struct {
type GetSubTreeParams struct { type GetSubTreeParams struct {
CID cid.ID CID cid.ID
TreeID string TreeID string
RootID uint64 RootID []uint64
Depth uint32 Depth uint32
BearerToken []byte BearerToken []byte
Order SubTreeSort 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) { if err := p.signRequest(request); err != nil {
request.Signature = &grpcService.Signature{
Key: key,
Sign: sign,
}
}); err != nil {
return nil, err 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 request.Body.OrderBy.Direction = grpcService.GetSubTreeRequest_Body_Order_None
} }
if err := p.signRequest(request.Body, func(key, sign []byte) { if err := p.signRequest(request); err != nil {
request.Signature = &grpcService.Signature{
Key: key,
Sign: sign,
}
}); err != nil {
return nil, err return nil, err
} }
@ -445,12 +435,7 @@ func (p *Pool) AddNode(ctx context.Context, prm AddNodeParams) (uint64, error) {
BearerToken: prm.BearerToken, BearerToken: prm.BearerToken,
}, },
} }
if err := p.signRequest(request.Body, func(key, sign []byte) { if err := p.signRequest(request); err != nil {
request.Signature = &grpcService.Signature{
Key: key,
Sign: sign,
}
}); err != nil {
return 0, err 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) { if err := p.signRequest(request); err != nil {
request.Signature = &grpcService.Signature{
Key: key,
Sign: sign,
}
}); err != nil {
return 0, err 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) { if err := p.signRequest(request); err != nil {
request.Signature = &grpcService.Signature{
Key: key,
Sign: sign,
}
}); err != nil {
return err return err
} }
@ -558,12 +533,7 @@ func (p *Pool) RemoveNode(ctx context.Context, prm RemoveNodeParams) error {
BearerToken: prm.BearerToken, BearerToken: prm.BearerToken,
}, },
} }
if err := p.signRequest(request.Body, func(key, sign []byte) { if err := p.signRequest(request); err != nil {
request.Signature = &grpcService.Signature{
Key: key,
Sign: sign,
}
}); err != nil {
return err return err
} }

View file

@ -1,25 +1,38 @@
package tree package tree
import ( import (
crypto "git.frostfs.info/TrueCloudLab/frostfs-crypto" frostfsecdsa "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/crypto/ecdsa"
"google.golang.org/protobuf/proto" tree "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/pool/tree/service"
) )
func (p *Pool) signData(buf []byte, f func(key, sign []byte)) error { type message interface {
sign, err := crypto.Sign(&p.key.PrivateKey, buf) 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 { if err != nil {
return err 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 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 #!/bin/bash
REVISION="b3695411d907c3c65485bab04f9ff8479a72906b" REVISION="9d1c915c428a4d07bc2bb62db2fe1832dfaecdb3"
echo "tree service revision ${REVISION}" 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") 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 for file in $FILES; do
if [[ $file == *"frostfs"* ]]; then
echo "skip '$file'"
continue
else
echo "sync '$file' in tree service" echo "sync '$file' in tree service"
fi
curl -s "https://git.frostfs.info/TrueCloudLab/frostfs-node/raw/commit/${REVISION}/pkg/services/tree/${file}" -o "./pool/tree/service/${file}" curl -s "https://git.frostfs.info/TrueCloudLab/frostfs-node/raw/commit/${REVISION}/pkg/services/tree/${file}" -o "./pool/tree/service/${file}"
done done