Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v1.8 RC #129

Merged
merged 44 commits into from
Aug 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
3ba2099
Init lite client from config file
May 21, 2023
1cc5332
Moved storage impl to dff repo & hash levels lazy recalc
xssnick May 29, 2023
b7bd1ee
ADNL Query packet retry experiment
xssnick May 30, 2023
1737504
tlb: add ShardDescB and FutureSplitMerge
iam047801 May 31, 2023
5f06004
ton api client: GetBlockShardsInfo update with ShardDescB
iam047801 May 31, 2023
d814168
Merge pull request #119 from iam047801/parse-old-block-data
xssnick May 31, 2023
78435f8
tlb.ShardStateUnsplit: McStateExtra as a cell
iam047801 May 31, 2023
c11f7ed
tlb.Block: StateUpdate as a cell
iam047801 May 31, 2023
6ffdf20
Merge pull request #120 from iam047801/parse-old-block-data-degrate-t…
xssnick May 31, 2023
9610883
tlb.AccountStorage: add ExtraCurrencies dict
iam047801 Jun 2, 2023
7236a8d
Merge pull request #121 from iam047801/account_storage_extra_currencies
xssnick Jun 2, 2023
a86793d
ADNL improvements
xssnick Jun 3, 2023
e14073a
Async close adnl
xssnick Jun 3, 2023
15afb88
ADNL confirm seqno reset on reinit
xssnick Jun 5, 2023
bef2d77
Added GetID for gateway
xssnick Jun 5, 2023
0067733
DHT wait for add node during find value
xssnick Jun 6, 2023
ae5a454
DHT node conn wait only for not tried
xssnick Jun 6, 2023
665842d
DHT new find value
xssnick Jun 6, 2023
bd68ec8
Experimental aggressive DHT
xssnick Jun 7, 2023
d8a7351
DHT Tunning
xssnick Jun 10, 2023
a4289c5
Added addr to adnl rldp interface
xssnick Jun 10, 2023
7285515
DHT dbg, disabled pinger
xssnick Jun 11, 2023
6e2e242
Simplified DHT
xssnick Jun 11, 2023
bfa3f0f
Unsafe cell methods added
xssnick Jun 15, 2023
5549e79
Fixed rldp compilation
xssnick Jun 22, 2023
26698fc
Liteclient Stop method
xssnick Jun 29, 2023
78c7c33
Bump golang.org/x/sys from 0.0.0-20220325203850-36772127a21f to 0.1.0
dependabot[bot] Jun 30, 2023
a2226a9
Merge pull request #126 from xssnick/dependabot/go_modules/golang.org…
xssnick Jun 30, 2023
f8d8e82
Proofs check for liteserver responses & imporvements
xssnick Aug 1, 2023
ab218d0
Merge pull request #117 from zloylos/d/init-from-config-file
xssnick Aug 3, 2023
41e9d42
More wallet versions support for wallets + payment channels wip
xssnick Aug 4, 2023
6b93b44
Liteserver proof chains validation & TL+TLB+Cell enhancements & impro…
xssnick Aug 13, 2023
457547a
Change from deprecated NanoTON to Nano
xssnick Aug 14, 2023
e1fb352
Fixed GetWalletAddress test
xssnick Aug 14, 2023
fd7ba07
Fixed GetAsyncChannel on inactive address
xssnick Aug 14, 2023
2fbb5f7
Added liteclient retrier wrapper & tests
xssnick Aug 14, 2023
13af789
LS Wrapper improvements & dbg
xssnick Aug 14, 2023
e3f1732
Fixed wait for block in tx confirmation wait
xssnick Aug 14, 2023
c743a98
Added max attempts to retrier and fixed
xssnick Aug 15, 2023
9aa1c93
Fixed tests
xssnick Aug 15, 2023
7554a49
New deploy contract method
xssnick Aug 15, 2023
06f040e
Updated examples and DecryptCommentCell accept sender
xssnick Aug 16, 2023
7ebe4b7
Merge 06f040eddbc1d68afa1b39ffd4e69bfe7b3391e5 into d9f8c2c9ac26bd140…
xssnick Aug 16, 2023
4110def
Updated coverage badge
Aug 16, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<img align="right" width="425px" src="https://github.com/xssnick/props/blob/master/logoimg.png?raw=true">

[![Based on TON][ton-svg]][ton]
![Coverage](https://img.shields.io/badge/Coverage-72.3%25-brightgreen)
![Coverage](https://img.shields.io/badge/Coverage-73.4%25-brightgreen)

Golang library for interacting with TON blockchain.

Expand Down Expand Up @@ -63,7 +63,7 @@ You can also join our **[Telegram group](https://t.me/tonutils)** and ask any qu

### Connection
You can get list of public lite servers from official TON configs:
* Mainnet - `https://ton-blockchain.github.io/global.config.json`
* Mainnet - `https://ton.org/global.config.json`
* Testnet - `https://ton-blockchain.github.io/testnet-global.config.json`

from liteservers section, you need to convert int to ip and take port and key.
Expand Down Expand Up @@ -108,7 +108,7 @@ if err != nil {
panic(err)
}

if balance.NanoTON().Uint64() >= 3000000 {
if balance.Nano().Uint64() >= 3000000 {
addr := address.MustParseAddr("EQCD39VS5jcptHL8vMjEXrzGaRcCVYto7HUn4bpAOg8xqB2N")
err = w.Transfer(context.Background(), addr, tlb.MustFromTON("0.003"), "Hey bro, happy birthday!")
if err != nil {
Expand Down Expand Up @@ -203,7 +203,7 @@ if err != nil {
// Balance: ACTIVE
fmt.Printf("Status: %s\n", account.State.Status)
// Balance: 66559946.09 TON
fmt.Printf("Balance: %s TON\n", account.State.Balance.TON())
fmt.Printf("Balance: %s TON\n", account.State.Balance.String())
if account.Data != nil { // Can be nil if account is not active
// Data: [0000003829a9a31772c9ed6b62a6e2eba14a93b90462e7a367777beb8a38fb15b9f33844d22ce2ff]
fmt.Printf("Data: %s\n", account.Data.Dump())
Expand Down Expand Up @@ -478,9 +478,10 @@ client.SetOnDisconnect(func(addr, serverKey string) {
* ✅ Overlays
* ✅ TL Parser/Serializer
* ✅ TL-B Parser/Serializer
* ✅ Payment channels
* ✅ Liteserver proofs automatic validation
* DHT Server
* Payment channels
* Merkle proofs automatic validation
* TVM

<!-- Badges -->
[ton-svg]: https://img.shields.io/badge/Based%20on-TON-blue
Expand Down
2 changes: 2 additions & 0 deletions address/addr.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ const (
VarAddress AddrType = 3
)

const MasterchainID int32 = -1

type Address struct {
flags flags
addrType AddrType
Expand Down
53 changes: 32 additions & 21 deletions adnl/adnl.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ func initADNL(key ed25519.PrivateKey) *ADNL {
}

func (a *ADNL) Close() {
a.mx.Lock()
defer a.mx.Unlock()
trigger := false

a.mx.Lock()
if !a.closed {
a.closed = true

Expand All @@ -111,10 +111,13 @@ func (a *ADNL) Close() {
con.Close()
}

if a.onDisconnect != nil {
// do it async to not get accidental deadlock
go a.onDisconnect(a.addr, a.peerKey)
}
trigger = true
}
a.mx.Unlock()

disc := a.onDisconnect
if trigger && disc != nil {
disc(a.addr, a.peerKey)
}
}

Expand Down Expand Up @@ -159,6 +162,11 @@ func (a *ADNL) processPacket(packet *PacketContent, ch *Channel) (err error) {
}

if packet.ReinitDate != nil && *packet.ReinitDate > a.dstReinit {
// reset their seqno even if it is lower,
// because other side could lose counter
a.confirmSeqno = seqno
a.loss = 0

// a.dstReinit = *packet.ReinitDate
// a.seqno = 0
// a.channel = nil
Expand Down Expand Up @@ -361,7 +369,7 @@ func (a *ADNL) processAnswer(id string, query any) {
res <- query
}
} else {
Logger("unknown response with id", id, a.addr, reflect.TypeOf(query).String())
// Logger("unknown response with id", id, a.addr, reflect.TypeOf(query).String())
}
}

Expand Down Expand Up @@ -397,23 +405,26 @@ func (a *ADNL) query(ctx context.Context, ch *Channel, req, result tl.Serializab
a.activeQueries[reqID] = res
a.mx.Unlock()

if err = a.sendRequestMaySplit(ctx, ch, q); err != nil {
a.mx.Lock()
delete(a.activeQueries, reqID)
a.mx.Unlock()
for {
if err = a.sendRequestMaySplit(ctx, ch, q); err != nil {
a.mx.Lock()
delete(a.activeQueries, reqID)
a.mx.Unlock()

return fmt.Errorf("request failed: %w", err)
}
return fmt.Errorf("request failed: %w", err)
}

select {
case resp := <-res:
if err, ok := resp.(error); ok {
return err
select {
case resp := <-res:
if err, ok := resp.(error); ok {
return err
}
reflect.ValueOf(result).Elem().Set(reflect.ValueOf(resp))
return nil
case <-ctx.Done():
return fmt.Errorf("deadline exceeded, addr %s %s, err: %w", a.addr, hex.EncodeToString(a.peerKey), ctx.Err())
case <-time.After(250 * time.Millisecond):
}
reflect.ValueOf(result).Elem().Set(reflect.ValueOf(resp))
return nil
case <-ctx.Done():
return fmt.Errorf("deadline exceeded, addr %s %s, err: %w", a.addr, hex.EncodeToString(a.peerKey), ctx.Err())
}
}

Expand Down
99 changes: 94 additions & 5 deletions adnl/adnl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func TestADNL_ClientServer(t *testing.T) {
gotSrvDiscon := make(chan any, 1)

s := NewGateway(srvKey)
err = s.StartServer("127.0.0.1:9055")
err = s.StartServer("127.0.0.1:9155")
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -66,7 +66,7 @@ func TestADNL_ClientServer(t *testing.T) {

time.Sleep(1 * time.Second)

cli, err := Connect(context.Background(), "127.0.0.1:9055", srvPub, nil)
cli, err := Connect(context.Background(), "127.0.0.1:9155", srvPub, nil)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -109,7 +109,7 @@ func TestADNL_ClientServer(t *testing.T) {
t.Fatal(err)
}

cliBad, err := Connect(context.Background(), "127.0.0.1:9055", rndPub, nil)
cliBad, err := Connect(context.Background(), "127.0.0.1:9155", rndPub, nil)
if err != nil {
t.Fatal(err)
}
Expand All @@ -130,7 +130,7 @@ func TestADNL_ClientServer(t *testing.T) {
t.Fatal(err)
}

cliBadQuery, err := Connect(context.Background(), "127.0.0.1:9055", srvPub, rndOur)
cliBadQuery, err := Connect(context.Background(), "127.0.0.1:9155", srvPub, rndOur)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -173,7 +173,7 @@ func TestADNL_ClientServer(t *testing.T) {
})

t.Run("custom msg channel reinited", func(t *testing.T) {
cli, err = Connect(context.Background(), "127.0.0.1:9055", srvPub, nil)
cli, err = Connect(context.Background(), "127.0.0.1:9155", srvPub, nil)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -236,3 +236,92 @@ func TestADNL_Connect(t *testing.T) {
}
adnl.Close()
}

func TestADNL_ClientServerStartStop(t *testing.T) {
_, aPriv, err := ed25519.GenerateKey(nil)
if err != nil {
t.Fatal(err)
}

bPub, bPriv, err := ed25519.GenerateKey(nil)
if err != nil {
t.Fatal(err)
}

a := NewGateway(aPriv)
err = a.StartServer("127.0.0.1:9055")
if err != nil {
t.Fatal(err)
}
a.SetConnectionHandler(connHandler)

b := NewGateway(bPriv)
err = b.StartServer("127.0.0.1:9065")
if err != nil {
t.Fatal(err)
}
b.SetConnectionHandler(connHandler)

p, err := a.RegisterClient("127.0.0.1:9065", bPub)
if err != nil {
t.Fatal(err)
}

ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()

var res MessagePong
err = p.Query(ctx, &MessagePing{7755}, &res)
if err != nil {
t.Fatal(err)
}

if res.Value != 7755 {
t.Fatal("value not eq")
}

_ = b.Close()
b = NewGateway(bPriv)
err = b.StartServer("127.0.0.1:9065")
if err != nil {
t.Fatal(err)
}
b.SetConnectionHandler(connHandler)

p.Close()
p, err = a.RegisterClient("127.0.0.1:9065", bPub)
if err != nil {
t.Fatal(err)
}

err = p.Query(ctx, &MessagePing{1111}, &res)
if err != nil {
t.Fatal(err)
}
}

func connHandler(client Peer) error {
client.SetQueryHandler(func(msg *MessageQuery) error {
switch m := msg.Data.(type) {
case MessagePing:
if m.Value == 9999 {
client.Close()
return fmt.Errorf("handle mock err")
}

err := client.Answer(context.Background(), msg.ID, MessagePong{
Value: m.Value,
})
if err != nil {
panic(err)
}
}
return nil
})
client.SetCustomMessageHandler(func(msg *MessageCustom) error {
return client.SendCustomMessage(context.Background(), TestMsg{Data: make([]byte, 1280)})
})
client.SetDisconnectHandler(func(addr string, key ed25519.PublicKey) {
})
return nil
}
16 changes: 2 additions & 14 deletions adnl/crypto.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import (
"crypto/aes"
"crypto/cipher"
"crypto/ed25519"
"crypto/sha256"
"fmt"
"github.com/oasisprotocol/curve25519-voi/curve"
ed25519crv "github.com/oasisprotocol/curve25519-voi/primitives/ed25519"
"github.com/oasisprotocol/curve25519-voi/primitives/x25519"
Expand Down Expand Up @@ -65,15 +63,5 @@ func NewCipherCtr(key, iv []byte) (cipher.Stream, error) {
return cipher.NewCTR(c, iv), nil
}

func ToKeyID(key any) ([]byte, error) {
data, err := tl.Serialize(key, true)
if err != nil {
return nil, fmt.Errorf("key serialize err: %w", err)
}

hash := sha256.New()
hash.Write(data)
s := hash.Sum(nil)

return s, nil
}
// Deprecated: use tl.Hash
var ToKeyID = tl.Hash
Loading