From b95df487c8a6affb4505d2dbd5d6d6a263d83a84 Mon Sep 17 00:00:00 2001 From: "aleksej.paschenko" Date: Tue, 13 Feb 2024 11:48:14 +0300 Subject: [PATCH] Handle pruned branch cells when decoding tlb.Block.StateUpdate --- tlb/block_test.go | 10 +++-- tlb/proof.go | 19 +++++++--- tlb/testdata/block-4/block.bin | Bin 0 -> 1088 bytes tlb/testdata/block-4/block.expected.json | 45 +++++++++++++++++++++++ 4 files changed, 65 insertions(+), 9 deletions(-) create mode 100644 tlb/testdata/block-4/block.bin create mode 100644 tlb/testdata/block-4/block.expected.json diff --git a/tlb/block_test.go b/tlb/block_test.go index 839e1f41..bd6b562d 100644 --- a/tlb/block_test.go +++ b/tlb/block_test.go @@ -49,6 +49,10 @@ func Test_tlb_Unmarshal(t *testing.T) { name: "block (0,8000000000000000,40484438)", folder: "testdata/block-3", }, + { + name: "block (0,D83800000000000,4168601)", + folder: "testdata/block-4", + }, } for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { @@ -56,16 +60,16 @@ func Test_tlb_Unmarshal(t *testing.T) { inputFilename := path.Join(tc.folder, "block.bin") data, err := os.ReadFile(inputFilename) if err != nil { - t.Errorf("ReadFile() failed: %v", err) + t.Fatalf("ReadFile() failed: %v", err) } cell, err := boc.DeserializeBoc(data) if err != nil { - t.Errorf("boc.DeserializeBoc() failed: %v", err) + t.Fatalf("boc.DeserializeBoc() failed: %v", err) } var block Block err = Unmarshal(cell[0], &block) if err != nil { - t.Errorf("Unmarshal() failed: %v", err) + t.Fatalf("Unmarshal() failed: %v", err) } accounts := map[string]*AccountBlock{} var txHashes []string diff --git a/tlb/proof.go b/tlb/proof.go index 8667a2db..bfdda06e 100644 --- a/tlb/proof.go +++ b/tlb/proof.go @@ -86,17 +86,24 @@ func (s *ShardState) UnmarshalTLB(c *boc.Cell, decoder *Decoder) error { if err != nil { return err } - err = decoder.Unmarshal(c1, &s.SplitState.Left) - if err != nil { - return err + if c1.CellType() != boc.PrunedBranchCell { + err = decoder.Unmarshal(c1, &s.SplitState.Left) + if err != nil { + return err + } + } else { + s.SplitState.Left = ShardStateUnsplit{} } c1, err = c.NextRef() if err != nil { return err } - err = decoder.Unmarshal(c1, &s.SplitState.Right) - if err != nil { - return err + if c1.CellType() != boc.PrunedBranchCell { + if err := decoder.Unmarshal(c1, &s.SplitState.Right); err != nil { + return err + } + } else { + s.SplitState.Right = ShardStateUnsplit{} } s.SumType = "SplitState" break diff --git a/tlb/testdata/block-4/block.bin b/tlb/testdata/block-4/block.bin new file mode 100644 index 0000000000000000000000000000000000000000..7e3221519c62a95d0325223315eb762fd5629597 GIT binary patch literal 1088 zcmdn`ZcfodCJ9Cc76t|e8HQC12N;7GpD{Htbup_kA7XyM{Eqn_OA5;dRx#EjHZwLq zwq$lQ_GRp!*ne>_vIq#i4_)>D|9?S7CT13*CLn?WQ4 zLtNJ#1qKF|n0Lvw2cY!9H0R#|3=I3+81zLL81&gcu(C1n?s(GsTY2XaPA;x47R8O7 zf!Yd;I=8k;Zt8OTl^=D#E;3|p$%F2+O*KZ&GuOP_bfNdNmPmqOkH)$S{Lf}Cu-b8o zZR+b?H$Pv}jA@pxXW(Pt<>q1T^fLbT_cJg19|yykPd4sUdGA+joyK*MyX6|2|C;1P zhI_0&YXh~ngyd{Y&Gm4&82CL#XCH^G*Mh~d`Aw_7FSuSOWZz=rASN!(FazxJ5bG9@ zixnHSvgI^3-pP|$wf*+`BDq_W+?=1}-fC0Od-*ES+i3Fkm47}RvwbM>U|Hq&j+~FN z-to_x1Yb1Fz8^IEa^;?uk4y~g91s)VRGS_I2HK42Oz-zyJtozs@n`*#U6XBKl6aIXG2b0sH=Y13{0 zoXDE$aKf!A|L&__)2F=^l)w7M$3^E>41dk-bicj7p1+Z7QP`4y=BH=-?3uHg|4)oP zbMRg0xwNFV#ff{0e!OLn3|#NmfBaK#RY{$F0|x^q1IN1z4keCwquQmse9F-il-EB3 zML$Y3!{Qz(x(|W^OF>XbSi^&n(P#aS$f5-T{Vsj2k+ZHuzPS5U<9E1>pA>sYL7S87 zmxl~Y2!jPd>4vwt0Yrfk)pQUQ*L8ayC>FqBrZ4$yYkRyZ(yw9j%{ zBFU@c@vMw9^_=@fH%9Jr!s(`xRRY@_;})o^?F+hMc;lN%Z-u7ShRpxlzaM6|KHeH* z;BUT3M>hYH=emH87K~t*gKP>AQRHoO+iPVne?b)0exM{H#QvU)ikpQKK=wa%-T}1V zfk{GW*~UlRvd12tT3x&AyW-oGDk*kucUL4ay_>g8WV5Dq)%^21$@c{NxYFlWw4E2d zvh`nvqFe{(-mjW_&1awRmte@=z;^He$bJR}@h%|2q*tybdl2Yjyx;&R93zz+`F8l8 t`n<>_r+;O~)!RotN@o-{9QC{TM)v^!Le51D+ziYN3Ji=)uG_E81^{=!x|IL` literal 0 HcmV?d00001 diff --git a/tlb/testdata/block-4/block.expected.json b/tlb/testdata/block-4/block.expected.json new file mode 100644 index 00000000..dc468df3 --- /dev/null +++ b/tlb/testdata/block-4/block.expected.json @@ -0,0 +1,45 @@ +{ + "Accounts": {}, + "TxHashes": null, + "ValueFlow": { + "FromPrevBlk": { + "Grams": "115778059391", + "Other": {} + }, + "ToNextBlk": { + "Grams": "115778059391", + "Other": {} + }, + "Imported": { + "Grams": "0", + "Other": {} + }, + "Exported": { + "Grams": "0", + "Other": {} + }, + "FeesCollected": { + "Grams": "15258", + "Other": {} + }, + "Burned": null, + "FeesImported": { + "Grams": "0", + "Other": {} + }, + "Recovered": { + "Grams": "0", + "Other": {} + }, + "Created": { + "Grams": "15258", + "Other": {} + }, + "Minted": { + "Grams": "0", + "Other": {} + } + }, + "InMsgDescrLength": 0, + "OutMsgDescrLength": 0 + } \ No newline at end of file