From 56a6db9e4e25f70ca84e51135876af3070a792fa Mon Sep 17 00:00:00 2001 From: klim0v Date: Fri, 25 Sep 2020 15:20:39 +0300 Subject: [PATCH 1/7] CHANGELOG.md --- CHANGELOG.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 81fecd723..23d768990 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,9 +8,12 @@ - [core] Added RecreateCoin tx - [core] Added ChangeCoinOwner tx - [core] Limit validators slots to 64 -- [core] Add EditMultisigOwnersData tx +- [core] Add EditMultisigData tx - [core] Add PriceVoteData tx - [core] Stake value calculation changes +- [console] Added PruneBlocks command +- [api] Marked as deprecated version of API v1 +- [api] Added Swagger UI for API v2 ## 1.1.8 From 0bc8c28673346df6d253df5fcac259335bd579f6 Mon Sep 17 00:00:00 2001 From: klim0v Date: Fri, 25 Sep 2020 15:26:08 +0300 Subject: [PATCH 2/7] fix tests --- core/state/frozenfunds/frozen_funds_test.go | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/core/state/frozenfunds/frozen_funds_test.go b/core/state/frozenfunds/frozen_funds_test.go index 5442fe58c..b5941e3bb 100644 --- a/core/state/frozenfunds/frozen_funds_test.go +++ b/core/state/frozenfunds/frozen_funds_test.go @@ -12,7 +12,11 @@ import ( ) func TestFrozenFundsToAddModel(t *testing.T) { - b, mutableTree := bus.NewBus(), tree.NewMutableTree(0, db.NewMemDB(), 1024) + mutableTree, err := tree.NewMutableTree(0, db.NewMemDB(), 1024) + if err != nil { + t.Fatal(err) + } + b := bus.NewBus() ff, err := NewFrozenFunds(b, mutableTree) if err != nil { t.Fatal(err) @@ -58,7 +62,11 @@ func TestFrozenFundsToAddModel(t *testing.T) { } func TestFrozenFundsToDeleteModel(t *testing.T) { - b, mutableTree := bus.NewBus(), tree.NewMutableTree(0, db.NewMemDB(), 1024) + mutableTree, err := tree.NewMutableTree(0, db.NewMemDB(), 1024) + if err != nil { + t.Fatal(err) + } + b := bus.NewBus() ff, err := NewFrozenFunds(b, mutableTree) if err != nil { t.Fatal(err) @@ -105,7 +113,11 @@ func TestFrozenFundsToDeleteModel(t *testing.T) { } func TestFrozenFundsToDeleteNotExistenFund(t *testing.T) { - b, mutableTree := bus.NewBus(), tree.NewMutableTree(0, db.NewMemDB(), 1024) + mutableTree, err := tree.NewMutableTree(0, db.NewMemDB(), 1024) + if err != nil { + t.Fatal(err) + } + b := bus.NewBus() ff, err := NewFrozenFunds(b, mutableTree) if err != nil { t.Fatal(err) From 4198e4159dfd1eb7a9bc90d14fe0eb1abafbca29 Mon Sep 17 00:00:00 2001 From: klim0v Date: Fri, 25 Sep 2020 16:03:38 +0300 Subject: [PATCH 3/7] tests --- core/minter/minter_test.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/core/minter/minter_test.go b/core/minter/minter_test.go index 286a420c9..7259ad03e 100644 --- a/core/minter/minter_test.go +++ b/core/minter/minter_test.go @@ -149,7 +149,7 @@ func initTestNode(t *testing.T) (*Blockchain, *rpc.Local, *privval.FilePV) { utils.MinterHome = t.TempDir() if err := tmos.EnsureDir(utils.GetMinterHome()+"/tmdata/blockstore.db", 0777); err != nil { - panic(err.Error()) + t.Fatal(err) } minterCfg := config.GetConfig() @@ -175,7 +175,7 @@ func initTestNode(t *testing.T) (*Blockchain, *rpc.Local, *privval.FilePV) { app := NewMinterBlockchain(minterCfg) nodeKey, err := p2p.LoadOrGenNodeKey(cfg.NodeKeyFile()) if err != nil { - panic(err) + t.Fatal(err) } node, err := tmNode.NewNode( @@ -190,11 +190,11 @@ func initTestNode(t *testing.T) (*Blockchain, *rpc.Local, *privval.FilePV) { ) if err != nil { - panic(fmt.Sprintf("Failed to create a node: %v", err)) + t.Fatal(fmt.Sprintf("Failed to create a node: %v", err)) } if err = node.Start(); err != nil { - panic(fmt.Sprintf("Failed to start node: %v", err)) + t.Fatal(fmt.Sprintf("Failed to start node: %v", err)) } logger.Info("Started node", "nodeInfo", node.Switch().NodeInfo()) From bba6acc5e7304b347df33e84a6655076cc5103cb Mon Sep 17 00:00:00 2001 From: klim0v Date: Fri, 25 Sep 2020 22:05:40 +0300 Subject: [PATCH 4/7] fix candidate not found --- core/state/waitlist/waitlist.go | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/core/state/waitlist/waitlist.go b/core/state/waitlist/waitlist.go index e5fd5f264..2b4f4ec06 100644 --- a/core/state/waitlist/waitlist.go +++ b/core/state/waitlist/waitlist.go @@ -103,7 +103,7 @@ func (wl *WaitList) Get(address types.Address, pubkey types.Pubkey, coin types.C candidate := wl.bus.Candidates().GetCandidate(pubkey) if candidate == nil { - log.Panicf("Candidate not found: %s", pubkey.String()) + return nil } for _, item := range waitlist.List { @@ -123,20 +123,16 @@ func (wl *WaitList) GetByAddressAndPubKey(address types.Address, pubkey types.Pu candidate := wl.bus.Candidates().GetCandidate(pubkey) if candidate == nil { - log.Panicf("Candidate not found: %s", pubkey.String()) + return nil } - items := make([]Item, len(waitlist.List)) - for i, item := range waitlist.List { + var items []Item + for _, item := range waitlist.List { if item.CandidateId == candidate.ID { - items[i] = item + items = append(items, item) } } - if len(items) == 0 { - return nil - } - return items } From 3fe504ac801fa12b8da04904df302957c1998911 Mon Sep 17 00:00:00 2001 From: klim0v Date: Fri, 25 Sep 2020 22:35:45 +0300 Subject: [PATCH 5/7] fix mutex --- api/v2/service/address.go | 6 +++--- api/v2/service/addresses.go | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/api/v2/service/address.go b/api/v2/service/address.go index ba0baa510..851ca513c 100644 --- a/api/v2/service/address.go +++ b/api/v2/service/address.go @@ -36,9 +36,6 @@ func (s *Service) Address(ctx context.Context, req *pb.AddressRequest) (*pb.Addr return new(pb.AddressResponse), status.Error(codes.NotFound, err.Error()) } - cState.RLock() - defer cState.RUnlock() - if req.Height != 0 && req.Delegated { cState.Lock() cState.Candidates().LoadCandidates() @@ -46,6 +43,9 @@ func (s *Service) Address(ctx context.Context, req *pb.AddressRequest) (*pb.Addr cState.Unlock() } + cState.RLock() + defer cState.RUnlock() + balances := cState.Accounts().GetBalances(address) var res pb.AddressResponse diff --git a/api/v2/service/addresses.go b/api/v2/service/addresses.go index f5f55c1fe..a9572e3e1 100644 --- a/api/v2/service/addresses.go +++ b/api/v2/service/addresses.go @@ -18,9 +18,6 @@ func (s *Service) Addresses(ctx context.Context, req *pb.AddressesRequest) (*pb. return new(pb.AddressesResponse), status.Error(codes.NotFound, err.Error()) } - cState.RLock() - defer cState.RUnlock() - if req.Height != 0 && req.Delegated { cState.Lock() cState.Candidates().LoadCandidates() @@ -28,6 +25,9 @@ func (s *Service) Addresses(ctx context.Context, req *pb.AddressesRequest) (*pb. cState.Unlock() } + cState.RLock() + defer cState.RUnlock() + response := &pb.AddressesResponse{ Addresses: make(map[string]*pb.AddressesResponse_Result, len(req.Addresses)), } From 345d062b85658ec161970134049493641e2c437a Mon Sep 17 00:00:00 2001 From: klim0v Date: Sun, 27 Sep 2020 20:09:08 +0300 Subject: [PATCH 6/7] add load candidates for /waitlist --- api/v2/service/waitlist.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/api/v2/service/waitlist.go b/api/v2/service/waitlist.go index bbcf91dba..f7d807f5d 100644 --- a/api/v2/service/waitlist.go +++ b/api/v2/service/waitlist.go @@ -29,6 +29,12 @@ func (s *Service) WaitList(ctx context.Context, req *pb.WaitListRequest) (*pb.Wa return new(pb.WaitListResponse), status.Error(codes.NotFound, err.Error()) } + if req.Height != 0 { + cState.Lock() + cState.Candidates().LoadCandidates() + cState.Unlock() + } + cState.RLock() defer cState.RUnlock() From 2d3184cd85add90ec9fa8be88975a3b30bb58a2f Mon Sep 17 00:00:00 2001 From: klim0v Date: Sun, 27 Sep 2020 20:18:33 +0300 Subject: [PATCH 7/7] add network to status --- api/v2/service/status.go | 1 + go.mod | 2 +- go.sum | 4 ++-- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/api/v2/service/status.go b/api/v2/service/status.go index bab346c13..3b40b2777 100644 --- a/api/v2/service/status.go +++ b/api/v2/service/status.go @@ -23,6 +23,7 @@ func (s *Service) Status(context.Context, *empty.Empty) (*pb.StatusResponse, err return &pb.StatusResponse{ Version: s.version, + Network: result.NodeInfo.Network, LatestBlockHash: fmt.Sprintf("%X", result.SyncInfo.LatestBlockHash), LatestAppHash: fmt.Sprintf("%X", result.SyncInfo.LatestAppHash), LatestBlockHeight: uint64(result.SyncInfo.LatestBlockHeight), diff --git a/go.mod b/go.mod index c5565a6ea..aabdeb8fb 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/MinterTeam/minter-go-node go 1.15 require ( - github.com/MinterTeam/node-grpc-gateway v1.1.3-0.20200925002945-15b5cde8e354 + github.com/MinterTeam/node-grpc-gateway v1.1.3-0.20200927171657-f776ba10feca github.com/btcsuite/btcd v0.20.1-beta github.com/c-bata/go-prompt v0.2.3 github.com/go-kit/kit v0.10.0 diff --git a/go.sum b/go.sum index 7265811eb..225e0f58a 100644 --- a/go.sum +++ b/go.sum @@ -7,8 +7,8 @@ github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym github.com/ChainSafe/go-schnorrkel v0.0.0-20200405005733-88cbf1b4c40d h1:nalkkPQcITbvhmL4+C4cKA87NW0tfm3Kl9VXRoPywFg= github.com/ChainSafe/go-schnorrkel v0.0.0-20200405005733-88cbf1b4c40d/go.mod h1:URdX5+vg25ts3aCh8H5IFZybJYKWhJHYMTnf+ULtoC4= github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible/go.mod h1:r7JcOSlj0wfOMncg0iLm8Leh48TZaKVeNIfJntJ2wa0= -github.com/MinterTeam/node-grpc-gateway v1.1.3-0.20200925002945-15b5cde8e354 h1:HpjApkir3UtOL4WzGzkgQcdT9SyqwiZ/wbGrahzIlLQ= -github.com/MinterTeam/node-grpc-gateway v1.1.3-0.20200925002945-15b5cde8e354/go.mod h1:LZ+Y8IYfSBx0IQZY+a9pHLjztMwmlaCQX2ncTejoE2o= +github.com/MinterTeam/node-grpc-gateway v1.1.3-0.20200927171657-f776ba10feca h1:dnzof1I43yr3aI+TX+cNxnveDKmtoqt1RHNGR3JfsOM= +github.com/MinterTeam/node-grpc-gateway v1.1.3-0.20200927171657-f776ba10feca/go.mod h1:LZ+Y8IYfSBx0IQZY+a9pHLjztMwmlaCQX2ncTejoE2o= github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= github.com/Shopify/sarama v1.19.0/go.mod h1:FVkBWblsNy7DGZRfXLU0O9RCGt5g3g3yEuWXgklEdEo= github.com/Shopify/toxiproxy v2.1.4+incompatible/go.mod h1:OXgGpZ6Cli1/URJOF1DMxUHB2q5Ap20/P/eIdh4G0pI=