Skip to content

Commit

Permalink
Merge pull request #239 from tonkeeper/pruned-branch-cell-when-decodi…
Browse files Browse the repository at this point in the history
…ng-block

Handle pruned branch cells when decoding tlb.Block.StateUpdate
  • Loading branch information
mr-tron authored Feb 13, 2024
2 parents bcc77d4 + b95df48 commit 016ef1d
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 9 deletions.
10 changes: 7 additions & 3 deletions tlb/block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,23 +49,27 @@ 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) {

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
Expand Down
19 changes: 13 additions & 6 deletions tlb/proof.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Binary file added tlb/testdata/block-4/block.bin
Binary file not shown.
45 changes: 45 additions & 0 deletions tlb/testdata/block-4/block.expected.json
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit 016ef1d

Please sign in to comment.