From fba909b12ec61b606d3e98c75f26481d99a859c1 Mon Sep 17 00:00:00 2001 From: Denis Kirillov Date: Thu, 11 Jul 2024 17:18:28 +0300 Subject: [PATCH] [#240] pool/tree: Update tree service client Update tree service to fix split tree problem. Tree intermediate nodes can be duplicated so we must handle this. Signed-off-by: Denis Kirillov --- go.mod | 2 +- pool/tree/pool.go | 44 ++++-------------------- pool/tree/pool_signature.go | 41 ++++++++++++++-------- pool/tree/service/service.pb.go | Bin 124265 -> 123722 bytes pool/tree/service/service_frostfs.pb.go | Bin 0 -> 60583 bytes pool/tree/service/service_grpc.pb.go | Bin 19139 -> 19139 bytes pool/tree/service/types.pb.go | Bin 9911 -> 9855 bytes pool/tree/service/types_frostfs.pb.go | Bin 0 -> 3111 bytes syncTree.sh | 9 ++--- 9 files changed, 37 insertions(+), 59 deletions(-) create mode 100644 pool/tree/service/service_frostfs.pb.go create mode 100644 pool/tree/service/types_frostfs.pb.go diff --git a/go.mod b/go.mod index 48c9453..c771411 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,6 @@ go 1.20 require ( 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-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 @@ -21,6 +20,7 @@ require ( ) require ( + git.frostfs.info/TrueCloudLab/frostfs-crypto v0.6.0 // indirect git.frostfs.info/TrueCloudLab/rfc6979 v0.4.0 // indirect github.com/benbjohnson/clock v1.1.0 // indirect github.com/davecgh/go-spew v1.1.1 // indirect diff --git a/pool/tree/pool.go b/pool/tree/pool.go index 2c55351..b610909 100644 --- a/pool/tree/pool.go +++ b/pool/tree/pool.go @@ -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 } diff --git a/pool/tree/pool_signature.go b/pool/tree/pool_signature.go index 0b3a2f6..5a8def1 100644 --- a/pool/tree/pool_signature.go +++ b/pool/tree/pool_signature.go @@ -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) -} diff --git a/pool/tree/service/service.pb.go b/pool/tree/service/service.pb.go index 63f3e714a2578d648309f46e53a12d3eda9f61f0..2ca3c0528763e90d2cead13c1bb9709d70986252 100644 GIT binary patch delta 3937 zcmai0Yfx3!6`loLkVgOsUI+*t>nN{~Cw65=)7Hj@iVCID(NM9Yafz4b^DtObt`rrkxu>5pSQ8p5>ING}K6ZC0 zD(1be6seY63s6h;`Ktq0LkIh=o%6tjG&KuTwRLohb`a_+UUz+Or8+R;re=(prtBo7 z>N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}P_CPZVqibTps)tX$$6VXB(De4y>GMU=N8Zj>Duv7UBty}BIX&~O7M?1WG~XOV1a!G6f!gH18I?hZ6! z-Mu#xa$2>EX33rF(EPu*3u;0B1`gi@axz=+^wlmX@pc8CptqZKZn~$3YBOU*gVoaC;u7k|0xY|xPq)&}s198S z;8WN1aXMn6Wcl;ekMv3gX{C@!W${CXY diff --git a/pool/tree/service/service_frostfs.pb.go b/pool/tree/service/service_frostfs.pb.go new file mode 100644 index 0000000000000000000000000000000000000000..1a49c5c0c1d0cf110c458c168ddc145ff9bc71c8 GIT binary patch literal 60583 zcmeHQ?{C{S6aF0k6+}KcU24B;`*tq|^h47YTY$DHl5Ag!qEIZ_7Ai}gM90a7{qOIQ z(#blCQtUWYD3!o~t~G!2xx43%CvrSyZ(^Ub8IO443GTD2TeeJM5l^1NzdfDBPp3(o zifKAxZ_n7rvrG2w?dj!cFj#t%Z{CbEk#Ig31dC;y2sRuXTm_Mr+_FO+O=3TYX5;K1 z4hILS*>#X`b~uaUS;$ATIP{{~C{AW$_2boQIxgxJ#SaHZMF)qoK#XuiK{SoWm&uC1 z3FDRj-n$y-zdZGp0StY7{cOAvL6|juI2eq_>_T`~A-@Rz<}Bf2l|(5MbIwxv5Al@U zupr9j4`X4|I9YgN1og72$!Y>sc*@p+m}m981!vQMhd#UZ!WH~9_pV`4WRvozd^KeA zqrr3)P1x{;J$dc>=lm}yExw+_{_Rm|RKp`SRD%g3am4-^90YPuuU@ez2<2Z7vQe}D z3=aMs9H^2%y~;*BI=K}*y@0NUKOeK3(VI9DUI6=g>L2MvFGK=+qsl&$WiMeD4aNRA zjl|0rs@QW`?30)9NT`CaHY{MjzG4Y%A&1{SaN(&D(m{QMS#lrx%hpb{^+L8K%YP2O zz|a~d@?Tlm(4cJqkv?2g^E%7t4?f9^T4E*%{y~SqCXU zCLqp-3<%B|l_*rzVN|k7!6O_~u^+o*8HM65H0S#*-S01@yX zKwnlafnWUDo&`n5QWhAkJcNkpDjw6dWJO3N-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;X-&hG zB-_b~-fRsyFy!tK@zI;1qcddhR3!?S68Sz^hBY4X8gw(PRATeJpE0W>5z5_7w|q>j z(35HLnwZl?ozO*P&{(948qlbVbB$K0(N`6Kc0sfsirHvOrGm3cblsOby?F`HXd4hf z7D@R1#n^qo)9nv<>JZw0*T2=H*t%uz_?hg*>Po)tS-vCb>zRBv7ImDmYCC;~P5tY4 z(Q1K~5uV_9{%m+NdK)BsB7!(N0_WZ_Tl<*pov5(b@=3tq@G7je34!)eSHm_ulvt|c zSd>fsd0;BRr5uGUGKUXqSGWJ(@OjScZo}JhCL`{9<1P>UcP|lW#>}7cd1;~3{W$BU0rvA zGWCE6FoY&iU+5Ld&KOcPs0z_*Yf1$BH>7P;w2JLE2&GD?+&x&KwnVBq7dq+JGm+pi zQ38YDL4mMPC2P3EkydzQaXZhJvTr!Fxc~>X!P+7Aol8v!(j&v1VJ$qj|c8HrEHCW+5AzYj?DhjGZely`5E@vX@Um%!e`6(@vIxs&g^p9O_1|<9?a$ff<`nb zS}LZ#`g;?vB3a5YNXr;x6Z$N+ppO*_&2WtiV~Btj@}LJ%X-&g-TbhVi#?3XHxX`H! zo$3szj-A&)2ZhK*Pu-;@k9lcHnS6m->mft02w*E5z0zw>SbFAk>={X=Y*{<4QS4gf z#~RL4Wli$dL#{{J!b{S*7pCk+Ui_o(os+7SXyweEg;!v%LJn{CN@q5fchjQddkW>V z^LQ6^Dx7|@f~Ba_2H*xr^uoFs;0N#^=#y9_`5X$_@l-=0hU~`U0mPl|6JN=9K{ns8 z2acCI`Q4qD7I7q{7<(bQE?KtQ$+Eg}={qw;5p0>7Vz-^lsgmWkLi(CC<)%}lPk!_B6v14K?u$?-VH-9dprXAe^o=QJ^%m! literal 0 HcmV?d00001 diff --git a/pool/tree/service/service_grpc.pb.go b/pool/tree/service/service_grpc.pb.go index 2c0828951aea66870e38f68316b12ef987686967..63f96e11a561bc8a96b26272e90478e59539536b 100644 GIT binary patch delta 19 bcmX>+mGSUY#tF;WO!SOQ^$a$y74rfBOJoMs delta 19 bcmX>+mGSUY#tF;WjP;BR^(;5874rfBOKS$% diff --git a/pool/tree/service/types.pb.go b/pool/tree/service/types.pb.go index b4d6981ef92d8434e0d3ffa6370d8cb860db9ce4..738b388614971ac85e6ab81790a8b264e75c9ceb 100644 GIT binary patch delta 119 zcmdn)``>3mmz=SQo)MS6z5-`KQGQ8&vH}#80fkNV3^uNqAmzz5-`KQGQ8&vH}#88S5Dt>RE1FF+-L+Gp{7IC@nELwYqk* nv)o}Oc_aZHg-it?R})0Q6ipUY{7O)bq|z5cYBtL#Co=;8$rw8r diff --git a/pool/tree/service/types_frostfs.pb.go b/pool/tree/service/types_frostfs.pb.go new file mode 100644 index 0000000000000000000000000000000000000000..707fcc3ccdbbd65a8fef39ef75885f67673b8bc1 GIT binary patch literal 3111 zcmeH}O>f&U42I9quONDIw#MGNVTS>|tlc44yADgYOVNX3)3#7W3M4scR`kD@l58|~ zyH6BD4g~@@w)xUD`Mi>|432bxP@zJ@9TqU(z|v@^^9fy>RC-bxZCz;B{RLgZH3${Un>Qtt+AO$BNf)K2$w`71*22|M#}^2t zKv}?w%Z6^%d_^_;l>XLSC~h_(eagy4<&a#%i%+=u?xV+BnoC&3qaAdneXrP{*bW;y+cra+0!`PrX$jQL5)DXH6?INn`e%LTxuRO`XOfKf zLE*X!r#LR9&OJ9>vajvbxY__3qYa?Sb)y^_f@@uiyoN#)ptK9(HLQ(r)SfVuf;$em zUMwX#lpCKE&S+X@EiCT$kZ4OL9%52I(;%m+d`gF^tBLymuVi$H{gjP%5Q*pU;&M(? z9Jj|`KoSFQ2o(AeNM5{!QaGj2USSd=JrUbeAbLo+;)Xm?T6E+J$42e{0d`%1L>}e6 zh(Yf!?>QXG0*Rf9U>vFjXwvN-nV#X^pgg<(&$}nOI@PNuv+lR4a_`;-Uk2-b;RcnP z7QgfFDLVcjW-Hkn-~Xdp$Rgxw7msI~?~2U_7vVUv!mg1qT z|42f4xI{bvd&d@unWz-^p9)X4!{6`Tf4af@5@>;VHvW$7?+?)EoVA12@9or&I6r=8 Q4&B>RJ+i;|$&Aju16E2Dvj6}9 literal 0 HcmV?d00001 diff --git a/syncTree.sh b/syncTree.sh index 90eeba7..8eec6bf 100755 --- a/syncTree.sh +++ b/syncTree.sh @@ -1,6 +1,6 @@ #!/bin/bash -REVISION="b3695411d907c3c65485bab04f9ff8479a72906b" +REVISION="9d1c915c428a4d07bc2bb62db2fe1832dfaecdb3" 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 -- 2.45.2