diff --git a/README.md b/README.md index 9ff96c5d..71bbdab3 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.3%25-brightgreen) +![Coverage](https://img.shields.io/badge/Coverage-73.4%25-brightgreen) Golang library for interacting with TON blockchain. diff --git a/adnl/rldp/http/client_test.go b/adnl/rldp/http/client_test.go index 24f4af93..9dd5e40f 100644 --- a/adnl/rldp/http/client_test.go +++ b/adnl/rldp/http/client_test.go @@ -440,7 +440,7 @@ func getDNSResolver() *dns.Client { } // initialize ton api lite connection wrapper - api := ton.NewAPIClient(client) + api := ton.NewAPIClient(client).WithRetry() // get root dns address from network config root, err := dns.RootContractAddr(api) diff --git a/liteclient/pool.go b/liteclient/pool.go index 5d4a0f7f..9cce370a 100644 --- a/liteclient/pool.go +++ b/liteclient/pool.go @@ -247,6 +247,11 @@ func (c *ConnectionPool) queryWithBalancer(req *ADNLRequest) (string, error) { return "", ErrNoActiveConnections } + if reqNode == nil { + // no active nodes in list + return "", ErrNoActiveConnections + } + host, err := reqNode.queryAdnl(req.QueryID, req.Data) if err != nil { if !errors.Is(err, NetworkErr{}) { diff --git a/tvm/cell/cell_test.go b/tvm/cell/cell_test.go index bd77b499..4a8448f7 100644 --- a/tvm/cell/cell_test.go +++ b/tvm/cell/cell_test.go @@ -212,6 +212,10 @@ func TestBOCBomb(t *testing.T) { if !bytes.Equal(c.Hash(), hash) { t.Fatal("incorrect hash", hex.EncodeToString(c.Hash()), hex.EncodeToString(hash)) } + + if len(c.ToBOCWithFlags(false)) != len(boc) { + t.Fatal("len", len(c.ToBOC()), len(boc)) + } } func TestCell_TxWithMerkleBody(t *testing.T) { diff --git a/tvm/cell/flattenIndex.go b/tvm/cell/flattenIndex.go index 9e4ae929..6f3abf27 100644 --- a/tvm/cell/flattenIndex.go +++ b/tvm/cell/flattenIndex.go @@ -16,13 +16,18 @@ func flattenIndex(cells []*Cell) ([]*idxItem, map[string]*idxItem) { for len(cells) > 0 { next := make([]*Cell, 0, len(cells)*4) for _, p := range cells { + hash := string(p.Hash()) + + if _, ok := index[hash]; ok { + continue + } + // move cell forward in boc, because behind reference is not allowed - index[string(p.Hash())] = &idxItem{ - index: idx, + index[hash] = &idxItem{ cell: p, + index: idx, } idx++ - next = append(next, p.refs...) } cells = next @@ -33,6 +38,26 @@ func flattenIndex(cells []*Cell) ([]*idxItem, map[string]*idxItem) { idxSlice = append(idxSlice, id) } + for verifyOrder := true; verifyOrder; { + verifyOrder = false + + for _, id := range idxSlice { + for _, ref := range id.cell.refs { + idRef := index[string(ref.Hash())] + + if idRef.index < id.index { + // if we found that ref index is behind parent, + // move ref index forward + idRef.index = idx + idx++ + + // we changed index, so we need to verify order again + verifyOrder = true + } + } + } + } + sort.Slice(idxSlice, func(i, j int) bool { return idxSlice[i].index < idxSlice[j].index })