From c8412ade0b127313fd42b1651459fd1f403251bf Mon Sep 17 00:00:00 2001 From: Oleg Baranov Date: Fri, 12 Jan 2024 16:03:05 +0400 Subject: [PATCH 1/3] Fixed block header proof parse with pruned after merge part & minor fixes --- tlb/block.go | 20 +++++++++++++------- tlb/stack.go | 4 ++++ tvm/cell/slice.go | 4 ++++ 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/tlb/block.go b/tlb/block.go index 401d6919..66d2e5cc 100644 --- a/tlb/block.go +++ b/tlb/block.go @@ -142,7 +142,7 @@ func (h *BlockHeader) LoadFromCell(loader *cell.Slice) error { var infoPart blockInfoPart err := LoadFromCell(&infoPart, loader) if err != nil { - return err + return fmt.Errorf("failed to load blockInfoPart: %w", err) } h.blockInfoPart = infoPart @@ -150,7 +150,7 @@ func (h *BlockHeader) LoadFromCell(loader *cell.Slice) error { var globalVer GlobalVersion err = LoadFromCell(&globalVer, loader) if err != nil { - return err + return fmt.Errorf("failed to load GlobalVersion: %w", err) } h.GenSoftware = &globalVer } @@ -163,29 +163,29 @@ func (h *BlockHeader) LoadFromCell(loader *cell.Slice) error { } err = LoadFromCell(&masterRef, l) if err != nil { - return err + return fmt.Errorf("failed to load ExtBlkRef: %w", err) } h.MasterRef = &masterRef } l, err := loader.LoadRef() if err != nil { - return err + return fmt.Errorf("failed to load ref for after merge: %w", err) } prevRef, err := loadBlkPrevInfo(l, infoPart.AfterMerge) if err != nil { - return err + return fmt.Errorf("failed to loadBlkPrevInfo for after merge: %w", err) } h.PrevRef = *prevRef if infoPart.VertSeqnoIncr { l, err := loader.LoadRef() if err != nil { - return err + return fmt.Errorf("failed to load ref for vert incr: %w", err) } prevVertRef, err := loadBlkPrevInfo(l, false) if err != nil { - return err + return fmt.Errorf("failed to loadBlkPrevInfo for prev vert ref: %w", err) } h.PrevVertRef = prevVertRef } @@ -195,6 +195,12 @@ func (h *BlockHeader) LoadFromCell(loader *cell.Slice) error { func loadBlkPrevInfo(loader *cell.Slice, afterMerge bool) (*BlkPrevInfo, error) { var res BlkPrevInfo + if loader.IsSpecial() { + // TODO: rewrite BlockHeader to pure tlb loader + // if it is a proof we skip load + return &res, nil + } + if !afterMerge { var blkRef ExtBlkRef err := LoadFromCell(&blkRef, loader) diff --git a/tlb/stack.go b/tlb/stack.go index 3d73f5bb..12db6fed 100644 --- a/tlb/stack.go +++ b/tlb/stack.go @@ -320,6 +320,10 @@ func (s *Stack) parseValue(slice *cell.Slice) (any, error) { } } + if root.RefsNum() == 0 { + return nil + } + ref, err := root.LoadRef() if err != nil { return fmt.Errorf("failed to load tuple's %d ref, err: %w", i, err) diff --git a/tvm/cell/slice.go b/tvm/cell/slice.go index 9ac257a3..6ecc7d04 100644 --- a/tvm/cell/slice.go +++ b/tvm/cell/slice.go @@ -478,6 +478,10 @@ func (c *Slice) LoadBinarySnake() ([]byte, error) { return data, nil } +func (c *Slice) IsSpecial() bool { + return c.special +} + func (c *Slice) BitsLeft() uint { return c.bitsSz - c.loadedSz } From 1d8937b93012e9376f63b174ae65b325972d5927 Mon Sep 17 00:00:00 2001 From: Oleg Baranov Date: Fri, 12 Jan 2024 21:57:48 +0400 Subject: [PATCH 2/3] Updated SubscribeOnTransactions test --- ton/integration_test.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/ton/integration_test.go b/ton/integration_test.go index f65d6c33..d3de034a 100644 --- a/ton/integration_test.go +++ b/ton/integration_test.go @@ -659,7 +659,7 @@ func TestAPIClient_SubscribeOnTransactions(t *testing.T) { defer cancel() ctx := api.Client().StickyContext(_ctx) - addr := address.MustParseAddr("EQCD39VS5jcptHL8vMjEXrzGaRcCVYto7HUn4bpAOg8xqB2N") + addr := address.MustParseAddr("Ef8zMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzM0vF") b, err := api.CurrentMasterchainInfo(ctx) if err != nil { @@ -672,7 +672,7 @@ func TestAPIClient_SubscribeOnTransactions(t *testing.T) { t.Fatal("get acc err:", err.Error()) return } - initLT := acc.LastTxLT - 600000000000 + initLT := acc.LastTxLT - 10 log.Println(initLT) lastLT := initLT @@ -682,16 +682,19 @@ func TestAPIClient_SubscribeOnTransactions(t *testing.T) { ch := make(chan *tlb.Transaction) go api.SubscribeOnTransactions(ctx, addr, lastLT, ch) + gotTx := false for tx := range ch { if lastLT > tx.LT { t.Fatal("incorrect tx order") } lastLT = tx.LT + gotTx = true println(tx.Now, tx.String()) + cancel() } - if lastLT == initLT { + if !gotTx { t.Fatal("no transactions") } } From 0b49db0e0df5502ae9abc84e39387502d88f522b Mon Sep 17 00:00:00 2001 From: Coverage Date: Fri, 12 Jan 2024 19:24:26 +0000 Subject: [PATCH 3/3] Updated coverage badge --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 71bbdab3..9ff96c5d 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ [![Based on TON][ton-svg]][ton] -![Coverage](https://img.shields.io/badge/Coverage-73.4%25-brightgreen) +![Coverage](https://img.shields.io/badge/Coverage-73.3%25-brightgreen) Golang library for interacting with TON blockchain.