Skip to content

Commit

Permalink
update sdk to v0.2.8 (#126)
Browse files Browse the repository at this point in the history
  • Loading branch information
AstaFrode authored Jul 4, 2023
1 parent a0352e2 commit d519bcb
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 84 deletions.
17 changes: 1 addition & 16 deletions configs/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,7 @@ const (
DefaultRpcAddr1 = "wss://testnet-rpc0.cess.cloud/ws/"
DefaultRpcAddr2 = "wss://testnet-rpc1.cess.cloud/ws/"
//
DefaultBootNodeAddr = "_dnsaddr.bootstrap-kldr.cess.cloud"
)

const (
HELP_common = `Please check with the following help information:
1.Check if the wallet balance is sufficient
2.Block hash:`
HELP_register = ` 3.Check the Sminer_Registered transaction event result in the block hash above:
If system.ExtrinsicFailed is prompted, it means failure;
If system.ExtrinsicSuccess is prompted, it means success;`
HELP_UpdateAddress = ` 3.Check the Sminer_UpdataIp transaction event result in the block hash above:
If system.ExtrinsicFailed is prompted, it means failure;
If system.ExtrinsicSuccess is prompted, it means success;`
HELP_UpdataBeneficiary = ` 3.Check the Sminer_UpdataBeneficiary transaction event result in the block hash above:
If system.ExtrinsicFailed is prompted, it means failure;
If system.ExtrinsicSuccess is prompted, it means success;`
DefaultBootNodeAddr = "_dnsaddr.boot-kldr-testnet.cess.cloud"
)

const (
Expand Down
2 changes: 1 addition & 1 deletion configs/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const (
// Name is the name of the program
Name = "bucket"
// version
Version = "v0.6.0 230621 dev"
Version = "v0.6.0"
// Description is the description of the program
Description = "Storage node implementation in CESS networks"
// NameSpace is the cached namespace
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ module github.com/CESSProject/cess-bucket
go 1.19

require (
github.com/CESSProject/cess-go-sdk v0.2.7
github.com/CESSProject/p2p-go v0.0.35
github.com/CESSProject/cess-go-sdk v0.2.8
github.com/CESSProject/p2p-go v0.0.36
github.com/btcsuite/btcutil v1.0.3-0.20201208143702-a53e38424cce
github.com/bytedance/sonic v1.9.2
github.com/centrifuge/go-substrate-rpc-client/v4 v4.0.13
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ git.apache.org/thrift.git v0.0.0-20180902110319-2566ecd5d999/go.mod h1:fPE2ZNJGy
github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/CESSProject/cess-go-sdk v0.2.7 h1:dsn2wC3Lx3MGmCgR7umogcc0ky0axrUb0vCAJFTEArc=
github.com/CESSProject/cess-go-sdk v0.2.7/go.mod h1:8EI7Zs5bFWOfekOAKlh0Uiu/uAvylRAWdHP+pRyE3F4=
github.com/CESSProject/p2p-go v0.0.35 h1:hrCfmO4DGaMrbCzA9urqITb+zrym41SEokUUXSx+jq4=
github.com/CESSProject/p2p-go v0.0.35/go.mod h1:MmuZ2UfXnEJMZMhOCC4Ec5QQUJCT7j2yg3Xk/oZ16yw=
github.com/CESSProject/cess-go-sdk v0.2.8 h1:Uw60WYYWEbPW54VA9qNbm2w0zevqew+gHxvAcbY5JXM=
github.com/CESSProject/cess-go-sdk v0.2.8/go.mod h1:Mh6/k9aT4r58WHpmsY2Nw1QEzYLAhgC9XN2eptiTi+E=
github.com/CESSProject/p2p-go v0.0.36 h1:FyXwuE6nrfgsb32BdTgQdZeSUqLjI/KHchOTIFiLn8c=
github.com/CESSProject/p2p-go v0.0.36/go.mod h1:MmuZ2UfXnEJMZMhOCC4Ec5QQUJCT7j2yg3Xk/oZ16yw=
github.com/ChainSafe/go-schnorrkel v1.0.0 h1:3aDA67lAykLaG1y3AOjs88dMxC88PgUuHRrLeDnvGIM=
github.com/ChainSafe/go-schnorrkel v1.0.0/go.mod h1:dpzHYVxLZcp8pjlV+O+UR8K0Hp/z7vcchBSbMBEhCw4=
github.com/aead/siphash v1.0.1/go.mod h1:Nywa3cDsYNNK3gaciGTWPwHt0wlpNV15vwmswBAUSII=
Expand Down
66 changes: 12 additions & 54 deletions node/chainMgt.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,39 +29,14 @@ func (n *Node) chainMgt(ch chan bool) {
var err error
var maAddr ma.Multiaddr
var addrInfo *peer.AddrInfo
var bootstrap []string
// var lastMem uint64

tickListening := time.NewTicker(time.Minute)
defer tickListening.Stop()

// memSt := &runtime.MemStats{}
// tikProgram := time.NewTicker(pattern.BlockInterval)
// defer tikProgram.Stop()

n.Log("info", ">>>>> Start chainMgt")
n.Log("info", ">>>>> start chainMgt <<<<<")

boots := n.GetBootNodes()
for _, b := range boots {
temp, err := sutils.ParseMultiaddrs(b)
if err != nil {
n.Log("err", fmt.Sprintf("[ParseMultiaddrs %v] %v", b, err))
continue
}
bootstrap = append(bootstrap, temp...)
}
n.Log("info", fmt.Sprintf("bootnode list: %s", bootstrap))
for {
select {
// case <-tikProgram.C:
// runtime.ReadMemStats(memSt)
// if memSt.HeapSys >= pattern.SIZE_1GiB*2 {
// if memSt.HeapAlloc != lastMem {
// n.Log("err", fmt.Sprintf("memory usage: %d bytes", memSt.HeapAlloc))
// }
// //os.Exit(1)
// }
// lastMem = memSt.HeapAlloc

case <-tickListening.C:
if !n.GetChainState() {
err = n.Reconnect()
Expand All @@ -75,6 +50,16 @@ func (n *Node) chainMgt(ch chan bool) {
}
}

boots := n.GetBootNodes()
var bootstrap []string
for _, b := range boots {
temp, err := sutils.ParseMultiaddrs(b)
if err != nil {
n.Log("err", fmt.Sprintf("[ParseMultiaddrs %v] %v", b, err))
continue
}
bootstrap = append(bootstrap, temp...)
}
for _, v := range bootstrap {
maAddr, err = ma.NewMultiaddr(v)
if err != nil {
Expand All @@ -88,35 +73,8 @@ func (n *Node) chainMgt(ch chan bool) {
if err != nil {
continue
}
//n.Log("info", fmt.Sprintf("connect to bootnode: %s", addrInfo.ID.Pretty()))
n.SavePeer(addrInfo.ID.Pretty(), *addrInfo)
}
// if !n.P2P.GetDiscoverSt() {
// n.Log("info", fmt.Sprintf("restart discover service"))
// n.P2P.StartDiscover()
// }
// case discoverPeer := <-n.DiscoveredPeer():
// peerid = discoverPeer.ID.Pretty()
// n.Log("info", fmt.Sprintf("discovered: %s", peerid))
// err = n.Connect(n.GetRootCtx(), discoverPeer)
// if err != nil {
// continue
// }
// n.SavePeer(peerid)
// n.Log("info", fmt.Sprintf("connect to %s", peerid))
// for _, v := range discoverPeer.Addrs {
// boots = strings.Split(v.String(), "/")
// for _, vv := range boots {
// if sutils.IsIPv4(vv) {
// if vv[len(vv)-1] == byte(49) && vv[len(vv)-3] == byte(48) {
// break
// }
// n.AddMultiaddrToPeerstore(fmt.Sprintf("%s/p2p/%s", v.String(), peerid), time.Hour)
// break
// }
// }
// }
//}
}
}
}
7 changes: 0 additions & 7 deletions node/discover.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,14 @@ func (n *Node) discoverMgt(ch chan bool) {
}
}()

// var err error
var peerid string

n.Discover(">>>>> Start discoverMgt <<<<<")
for {
select {
case discoverPeer := <-n.DiscoveredPeer():
peerid = discoverPeer.ID.Pretty()
n.Discover(fmt.Sprintf("discovered: %s", peerid))
// err = n.P2P.Connect(n.P2P.GetRootCtx(), discoverPeer)
// if err != nil {
// continue
// }
n.SavePeer(peerid, discoverPeer)
// n.Discover(fmt.Sprintf("connect to %s", peerid))
}
}
}
30 changes: 30 additions & 0 deletions pkg/utils/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ import (
"runtime/debug"
"time"

"github.com/pkg/errors"
"github.com/shirou/gopsutil/disk"
"github.com/shirou/gopsutil/mem"
)

type MountPathInfo struct {
Expand Down Expand Up @@ -159,3 +161,31 @@ func RecoverError(err interface{}) string {
fmt.Fprintf(buf, "%v\n", string(debug.Stack()))
return buf.String()
}

func GetSysMemAvailable() (uint64, error) {
var result uint64
memInfo, err := mem.VirtualMemory()
if err != nil {
return 0, errors.Wrapf(err, "[mem.VirtualMemory]")
}
result = memInfo.Available
swapInfo, err := mem.SwapMemory()
if err != nil {
return result, nil
}
return result + swapInfo.Free, nil
}

func GetSysMemTotle() (uint64, error) {
var result uint64
memInfo, err := mem.VirtualMemory()
if err != nil {
return 0, errors.Wrapf(err, "[mem.VirtualMemory]")
}
result = memInfo.Total
swapInfo, err := mem.SwapMemory()
if err != nil {
return result, nil
}
return result + swapInfo.Free, nil
}

0 comments on commit d519bcb

Please sign in to comment.